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 
25 #include "sdf/interface/Param.hh"
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 
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,
84  int _spacing, int &_index);
85 
86  private: void ToString(const std::string &_prefix,
87  std::ostringstream &_out) const;
88  public: std::string ToString(const std::string &_prefix) const;
89 
90  public: void AddAttribute(const std::string &_key,
91  const std::string &_type,
92  const std::string &_defaultvalue,
93  bool _required,
94  const std::string &_description="");
95 
96  public: void AddValue(const std::string &_type,
97  const std::string &_defaultValue, bool _required,
98  const std::string &_description="");
99 
102  public: ParamPtr GetAttribute(const std::string &_key);
103 
105  public: unsigned int GetAttributeCount() const;
106 
108  public: ParamPtr GetAttribute(unsigned int _index) const;
109 
111  public: unsigned int GetElementDescriptionCount() const;
112 
114  public: ElementPtr GetElementDescription(unsigned int _index) const;
115 
117  public: ElementPtr GetElementDescription(const std::string &_key) const;
118 
120  public: bool HasElementDescription(const std::string &_name);
121 
122  public: bool HasAttribute(const std::string &_key);
123 
125  public: bool GetAttributeSet(const std::string &_key);
126 
128  public: ParamPtr GetValue();
129 
130  public: bool GetValueBool(const std::string &_key = "");
131  public: int GetValueInt(const std::string &_key = "");
132  public: float GetValueFloat(const std::string &_key = "");
133  public: double GetValueDouble(const std::string &_key = "");
134  public: unsigned int GetValueUInt(const std::string &_key = "");
135  public: char GetValueChar(const std::string &_key = "");
136  public: std::string GetValueString(const std::string &_key = "");
137  public: gazebo::math::Vector3 GetValueVector3(const std::string &_key = "");
139  const std::string &_key = "");
141  const std::string &_key = "");
142  public: gazebo::math::Pose GetValuePose(const std::string &_key = "");
143  public: gazebo::common::Color GetValueColor(const std::string &_key = "");
144  public: gazebo::common::Time GetValueTime(const std::string &_key = "");
145 
146  public: bool Set(const bool &_value);
147  public: bool Set(const int &_value);
148  public: bool Set(const unsigned int &_value);
149  public: bool Set(const float &_value);
150  public: bool Set(const double &_value);
151  public: bool Set(const char &_value);
152  public: bool Set(const std::string &_value);
153  public: bool Set(const char *_value);
154  public: bool Set(const gazebo::math::Vector3 &_value);
155  public: bool Set(const gazebo::math::Vector2i &_value);
156  public: bool Set(const gazebo::math::Vector2d &_value);
157  public: bool Set(const gazebo::math::Quaternion &_value);
158  public: bool Set(const gazebo::math::Pose &_value);
159  public: bool Set(const gazebo::common::Color &_value);
160  public: bool Set(const gazebo::common::Time &_value);
161 
162  public: bool HasElement(const std::string &_name) const;
163 
164  public: ElementPtr GetElement(const std::string &_name) const;
165  public: ElementPtr GetFirstElement() const;
166 
167  public: ElementPtr GetNextElement(const std::string &_name = "") const;
168 
169  public: ElementPtr GetElement(const std::string &_name);
170  public: ElementPtr AddElement(const std::string &_name);
171  public: void InsertElement(ElementPtr _elem);
172 
174  public: void RemoveFromParent();
175 
178  public: void RemoveChild(ElementPtr _child);
179 
181  public: void ClearElements();
182 
183  public: void Update();
184  public: void Reset();
185 
186  public: void SetInclude(const std::string &_filename);
187  public: std::string GetInclude() const;
188 
190  public: std::string GetDescription() const;
191 
193  public: void SetDescription(const std::string &_desc);
194 
196  public: void AddElementDescription(ElementPtr _elem);
197 
198  private: boost::shared_ptr<Param> CreateParam(const std::string &_key,
199  const std::string &_type, const std::string &_defaultValue,
200  bool _required, const std::string &_description="");
201 
202  public: ElementPtr GetElementImpl(const std::string &_name) const;
203 
204  private: std::string name;
205  private: std::string required;
206  private: std::string description;
207  private: bool copyChildren;
208 
209  private: ElementPtr parent;
210 
211  // Attributes of this element
212  private: Param_V attributes;
213 
214  // Value of this element
215  private: ParamPtr value;
216 
217  // The existing child elements
218  private: ElementPtr_V elements;
219 
220  // The possible child elements
221  private: ElementPtr_V elementDescriptions;
222 
224  private: std::string includeFilename;
225  };
226 
227 
229  class SDF
230  {
231  public: SDF();
232  public: void PrintDescription();
233  public: void PrintValues();
234  public: void PrintWiki();
235  public: void PrintDoc();
236  public: void Write(const std::string &_filename);
237  public: std::string ToString() const;
238 
240  public: void SetFromString(const std::string &_sdfData);
241 
242  public: ElementPtr root;
243 
244  public: static std::string version;
245  };
247 }
248 #endif