Example #1
0
 void SpriteRenderer::onDeserialize( const std::string& property, const Json::Value& root )
 {
     if( property == "Texture" && root.isString() )
         setTexture( Assets::use().getTexture( root.asString() ) );
     else if( property == "Size" && root.isArray() && root.size() == 2 )
     {
         setSize( sf::Vector2f(
             (float)root[ 0u ].asDouble(),
             (float)root[ 1u ].asDouble()
         ) );
     }
     else if( property == "Origin" && root.isArray() && root.size() == 2 )
     {
         setOrigin( sf::Vector2f(
             (float)root[ 0u ].asDouble(),
             (float)root[ 1u ].asDouble()
         ) );
     }
     else if( property == "OriginPercent" && root.isArray() && root.size() == 2 )
     {
         setOriginPercent( sf::Vector2f(
             (float)root[ 0u ].asDouble(),
             (float)root[ 1u ].asDouble()
         ) );
     }
     else if( property == "Color" && root.isArray() && root.size() == 4 )
     {
         setColor( sf::Color(
             root[ 0u ].asUInt(),
             root[ 1u ].asUInt(),
             root[ 2u ].asUInt(),
             root[ 3u ].asUInt()
         ) );
     }
     else if( property == "RenderStates" && root.isObject() )
     {
         Json::Value blendMode = root[ "blendMode" ];
         if( blendMode.isString() )
             m_renderStates.blendMode = Serialized::deserializeCustom< sf::BlendMode >( "BlendMode", blendMode );
         Json::Value shader = root[ "shader" ];
         if( shader.isString() )
             m_renderStates.shader = Assets::use().getShader( shader.asString() );
     }
     else if( property == "Material" && root.isObject() )
         m_material.deserialize( root );
     else if( property == "MaterialValidation" && root.isBool() )
         m_materialValidation = root.asBool();
     else
         Component::onDeserialize( property, root );
 }
Example #2
0
Color ResourceObjectManager::ResourceObjectFactory::parseColor(const Json::Value& object)
{
    if (!object.isString())
        return Color();

    return Color::fromString(object.asString());
}
Example #3
0
    void ParsedAlias::m_parse(Json::Value &val) {
        if (val.isString()) {
            // Assume a string is just a string.
            m_value = val;
            return;
        }
        if (val.isObject()) {
            if (val.isMember(SOURCE_KEY)) {
                // Strip any initial "source" level
                m_parse(val[SOURCE_KEY]);
                return;
            }

            // Assume an object means a transform.
            m_simple = false;
            m_value = val;

            auto &leaf = m_leaf();
            if (leaf.isString()) {
                return;
            }

            auto trackerEquiv = getPathFromOldRouteSource(leaf);
            if (!trackerEquiv.empty()) {
                leaf = trackerEquiv;
                return;
            }

            OSVR_DEV_VERBOSE(
                "Couldn't handle transform leaf: " << leaf.toStyledString());
        }
        m_value = Json::nullValue;
        /// @todo finish by throwing?
    }
Example #4
0
    void LuaModule::pushJsonScalarValue(const Json::Value &key,
                                        const Json::Value &val, lua_State * stack) {
        if (val.isObject() || val.isArray()) {
            throw std::runtime_error("Not a scalar value");
        }

        if (key.isString()) {
            pushKey(key, stack);
        }
        pushValue(val, stack);
        if (key.isNumeric()) {
            lua_rawseti(stack, -2, key.asInt() + 1);
        } else if (key.isString()) {
            lua_settable(stack, -3);
        }
    }
