bool MultitypeVar::readFromValue(const rapidjson::Value& obj)
{
    if (obj.IsNull())
    {
        mType = MultitypeNull;
    }
    else if (obj.IsBool())
    {
        mType = MultitypeBool;
        mBool = obj.GetBool();
    }
    else if (obj.IsNumber())
    {
        mType = MultitypeNumber;
        mNumber = obj.GetDouble();
    }
    else if (obj.IsString())
    {
        mType = MultitypeNumber;
        mString = obj.GetString();
    }
    else
    {
        mType = MultitypeNull;
        return false;
    }
    return true;
}
double get_value(const rapidjson::Value& root, const char* key)
{
  if (key != nullptr)
  {
    if (root[key].IsNumber() && root.HasMember(key))
      return root[key].GetDouble();
    else
      throw std::system_error(std::error_code(), "Parse error.");
  }
  else
  {
    if (root.IsNumber())
      return root.GetDouble();
    else
      throw std::system_error(std::error_code(), "Parse error.");
  }
}
std::string SettingRegistry::toString(const rapidjson::Value& dflt, std::string setting_name)
{
    if (dflt.IsString())
    {
        return dflt.GetString();
    }
    else if (dflt.IsTrue())
    {
        return "true";
    }
    else if (dflt.IsFalse())
    {
        return "false";
    }
    else if (dflt.IsNumber())
    {
        std::ostringstream ss;
        ss << dflt.GetDouble();
        return ss.str();
    } 
    else if (dflt.IsArray())
    {
        std::stringstream ss;
        ss << "[";
        bool first = true;
        for (auto it = dflt.Begin(); it != dflt.End(); ++it)
        {
            if (!first)
            {
                ss << ",";
            }
            ss << toString(*it);
            first = false;
        }
        ss << "]";
        return ss.str();
    }
    else 
    {
        logError("Unrecognized data type in JSON: %s has type %s\n", setting_name.c_str(), toString(dflt.GetType()).c_str());
        return "";
    }
}
Example #4
0
double traverse_rapidjson(const rapidjson::Value &v)
{
	double x = 0;
	if (v.IsObject())
	{
		for (auto i = v.MemberBegin(); i != v.MemberEnd(); ++i)
		{
			x += traverse_rapidjson(i->value);
		}
	}
	else if (v.IsArray())
	{
		for (auto i = v.Begin(); i != v.End(); ++i)
		{
			x += traverse_rapidjson(*i);
		}
	}
	else if (v.IsNumber())
	{
		x = v.GetDouble();
	}
	return x;
}
Example #5
0
	float Deserialize_Float(const rapidjson::Value& value)
	{
		assert(value.IsNumber());

		return value.GetFloat();
	}