bool Deserialize ( const Json::Value& json_val, bool& obj_val )
 {
     /**
      * Warning: the default type may be int, even you Serialize a bool value
      */
     if ( json_val.isBool () )
     {
         obj_val = json_val.asBool ();
         return true;
     }
     else if ( json_val.isInt () )
     {
         int tmp = json_val.asInt ();
         if ( ! tmp )
         {
             obj_val = false;
         }
         else
         {
             obj_val = true;
         }
         return true;
     }
     return false;
 }
Example #2
0
void mtsIntuitiveResearchKitECM::Configure(const std::string & filename)
{
    try {
        std::ifstream jsonStream;
        Json::Value jsonConfig;
        Json::Reader jsonReader;

        jsonStream.open(filename.c_str());
        if (!jsonReader.parse(jsonStream, jsonConfig)) {
            CMN_LOG_CLASS_INIT_ERROR << "Configure " << this->GetName()
                                     << ": failed to parse configuration\n"
                                     << jsonReader.getFormattedErrorMessages();
            return;
        }

        ConfigureDH(jsonConfig);

        // should arm go to zero position when homing, default set in Init method
        const Json::Value jsonHomingGoesToZero = jsonConfig["homing-zero-position"];
        if (!jsonHomingGoesToZero.isNull()) {
            HomingGoesToZero = jsonHomingGoesToZero.asBool();
        }

        // load tool tip transform if any (for up/down endoscopes)
        const Json::Value jsonToolTip = jsonConfig["tooltip-offset"];
        if (!jsonToolTip.isNull()) {
            cmnDataJSON<vctFrm4x4>::DeSerializeText(ToolOffsetTransformation, jsonToolTip);
            ToolOffset = new robManipulator(ToolOffsetTransformation);
            Manipulator.Attach(ToolOffset);
        }
    } catch (...) {
        CMN_LOG_CLASS_INIT_ERROR << "Configure " << this->GetName() << ": make sure the file \""
                                 << filename << "\" is in JSON format" << std::endl;
    }
}
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();
    }
}
 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;
 }
Example #5
0
void GetVal(Json::Value &config, bool* setting)
{
	if (config.isNull())
		return;

	*setting = config.asBool();
}
Example #6
0
	Value convert_json(const Json::Value &val)
	{
		using namespace Json;
		switch (val.type())
		{
		case nullValue:
			return Nil;
		case intValue:
			return value(val.asInt64());
		case uintValue:
			return value((int64_t)val.asUInt64());
		case realValue:
			return value(val.asDouble());
		case stringValue:
			return value(val.asString());
		case booleanValue:
			return bvalue(val.asBool());
		case arrayValue:
			return convert_json_array(val);
		case objectValue:
			return convert_json_complex(val);
		default:
			throw loader_error("Invalid value encountered while parsing json");
		}
	}
Example #7
0
		AnyValue JsonSerializer::toAny(const Json::Value & val)
		{
			std::vector<AnyValue> arr;
			Bundle b;
			switch (val.type())
			{
			case Json::ValueType::arrayValue:
				for (auto e : val) arr.push_back(this->toAny(e));
				return arr;
			case Json::ValueType::booleanValue:
				return val.asBool();
			case Json::ValueType::intValue:
				return (int64_t)val.asInt64();
			case Json::ValueType::nullValue:
				return nullptr;
			case Json::ValueType::objectValue:
				for (Json::ValueConstIterator it = val.begin(); it != val.end(); it++)
				{
					std::string name = it.name();
					b.set(name, this->toAny(*it));
				}
				return b;
			case Json::ValueType::realValue:
				return val.asDouble();
			case Json::ValueType::stringValue:
				return val.asString();
			case Json::ValueType::uintValue:
				return (uint64_t)val.asUInt64();
			}
			return AnyValue();
		}
Example #8
0
    Expectations::Expectations(Json::Value jsonElement) {
        if (jsonElement.empty()) {
            fIgnoreFailure = kDefaultIgnoreFailure;
        } else {
            Json::Value ignoreFailure = jsonElement[kJsonKey_ExpectedResults_IgnoreFailure];
            if (ignoreFailure.isNull()) {
                fIgnoreFailure = kDefaultIgnoreFailure;
            } else if (!ignoreFailure.isBool()) {
                SkDebugf("found non-boolean json value for key '%s' in element '%s'\n",
                         kJsonKey_ExpectedResults_IgnoreFailure,
                         jsonElement.toStyledString().c_str());
                DEBUGFAIL_SEE_STDERR;
                fIgnoreFailure = kDefaultIgnoreFailure;
            } else {
                fIgnoreFailure = ignoreFailure.asBool();
            }

            Json::Value allowedDigests = jsonElement[kJsonKey_ExpectedResults_AllowedDigests];
            if (allowedDigests.isNull()) {
                // ok, we'll just assume there aren't any AllowedDigests to compare against
            } else if (!allowedDigests.isArray()) {
                SkDebugf("found non-array json value for key '%s' in element '%s'\n",
                         kJsonKey_ExpectedResults_AllowedDigests,
                         jsonElement.toStyledString().c_str());
                DEBUGFAIL_SEE_STDERR;
            } else {
                for (Json::ArrayIndex i=0; i<allowedDigests.size(); i++) {
                    fAllowedResultDigests.push_back(GmResultDigest(allowedDigests[i]));
                }
            }
        }
    }