Example #5
0
boost::shared_ptr< ResourceObject > ResourceObjectManager::loadObject(const Json::Value& object, const std::string& type)
{
    if (object.isNull())
        return boost::shared_ptr< ResourceObject >();

    if (object.isString())
    {
        std::string path = object.asString();
        return getResourceObject(path);
    }
    if (type.empty() && !object.isMember("@type"))
    {
        Log::error() << "[ROM] Invalid JSON object (no @type field)";
        return boost::shared_ptr< ResourceObject >();
    }
    std::string t = type;
    if (object.isMember("@type"))
        t = object.get("@type", "").asString();

    auto fi = m_objectFactories.find(t);
    if (fi == m_objectFactories.end())
    {
        Log::warning() << "[ROM] No object loader found for type " << t;
        return boost::shared_ptr< ResourceObject >();
    }
    return (*(fi->second))("", object, *this);
}
 bool JsonHelper::ToBool( const Json::Value& value, bool defaultResult )
 {
     if ( value.isBool() )
     {
         return value.asBool();
     }
     if ( value.isInt() )
     {
         return (bool)value.asInt();
     }
     if ( value.isDouble() )
     {
         return (bool)value.asDouble();
     }
     if ( value.isUInt() )
     {
         return (bool)value.asUInt();
     }
     if ( value.isString() )
     {
         const std::string& str = value.asString();
         return ( str == "true" || str == "1" );
     }
     return defaultResult;
 }
FB::variant jsonValueToVariant( Json::Value root )
{
    Json::Value def;
    if (root.isString())
        return root.asString();
    else if (root.isBool())
        return root.asBool();
    else if (root.isDouble())
        return root.asDouble();
    else if (root.isInt())
        return root.asInt();
    else if (root.isUInt())
        return root.asUInt();
    else if (root.isNull())
        return FB::FBNull();
    else if (root.isArray()) {
        FB::VariantList outList;
        for (size_t i = 0; i < root.size(); ++i) {
            outList.push_back(jsonValueToVariant(root.get(i, def)));
        }
        return outList;
    } else if (root.isObject()) {
        Json::Value::Members members = root.getMemberNames();
        FB::VariantMap outMap;
        for (Json::Value::Members::iterator it = members.begin(); it != members.end(); ++it)
        {
            outMap[*it] = jsonValueToVariant(root.get(*it, def));
        }
        return outMap;
    } else {
        return FB::FBVoid();
    }
}
Example #8
0
 Json::Value Connection::process_result(const Json::Value& value) {
   if(value.isObject()) {
     Json::Value id = value["id"];
     if(!id.isIntegral() or id.asInt() != 0) {
       std::stringstream error;
       error << value.toStyledString() << " is no id=0";
       throw ConnectionError(error.str());
     }
     Json::Value jsonrpc = value["jsonrpc"];
     if(!jsonrpc.isString()) {
       std::stringstream error;
       error << value.toStyledString() << " has no string member: jsonrpc";
       throw ConnectionError(error.str());
     }
     Json::Value result = value["result"];
     if(!result.isObject()) {
       std::stringstream error;
       error << value.toStyledString() << " has no object member: result";
       throw ConnectionError(error.str());
     }
     return result;
   } else {
     std::stringstream error;
     error << value.toStyledString() << " is no json object";
     throw ConnectionError(error.str());
   }
 }
Example #9
0
 static void add(
     MetadataNode&      parent,
     const std::string& name,
     const Json::Value& node
 )
 {
     if      (node.isNull())   { parent.add(name, ""); }
     else if (node.isBool())   { parent.add(name, node.asBool()); }
     else if (node.isInt())    { parent.add(name, node.asInt64()); }
     else if (node.isUInt())   { parent.add(name, node.asUInt64()); }
     else if (node.isDouble()) { parent.add(name, node.asDouble()); }
     else if (node.isString()) { parent.add(name, node.asString()); }
     else if (node.isObject())
     {
         MetadataNode object = parent.add(name);
         for (const std::string& name: node.getMemberNames())
         {
             add(object, name, node[name]);
         }
     }
     else if (node.isArray())
     {
         for (const Json::Value& item: node)
         {
             add(parent, name, item);
         }
     }
 }
