LEMUR Packages: ompl_lemur or_lemur pr_bgl prpy_lemur
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Groups Pages
params_family.h
Go to the documentation of this file.
1 
7 namespace or_lemur
8 {
9 
10 //
12 {
13 public:
14 
15  bool has_family_module;
16  std::string family_module;
17 
18  // list of family cache filenames
19  // note there's a difference between no <family_caches> and an empty <family_caches>
20  struct SetCache
21  {
22  std::string name;
23  std::string filename;
24  };
25  bool has_family_setcaches;
26  std::vector< SetCache > family_setcaches;
27 
29  has_family_module(false)
30  {
31  _vXMLParameters.push_back("family_module");
32  _vXMLParameters.push_back("family_setcaches");
33  }
34 
35 private:
36  // path we're currently deserializing
37  std::string family_path;
38  SetCache family_setcache_cur;
39 
40 protected:
41  bool serialize(std::ostream& sout, int options=0) const
42  {
43  if (!or_lemur::LEMURParameters::serialize(sout,options))
44  return false;
45  if (has_family_module)
46  sout << "<family_module>" << family_module << "</family_module>";
47  if (has_family_setcaches)
48  {
49  sout << "<family_setcaches>";
50  for (unsigned int ui=0; ui<family_setcaches.size(); ui++)
51  {
52  sout << "<setcache>";
53  sout << "<name>" << family_setcaches[ui].name << "</name>";
54  sout << "<filename>" << family_setcaches[ui].filename << "</filename>";
55  sout << "</setcache>";
56  }
57  sout << "</family_setcaches>";
58  }
59  return !!sout;
60  }
61 
62  OpenRAVE::BaseXMLReader::ProcessElement startElement(
63  const std::string & name, const OpenRAVE::AttributesList & atts)
64  {
65  OpenRAVE::BaseXMLReader::ProcessElement ret = PE_Ignore;
66  if (family_path == "")
67  {
68  if (name == "family_module"
69  || name == "family_setcaches")
70  {
71  family_path = name;
72  ret = PE_Support;
73  }
74  else
75  {
76  // ask base class
77  return or_lemur::LEMURParameters::startElement(name,atts);
78  }
79  }
80  else if (family_path == "family_setcaches")
81  {
82  if (name == "setcache")
83  {
84  family_path = "family_setcaches/" + name;
85  family_setcache_cur.name = "";
86  family_setcache_cur.filename = "";
87  ret = PE_Support;
88  }
89  }
90  else if (family_path == "family_setcaches/setcache")
91  {
92  if (name == "name"
93  || name == "filename")
94  {
95  family_path = "family_setcaches/setcache/" + name;
96  ret = PE_Support;
97  }
98  }
99  if (ret == PE_Support)
100  _ss.str("");
101  if (ret == PE_Ignore)
102  RAVELOG_WARN("Ignoring unknown tag <%s>!\n", name.c_str());
103  return ret;
104  }
105 
106  bool endElement(const std::string & name)
107  {
108  if (family_path == "")
109  return or_lemur::LEMURParameters::endElement(name);
110  if (family_path == "family_module")
111  {
112  family_module = _ss.str();
113  has_family_module = true;
114  family_path = "";
115  return false;
116  }
117  if (family_path == "family_setcaches/setcache/name")
118  {
119  if (name != "name")
120  RAVELOG_WARN("Closing tag <%s> doesn't match opening tag <name>!\n", name.c_str());
121  family_setcache_cur.name = _ss.str();
122  family_path = "family_setcaches/setcache";
123  return false;
124  }
125  if (family_path == "family_setcaches/setcache/filename")
126  {
127  if (name != "filename")
128  RAVELOG_WARN("Closing tag <%s> doesn't match opening tag <filename>!\n", name.c_str());
129  family_setcache_cur.filename = _ss.str();
130  family_path = "family_setcaches/setcache";
131  return false;
132  }
133  if (family_path == "family_setcaches/setcache")
134  {
135  family_setcaches.push_back(family_setcache_cur);
136  family_path = "family_setcaches";
137  return false;
138  }
139  if (family_path == "family_setcaches")
140  {
141  has_family_setcaches = true;
142  family_path = "";
143  return false;
144  }
145  RAVELOG_ERROR("Parse error!");
146  return false;
147  }
148 };
149 
150 typedef boost::shared_ptr<FamilyParameters> FamilyParametersPtr;
151 typedef boost::shared_ptr<FamilyParameters const> FamilyParametersConstPtr;
152 
153 } // namespace or_lemur
Definition: params_family.h:11
Definition: params_lemur.h:11
Definition: params_family.h:20