All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SDF.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef SDF_HH
18 #define SDF_HH
19 
20 #include <vector>
21 #include <string>
22 #include <boost/shared_ptr.hpp>
23 #include <boost/enable_shared_from_this.hpp>
24 
26 
27 #define SDF_VERSION "1.4"
28 
31 namespace sdf
32 {
33  class SDF;
34  class Element;
35  typedef boost::shared_ptr<SDF> SDFPtr;
36  typedef boost::shared_ptr<Element> ElementPtr;
37  typedef std::vector< ElementPtr > ElementPtr_V;
38 
41  void addURIPath(const std::string &_uri, const std::string &_path);
42 
45  void setFindCallback(boost::function<std::string (const std::string &)> _cb);
46 
49 
51  class Element : public boost::enable_shared_from_this<Element>
52  {
53  public: Element();
54  public: virtual ~Element() GAZEBO_DEPRECATED(1.6);
55 
56  public: boost::shared_ptr<Element> Clone() const GAZEBO_DEPRECATED(1.6);
57 
59  public: void Copy(const ElementPtr _elem) GAZEBO_DEPRECATED(1.6);
60 
61  public: ElementPtr GetParent() const GAZEBO_DEPRECATED(1.6);
62  public: void SetParent(const ElementPtr _parent) GAZEBO_DEPRECATED(1.6);
63 
64  public: void SetName(const std::string &_name) GAZEBO_DEPRECATED(1.6);
65  public: const std::string &GetName() const GAZEBO_DEPRECATED(1.6);
66 
67  public: void SetRequired(const std::string &_req) GAZEBO_DEPRECATED(1.6);
68  public: const std::string &GetRequired() const GAZEBO_DEPRECATED(1.6);
69 
70  public: void SetCopyChildren(bool _value) GAZEBO_DEPRECATED(1.6);
71  public: bool GetCopyChildren() const GAZEBO_DEPRECATED(1.6);
72 
73  public: void PrintDescription(std::string _prefix) GAZEBO_DEPRECATED(1.6);
74  public: void PrintValues(std::string _prefix) GAZEBO_DEPRECATED(1.6);
75  public: void PrintWiki(std::string _prefix) GAZEBO_DEPRECATED(1.6);
76 
83  public: void PrintDocLeftPane(std::string &_html,
84  int _spacing, int &_index) GAZEBO_DEPRECATED(1.6);
85 
91  public: void PrintDocRightPane(std::string &_html,
92  int _spacing, int &_index) GAZEBO_DEPRECATED(1.6);
93 
94  private: void ToString(const std::string &_prefix,
95  std::ostringstream &_out) const GAZEBO_DEPRECATED(1.6);
96  public: std::string ToString(
97  const std::string &_prefix) const GAZEBO_DEPRECATED(1.6);
98 
99  public: void AddAttribute(const std::string &_key,
100  const std::string &_type,
101  const std::string &_defaultvalue,
102  bool _required,
103  const std::string &_description="")
104  GAZEBO_DEPRECATED(1.6);
105 
106  public: void AddValue(const std::string &_type,
107  const std::string &_defaultValue, bool _required,
108  const std::string &_description="")
109  GAZEBO_DEPRECATED(1.6);
110 
113  public: ParamPtr GetAttribute(
114  const std::string &_key) GAZEBO_DEPRECATED(1.6);
115 
117  public: unsigned int GetAttributeCount() const GAZEBO_DEPRECATED(1.6);
118 
120  public: ParamPtr GetAttribute(
121  unsigned int _index) const GAZEBO_DEPRECATED(1.6);
122 
124  public: unsigned int GetElementDescriptionCount() const
125  GAZEBO_DEPRECATED(1.6);
126 
128  public: ElementPtr GetElementDescription(unsigned int _index) const
129  GAZEBO_DEPRECATED(1.6);
130 
132  public: ElementPtr GetElementDescription(const std::string &_key) const
133  GAZEBO_DEPRECATED(1.6);
134 
136  public: bool HasElementDescription(
137  const std::string &_name) GAZEBO_DEPRECATED(1.6);
138 
139  public: bool HasAttribute(const std::string &_key) GAZEBO_DEPRECATED(1.6);
140 
142  public: bool GetAttributeSet(const std::string &_key)
143  GAZEBO_DEPRECATED(1.6);
144 
146  public: ParamPtr GetValue() GAZEBO_DEPRECATED(1.6);
147 
148  public: bool GetValueBool(
149  const std::string &_key = "") GAZEBO_DEPRECATED(1.6);
150  public: int GetValueInt(const std::string &_key = "")
151  GAZEBO_DEPRECATED(1.6);
152  public: float GetValueFloat(const std::string &_key = "")
153  GAZEBO_DEPRECATED(1.6);
154  public: double GetValueDouble(const std::string &_key = "")
155  GAZEBO_DEPRECATED(1.6);
156  public: unsigned int GetValueUInt(const std::string &_key = "")
157  GAZEBO_DEPRECATED(1.6);
158  public: char GetValueChar(const std::string &_key = "")
159  GAZEBO_DEPRECATED(1.6);
160  public: std::string GetValueString(const std::string &_key = "")
161  GAZEBO_DEPRECATED(1.6);
162  public: gazebo::math::Vector3 GetValueVector3(const std::string &_key = "")
163  GAZEBO_DEPRECATED(1.6);
165  const std::string &_key = "") GAZEBO_DEPRECATED(1.6);
167  const std::string &_key = "") GAZEBO_DEPRECATED(1.6);
168  public: gazebo::math::Pose GetValuePose(const std::string &_key = "")
169  GAZEBO_DEPRECATED(1.6);
170  public: gazebo::common::Color GetValueColor(const std::string &_key = "")
171  GAZEBO_DEPRECATED(1.6);
172  public: gazebo::common::Time GetValueTime(const std::string &_key = "")
173  GAZEBO_DEPRECATED(1.6);
174 
175  public: template<typename T>
176  T Get(const std::string &_key = "")
177  {
178  T result = T();
179 
180  if (_key.empty() && this->value)
181  this->value->Get<T>(result);
182  else if (!_key.empty())
183  {
184  ParamPtr param = this->GetAttribute(_key);
185  if (param)
186  param->Get(result);
187  else if (this->HasElement(_key))
188  result = this->GetElementImpl(_key)->Get<T>();
189  else if (this->HasElementDescription(_key))
190  result = this->GetElementDescription(_key)->Get<T>();
191  else
192  gzerr << "Unable to find value for key[" << _key << "]\n";
193  }
194  return result;
195  }
196 
197  public: bool Set(const bool &_value) GAZEBO_DEPRECATED(1.6);
198  public: bool Set(const int &_value) GAZEBO_DEPRECATED(1.6);
199  public: bool Set(const unsigned int &_value) GAZEBO_DEPRECATED(1.6);
200  public: bool Set(const float &_value) GAZEBO_DEPRECATED(1.6);
201  public: bool Set(const double &_value) GAZEBO_DEPRECATED(1.6);
202  public: bool Set(const char &_value) GAZEBO_DEPRECATED(1.6);
203  public: bool Set(const std::string &_value) GAZEBO_DEPRECATED(1.6);
204  public: bool Set(const char *_value) GAZEBO_DEPRECATED(1.6);
205  public: bool Set(
206  const gazebo::math::Vector3 &_value) GAZEBO_DEPRECATED(1.6);
207  public: bool Set(
208  const gazebo::math::Vector2i &_value) GAZEBO_DEPRECATED(1.6);
209  public: bool Set(
210  const gazebo::math::Vector2d &_value) GAZEBO_DEPRECATED(1.6);
211  public: bool Set(
212  const gazebo::math::Quaternion &_value) GAZEBO_DEPRECATED(1.6);
213  public: bool Set(
214  const gazebo::math::Pose &_value) GAZEBO_DEPRECATED(1.6);
215  public: bool Set(
216  const gazebo::common::Color &_value) GAZEBO_DEPRECATED(1.6);
217  public: bool Set(
218  const gazebo::common::Time &_value) GAZEBO_DEPRECATED(1.6);
219 
220  public: bool HasElement(
221  const std::string &_name) const GAZEBO_DEPRECATED(1.6);
222 
223  public: ElementPtr GetElement(
224  const std::string &_name) const GAZEBO_DEPRECATED(1.6);
225  public: ElementPtr GetFirstElement() const GAZEBO_DEPRECATED(1.6);
226 
227  public: ElementPtr GetNextElement(
228  const std::string &_name = "") const GAZEBO_DEPRECATED(1.6);
229 
230  public: ElementPtr GetElement(
231  const std::string &_name) GAZEBO_DEPRECATED(1.6);
232  public: ElementPtr AddElement(
233  const std::string &_name) GAZEBO_DEPRECATED(1.6);
234  public: void InsertElement(ElementPtr _elem) GAZEBO_DEPRECATED(1.6);
235 
237  public: void RemoveFromParent() GAZEBO_DEPRECATED(1.6);
238 
241  public: void RemoveChild(ElementPtr _child) GAZEBO_DEPRECATED(1.6);
242 
244  public: void ClearElements() GAZEBO_DEPRECATED(1.6);
245 
246  public: void Update() GAZEBO_DEPRECATED(1.6);
247  public: void Reset() GAZEBO_DEPRECATED(1.6);
248 
249  public: void SetInclude(
250  const std::string &_filename) GAZEBO_DEPRECATED(1.6);
251  public: std::string GetInclude() const GAZEBO_DEPRECATED(1.6);
252 
254  public: std::string GetDescription() const GAZEBO_DEPRECATED(1.6);
255 
257  public: void SetDescription(
258  const std::string &_desc) GAZEBO_DEPRECATED(1.6);
259 
261  public: void AddElementDescription(ElementPtr _elem) GAZEBO_DEPRECATED(1.6);
262 
263  private: boost::shared_ptr<Param> CreateParam(const std::string &_key,
264  const std::string &_type, const std::string &_defaultValue,
265  bool _required,
266  const std::string &_description="") GAZEBO_DEPRECATED(1.6);
267 
268  public: ElementPtr GetElementImpl(
269  const std::string &_name) const GAZEBO_DEPRECATED(1.6);
270 
271  private: std::string name;
272  private: std::string required;
273  private: std::string description;
274  private: bool copyChildren;
275 
276  private: ElementPtr parent;
277 
278  // Attributes of this element
279  private: Param_V attributes;
280 
281  // Value of this element
282  private: ParamPtr value;
283 
284  // The existing child elements
285  private: ElementPtr_V elements;
286 
287  // The possible child elements
288  private: ElementPtr_V elementDescriptions;
289 
291  private: std::string includeFilename;
292  };
293 
294 
296  class SDF
297  {
298  public: SDF() GAZEBO_DEPRECATED(1.6);
299  public: void PrintDescription() GAZEBO_DEPRECATED(1.6);
300  public: void PrintValues() GAZEBO_DEPRECATED(1.6);
301  public: void PrintWiki() GAZEBO_DEPRECATED(1.6);
302  public: void PrintDoc() GAZEBO_DEPRECATED(1.6);
303  public: void Write(const std::string &_filename) GAZEBO_DEPRECATED(1.6);
304  public: std::string ToString() const GAZEBO_DEPRECATED(1.6);
305 
307  public: void SetFromString(
308  const std::string &_sdfData) GAZEBO_DEPRECATED(1.6);
309 
310  public: ElementPtr root;
311 
312  public: static std::string version;
313  };
315 }
316 
317 #endif