Example #10
0
void _PlanOperation::addField(const Json::Value &field) {
  if (field.isNumeric()) {
    addField(field.asUInt());
  } else if (field.isString()) {
    addNamedField(field.asString());
  } else throw std::runtime_error("Can't parse field name, neither numeric nor std::string");
}
Example #11
0
	Json::Value Serialize_String( const String& stringValue )
	{
		Json::Value	outValue;
		outValue = stringValue.ToChars();
		Assert(outValue.isString());
		return outValue;
	}
Example #12
0
    /**
     * Reads a key-value pair
     * @param key the key to lookup in Scalaris
     */
    Json::Value read(const std::string key) {
      Json::Value val = c.rpc("rbr_read", key);

      // std::cout << "read: " << Json::StyledWriter().write(val) << std::endl;

      if (!val.isObject())
        throw MalFormedJsonError();
      Json::Value status = val["status"];

      if (!status.isString())
        throw MalFormedJsonError();

      std::string status_str = status.asString();
      if (status_str.compare("ok") != 0)
        throw ReadFailedError(val["reason"].asString());

      Json::Value value = val["value"];
      if (!value.isObject())
        throw MalFormedJsonError();

      Json::Value value_type = value["type"];
      if (!value_type.isString())
        throw MalFormedJsonError();
      Json::Value value_type_str = value_type.asString();
      if (value_type_str.compare("as_is") != 0)
        throw ReadFailedError("unsupported value type");

      Json::Value value_value = value["value"];

      return value_value;
    }
Example #13
0
RGBColor Config::jsonToColor(Json::Value & colorJSON) {
	if(colorJSON.isString()) {
		return RGBColor::commonColor(colorJSON.asString());
	}
	return RGBColor(colorJSON["m_R"].asDouble(),
			     colorJSON["m_G"].asDouble(),
			     colorJSON["m_B"].asDouble());
}
Example #14
0
inline bool isAttributeString(const std::string &name, Json::Value &root){
    Json::Value errorVal = Json::Value(-99999); //TODO: Very temp
    Json::Value value = root.get( name.c_str(), errorVal );
    if (value == errorVal) {
        LOG_ERROR("Can't find json attribute: " << name);
    }
    return value.isString();
}
Example #15
0
bool Utils::GetBoolFromJsonValue(Json::Value &value) {
    // some json responses have string bools formated as string literals
    if (value.isString()) {
        return value.asString().compare("true") == 0;
    } else {
        return value.asBool();
    }
}
Example #16
0
		std::string readString(std::string key, std::string def)
		{
			Json::Value val = root.get(key, def);
			if (val.isString())
				return val.asString();
			else
				return def;
		}