Example #9
0
void Object::set (std::string const& k, Json::Value const& v)
{
    auto t = v.type();
    switch (t)
    {
    case Json::nullValue:
        return set (k, nullptr);
    case Json::intValue:
        return set (k, v.asInt());
    case Json::uintValue:
        return set (k, v.asUInt());
    case Json::realValue:
        return set (k, v.asDouble());
    case Json::stringValue:
        return set (k, v.asString());
    case Json::booleanValue:
        return set (k, v.asBool());

    case Json::objectValue:
    {
        auto object = setObject (k);
        copyFrom (object, v);
        return;
    }

    case Json::arrayValue:
    {
        auto array = setArray (k);
        for (auto& item: v)
            array.append (item);
        return;
    }
    }
    assert (false);  // Can't get here.
}
Example #10
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 #11
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 #12
0
static void
printValueTree( FILE *fout, Json::Value &value, const std::string &path = "." )
{
   switch ( value.type() )
   {
   case Json::nullValue:
      fprintf( fout, "%s=null\n", path.c_str() );
      break;
   case Json::intValue:
      fprintf( fout, "%s=%s\n", path.c_str(), Json::valueToString( value.asLargestInt() ).c_str() );
      break;
   case Json::uintValue:
      fprintf( fout, "%s=%s\n", path.c_str(), Json::valueToString( value.asLargestUInt() ).c_str() );
      break;
   case Json::realValue:
       fprintf( fout, "%s=%s\n", path.c_str(), normalizeFloatingPointStr(value.asDouble()).c_str() );
      break;
   case Json::stringValue:
      fprintf( fout, "%s=\"%s\"\n", path.c_str(), value.asString().c_str() );
      break;
   case Json::booleanValue:
      fprintf( fout, "%s=%s\n", path.c_str(), value.asBool() ? "true" : "false" );
      break;
   case Json::arrayValue:
      {
         fprintf( fout, "%s=[]\n", path.c_str() );
         int size = value.size();
         for ( int index =0; index < size; ++index )
         {
            static char buffer[16];
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
            sprintf_s( buffer, sizeof(buffer), "[%d]", index );
#else
            snprintf( buffer, sizeof(buffer), "[%d]", index );
#endif
            printValueTree( fout, value[index], path + buffer );
         }
      }
      break;
   case Json::objectValue:
      {
         fprintf( fout, "%s={}\n", path.c_str() );
         Json::Value::Members members( value.getMemberNames() );
         std::sort( members.begin(), members.end() );
         std::string suffix = *(path.end()-1) == '.' ? "" : ".";
         for ( Json::Value::Members::iterator it = members.begin(); 
               it != members.end(); 
               ++it )
         {
            const std::string &name = *it;
            printValueTree( fout, value[name], path + suffix + name );
         }
      }
      break;
   default:
      break;
   }
}
Example #13
0
bool GetBool( Json::Value const &V, bool& O)
{
    if ( !V.isBool() )
    {
        return false;
    }
    O = V.asBool();
    return true;
}
Example #14
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 #15
0
bool BlockChain::isSyncing()
{
    Json::Value result = _provider.request("eth_isSyncing");
    if(result.isBool())
    {
        return result.asBool();
    }
    return true;
}
Example #16
0
bool ConfigFile::is_data_shared_1(std::string package) {
    const Json::Value sharedata =
            m_root[CONF_PACKAGES][package][CONF_SHARE_DATA];

    if (!sharedata.isNull() && !sharedata.isBool()) {
        return sharedata.asBool();
    }

    return false;
}
Example #17
0
bool GetBool(const Json::Value& value, bool* out) {
  if (value.isNull()) {
    return false;
  }
  if (!value.isBool()) {
    return false;
  }
  *out = value.asBool();
  return true;
}
Example #18
0
int GetJsonInt(const Json::Value& _jsValue)
{
	if ( _jsValue.type() == Json::intValue)
		return _jsValue.asInt();
	else if (_jsValue.type() == Json::stringValue)
		return atoi(_jsValue.asCString());
	else if (_jsValue.isBool())
		return (int)_jsValue.asBool();
	return 0;
}
Example #19
0
File: main.cpp Project: tuita/DOMQ
static void
printValueTree( FILE *fout, Json::Value &value, const std::string &path = "." )
{
   switch ( value.type() )
   {
   case Json::nullValue:
      fprintf( fout, "%s=null\n", path.c_str() );
      break;
   case Json::intValue:
      fprintf( fout, "%s=%ld\n", path.c_str(), value.asInt() );
      break;
   case Json::uintValue:
      fprintf( fout, "%s=%lu\n", path.c_str(), value.asUInt() );
      break;
   case Json::realValue:
      fprintf( fout, "%s=%.16g\n", path.c_str(), value.asDouble() );
      break;
   case Json::stringValue:
      fprintf( fout, "%s=\"%s\"\n", path.c_str(), value.asString().c_str() );
      break;
   case Json::booleanValue:
      fprintf( fout, "%s=%s\n", path.c_str(), value.asBool() ? "true" : "false" );
      break;
   case Json::arrayValue:
      {
         fprintf( fout, "%s=[]\n", path.c_str() );
         int size = value.size();
         for ( int index =0; index < size; ++index )
         {
            static char buffer[16];
            sprintf( buffer, "[%d]", index );
            printValueTree( fout, value[index], path + buffer );
         }
      }
      break;
   case Json::objectValue:
      {
         fprintf( fout, "%s={}\n", path.c_str() );
         Json::Value::Members members( value.getMemberNames() );
         std::sort( members.begin(), members.end() );
         std::string suffix = *(path.end()-1) == '.' ? "" : ".";
         for ( Json::Value::Members::iterator it = members.begin(); 
               it != members.end(); 
               ++it )
         {
            const std::string &name = *it;
            printValueTree( fout, value[name], path + suffix + name );
         }
      }
      break;
   default:
      break;
   }
}
Example #20
0
    bool JsonUtils::asBool(const Json::Value &value, bool defaultValue)
    {
        bool returned = defaultValue;

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

        if(value.isBool())
            returned = value.asBool();

        return returned;
    }
