当前位置: 首页>>代码示例>>C++>>正文


C++ JsonTree类代码示例

本文整理汇总了C++中JsonTree的典型用法代码示例。如果您正苦于以下问题:C++ JsonTree类的具体用法?C++ JsonTree怎么用?C++ JsonTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了JsonTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: JsonTree

std::vector<Joint *> SkeletonData::LoadSkeleton(std::string filePath) {
	//Not sure about this error catching setup
	std::vector<Joint*> joints;

	if( PathFileExistsA(filePath.c_str()) == TRUE)  { 
		try{
			JsonTree doc = JsonTree(loadFile(filePath));

			JsonTree jointsJson = doc.getChild( "joints" );
			Joint * parent = nullptr;
			unsigned int i = 0;
			for( JsonTree::ConstIter joint = jointsJson.begin(); joint != jointsJson.end(); ++joint ) {
				// Apparently, getKey DOESN't return an index if there is no key? (Even though it says it will in the json.h header...)
				//JsonTree jJson = jointsJson.getChild(joint->getKey());
				JsonTree jJson = jointsJson.getChild(i);
				Joint * j = readJoint(jJson);
				joints.push_back(j);
				i++;
			}
		}catch (std::exception ex) {
			//throw ex;
			throw std::exception("Invalid File Format. File may be out of date.");
		}
	}else{
		throw std::exception("File does not exist!");
	}
	return joints;
}
开发者ID:seleb,项目名称:Ludum-Dare-32,代码行数:28,代码来源:SkeletonData.cpp

示例2: getAppPath

void OculusSocketServerApp::setup()
{
    mServerPort = 9005;

    string configPath = getAppPath().string() + "/config.json";
    
    if(fs::exists(configPath)) {
        JsonTree::ParseOptions options;
        options.ignoreErrors(true);

        try{
            JsonTree config = JsonTree( loadFile( configPath ));
            
            for( JsonTree::ConstIter cIt = config.begin(); cIt != config.end(); ++cIt )
            {
                if( "port" == (*cIt).getKey()){
                    mServerPort = std::stoi((*cIt).getValue());
                    console() << "Port found: " << mServerPort << std::endl;
                }
            }
            
        } catch(JsonTree::Exception ex){
            console() << "Unable to parse config file." << std::endl;
        }
    } else {
        console() << "No config file found." << std::endl;
    }

    mOculusConnected = false;
    mSocketConnected = false;
    
    mServer.addConnectCallback( &OculusSocketServerApp::onConnect, this );
	mServer.addDisconnectCallback( &OculusSocketServerApp::onDisconnect, this );
   
    mServer.listen(mServerPort);
    mOculusVR = Oculus::create();
    
    mBackgroundTexture = gl::Texture( loadImage( loadResource( RES_BACKGROUND_TEX ) ) );
}
开发者ID:nickoneill,项目名称:oculus-bridge,代码行数:39,代码来源:OculusSocketServerApp.cpp

示例3: clear

void ColorCubePoints::fromJson(const JsonTree &tree)
{
    clear();
    mOrigin = tree.getValueForKey<float>("origin");

    const JsonTree& points = tree.getChild("points");
    for (unsigned i = 0; i < points.getNumChildren(); i++) {
        const JsonTree& point = points.getChild(i);
        push(point.getValueAtIndex<float>(0),
             point.getValueAtIndex<float>(1),
             point.getValueAtIndex<float>(2));
    }
}
开发者ID:UIKit0,项目名称:forest,代码行数:13,代码来源:ColorCubePoints.cpp

示例4: JsonTree

std::string   Server::sendFbSharePlus()
{
	if (!RELEASE_VER) return SERVER_OK;

	std::map<string,string> strings;
	strings.insert(pair<string, string>( "action" , "cnt"));
	strings.insert(pair<string, string>( "cnt" ,     "1"));
	strings.insert(pair<string, string>( "type" ,  "fb"));
	string request =  Curl::post( SERVER"/save.php", strings);

	JsonTree jTree;

	try 
	{
		jTree = JsonTree(request);
		console()<<"Facebook PLUS   "<< jTree.getChild("cnt").getValue()<<std::endl;
		return SERVER_OK;
	}
	catch(...)
	{

	}
	return SERVER_ERROR;
}
开发者ID:20SecondsToSun,项目名称:PhotoBooth,代码行数:24,代码来源:Server.cpp

示例5: warp

