BinaryStreamReaderImpl.cpp dna/stream/BinaryStreamReaderImpl.h dna/TypeDefs.h dna/types/Limits.h status/Provider.h trio/utils/StreamScope.h cstddef limits tuple dna //CopyrightEpicGames,Inc.AllRightsReserved. #include"dna/stream/BinaryStreamReaderImpl.h" #include"dna/TypeDefs.h" #include"dna/types/Limits.h" #include<status/Provider.h> #include<trio/utils/StreamScope.h> #ifdef_MSC_VER #pragmawarning(push) #pragmawarning(disable:43654987) #endif #include<cstddef> #include<limits> #include<tuple> #ifdef_MSC_VER #pragmawarning(pop) #endif namespacedna{ #ifdef__clang__ #pragmaclangdiagnosticpush #pragmaclangdiagnosticignored"-Wglobal-constructors" #endif sc::StatusProviderBinaryStreamReaderImpl::status{SignatureMismatchError,VersionMismatchError,InvalidDataError}; #ifdef__clang__ #pragmaclangdiagnosticpop #endif BinaryStreamReader::~BinaryStreamReader()=default; BinaryStreamReader*BinaryStreamReader::create(BoundedIOStream*stream, DataLayerlayer, std::uint16_tmaxLOD, MemoryResource*memRes){ PolyAllocator<BinaryStreamReaderImpl>alloc{memRes}; returnalloc.newObject(stream,layer,maxLOD,LODLimits::min(),memRes); } BinaryStreamReader*BinaryStreamReader::create(BoundedIOStream*stream, DataLayerlayer, std::uint16_tmaxLOD, std::uint16_tminLOD, MemoryResource*memRes){ PolyAllocator<BinaryStreamReaderImpl>alloc{memRes}; returnalloc.newObject(stream,layer,maxLOD,minLOD,memRes); } BinaryStreamReader*BinaryStreamReader::create(BoundedIOStream*stream, DataLayerlayer, std::uint16_t*lods, std::uint16_tlodCount, MemoryResource*memRes){ PolyAllocator<BinaryStreamReaderImpl>alloc{memRes}; returnalloc.newObject(stream,layer,ConstArrayView<std::uint16_t>{lods,lodCount},memRes); } voidBinaryStreamReader::destroy(BinaryStreamReader*instance){ //NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast) autoreader=static_cast<BinaryStreamReaderImpl*>(instance); PolyAllocator<BinaryStreamReaderImpl>alloc{reader->getMemoryResource()}; alloc.deleteObject(reader); } BinaryStreamReaderImpl::BinaryStreamReaderImpl(BoundedIOStream*stream_, DataLayerlayer_, std::uint16_tmaxLOD_, std::uint16_tminLOD_, MemoryResource*memRes_): BaseImpl{memRes_}, ReaderImpl{memRes_}, stream{stream_}, archive{stream_,layer_,maxLOD_,minLOD_,memRes_}, lodConstrained{(maxLOD_!=LODLimits::max())||(minLOD_!=LODLimits::min())}{ } BinaryStreamReaderImpl::BinaryStreamReaderImpl(BoundedIOStream*stream_, DataLayerlayer_, ConstArrayView<std::uint16_t>lods_, MemoryResource*memRes_): BaseImpl{memRes_}, ReaderImpl{memRes_}, stream{stream_}, archive{stream_,layer_,lods_,memRes_}, lodConstrained{true}{ } boolBinaryStreamReaderImpl::isLODConstrained()const{ returnlodConstrained; } voidBinaryStreamReaderImpl::unload(DataLayerlayer){ if((layer==DataLayer::All)|| (layer==DataLayer::AllWithoutBlendShapes)|| (layer==DataLayer::Descriptor)){ dna=DNA{memRes}; }elseif((layer==DataLayer::Geometry)||(layer==DataLayer::GeometryWithoutBlendShapes)){ dna.unloadGeometry(); }elseif(layer==DataLayer::Behavior){ dna.unloadBehavior(); }elseif(layer==DataLayer::Definition){ dna.unloadGeometry(); dna.unloadBehavior(); dna.unloadDefinition(); } } voidBinaryStreamReaderImpl::read(){ //Duetopossibleusageofcustomstreamimplementations,thestatusactuallymustbeclearedatthispoint //asexternalstreamsdonothaveaccesstothestatusresetAPI status.reset(); trio::StreamScopescope{stream}; if(!sc::Status::isOk()){ return; } archive>>dna; if(!sc::Status::isOk()){ return; } if(!dna.signature.matches()){ status.set(SignatureMismatchError,dna.signature.value.expected.data(),dna.signature.value.got.data()); return; } if(!dna.version.matches()){ status.set(VersionMismatchError, dna.version.generation.expected, dna.version.version.expected, dna.version.generation.got, dna.version.version.got); return; } } }//namespacedna