本文整理汇总了C++中Require函数的典型用法代码示例。如果您正苦于以下问题:C++ Require函数的具体用法?C++ Require怎么用?C++ Require使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Require函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckAvailableParameters
void CheckAvailableParameters(std::size_t parameters, std::size_t position)
{
if (!parameters)
{
return;
}
const std::size_t start = GroupStarts.empty() ? 0 : GroupStarts.top();
if (Groups.empty() || Groups.top().End < start)
{
Require(parameters + start <= position);
return;
}
const Group top = Groups.top();
const std::size_t nonGrouped = position - top.End;
if (nonGrouped < parameters)
{
if (nonGrouped)
{
CheckAvailableParameters(parameters - nonGrouped, top.End);
}
else
{
Require(top.Size() == 1);
Groups.pop();
CheckAvailableParameters(parameters - 1, top.Begin);
Groups.push(top);
}
}
}
示例2: ParsePositions
void ParsePositions(Builder& builder) const
{
std::vector<PositionEntry> positions;
uint_t loop = 0;
PositionEntry entry;
for (std::size_t posCursor = fromLE(Source.PositionsOffset); ; ++posCursor)
{
Require(positions.size() <= MAX_POSITIONS_COUNT);
const uint_t val = PeekByte(posCursor);
if (val == 0xff)
{
break;
}
else if (val == 0xfe)
{
loop = positions.size();
}
else if (val >= 0x60)
{
entry.Transposition = val - 0x60;
}
else
{
Require(0 == val % 3);
entry.PatternIndex = val / 3;
positions.push_back(entry);
}
}
Require(!positions.empty());
builder.SetPositions(positions, loop);
Dbg("Positions: %1% entries, loop to %2%", positions.size(), loop);
}
示例3: ParseSectors
void ParseSectors(SourceStream& stream, ImageVisitor& visitor)
{
for (;;)
{
const RawTrack& track = stream.Get<RawTrack>();
if (track.IsLast())
{
break;
}
Require(Math::InRange<uint_t>(track.Cylinder, 0, MAX_CYLINDERS_COUNT));
for (uint_t sect = 0; sect != track.Sectors; ++sect)
{
const RawSector& sector = stream.Get<RawSector>();
if (sector.NoData())
{
continue;
}
Require(Math::InRange<uint_t>(sector.Size, 0, 6));
const std::size_t sectorSize = std::size_t(128) << sector.Size;
const RawData& srcDataDesc = stream.Get<RawData>();
Require(Math::InRange<uint_t>(srcDataDesc.Method, RAW_SECTOR, RLE_SECTOR));
const std::size_t dataSize = fromLE(srcDataDesc.Size) - 1;
const uint8_t* const rawData = stream.GetData(dataSize);
//use track parameters for layout
if (!sector.NoId())
{
const Formats::CHS loc(sector.Cylinder, track.Head, sector.Number);
visitor.OnSector(loc, rawData, dataSize, static_cast<SectorDataType>(srcDataDesc.Method), sectorSize);
}
}
}
}
示例4: ParseSubchunks
static void ParseSubchunks(const Binary::Data& data, Builder& target)
{
try
{
Binary::TypedContainer typed(data);
for (std::size_t pos = 0; pos < typed.GetSize(); )
{
const SubChunkHeader* const hdr = typed.GetField<SubChunkHeader>(pos);
Require(hdr != nullptr);
if (hdr->ID == 0 && 0 != (pos % 4))
{
//in despite of official format description, subchunks can be not aligned by 4 byte boundary
++pos;
}
else
{
Dbg("ParseSubchunk id=%u, type=%u, size=%u", uint_t(hdr->ID), uint_t(hdr->Type), fromLE(hdr->DataSize));
pos += sizeof(*hdr) + hdr->GetDataSize();
Require(pos <= typed.GetSize());
ParseSubchunk(*hdr, target);
}
}
}
catch (const std::exception&)
{
//ignore
}
}
示例5: DecodeRLE
void DecodeRLE(const uint8_t* data, std::size_t size, Dump& result)
{
Dump tmp;
tmp.reserve(MAX_SECTOR_SIZE);
ByteStream stream(data, size);
while (!stream.Eof())
{
const uint_t len = 2 * stream.GetByte();
Require(!stream.Eof());
const uint_t count = stream.GetByte();
Require(count != 0);
const bool isRLE = len != 0;
const uint_t blockSize = isRLE ? len : count;
Require(stream.GetRestBytes() >= blockSize);
for (uint_t idx = 0; idx != blockSize; ++idx)
{
tmp.push_back(stream.GetByte());
}
if (isRLE)
{
Require(CopyFromBack(len, tmp, len * (count - 1)));
}
}
result.swap(tmp);
}
示例6: GroupEnd
void GroupEnd() override
{
Require(!GroupStarts.empty());
Require(GroupStarts.top() != Position);
Groups.push(Group(GroupStarts.top(), Position));
GroupStarts.pop();
Delegate.GroupEnd();
}
示例7: Parse
std::size_t Parse(const Binary::Container& rawData, ImageVisitor& visitor)
{
SourceStream stream(rawData);
try
{
const RawHeader& header = stream.Get<RawHeader>();
const uint_t id = fromLE(header.ID);
Require(id == ID_OLD || id == ID_NEW);
Require(header.Sequence == 0);
Require(Math::InRange<uint_t>(header.Sides, MIN_SIDES_COUNT, MAX_SIDES_COUNT));
if (header.HasComment())
{
const RawComment& comment = stream.Get<RawComment>();
if (const std::size_t size = fromLE(comment.Size))
{
stream.GetData(size);
}
}
const bool compressedData = id == ID_NEW;
const bool newCompression = header.Version > 20;
if (compressedData)
{
if (!newCompression)
{
Dbg("Old compression is not supported.");
return 0;
}
const std::size_t packedSize = rawData.Size() - sizeof(header);
const Binary::Container::Ptr packed = rawData.GetSubcontainer(sizeof(header), packedSize);
if (const Formats::Packed::Container::Ptr fullDecoded =
Formats::Packed::Lha::DecodeRawDataAtLeast(*packed, COMPRESSION_ALGORITHM, MAX_IMAGE_SIZE))
{
SourceStream subStream(*fullDecoded);
ParseSectors(subStream, visitor);
const std::size_t usedInPacked = subStream.GetOffset();
Dbg("Used %1% bytes in packed stream", usedInPacked);
if (const Formats::Packed::Container::Ptr decoded =
Formats::Packed::Lha::DecodeRawDataAtLeast(*packed, COMPRESSION_ALGORITHM, usedInPacked))
{
const std::size_t usedSize = decoded->PackedSize();
return sizeof(header) + usedSize;
}
}
Dbg("Failed to decode lha stream");
return 0;
}
else
{
ParseSectors(stream, visitor);
}
return stream.GetOffset();
}
catch (const std::exception&)
{
return 0;
}
}
示例8: GetData
const uint8_t* GetData(std::size_t size)
{
Require(size != 0);
const uint8_t* const first = Data.GetField<uint8_t>(Offset);
const uint8_t* const last = Data.GetField<uint8_t>(Offset + size - 1);
Require(first != nullptr && last != nullptr);
Offset += size;
return first;
}
示例9: ParseBuffer
void ParseBuffer(uint_t count, Stream& source, Builder& target)
{
const std::size_t bufSize = source.GetBufferSize();
Dump buf(bufSize);
std::size_t cursor = 0;
uint_t flag = 0x40;
//dX_flag
while (count)
{
//dX_next
flag <<= 1;
if ((flag & 0xff) == 0)
{
flag = source.ReadByte();
flag = (flag << 1) | 1;
}
if ((flag & 0x100) != 0)
{
flag &= 0xff;
uint_t counter = source.ReadCounter();
std::size_t srcPtr = source.ReadBackRef();
Require(count >= counter);
Require(srcPtr < bufSize);
count -= counter;
while (counter--)
{
buf[cursor++] = buf[srcPtr++];
if (cursor >= bufSize)
{
target.AddValues(buf);
cursor -= bufSize;
}
if (srcPtr >= bufSize)
{
srcPtr -= bufSize;
}
}
}
else
{
//dX_chr
--count;
buf[cursor++] = source.ReadByte();
if (cursor >= bufSize)
{
target.AddValues(buf);
cursor -= bufSize;
}
}
}
if (cursor)
{
buf.resize(cursor);
target.AddValues(buf);
}
}
示例10: ParseDecimalValue
inline uint_t ParseDecimalValue(const std::string& num)
{
Require(!num.empty());
uint_t res = 0;
for (RangeIterator<std::string::const_iterator> it(num.begin(), num.end()); it; ++it)
{
Require(0 != std::isdigit(*it));
res = res * 10 + (*it - '0');
}
return res;
}
示例11: OnSector
void OnSector(const Formats::CHS& /*loc*/, const uint8_t* /*rawData*/, std::size_t rawSize, SectorDataType type, std::size_t targetSize) override
{
switch (type)
{
case RAW_SECTOR:
Require(rawSize == targetSize);
break;
case R2P_SECTOR:
Require(rawSize % sizeof(R2PEntry) == 0);
break;
default:
break;
}
}
示例12: DecodeR2P
void DecodeR2P(const uint8_t* data, std::size_t size, Dump& result)
{
Require(size % sizeof(R2PEntry) == 0);
Dump tmp;
tmp.reserve(MAX_SECTOR_SIZE);
for (const R2PEntry* it = safe_ptr_cast<const R2PEntry*>(data), *lim = it + size / sizeof(*it); it != lim; ++it)
{
const uint_t count = fromLE(it->Count);
Require(count != 0);
tmp.push_back(it->Data[0]);
tmp.push_back(it->Data[1]);
Require(CopyFromBack(sizeof(it->Data), tmp, sizeof(it->Data) * (count - 1)));
}
result.swap(tmp);
}
示例13: Parse
Formats::Chiptune::Container::Ptr Parse(const Binary::Container& data, Builder& target)
{
if (!FastCheck(data))
{
return Formats::Chiptune::Container::Ptr();
}
try
{
Binary::InputStream stream(data);
stream.ReadField<SignatureType>();
target.SetTitle(DecodeString(stream.ReadCString(MAX_STRING_SIZE)));
target.SetAuthor(DecodeString(stream.ReadCString(MAX_STRING_SIZE)));
target.SetComment(DecodeString(stream.ReadCString(MAX_COMMENT_SIZE)));
const std::size_t fixedOffset = stream.GetPosition();
std::size_t totalFrames = 0;
for (;;)
{
const uint8_t val = stream.ReadField<uint8_t>();
if (val == FINISH)
{
break;
}
switch (val)
{
case BEGIN_FRAME:
++totalFrames;
target.BeginFrames(1);
break;
case SKIP_FRAMES:
{
const uint_t frames = 3 + stream.ReadField<uint8_t>();
totalFrames += frames;
target.BeginFrames(frames);
}
break;
case SELECT_SECOND_CHIP:
target.SelectChip(1);
break;
case SELECT_FIRST_CHIP:
target.SelectChip(0);
break;
case LOOP_MARKER:
target.SetLoop();
break;
default:
target.SetRegister(val, stream.ReadField<uint8_t>());
break;
}
}
Require(totalFrames >= MIN_FRAMES);
const std::size_t usedSize = stream.GetPosition();
const auto subData = stream.GetReadData();
return CreateCalculatingCrcContainer(subData, fixedOffset, usedSize - fixedOffset);
}
catch (const std::exception&)
{
return Formats::Chiptune::Container::Ptr();
}
}
示例14: Hex2Bin
uint8_t Hex2Bin(char val)
{
Require(std::isxdigit(val));
return std::isdigit(val)
? val - '0'
: std::toupper(val) - 'A' + 10;
}
示例15: FillVer3Traits
void FillVer3Traits(uint_t hwMode)
{
switch (hwMode)
{
case Version3_0::Ver_48k:
case Version3_0::Ver_48k_iface1:
case Version3_0::Ver_48k_mgt:
Fill48kTraits();
break;
case Version3_0::Ver_SamRam:
FillSamRamTraits();
break;
case Version3_0::Ver_128k:
case Version3_0::Ver_128k_iface1:
case Version3_0::Ver_128k_mgt:
case Version3_0::Ver_Pentagon:
Fill128kTraits();
break;
case Version3_0::Ver_Scorpion:
Fill256kTraits();
break;
default:
Require(false);
break;
}
}