//! to json
JsonTree	WarpPerspectiveBilinear::toJson() const
{
	JsonTree		json = WarpBilinear::toJson();
	if (json.hasChild("warp")) {
		JsonTree warp(json.getChild("warp"));
		// set corners
		JsonTree	corners = JsonTree::makeArray("corners");
		for (unsigned i = 0; i < 4; ++i) {
			vec2 corner = mWarp->getControlPoint(i);
			JsonTree	cr;
			cr.addChild(ci::JsonTree("corner", i));
			cr.addChild(ci::JsonTree("x", corner.x));
			cr.addChild(ci::JsonTree("y", corner.y));

			corners.pushBack(cr);
		}
		warp.pushBack(corners);
		json.pushBack(warp);
	}
	return json;
}
开发者ID:AVUIs,项目名称:AdamBrucePiotr,代码行数:22,代码来源:WarpPerspectiveBilinear.cpp

示例6: BeginPut

void AsyncHttpRequest::BeginPut(std::string path, JsonTree reqData, std::function<void(std::string)>&& Callback)
{
	std::string paramstr = reqData.serialize();
	tcp::resolver::query	query(_hostname, "http");

	std::ostream request_stream(&_request);
	request_stream << "PUT " << path << " HTTP/1.1\r\n";
	request_stream << "Host: " << _hostname << "\r\n";
	request_stream << "Accept: */*\r\n";
	request_stream << "Connection: close\r\n";
	request_stream << "Content-Length: " << paramstr.size() << "\r\n\r\n";
	request_stream << paramstr;

	_callback = Callback;
	_resolver.async_resolve(query,
		std::bind(&AsyncHttpRequest::handle_resolve, shared_from_this(), std::placeholders::_1, std::placeholders::_2));
}
开发者ID:greenbaum,项目名称:Cinder-HttpRequest,代码行数:17,代码来源:HttpRequest.cpp

示例7: toJson

void ColorCubePoints::toJson(JsonTree &tree)
{
    JsonTree points = JsonTree::makeArray("points");
 
    for (unsigned i = 0; i < mPoints.size(); i++) {
        JsonTree point;
        point.addChild(JsonTree("", mPoints[i].x));
        point.addChild(JsonTree("", mPoints[i].y));
        point.addChild(JsonTree("", mPoints[i].z));
        points.addChild(point);
    }

    tree.addChild(JsonTree("origin", mOrigin));
    tree.addChild(points);
}
开发者ID:UIKit0,项目名称:forest,代码行数:15,代码来源:ColorCubePoints.cpp

示例8: norm

JsonTree BSplineEditor::save()
{
	JsonTree tree = View::save();
	JsonTree subtree = JsonTree::makeArray( "POINTS" );
	for( auto &it : mControlPoints ) {
		vec2 mapped = norm( it );
		JsonTree subsubtree;
		subsubtree.addChild( JsonTree( "X", mapped.x ) );
		subsubtree.addChild( JsonTree( "Y", mapped.y ) );
		subtree.addChild( subsubtree );
	}
	if( subtree.getNumChildren() ) {
		tree.addChild( subtree );
	}
	return tree;
}
开发者ID:rezaali,项目名称:Cinder-UI,代码行数:16,代码来源:BSplineEditor.cpp

示例9: JsonTree

JsonTree View::save()
{
    JsonTree tree; 
    tree.addChild( JsonTree( "NAME", getName() ) );
    tree.addChild( JsonTree( "ID", getID() ) );
    tree.addChild( JsonTree( "TYPE", getType() ) );
    JsonTree subtree = JsonTree::makeArray( "SUBVIEWS" );
    for ( auto &it : mSubViews )
    {
        if( it->isSaveable() )
        {
            subtree.addChild( it->save() );
        }
    }
    if( subtree.getNumChildren() )
    {
        tree.addChild( subtree );
    }
    return tree;
}
开发者ID:pizthewiz,项目名称:Cinder-UI,代码行数:20,代码来源:View.cpp

示例10: while

