NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
AppJSONTests.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
27 // This application
28 
29 // This library
30 #include "helpers/FileHelpers.h"
31 // JSON
32 #include <json/json.h>
33 #include <json/value.h>
34 // The C++ Standard Library
35 #include <iostream>
36 #include <exception>
37 #include <vector>
38 
46 int main(int argc, char** argv)
47 {
48  std::cout << "AppJSONTests" << std::endl;
49 
50  //BEGIN DESERIALIZING
51 
52  Json::Value root; // will contains the root value after parsing.
53  Json::Reader reader;
54 
55  bool parsingSuccessful = reader.parse( FileHelpers::getFileString("controlVars.json"), root );
56  if ( !parsingSuccessful )
57  {
58  // report to the user the failure and their locations in the document.
59  std::cout << "Failed to parse configuration\n"
60  << reader.getFormattedErrorMessages();
62  }
63  // Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
64  // such member.
65  Json::Value CPGVals = root.get("CPGVals", "UTF-8");
66 
67  std::cout << CPGVals.size() << " " << CPGVals[0].size()<< std::endl;
68 
69  Json::Value::iterator CPGIt = CPGVals.begin();
70 
71  std::vector<double> CPGVect;
72 
73  for(CPGIt = CPGVals.begin(); CPGIt != CPGVals.end(); CPGIt++)
74  {
75  std::cout << *CPGIt << std::endl;
76  CPGVect.push_back((*CPGIt)[0].asDouble());
77  }
78 
79  std::cout << CPGVals << std::endl;
80 
81  for(std::size_t i = 0; i < CPGVect.size(); i++)
82  {
83  std::cout << CPGVect[i] << " ";
84  }
85 
86  std::cout << std::endl;
87 
88  //Teardown is handled by delete, so that should be automatic
89  return 0;
90 }
int main(int argc, char **argv)
A series of functions to assist with file input/output.