SDF.hh
00001 /*
00002  * Copyright 2011 Nate Koenig & Andrew Howard
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 #ifndef SDF_HH
00018 #define SDF_HH
00019 
00020 #include <vector>
00021 #include <string>
00022 #include <boost/shared_ptr.hpp>
00023 #include <boost/enable_shared_from_this.hpp>
00024 
00025 #include "sdf/interface/Param.hh"
00026 
00027 #define SDF_VERSION "1.0"
00028 
00029 namespace sdf
00030 {
00031   class SDF;
00032   class Element;
00033   typedef boost::shared_ptr<SDF> SDFPtr;
00034   typedef boost::shared_ptr<Element> ElementPtr;
00035   typedef std::vector< ElementPtr > ElementPtr_V;
00036 
00038   class Element : public boost::enable_shared_from_this<Element>
00039   {
00040     public: Element();
00041     public: virtual ~Element();
00042 
00043     public: boost::shared_ptr<Element> Clone() const;
00044 
00046     public: void Copy( const ElementPtr &_elem );
00047 
00048     public: ElementPtr GetParent() const;
00049     public: void SetParent(const ElementPtr &_parent);
00050 
00053     public: std::string GetLinkName() const;
00054 
00057     public: std::string GetModelName() const;
00058 
00061     public: std::string GetWorldName() const;
00062 
00063     public: void SetName(const std::string &_name);
00064     public: const std::string &GetName() const;
00065 
00066     public: void SetRequired(const std::string &_req);
00067     public: const std::string &GetRequired() const;
00068 
00069     public: void SetCopyChildren( bool _value );
00070     public: bool GetCopyChildren() const;
00071 
00072     public: void PrintDescription(std::string _prefix);
00073     public: void PrintValues(std::string _prefix);
00074 
00075     private: void ToString(const std::string &_prefix,
00076                            std::ostringstream &_out) const;
00077     public: std::string ToString(const std::string &_prefix) const;
00078 
00079     public: void AddAttribute(const std::string &_key, 
00080                               const std::string &_type, 
00081                               const std::string &_defaultvalue,
00082                               bool _required);
00083 
00084     public: void AddValue(const std::string &_type, 
00085                           const std::string &_defaultValue, bool _required);
00086 
00089     public: ParamPtr GetAttribute(const std::string &_key);
00090 
00091     public: bool HasAttribute(const std::string &_key);
00092 
00094     public: ParamPtr GetValue();
00095 
00096     public: bool GetValueBool(const std::string &_key = "");
00097     public: int GetValueInt(const std::string &_key = "");
00098     public: float GetValueFloat(const std::string &_key = "");
00099     public: double GetValueDouble(const std::string &_key = "");
00100     public: unsigned int GetValueUInt(const std::string &_key = "");
00101     public: char GetValueChar(const std::string &_key = "" );
00102     public: std::string GetValueString(const std::string &_key = "");
00103     public: gazebo::math::Vector3 GetValueVector3(const std::string &_key = "");
00104     public: gazebo::math::Quaternion GetValueQuaternion(const std::string &_key = "");
00105     public: gazebo::math::Pose GetValuePose(const std::string &_key = "");
00106     public: gazebo::common::Color GetValueColor(const std::string &_key = "");
00107  
00108     public: bool HasElement(const std::string &_name) const;
00109 
00110     public: ElementPtr GetElement(const std::string &_name) const;
00111     public: ElementPtr GetFirstElement() const;
00112 
00113     public: ElementPtr GetNextElement(const std::string &_name) const;
00114     public: ElementPtr GetNextElement() const;
00115 
00116 
00117     public: ElementPtr GetOrCreateElement(const std::string &_name);
00118     public: ElementPtr AddElement(const std::string &_name);
00119     public: void InsertElement(ElementPtr _elem);
00120     public: void ClearElements();
00121 
00122     public: void Update();
00123     public: void Reset();
00124 
00125     private: boost::shared_ptr<Param> CreateParam(const std::string &_key, 
00126                  const std::string &_type, const std::string &_defaultValue, 
00127                  bool _required);
00128 
00129     private: std::string name;
00130     private: std::string required;
00131     private: bool copyChildren;
00132 
00133     private: ElementPtr parent;
00134 
00135     // Attributes of this element
00136     public: Param_V attributes;
00137 
00138     // Value of this element
00139     public: ParamPtr value;
00140 
00141     // The existing child elements
00142     public: ElementPtr_V elements;
00143 
00144     // The possible child elements
00145     public: ElementPtr_V elementDescriptions;
00146   };
00147 
00148 
00150   class SDF
00151   {
00152     public: SDF();
00153     public: void PrintDescription();
00154     public: void PrintValues();
00155     public: void Write(const std::string &_filename);
00156     public: std::string ToString() const;
00157 
00158     public: ElementPtr root;
00159   };
00160 }
00161 #endif