Globals.fbs
// Just a table of some values I want to define various globals for
table ValuesTB {
v1:int;
v2:int;
v3:int;
}
// The table of different globals I want to reference
table GlobalsTB {
global1: ValuesTB;
global2: ValuesTB;
..etc.
}
root_type GlobalsTB;include "Globals.fbs"
// A single Data entry. This can have it's own ValuesTB in 'values' or can reference a global value via 'valuesRef'
table DataTB {
values: ValuesTB;
valuesRef: int (hash: "fnv1_32"); // Not correct, but I think I need to use a hash somehow
}
table TheData {
thedData : [DataTB];
}
root_type TheData;
Data.json
{
theData: [
{ values: { v1:1, v2:42, v3:99 } },
{ valueRef: "global1" }, // Again, not correct. Just to show I somehow want to
{ valueRef: "global1" }, // reference a "ValuesTB" defined "globally"
{ valueRef: "global3" },
{ values: { v1:77, v2:77, v3:77 } },
{ valueRef: "global1" },
]
}
Thanks,
Stuart.
--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ahh I see. Thanks. I don't use the object API so I've just gone with the simple idea of storing a map of name -> table offset. e.g. (just posting to hoping add some more value to this thread).
class GlobalData
{
public:
typedef std::map<std::string, flatbuffers::voffset_t> Lookup;
template<typename T>
const T* get(const std::string& name) const {
auto find = mLookup.find(name);
return (find != mLookup.end())
? mRoot->GetPointer<const T*>(find->second)
: nullptr;
}
private
const Lookup& mLookup;
const flatbuffers::Table* mRoot;
};
And
GlobalData::Lookup lookup;
lookup["global1"] = Globals::VT_GLOBAL1;
lookup["global2"] = Globals::VT_GLOBAL2;
lookup["global3"] = Globals::VT_GLOBAL3;
auto g1 = globals.get<ValuesTB>("global1");