Fixing gcc errors - second attempt

pull/699/head
Otger 2015-11-29 21:11:38 +01:00
parent d72443d6b0
commit f2c49a69ba
3 changed files with 42 additions and 23 deletions

View File

@ -754,6 +754,13 @@ namespace glTF
virtual void WriteObjects(AssetWriter& writer) = 0; virtual void WriteObjects(AssetWriter& writer) = 0;
}; };
//! (Stub class that is specialized in glTFAssetWriter.h)
template<class T>
struct LazyDictWriter
{
static void Write(T& d, AssetWriter& w) {}
};
//! Manages lazy loading of the glTF top-level objects, and keeps a reference to them by ID //! Manages lazy loading of the glTF top-level objects, and keeps a reference to them by ID
//! It is the owner the loaded objects, so when it is destroyed it also deletes them //! It is the owner the loaded objects, so when it is destroyed it also deletes them
template<class T> template<class T>
@ -774,10 +781,8 @@ namespace glTF
void AttachToDocument(Document& doc); void AttachToDocument(Document& doc);
void DetachFromDocument(); void DetachFromDocument();
void WriteObjectsImpl(AssetWriter& writer);
void WriteObjects(AssetWriter& writer) void WriteObjects(AssetWriter& writer)
{ WriteObjectsImpl(writer); } { LazyDictWriter< LazyDict >::Write(*this, writer); }
Ref<T> Add(T* obj); Ref<T> Add(T* obj);

View File

@ -57,6 +57,9 @@ using rapidjson::MemoryPoolAllocator;
class AssetWriter class AssetWriter
{ {
template<class T>
friend struct LazyDictWriter;
private: private:
void WriteBinaryData(IOStream* outfile, size_t sceneLength); void WriteBinaryData(IOStream* outfile, size_t sceneLength);
@ -64,6 +67,9 @@ private:
void WriteMetadata(); void WriteMetadata();
void WriteExtensionsUsed(); void WriteExtensionsUsed();
template<class T>
void WriteObjects(LazyDict<T>& d);
public: public:
Document mDoc; Document mDoc;
Asset& mAsset; Asset& mAsset;

View File

@ -441,49 +441,57 @@ namespace glTF {
mDoc.AddMember("extensionsUsed", exts, mAl); mDoc.AddMember("extensionsUsed", exts, mAl);
} }
template<class T> template<class T>
void LazyDict<T>::WriteObjectsImpl(AssetWriter& w) void AssetWriter::WriteObjects(LazyDict<T>& d)
{ {
if (mObjs.empty()) return; if (d.mObjs.empty()) return;
Value* container = &w.mDoc; Value* container = &mDoc;
if (mExtId) { if (d.mExtId) {
Value* exts = FindObject(w.mDoc, "extensions"); Value* exts = FindObject(mDoc, "extensions");
if (!exts) { if (!exts) {
w.mDoc.AddMember("extensions", Value().SetObject().Move(), w.mDoc.GetAllocator()); mDoc.AddMember("extensions", Value().SetObject().Move(), mDoc.GetAllocator());
exts = FindObject(w.mDoc, "extensions"); exts = FindObject(mDoc, "extensions");
} }
if (!(container = FindObject(*exts, mExtId))) { if (!(container = FindObject(*exts, d.mExtId))) {
exts->AddMember(StringRef(mExtId), Value().SetObject().Move(), w.mDoc.GetAllocator()); exts->AddMember(StringRef(d.mExtId), Value().SetObject().Move(), mDoc.GetAllocator());
container = FindObject(*exts, mExtId); container = FindObject(*exts, d.mExtId);
} }
} }
Value* dict; Value* dict;
if (!(dict = FindObject(*container, mDictId))) { if (!(dict = FindObject(*container, d.mDictId))) {
container->AddMember(StringRef(mDictId), Value().SetObject().Move(), w.mDoc.GetAllocator()); container->AddMember(StringRef(d.mDictId), Value().SetObject().Move(), mDoc.GetAllocator());
dict = FindObject(*container, mDictId); dict = FindObject(*container, d.mDictId);
} }
for (size_t i = 0; i < mObjs.size(); ++i) { for (size_t i = 0; i < d.mObjs.size(); ++i) {
if (mObjs[i]->IsSpecial()) continue; if (d.mObjs[i]->IsSpecial()) continue;
Value obj; Value obj;
obj.SetObject(); obj.SetObject();
if (!mObjs[i]->name.empty()) { if (!d.mObjs[i]->name.empty()) {
obj.AddMember("name", StringRef(mObjs[i]->name.c_str()), w.mAl); obj.AddMember("name", StringRef(d.mObjs[i]->name.c_str()), mAl);
} }
Write(obj, *mObjs[i], w); Write(obj, *d.mObjs[i], *this);
dict->AddMember(StringRef(mObjs[i]->id), obj, w.mAl); dict->AddMember(StringRef(d.mObjs[i]->id), obj, mAl);
} }
} }
template<class T>
struct LazyDictWriter< LazyDict<T> >
{
static void Write(LazyDict<T>& d, AssetWriter& w)
{
w.WriteObjects(d);
}
};
} }