本文整理汇总了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;
}
示例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 ) ) );
}
示例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));
}
}
示例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;
}
示例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;
}
示例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));
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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;
}
}
}
}
示例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 );
}
}
}
}
示例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();
}
示例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);
}
示例15: throw
JsonTree::ExcNonConvertible::ExcNonConvertible( const JsonTree &node ) throw()
{
sprintf( mMessage, "Unable to convert value for node: %s", node.getPath().c_str() );
}