bool JSONSerialize::isValidObjectProperty(void* _1, string propname, int counter) { JSONElement* node = (JSONElement*)_1; if((int)node->getChildren().size()>counter && node->getChildren().at(counter)->getName()==propname) return true; return false; }
void* JSONSerialize::getContainerElement(void* _1, int counter, int counter1) { JSONElement* root = (JSONElement*)_1; if((int)root->getChildren().size()<counter) return NULL; JSONElement* ele = root->getChildren().at(counter); return ele; }
string JSONSerialize::elementToSerializedString(void* _1, int counter) { JSONElement* root = (JSONElement*)_1; if((int)root->getChildren().size()<counter) return NULL; JSONElement* ele = root->getChildren().at(counter); return ele->toString(); }
bool JSONSerialize::isValidClassNamespace(void* _1, string classname, string namespc, bool iscontainer) { JSONElement* node = (JSONElement*)_1; if(iscontainer && node->getChildren().size()==0) return false; return true; }
string JSONUtil::getDocumentStr(const JSONElement& doc) { string jsonText; if(doc.getType()==JSONElement::JSON_OBJECT) jsonText += "{"; else jsonText += "["; if(doc.hasChildren()) { for (int var = 0; var < (int)doc.getChildren().size(); ++var) { JSONElement* child = doc.getChildren().at(var); if(doc.getType()==JSONElement::JSON_OBJECT) jsonText += "\"" + child->getName() + "\":"; if(child->getType()==JSONElement::JSON_OBJECT || child->getType()==JSONElement::JSON_ARRAY) { jsonText += getDocumentStr(*child); } else { if(child->getType()==JSONElement::JSON_STRING) jsonText += "\"" + child->getValue() + "\""; else jsonText += child->getValue(); } if(var!=(int)doc.getChildren().size()-1) { jsonText += ", "; } } } if(doc.getType()==JSONElement::JSON_OBJECT) jsonText += "}"; else jsonText += "]"; return jsonText; }
void* JSONSerialize::getObjectProperty(void* _1, int counter) { JSONElement* elel = (JSONElement*)_1; return elel->getChildren().at(counter); }
int JSONSerialize::getContainerSize(void* _1) { JSONElement* root = (JSONElement*)_1; return root->getChildren().size(); }
void JSONSerialize::addPrimitiveElementToContainer(void* _1, int counter, string className, void* cont, string container) { JSONElement* root = (JSONElement*)_1; JSONElement ele = *(root->getChildren().at(counter)); if(className=="std::string" || className=="string") { string retVal = ele.getValue(); addValueToNestedContainer(container, retVal, cont); } else if(className=="int") { int retVal = CastUtil::lexical_cast<int>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } else if(className=="short") { short retVal = CastUtil::lexical_cast<short>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } else if(className=="long") { long retVal = CastUtil::lexical_cast<long>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } else if(className=="long long") { long long retVal = CastUtil::lexical_cast<long long>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } else if(className=="long double") { long double retVal = CastUtil::lexical_cast<long double>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } else if(className=="unsigned int") { unsigned int retVal = CastUtil::lexical_cast<unsigned int>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } else if(className=="unsigned short") { unsigned short retVal = CastUtil::lexical_cast<unsigned short>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } else if(className=="unsigned long") { unsigned long retVal = CastUtil::lexical_cast<unsigned long>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } else if(className=="unsigned long long") { unsigned long long retVal = CastUtil::lexical_cast<unsigned long long>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } else if(className=="float") { float retVal = CastUtil::lexical_cast<float>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } else if(className=="double") { double retVal = CastUtil::lexical_cast<double>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } else if(className=="bool") { bool retVal = CastUtil::lexical_cast<bool>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } else if(className=="char") { char retVal = CastUtil::lexical_cast<char>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } else if(className=="unsigned char") { unsigned char retVal = CastUtil::lexical_cast<unsigned char>(ele.getValue()); addValueToNestedContainer(container, retVal, cont); } }