1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Insere exceções em ContentReader

This commit is contained in:
Danilo 2024-06-03 11:05:10 -03:00
parent 163b5ba4b5
commit 98dbb64c6f
2 changed files with 14 additions and 22 deletions

View File

@ -92,7 +92,7 @@ namespace xna {
return *(double*)&int64;
}
std::vector<Byte> ContentReader::ReadByteBuffer(size_t size, xna_error_ptr_arg)
std::vector<Byte> ContentReader::ReadByteBuffer(size_t size)
{
if (byteBuffer.empty() || byteBuffer.size() < size)
{
@ -104,8 +104,7 @@ namespace xna {
{
num = Read(byteBuffer, index, size - index);
if (num == 0) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return std::vector<Byte>();
throw std::runtime_error("ContentReader::ReadByteBuffer: Bad xbn.");
}
}
@ -161,12 +160,7 @@ namespace xna {
Int ContentReader::ReadHeader() {
auto _this = shared_from_this();
typeReaders = ContentTypeReaderManager::ReadTypeManifest(this->Read7BitEncodedInt(), _this);
auto length = this->Read7BitEncodedInt();
if (length > 0)
{
//TODO: length > 0
}
auto length = this->Read7BitEncodedInt();
return length;

View File

@ -63,7 +63,7 @@ namespace xna {
template <typename T>
auto ReadAsset();
std::vector<Byte> ReadByteBuffer(size_t size, xna_error_nullarg);
std::vector<Byte> ReadByteBuffer(size_t size);
private:
ContentReader(sptr<xna::ContentManager> const& contentManager, sptr<Stream>& input, String const& assetName, Int graphicsProfile)
@ -74,13 +74,13 @@ namespace xna {
Int ReadHeader();
template <typename T>
auto ReadObjectInternal(std::any& existingInstance, xna_error_nullarg);
auto ReadObjectInternal(std::any& existingInstance);
template <typename T>
auto ReadObjectInternal(ContentTypeReader& typeReader, std::any& existingInstance, xna_error_nullarg);
auto ReadObjectInternal(ContentTypeReader& typeReader, std::any& existingInstance);
template <typename T>
auto InvokeReader(ContentTypeReader& reader, std::any& existingInstance, xna_error_nullarg);
auto InvokeReader(ContentTypeReader& reader, std::any& existingInstance);
private:
sptr<xna::ContentManager> _contentManager = nullptr;
@ -96,7 +96,7 @@ namespace xna {
};
template<typename T>
inline auto ContentReader::ReadObjectInternal(std::any& existingInstance, xna_error_ptr_arg)
inline auto ContentReader::ReadObjectInternal(std::any& existingInstance)
{
const auto num = Read7BitEncodedInt();
@ -107,18 +107,16 @@ namespace xna {
const auto index = num - 1;
if (index >= typeReaders.size()) {
xna_error_apply(err, XnaErrorCode::ARGUMENT_OUT_OF_RANGE);
XnaHelper::ReturnDefaultOrNull<T>();
throw std::runtime_error("ContentReader::ReadObjectInternal: Bad xbn.");
}
auto reader = typeReaders[index];
return InvokeReader<T>(*reader, existingInstance, err);
return InvokeReader<T>(*reader, existingInstance);
}
template<typename T>
inline auto ContentReader::InvokeReader(ContentTypeReader& reader, std::any& existingInstance, xna_error_ptr_arg)
inline auto ContentReader::InvokeReader(ContentTypeReader& reader, std::any& existingInstance)
{
auto contentTypeReader = reinterpret_cast<ContentTypeReaderT<T>*>(&reader);
T objB;
@ -167,11 +165,11 @@ namespace xna {
}
template<typename T>
inline auto ContentReader::ReadObjectInternal(ContentTypeReader& typeReader, std::any& existingInstance, xna_error_ptr_arg)
inline auto ContentReader::ReadObjectInternal(ContentTypeReader& typeReader, std::any& existingInstance)
{
return typeReader.TargetIsValueType
? InvokeReader<T>(typeReader, existingInstance, err)
: ReadObjectInternal<T>(existingInstance, err);
? InvokeReader<T>(typeReader, existingInstance)
: ReadObjectInternal<T>(existingInstance);
}
}