diff --git a/loader_example.cc b/loader_example.cc index 23337e4..64e36be 100644 --- a/loader_example.cc +++ b/loader_example.cc @@ -234,7 +234,7 @@ static std::string PrintValue(const std::string& name, const tinygltf::Value &va } else if (value.IsNumber()) { ss << Indent(indent) << name << " : " << value.Get() << std::endl; } else if (value.IsInt()) { - ss << Indent(indent) << name << " : " << value.Get() << std::endl; + ss << Indent(indent) << name << " : " << value.Get() << std::endl; } // @todo { binary, array } diff --git a/tiny_gltf_loader.h b/tiny_gltf_loader.h index 3a5f413..c5ebb12 100644 --- a/tiny_gltf_loader.h +++ b/tiny_gltf_loader.h @@ -43,13 +43,10 @@ #define TINY_GLTF_LOADER_H_ #include +#include #include #include #include -#include - -#define __STDC_FORMAT_MACROS -#include namespace tinygltf { @@ -160,12 +157,12 @@ class Value { Value() : type_(NULL_TYPE) {} explicit Value(bool b) : type_(BOOL_TYPE) { boolean_value_ = b; } - explicit Value(int64_t i) : type_(INT_TYPE) { int64_value_ = i; } + explicit Value(int i) : type_(INT_TYPE) { int_value_ = i; } explicit Value(double n) : type_(NUMBER_TYPE) { number_value_ = n; } explicit Value(const std::string &s) : type_(STRING_TYPE) { string_value_ = s; } - explicit Value(const uint8_t *p, uint64_t n) : type_(BINARY_TYPE) { + explicit Value(const unsigned char *p, size_t n) : type_(BINARY_TYPE) { binary_value_.resize(n); memcpy(binary_value_.data(), p, n); } @@ -175,7 +172,6 @@ class Value { explicit Value(const Object &o) : type_(OBJECT_TYPE) { object_value_ = Object(o); } - ~Value() {} char Type() const { return static_cast(type_); } @@ -200,12 +196,12 @@ class Value { T &Get(); // Lookup value from an array - const Value &Get(int64_t idx) const { + const Value &Get(int idx) const { static Value &null_value = *(new Value()); assert(IsArray()); assert(idx >= 0); - return (static_cast(idx) < array_value_.size()) - ? array_value_[static_cast(idx)] + return (static_cast(idx) < array_value_.size()) + ? array_value_[static_cast(idx)] : null_value; } @@ -243,16 +239,18 @@ class Value { } protected: - int64_t int64_value_; + int type_; + + int int_value_; double number_value_; std::string string_value_; - std::vector binary_value_; + std::vector binary_value_; Array array_value_; Object object_value_; bool boolean_value_; char pad[3]; - int type_; + int pad0; }; #define TINYGLTF_VALUE_GET(ctype, var) \ @@ -266,9 +264,9 @@ class Value { } TINYGLTF_VALUE_GET(bool, boolean_value_) TINYGLTF_VALUE_GET(double, number_value_) -TINYGLTF_VALUE_GET(int64_t, int64_value_) +TINYGLTF_VALUE_GET(int, int_value_) TINYGLTF_VALUE_GET(std::string, string_value_) -TINYGLTF_VALUE_GET(std::vector, binary_value_) +TINYGLTF_VALUE_GET(std::vector, binary_value_) TINYGLTF_VALUE_GET(Value::Array, array_value_) TINYGLTF_VALUE_GET(Value::Object, object_value_) #undef TINYGLTF_VALUE_GET @@ -1011,7 +1009,8 @@ static void ParseObjectProperty(Value *ret, const picojson::object &o) { } else if (v.is()) { vo[it->first] = tinygltf::Value(v.get()); } else if (v.is()) { - vo[it->first] = tinygltf::Value(v.get()); + vo[it->first] = + tinygltf::Value(static_cast(v.get())); // truncate } else if (v.is()) { vo[it->first] = tinygltf::Value(v.get()); } else if (v.is()) {