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:
parent
163b5ba4b5
commit
98dbb64c6f
@ -92,7 +92,7 @@ namespace xna {
|
|||||||
return *(double*)&int64;
|
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)
|
if (byteBuffer.empty() || byteBuffer.size() < size)
|
||||||
{
|
{
|
||||||
@ -104,8 +104,7 @@ namespace xna {
|
|||||||
{
|
{
|
||||||
num = Read(byteBuffer, index, size - index);
|
num = Read(byteBuffer, index, size - index);
|
||||||
if (num == 0) {
|
if (num == 0) {
|
||||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
throw std::runtime_error("ContentReader::ReadByteBuffer: Bad xbn.");
|
||||||
return std::vector<Byte>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,12 +160,7 @@ namespace xna {
|
|||||||
Int ContentReader::ReadHeader() {
|
Int ContentReader::ReadHeader() {
|
||||||
auto _this = shared_from_this();
|
auto _this = shared_from_this();
|
||||||
typeReaders = ContentTypeReaderManager::ReadTypeManifest(this->Read7BitEncodedInt(), _this);
|
typeReaders = ContentTypeReaderManager::ReadTypeManifest(this->Read7BitEncodedInt(), _this);
|
||||||
auto length = this->Read7BitEncodedInt();
|
auto length = this->Read7BitEncodedInt();
|
||||||
|
|
||||||
if (length > 0)
|
|
||||||
{
|
|
||||||
//TODO: length > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ namespace xna {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
auto ReadAsset();
|
auto ReadAsset();
|
||||||
|
|
||||||
std::vector<Byte> ReadByteBuffer(size_t size, xna_error_nullarg);
|
std::vector<Byte> ReadByteBuffer(size_t size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ContentReader(sptr<xna::ContentManager> const& contentManager, sptr<Stream>& input, String const& assetName, Int graphicsProfile)
|
ContentReader(sptr<xna::ContentManager> const& contentManager, sptr<Stream>& input, String const& assetName, Int graphicsProfile)
|
||||||
@ -74,13 +74,13 @@ namespace xna {
|
|||||||
Int ReadHeader();
|
Int ReadHeader();
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto ReadObjectInternal(std::any& existingInstance, xna_error_nullarg);
|
auto ReadObjectInternal(std::any& existingInstance);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto ReadObjectInternal(ContentTypeReader& typeReader, std::any& existingInstance, xna_error_nullarg);
|
auto ReadObjectInternal(ContentTypeReader& typeReader, std::any& existingInstance);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto InvokeReader(ContentTypeReader& reader, std::any& existingInstance, xna_error_nullarg);
|
auto InvokeReader(ContentTypeReader& reader, std::any& existingInstance);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sptr<xna::ContentManager> _contentManager = nullptr;
|
sptr<xna::ContentManager> _contentManager = nullptr;
|
||||||
@ -96,7 +96,7 @@ namespace xna {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
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();
|
const auto num = Read7BitEncodedInt();
|
||||||
|
|
||||||
@ -107,18 +107,16 @@ namespace xna {
|
|||||||
const auto index = num - 1;
|
const auto index = num - 1;
|
||||||
|
|
||||||
if (index >= typeReaders.size()) {
|
if (index >= typeReaders.size()) {
|
||||||
xna_error_apply(err, XnaErrorCode::ARGUMENT_OUT_OF_RANGE);
|
throw std::runtime_error("ContentReader::ReadObjectInternal: Bad xbn.");
|
||||||
|
|
||||||
XnaHelper::ReturnDefaultOrNull<T>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto reader = typeReaders[index];
|
auto reader = typeReaders[index];
|
||||||
|
|
||||||
return InvokeReader<T>(*reader, existingInstance, err);
|
return InvokeReader<T>(*reader, existingInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
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);
|
auto contentTypeReader = reinterpret_cast<ContentTypeReaderT<T>*>(&reader);
|
||||||
T objB;
|
T objB;
|
||||||
@ -167,11 +165,11 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
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
|
return typeReader.TargetIsValueType
|
||||||
? InvokeReader<T>(typeReader, existingInstance, err)
|
? InvokeReader<T>(typeReader, existingInstance)
|
||||||
: ReadObjectInternal<T>(existingInstance, err);
|
: ReadObjectInternal<T>(existingInstance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user