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 2011 Nate Koenig
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 
25 #include "sdf/interface/Param.hh"
26 
27 #define SDF_VERSION "1.3"
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 
43  class Element : public boost::enable_shared_from_this<Element>
44  {
45  public: Element();
46  public: virtual ~Element();
47 
48  public: boost::shared_ptr<Element> Clone() const;
49 
51  public: void Copy(const ElementPtr _elem);
52 
53  public: ElementPtr GetParent() const;
54  public: void SetParent(const ElementPtr _parent);
55 
56  public: void SetName(const std::string &_name);
57  public: const std::string &GetName() const;
58 
59  public: void SetRequired(const std::string &_req);
60  public: const std::string &GetRequired() const;
61 
62  public: void SetCopyChildren(bool _value);
63  public: bool GetCopyChildren() const;
64 
65  public: void PrintDescription(std::string _prefix);
66  public: void PrintValues(std::string _prefix);
67  public: void PrintWiki(std::string _prefix);
68 
75  public: void PrintDocLeftPane(std::string &_html,
76  int _spacing, int &_index);
77 
83  public: void PrintDocRightPane(std::string &_html, int _spacing);
84 
85  private: void ToString(const std::string &_prefix,
86  std::ostringstream &_out) const;
87  public: std::string ToString(const std::string &_prefix) const;
88 
89  public: void AddAttribute(const std::string &_key,
90  const std::string &_type,
91  const std::string &_defaultvalue,
92  bool _required,
93  const std::string &_description="");
94 
95  public: void AddValue(const std::string &_type,
96  const std::string &_defaultValue, bool _required,
97  const std::string &_description="");
98 
101  public: ParamPtr GetAttribute(const std::string &_key);
102 
104  public: unsigned int GetAttributeCount() const;
105 
107  public: ParamPtr GetAttribute(unsigned int _index) const;
108 
110  public: unsigned int GetElementDescriptionCount() const;
111 
113  public: ElementPtr GetElementDescription(unsigned int _index) const;
114 
116  public: ElementPtr GetElementDescription(const std::string &_key) const;
117 
119  public: bool HasElementDescription(const std::string &_name);
120 
121  public: bool HasAttribute(const std::string &_key);
122 
124  public: bool GetAttributeSet(const std::string &_key);
125 
127  public: ParamPtr GetValue();
128 
129  public: bool GetValueBool(const std::string &_key = "");
130  public: int GetValueInt(const std::string &_key = "");
131  public: float GetValueFloat(const std::string &_key = "");
132  public: double GetValueDouble(const std::string &_key = "");
133  public: unsigned int GetValueUInt(const std::string &_key = "");
134  public: char GetValueChar(const std::string &_key = "");
135  public: std::string GetValueString(const std::string &_key = "");
136  public: gazebo::math::Vector3 GetValueVector3(const std::string &_key = "");
138  const std::string &_key = "");
140  const std::string &_key = "");
141  public: gazebo::math::Pose GetValuePose(const std::string &_key = "");
142  public: gazebo::common::Color GetValueColor(const std::string &_key = "");
143  public: gazebo::common::Time GetValueTime(const std::string &_key = "");
144 
145  public: bool Set(const bool &_value);
146  public: bool Set(const int &_value);
147  public: bool Set(const unsigned int &_value);
148  public: bool Set(const float &_value);
149  public: bool Set(const double &_value);
150  public: bool Set(const char &_value);
151  public: bool Set(const std::string &_value);
152  public: bool Set(const char *_value);
153  public: bool Set(const gazebo::math::Vector3 &_value);
154  public: bool Set(const gazebo::math::Vector2i &_value);
155  public: bool Set(const gazebo::math::Vector2d &_value);
156  public: bool Set(const gazebo::math::Quaternion &_value);
157  public: bool Set(const gazebo::math::Pose &_value);
158  public: bool Set(const gazebo::common::Color &_value);
159  public: bool Set(const gazebo::common::Time &_value);
160 
161  public: bool HasElement(const std::string &_name) const;
162 
163  public: ElementPtr GetElement(const std::string &_name) const;
164  public: ElementPtr GetFirstElement() const;
165 
166  public: ElementPtr GetNextElement(const std::string &_name = "") const;
167 
168  public: ElementPtr GetElement(const std::string &_name);
169  public: ElementPtr AddElement(const std::string &_name);
170  public: void InsertElement(ElementPtr _elem);
171  public: void ClearElements();
172 
173  public: void Update();
174  public: void Reset();
175 
176  public: void SetInclude(const std::string &_filename);
177  public: std::string GetInclude() const;
178 
180  public: std::string GetDescription() const;
181 
183  public: void SetDescription(const std::string &_desc);
184 
186  public: void AddElementDescription(ElementPtr _elem);
187 
188  private: boost::shared_ptr<Param> CreateParam(const std::string &_key,
189  const std::string &_type, const std::string &_defaultValue,
190  bool _required, const std::string &_description="");
191 
192  public: ElementPtr GetElementImpl(const std::string &_name) const;
193 
194  private: std::string name;
195  private: std::string required;
196  private: std::string description;
197  private: bool copyChildren;
198 
199  private: ElementPtr parent;
200 
201  // Attributes of this element
202  private: Param_V attributes;
203 
204  // Value of this element
205  private: ParamPtr value;
206 
207  // The existing child elements
208  private: ElementPtr_V elements;
209 
210  // The possible child elements
211  private: ElementPtr_V elementDescriptions;
212 
214  private: std::string includeFilename;
215  };
216 
217 
219  class SDF
220  {
221  public: SDF();
222  public: void PrintDescription();
223  public: void PrintValues();
224  public: void PrintWiki();
225  public: void PrintDoc();
226  public: void Write(const std::string &_filename);
227  public: std::string ToString() const;
228 
230  public: void SetFromString(const std::string &_sdfData);
231 
232  public: ElementPtr root;
233 
234  public: static std::string version;
235  };
237 }
238 #endif