// Function the background thread lives in
void TweetStream::serviceTweets()
{
	ThreadSetup threadSetup;
	std::string nextQueryString = "?q=" + Url::encode( mSearchPhrase );
	JsonTree searchResults;
	JsonTree::ConstIter resultIt = searchResults.end();

	// This function loops until the app quits. Each iteration a pulls out the next result from the Twitter API query.
	// When it reaches the last result of the current query it issues a new one, based on the "refresh_url" property
	// of the current query.
	// The loop doesn't spin (max out the processor) because ConcurrentCircularBuffer.pushFront() non-busy-waits for a new
	// slot in the circular buffer to become available.
	while( ! mCanceled ) {
		if( resultIt == searchResults.end() ) { 		// are we at the end of the results of this JSON query?
			// issue a new query
			try {
				JsonTree queryResult = queryTwitter( nextQueryString );
				// the next query will be the "refresh_url" of this one.
				nextQueryString = queryResult["refresh_url"].getValue();
				searchResults = queryResult.getChild( "results" );
				resultIt = searchResults.begin();
			}
			catch( ci::Exception &exc ) {
				// our API query failed: put up a "tweet" with our error
				CI_LOG_W( "exception caught parsing query: " << exc.what() );
				mBuffer.pushFront( Tweet( "Twitter API query failed", "sadness", SurfaceRef() ) );
				ci::sleep( 2000 ); // try again in 2 seconds
			}
		}
		if( resultIt != searchResults.end() ) {
			try {
				// get the URL and load the image for this profile
				Url profileImgUrl = (*resultIt)["profile_image_url"].getValue<Url>();
				SurfaceRef userIcon = Surface::create( loadImage( loadUrl( profileImgUrl ) ) );
				// pull out the text of the tweet and replace any XML-style escapes
				string text = replaceEscapes( (*resultIt)["text"].getValue() );
				string userName = (*resultIt)["from_user"].getValue();
				mBuffer.pushFront( Tweet( text, userName, userIcon ) );
			}
			catch( ci::Exception &exc ) {
				CI_LOG_W( "exception caught parsing search results: " << exc.what() );
			}
			++resultIt;
		}
	}
}
开发者ID:AbdelghaniDr,项目名称:Cinder,代码行数:47,代码来源:TweetStream.cpp

示例11: getAppPath

	void PretzelGlobal::loadSettings(fs::path settingsPath){
		fs::path loadPath = settingsPath;
		if (loadPath.string() == ""){
			loadPath = getAppPath() / "guiSettings" / "settings.json";
		}

		if (!fs::exists(loadPath)){
			console() << loadPath << " does not exist" << endl;
		}
		else{
			JsonTree loadTree(loadFile(loadPath));
			JsonTree appSettings = loadTree.getChild(0);

			for (int i = 0; i < mParamList.size(); i++){
				string pName = mParamList[i].name;
				switch (mParamList[i].type){
				case _FLOAT:
					if (appSettings.hasChild(pName)){
						float fVal = appSettings.getChild(pName).getValue<float>();
						*((float*)mParamList[i].value) = fVal;
					}
					break;
				case _INT:
					if (appSettings.hasChild(pName)){
						int fVal = appSettings.getChild(pName).getValue<int>();
						*((int*)mParamList[i].value) = fVal;
					}
					break;
				case _BOOL:
					if (appSettings.hasChild(pName)){
						bool bVal = appSettings.getChild(pName).getValue<float>();
						*((bool*)mParamList[i].value) = bVal;
					}
					break;
				default:
					console() << "Pretzel :: Can't load settings type " << endl;
					break;
				}
			}
		}
	}
开发者ID:imclab,项目名称:PretzelGui,代码行数:41,代码来源:PretzelGlobal.cpp

示例12: load

void View::load( const JsonTree &data )
{
    if( data.hasChild( "SUBVIEWS" ) && mLoadSubViews )
    {
        JsonTree tree = data.getChild( "SUBVIEWS" );
        int numSubViews = tree.getNumChildren();
        for(int i = 0; i < numSubViews; i++)
        {
            JsonTree sub = tree[i];
            ViewRef subview = getSubView( sub.getValueForKey( "NAME" ) );
            if( subview )
            {
                subview->load( sub ); 
            }
        }
    }    
}
开发者ID:pizthewiz,项目名称:Cinder-UI,代码行数:17,代码来源:View.cpp