Example #21
0
//------------------------------------------------------------------------------
bool WidgetHints::isEnabled(const std::string &name) const
{
  Json::Value value = this->Internals->findValue(name + "/enabled");

  if (value.isBool())
    {
    return value.asBool();
    }

  // True by default:
  return true;
}
Example #22
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 #23
0
void util::PrintJSONValue( Json::Value val ){
	if( val.isString() ) {
		printf( "string(%s)", val.asString().c_str() ); 
	} else if( val.isBool() ) {
		printf( "bool(%d)", val.asBool() ); 
	} else if( val.isInt() ) {
		printf( "int(%d)", val.asInt() ); 
	} else if( val.isUInt() ) {
		printf( "uint(%u)", val.asUInt() ); 
	} else if( val.isDouble() ) {
		printf( "double(%f)", val.asDouble() ); 
	} else {
		printf( "unknown type=[%d]", val.type() ); 
	}
}
Example #24
0
bool deserialize(const Json::Value& node, bool& b)
{
	if (node.empty())
	{
		std::cout << "Node is empty." << std::endl;
		return false;
	}
	if (!node.isBool())
	{
		std::cout << "Node data type is not boolean." << std::endl;
		return false;
	}
	b = node.asBool();
	return true;
}
bool JsonParser::GetBool(const int nIndex)
{
	if((nIndex < 0) || (m_pRoot == NULL))
	{
		return false;
	}

	Json::Value *pChild = GetChildByIndex(nIndex);
	if( pChild  == NULL)
	{
		return false;
	}

	return pChild->asBool();
}
bool JsonParser::GetBool(const char* pName)
{
	if(!pName || (m_pRoot == NULL))
	{
		return false;
	}

	Json::Value *pChild = GetChildByName(string(pName));
	if( pChild  == NULL)
	{
		return false;
	}

	return pChild->asBool();
}
Example #27
0
    static inline
    void
    pack(msgpack::packer<Stream>& packer, const Json::Value& source) {
        switch(source.type()) {
        case Json::objectValue: {
            packer.pack_map(source.size());

            const Json::Value::Members keys(source.getMemberNames());

            for(auto it = keys.begin(); it != keys.end(); ++it) {
                packer << *it;
                pack(packer, source[*it]);
            }
        } break;

        case Json::arrayValue: {
            packer.pack_array(source.size());

            for(auto it = source.begin(); it != source.end(); ++it) {
                pack(packer, *it);
            }
        } break;

        case Json::booleanValue: {
            packer << source.asBool();
        } break;

        case Json::stringValue: {
            packer << source.asString();
        } break;

        case Json::realValue: {
            packer << source.asDouble();
        } break;

        case Json::intValue: {
            packer << source.asLargestInt();
        } break;

        case Json::uintValue: {
            packer << source.asLargestUInt();
        } break;

        case Json::nullValue: {
            packer << msgpack::type::nil();
        }}
    }
