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;
};
//! (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
//! It is the owner the loaded objects, so when it is destroyed it also deletes them
template<class T>
@ -774,10 +781,8 @@ namespace glTF
void AttachToDocument(Document& doc);
void DetachFromDocument();
void WriteObjectsImpl(AssetWriter& writer);
void WriteObjects(AssetWriter& writer)
{ WriteObjectsImpl(writer); }
{ LazyDictWriter< LazyDict >::Write(*this, writer); }
Ref<T> Add(T* obj);

View File

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

View File

@ -441,49 +441,57 @@ namespace glTF {
mDoc.AddMember("extensionsUsed", exts, mAl);
}
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) {
Value* exts = FindObject(w.mDoc, "extensions");
if (d.mExtId) {
Value* exts = FindObject(mDoc, "extensions");
if (!exts) {
w.mDoc.AddMember("extensions", Value().SetObject().Move(), w.mDoc.GetAllocator());
exts = FindObject(w.mDoc, "extensions");
mDoc.AddMember("extensions", Value().SetObject().Move(), mDoc.GetAllocator());
exts = FindObject(mDoc, "extensions");
}
if (!(container = FindObject(*exts, mExtId))) {
exts->AddMember(StringRef(mExtId), Value().SetObject().Move(), w.mDoc.GetAllocator());
container = FindObject(*exts, mExtId);
if (!(container = FindObject(*exts, d.mExtId))) {
exts->AddMember(StringRef(d.mExtId), Value().SetObject().Move(), mDoc.GetAllocator());
container = FindObject(*exts, d.mExtId);
}
}
Value* dict;
if (!(dict = FindObject(*container, mDictId))) {
container->AddMember(StringRef(mDictId), Value().SetObject().Move(), w.mDoc.GetAllocator());
dict = FindObject(*container, mDictId);
if (!(dict = FindObject(*container, d.mDictId))) {
container->AddMember(StringRef(d.mDictId), Value().SetObject().Move(), mDoc.GetAllocator());
dict = FindObject(*container, d.mDictId);
}
for (size_t i = 0; i < mObjs.size(); ++i) {
if (mObjs[i]->IsSpecial()) continue;
for (size_t i = 0; i < d.mObjs.size(); ++i) {
if (d.mObjs[i]->IsSpecial()) continue;
Value obj;
obj.SetObject();
if (!mObjs[i]->name.empty()) {
obj.AddMember("name", StringRef(mObjs[i]->name.c_str()), w.mAl);
if (!d.mObjs[i]->name.empty()) {
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);
}
};
}