Klamp't  0.8.1
JSON.h
1 #ifndef IO_JSON_H
2 #define IO_JSON_H
3 
4 #include <Klampt/Modeling/Resources.h>
5 #include <KrisLibrary/utils/AnyCollection.h>
6 
8 template <class T>
9 void Convert(const T& x,AnyCollection& c) { c = x; }
11 template <class T>
12 bool Convert(const AnyCollection& c,T& x) { return c.as<T>(x); }
13 
15 template <class T>
16 void Convert(const std::vector<T>& v,AnyCollection& c)
17 {
18  c.resize(v.size());
19  for(size_t i=0;i<v.size();i++)
20  Convert(v[i],c[(int)i]);
21 }
22 
24 template <class T>
25 bool Convert(const AnyCollection& c,std::vector<T>& v)
26 {
27  v.resize(c.size());
28  for(size_t i=0;i<v.size();i++)
29  if(!Convert(c[(int)i],v[i])) return false;
30  return true;
31 }
32 
33 void Convert(const Vector3& x,AnyCollection& c);
34 void Convert(const Vector& x,AnyCollection& c);
35 void Convert(const IKGoal& g,AnyCollection& c);
36 void Convert(const Hold& h,AnyCollection& c);
37 void Convert(const Grasp& g,AnyCollection& c);
38 void Convert(const Stance& s,AnyCollection& c);
39 bool Convert(const AnyCollection& c,Vector3& x);
40 bool Convert(const AnyCollection& c,Vector& x);
41 bool Convert(const AnyCollection& c,IKGoal& g);
42 bool Convert(const AnyCollection& c,Hold& h);
43 bool Convert(const AnyCollection& c,Grasp& g);
44 bool Convert(const AnyCollection& c,Stance& s);
45 
46 template <class T>
47 void SaveJSON(std::ostream& out,const T& x) {
48  AnyCollection msg;
49  Convert(x,msg);
50  out<<msg;
51 }
52 
53 
54 template <class T>
55 bool LoadJSON(std::istream& in,const T& x) {
56  AnyCollection msg;
57  in >> msg;
58  if(!in) return false;
59  return Convert(msg,x);
60 }
61 
62 #endif
A single contact between the robot and the environment.
Definition: Hold.h:26
A collection of holds.
Definition: Stance.h:19
Slightly more sophisticated than a Stance, a Grasp allows some of the robot&#39;s degrees of freedom to b...
Definition: Grasp.h:15
void Convert(const LinearPath &in, MultiPath &out)
Exact, direct conversion from LinearPath to MultiPath.