示例13: getAppPath

	void PretzelGlobal::loadSettings(fs::path settingsPath){
		fs::path loadPath = settingsPath;
		if (loadPath.string() == ""){
			loadPath = getAppPath() / "guiSettings" / "settings.json";
		}

		if (!fs::exists(loadPath)){
			CI_LOG_W("Pretzel :: Can't load ") << loadPath << " Path does not exist.";
		}
		else{
			JsonTree loadTree(loadFile(loadPath));
			JsonTree appSettings = loadTree.getChild(0);

			for (int i = 0; i < mParamList.size(); i++){
				string pName = mParamList[i].name;
				switch (mParamList[i].type){
				case _FLOAT:
					if (appSettings.hasChild(pName)){
						float fVal = appSettings.getChild(pName).getValue<float>();
						*((float*)mParamList[i].value) = fVal;
					}
					break;
				case _INT:
					if (appSettings.hasChild(pName)){
						int fVal = appSettings.getChild(pName).getValue<int>();
						*((int*)mParamList[i].value) = fVal;
					}
					break;
				case _BOOL:
					if (appSettings.hasChild(pName)){
						bool bVal = appSettings.getChild(pName).getValue<float>();
						*((bool*)mParamList[i].value) = bVal;
					}
					break;
				case _STRING:
					if (appSettings.hasChild(pName)){
						std::string sVal = appSettings.getChild(pName).getValue<std::string>();
						*((std::string*)mParamList[i].value) = sVal;
					}
					break;
                case _VEC2:
                    if (appSettings.hasChild(pName)){
                        vec2 p;
                        p.x = appSettings.getChild(pName).getChild("x").getValue<float>();
                        p.y = appSettings.getChild(pName).getChild("y").getValue<float>();
                        *((vec2*)mParamList[i].value) = p;
                    }
                    break;
                case _VEC3:
                    if (appSettings.hasChild(pName)){
                        vec3 p;
                        p.x = appSettings.getChild(pName).getChild("x").getValue<float>();
                        p.y = appSettings.getChild(pName).getChild("y").getValue<float>();
                        p.z = appSettings.getChild(pName).getChild("z").getValue<float>();
                        *((vec3*)mParamList[i].value) = p;
                    }
                    break;
                case _COLOR:
                    if (appSettings.hasChild(pName)){
                        Color p;
                        p.r = appSettings.getChild(pName).getChild("r").getValue<float>();
                        p.g = appSettings.getChild(pName).getChild("g").getValue<float>();
                        p.b = appSettings.getChild(pName).getChild("b").getValue<float>();
                        *((Color*)mParamList[i].value) = p;
                    }
                    break;
                case _COLORA:
                    if (appSettings.hasChild(pName)){
                        ColorA p;
                        p.r = appSettings.getChild(pName).getChild("r").getValue<float>();
                        p.g = appSettings.getChild(pName).getChild("g").getValue<float>();
                        p.b = appSettings.getChild(pName).getChild("b").getValue<float>();
                        p.a = appSettings.getChild(pName).getChild("a").getValue<float>();
                        *((ColorA*)mParamList[i].value) = p;
                    }
                    break;
				default:
					CI_LOG_W( "Pretzel :: Unrecognized settings type.");
					break;
				}
			}
		}
        signalOnSettingsLoad.emit();
	}
开发者ID:cwhitney,项目名称:PretzelGui,代码行数:84,代码来源:PretzelGlobal.cpp

示例14: save

void Param::save() {
  JsonTree Position;
  Position = JsonTree::makeObject("Position");
  Position.addChild(JsonTree("x", pos.x));
  Position.addChild(JsonTree("y", pos.y));
  Position.addChild(JsonTree("z", pos.z));
  
  JsonTree Size;
  Size = JsonTree::makeObject("Size");
  Size.addChild(JsonTree("x", size.x));
  Size.addChild(JsonTree("y", size.y));
  Size.addChild(JsonTree("z", size.z));
  
  JsonTree Color;
  Color = JsonTree::makeObject("Color");
  Color.addChild(JsonTree("r", color.r));
  Color.addChild(JsonTree("g", color.g));
  Color.addChild(JsonTree("b", color.b));
  Color.addChild(JsonTree("a", color.a));
  
  JsonTree data;
  data = JsonTree::makeObject(name);
  data.addChild(Position);
  data.addChild(Size);
  data.addChild(Color);
}
开发者ID:PS14,项目名称:Cinder-Sample,代码行数:26,代码来源:Param.cpp

示例15: throw

JsonTree::ExcNonConvertible::ExcNonConvertible( const JsonTree &node ) throw()
{
	sprintf( mMessage, "Unable to convert value for node: %s", node.getPath().c_str() );
}
开发者ID:RudyOddity,项目名称:Cinder,代码行数:4,代码来源:Json.cpp


注:本文中的JsonTree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。