/// 从 Json 解析数据到 dictNode 中
static void parseFromJsonToDictionary(const Json::Value & jsonNode, CCDictionary * dictNode)
{
	Json::Value::Members members = jsonNode.getMemberNames();
	for (Json::Value::Members::iterator beg = members.begin(); beg != members.end(); ++beg)
	{
        std::string name = *beg;
		Json::Value child = jsonNode[name];
		
		if (child.isArray())
		{
			CCArray * arr = CCArray::create();
			parseFromJsonToArray(child, arr);
			dictNode->setObject(arr, name);
		}
		else if (child.isObject())
		{
			CCDictionary * dict = CCDictionary::create();
			parseFromJsonToDictionary(child, dict);
			dictNode->setObject(dict, name);
		}
		else if (child.isString())
		{
			CCString * str = CCString::createWithFormat("%s", child.asCString());
			dictNode->setObject(str, name);
		}
		else if (child.isInt())
		{
			CCString * str = CCString::createWithFormat("%d", child.asInt());
			dictNode->setObject(str, name);
		}
		else if (child.isUInt())
		{
			CCString * str = CCString::createWithFormat("%u", child.asUInt());
			dictNode->setObject(str, name);
		}
		else if (child.isInt64())
		{
			CCString * str = CCString::createWithFormat("%lld", child.asInt64());
			dictNode->setObject(str, name);
			
		}
		else if (child.isUInt64())
		{
			CCString * str = CCString::createWithFormat("%llu", child.asUInt64());
			dictNode->setObject(str, name);
		}
		else if (child.isDouble())
		{
			CCString * str = CCString::createWithFormat("%f", child.asDouble());
			dictNode->setObject(str, name);
		}
		else if (child.isBool())
		{
			CCString * str = CCString::createWithFormat("%d", child.asInt());
			dictNode->setObject(str, name);
		}
	}
}
Example #18
0
static RoundConfig* loadRoundFromObj(const JsonLoader& loader,
                                     const Json::Value& obj) {
  Json::Value name = obj["name"];
  if (!name.isString())
    return NULL;
  RoundConfig* config = new RoundConfig(name.asString());
  config->readJson(loader, obj);
  return config;
}
Example #19
0
void JsonTree::init( const string &key, const Json::Value &value, bool setType, NodeType nodeType, ValueType valueType )
{
    mKey = key;
	mNodeType = nodeType;
	mParent = 0;
	mValue = "";
	mValueType = valueType;

	if( ! value.isNull() && ( value.isArray() || value.isObject() ) ) {
        if( value.isArray() ) {
            mNodeType = NODE_ARRAY;
            for ( uint32_t i = 0; i < value.size(); i++ ) {
                pushBack( JsonTree( "", value[ i ] ) );
            }
        }
		else if( value.isObject() ) {
            mNodeType = NODE_OBJECT;
            Json::Value::Members members = value.getMemberNames();
            for( Json::Value::Members::const_iterator memberIt = members.begin(); memberIt != members.end(); ++memberIt ) {
				string key = *memberIt;
                pushBack( JsonTree( key, value[ key ] ) );
            }
        }
    }
	else {
		if( value.isBool() ) {
			mValue = toString( value.asBool() );
			if( setType ) {
				mValueType = VALUE_BOOL;
			}
		}
		else if ( value.isDouble() ) { 
			mValue = toString( value.asDouble() );
			if ( setType ) {
				mValueType = VALUE_DOUBLE;
			}
		}
		else if ( value.isInt() ) { 
			mValue = toString( value.asInt() );
			if ( setType ) {
				mValueType = VALUE_INT;
			}
		}
		else if ( value.isString() ) { 
			mValue = toString( value.asString() );
			if ( setType ) {
				mValueType = VALUE_STRING;
			}
		}
		else if ( value.isUInt() ) { 
			mValue = toString( value.asUInt() );
			if ( setType ) {
				mValueType = VALUE_UINT;
			}
		}
	}
}
Example #20
0
    Ogre::String JsonUtils::asString(Json::Value const &value, const Ogre::String &defaultValue)
    {
        Ogre::String returned = defaultValue;

        if(value.isString())
            returned = value.asString();

        return returned;
    }
Example #21
0
    Ogre::Quaternion JsonUtils::asQuaternion(Json::Value const &value, const Ogre::Quaternion &defaultValue)
    {
        Ogre::Quaternion returned = defaultValue;

        if(value.isString())
            returned = Ogre::StringConverter::parseQuaternion(value.asString(), defaultValue);

        return returned;
    }