static void JsonToLLSD(const Json::Value &root, LLSD &output)
{
	if(root.isObject())
	{
		Json::Value::Members keys = root.getMemberNames();
		for(Json::Value::Members::const_iterator itr = keys.begin(); itr != keys.end(); ++itr)
		{
			LLSD elem;
			JsonToLLSD(root[*itr], elem);
			output[*itr] = elem;
		}
	}
	else if(root.isArray())
	{
		for(Json::Value::const_iterator itr = root.begin(); itr != root.end(); ++itr)
		{
			LLSD elem;
			JsonToLLSD(*itr, elem);
			output.append(elem);
		}
	}
	else
	{
		switch(root.type())
		{
			case Json::intValue:
				output = root.asInt();
				break;
			case Json::realValue:
			case Json::uintValue:
				output = root.asDouble();
				break;
			case Json::stringValue:
				output = root.asString();
				break;
			case Json::booleanValue:
				output = root.asBool();
				break;
			case Json::nullValue:
				output = LLSD();
				break;
			default:
				break;
		}
	}
}
Example #29
0
inline void duk_push_json(duk_context *ctx, Json::Value val) {
	Json::ValueType type = val.type();

	int length, obj_index;

	switch (type) {
		case Json::nullValue:
			duk_push_null(ctx);
			break;
		case Json::intValue:
		case Json::uintValue:
		case Json::realValue:
			duk_push_number(ctx, val.asDouble());
			break;
		case Json::stringValue:
			duk_push_string(ctx, val.asCString());
			break;
		case Json::booleanValue:
			duk_push_boolean(ctx, val.asBool());
			break;
		case Json::arrayValue:
			length = val.size();
			obj_index = duk_push_array(ctx);

			for (int ndx = 0; ndx < length; ndx ++) {
				duk_push_json(ctx, val[ndx]);
				duk_put_prop_index(ctx, obj_index, ndx);
			}
			break;
		case Json::objectValue:
			obj_index = duk_push_object(ctx);

			Json::Value::Members keys = val.getMemberNames();
			Json::Value::Members::iterator it = keys.begin();
			while (it != keys.end()) {
				Json::Value value = val[*it];
				duk_push_string(ctx, it->c_str());
				duk_push_json(ctx, value);

				duk_put_prop(ctx, obj_index);

				it ++;
			}
			break;
	}
}
Example #30
0
void LCDCore::StartLayout(std::string key) {
    if(key == "") {
        gen_(current_layout_, last_layout_);
    } else {
        current_layout_ = key;
    }

    LCDError("StartLayout: %s", current_layout_.c_str());
    //emit static_cast<LCDEvents *>(wrapper_)->_LayoutChangeBefore();
    std::map<std::string, Widget *> widgets = widgets_;
    for(std::map<std::string,Widget *>::iterator w = widgets.begin(); 
        w != widgets.end(); w++){

	if(!w->second) LCDError("w->second is null");
    	if(w->second && (current_layout_ == w->second->GetLayoutBase() || w->second->GetLayoutBase() == name_ )) {
            if( type_ == LCD_TEXT &&
                (w->second->GetType() & WIDGET_TYPE_SPECIAL)) {

                    w->second->SetupChars();
            }
            w->second->Start();
    	}
    }

    //emit static_cast<LCDEvents *>(wrapper_)->_LayoutChangeAfter();

    Json::Value *timeout = CFG_Fetch(CFG_Get_Root(), 
        current_layout_ + ".timeout", new Json::Value(layout_timeout_));

/*
    if(timeout->asInt() > 0)
        timer_->start(timeout->asInt());
*/

    delete timeout;

    Json::Value *val = CFG_Fetch_Raw(CFG_Get_Root(), current_layout_ + 
        ".clear_on_layout_change", new Json::Value(clear_on_layout_change_));

    clear_on_layout_change_ = val->asBool();

    LCDError("StartLayout end: %s", current_layout_.c_str());
    delete val;
}