Tie the new serialization code into the Json code.

Small cleanups.
This commit is contained in:
JoelKatz
2012-03-26 20:31:03 -07:00
parent ec7833d56e
commit bd9780e503
5 changed files with 56 additions and 10 deletions

View File

@@ -1,6 +1,8 @@
#include "SerializedObject.h"
#include "boost/lexical_cast.hpp"
SerializedType* STObject::makeDefaultObject(SerializedTypeID id, const char *name)
{
switch(id)
@@ -455,3 +457,19 @@ void STObject::setValueFieldTL(SOE_Field field, const std::vector<TaggedListItem
if(!cf) throw(std::runtime_error("Wrong field type"));
cf->setValue(v);
}
Json::Value STObject::getJson(int options) const
{
Json::Value ret(Json::objectValue);
int index=1;
for(boost::ptr_vector<SerializedType>::const_iterator it=mData.begin(), end=mData.end(); it!=end; ++it, ++index)
{
if(it->getType()!=STI_NOTPRESENT)
{
if(it->getName()==NULL)
ret[boost::lexical_cast<std::string>(index)]=it->getText();
else ret[it->getName()]=it->getText();
}
}
return ret;
}