Example #22
0
bool ActionPerformerMarshaller::fromJSON(const Json::Value& s,ActionPerformer& e)
{
  e.mInternal=ActionPerformer::INVALID_ENUM;
  if(!s.isString())
    return false;

  e.mInternal=getIndex(s.asString().c_str());
  return (e.mInternal!=ActionPerformer::INVALID_ENUM);
}
bool AppInterfaceUnregisteredReasonMarshaller::fromJSON(const Json::Value& s,AppInterfaceUnregisteredReason& e)
{
  e.mInternal=AppInterfaceUnregisteredReason::INVALID_ENUM;
  if(!s.isString())
    return false;

  e.mInternal=getIndex(s.asString().c_str());
  return (e.mInternal!=AppInterfaceUnregisteredReason::INVALID_ENUM);
}
bool DeactivateReasonMarshaller::fromJSON(const Json::Value& s,DeactivateReason& e)
{
  e.mInternal=DeactivateReason::INVALID_ENUM;
  if(!s.isString())
    return false;

  e.mInternal=getIndex(s.asString().c_str());
  return (e.mInternal!=DeactivateReason::INVALID_ENUM);
}
Example #25
0
bool ButtonNameMarshaller::fromJSON(const Json::Value& s,ButtonName& e)
{
  e.mInternal=ButtonName::INVALID_ENUM;
  if(!s.isString())
    return false;

  e.mInternal=getIndex(s.asString().c_str());
  return (e.mInternal!=ButtonName::INVALID_ENUM);
}
Example #26
0
bool SamplingRateMarshaller::fromJSON(const Json::Value& s,SamplingRate& e)
{
  e.mInternal=SamplingRate::INVALID_ENUM;
  if(!s.isString())
    return false;

  e.mInternal=getIndex(s.asString().c_str());
  return (e.mInternal!=SamplingRate::INVALID_ENUM);
}
Example #27
0
bool HMILevelMarshaller::fromJSON(const Json::Value& s,HMILevel& e)
{
  e.mInternal=HMILevel::INVALID_ENUM;
  if(!s.isString())
    return false;

  e.mInternal=getIndex(s.asString().c_str());
  return (e.mInternal!=HMILevel::INVALID_ENUM);
}
Example #28
0
bool SystemContextMarshaller::fromJSON(const Json::Value& s,SystemContext& e)
{
  e.mInternal=SystemContext::INVALID_ENUM;
  if(!s.isString())
    return false;

  e.mInternal=getIndex(s.asString().c_str());
  return (e.mInternal!=SystemContext::INVALID_ENUM);
}
Example #29
0
bool messageTypeMarshaller::fromJSON(const Json::Value& s,messageType& e)
{
  e.mInternal=messageType::INVALID_ENUM;
  if(!s.isString())
    return false;

  e.mInternal=getIndex(s.asString().c_str());
  return (e.mInternal!=messageType::INVALID_ENUM);
}
std::string GlobalizationNDK::stringToDate(const std::string& args)
{
    if (args.empty())
        return errorInJson(PARSING_ERROR, "No dateString provided!");

    Json::Reader reader;
    Json::Value root;
    bool parse = reader.parse(args, root);

    if (!parse) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::stringToDate: invalid json data: %s",
                args.c_str());
        return errorInJson(PARSING_ERROR, "Parameters not valid json format!");
    }

    Json::Value dateString = root["dateString"];
    if (!dateString.isString()) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::stringToDate: invalid dateString type: %d",
                dateString.type());
        return errorInJson(PARSING_ERROR, "dateString not a string!");
    }

    std::string dateValue = dateString.asString();
    if (dateValue.empty()) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::stringToDate: empty dateString.");
        return errorInJson(PARSING_ERROR, "dateString is empty!");
    }

    Json::Value options = root["options"];

    DateFormat::EStyle dstyle, tstyle;
    std::string error;
    if (!handleDateOptions(options, dstyle, tstyle, error))
        return errorInJson(PARSING_ERROR, error);

    const Locale& loc = Locale::getDefault();
    DateFormat* df = DateFormat::createDateTimeInstance(dstyle, tstyle, loc);

    if (!df) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::stringToDate: unable to create DateFormat instance!");
        return errorInJson(UNKNOWN_ERROR, "Unable to create DateFormat instance!");
    }
    std::auto_ptr<DateFormat> deleter(df);

    UnicodeString uDate = UnicodeString::fromUTF8(dateValue);
    UErrorCode status = U_ZERO_ERROR;
    UDate date = df->parse(uDate, status);

    // Note: not sure why U_ERROR_WARNING_START is returned when parse succeeded.
    if (status != U_ZERO_ERROR && status != U_ERROR_WARNING_START) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::stringToDate: DataFormat::parse error: %d: %s",
                status, dateValue.c_str());
        return errorInJson(PARSING_ERROR, "Failed to parse dateString!");
    }

    return resultDateInJson(date);
}