Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laeXmlCfg.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelaps
4 //
5 // Library: liblaelaps
6 //
7 // File: laeXmlCfg.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2016-01-21 16:50:25 -0700 (Thu, 21 Jan 2016) $
12  * $Rev: 4268 $
13  *
14  * \brief \h_laelaps XML configuration class interface.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \par Copyright
19  * \h_copy 2015-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  *
26  * Unless otherwise stated explicitly, all materials contained are copyrighted
27  * and may not be used without RoadNarrows LLC's written consent,
28  * except as provided in these terms and conditions or in the copyright
29  * notice (documents and software) or other proprietary notice provided with
30  * the relevant materials.
31  *
32  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
33  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
34  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
35  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
36  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
40  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
41  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
42  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
43  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
44  *
45  * @EulaEnd@
46  */
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 #ifndef _LAE_XML_CFG_H
50 #define _LAE_XML_CFG_H
51 
52 #include <string>
53 
54 #include "rnr/rnrconfig.h"
55 #include "rnr/appkit/Xml.h"
56 #include "rnr/tinyxml/tinyxml.h"
57 
58 #include "Laelaps/laelaps.h"
59 #include "Laelaps/laeDesc.h"
60 
61 
62 namespace laelaps
63 {
64  //----------------------------------------------------------------------------
65  // LaeXmlCfg Class
66  //----------------------------------------------------------------------------
67 
68  /*!
69  * \brief LaeXmlCfg \h_laelaps XML configuration class.
70  */
71  class LaeXmlCfg : public rnr::Xml
72  {
73  public:
74  /*!
75  * \brief Default constructor.
76  */
77  LaeXmlCfg() :
78  Xml("laelaps", LaeXsiUrl, LaeXslUrl),
79 
80  m_strMajElemBase("base"),
81  m_strMajElemOptions("options")
82  {
83  }
84 
85  /*!
86  * \brief Destructor.
87  */
88  virtual ~LaeXmlCfg()
89  {
90  }
91 
92  /*!
93  * \brief Load XML file into DOM and set the \h_laelaps description.
94  *
95  * \param [out] desc \h_laelaps robot description.
96  * \param strSearchPath Search path of directory paths.
97  * \param strXmlFileName XML file name.
98  * \param bAllInstances Do [not] load and set all instances of XML files
99  * found.
100  *
101  * \copydoc doc_return_std
102  */
103  virtual int load(LaeDesc &desc,
104  const std::string &strSearchPath,
105  const std::string &strXmlFileName,
106  bool bAllInstances=false);
107 
108  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
109  // I/O Methods
110  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
111 
112  /*!
113  * \brief Load XML file into DOM.
114  *
115  * \param strXmlFileName XML file path name.
116  *
117  * \copydoc doc_return_std
118  */
119  virtual int loadFile(const std::string &strXmlFileName=LaeEtcCfg);
120 
121  /*!
122  * \brief Load XML file into DOM and set the \h_laelaps description.
123  *
124  * \param desc \h_laelaps robot description.
125  * \param strXmlFileName XML file path name.
126  *
127  * \copydoc doc_return_std
128  */
129  virtual int loadFile(LaeDesc &desc,
130  const std::string &strXmlFileName=LaeEtcCfg);
131 
132  /*!
133  * \brief Save DOM to XML file.
134  *
135  * \param strXmlFileName XML file path name.
136  *
137  * \copydoc doc_return_std
138  */
139  virtual int saveFile(const std::string &strXmlFileName=LaeEtcCfg);
140 
141  /*!
142  * \brief Set DOM from \h_laelaps description and save XML file.
143  *
144  * \param desc \h_laelaps robot description.
145  * \param strXmlFileName XML file path name.
146  *
147  * \copydoc doc_return_std
148  */
149  virtual int saveFile(const LaeDesc &desc,
150  const std::string &strXmlFileName=LaeEtcCfg);
151 
152  /*!
153  * \brief Create a template \h_laelaps XML configuration file.
154  * root element.
155  *
156  * Any current DOM is not accessed nor altered.
157  *
158  * \param strXmlFileName XML file path name.
159  *
160  * \copydoc doc_return_std
161  */
162  virtual int createTemplateFile(const std::string &strXmlFileName=LaeEtcCfg);
163 
164  /*!
165  * \brief Set \h_laelaps description for DOM.
166  *
167  * \param desc \h_laelaps robot description.
168  *
169  * \copydoc doc_return_std
170  */
171  virtual int setDescFromDOM(LaeDesc &desc);
172 
173  /*!
174  * \brief Set the DOM from the \h_laelaps description.
175  *
176  * \param desc \h_laelaps robot description.
177  *
178  * \copydoc doc_return_std
179  */
180  virtual int setDOMFromDesc(const LaeDesc &desc);
181 
182  protected:
183  // <base product_id=ID> ...</base>
184  std::string m_strMajElemBase; ///< robotic base major element name
185  std::string m_strMajElemOptions; ///< package options major element name
186 
187  /*!
188  * \brief Set \h_laelaps robotic base description for DOM.
189  *
190  * \param pElemMaj Pointer to major DOM base description element.
191  * \param desc \h_laelaps robot description.
192  *
193  * \copydoc doc_return_std
194  */
195  virtual int setBaseDesc(TiXmlElement *pElemMaj, LaeDesc &desc);
196 
197  /*!
198  * \brief Set \h_laelaps package options descriptions for DOM.
199  *
200  * \param pElemMaj Pointer to major DOM base description element.
201  * \param desc \h_laelaps robot description.
202  *
203  * \copydoc doc_return_std
204  */
205  virtual int setOptionsDesc(TiXmlElement *pElemMaj, LaeDesc &desc);
206 
207  /*!
208  * \brief Warn on unknown element.
209  *
210  * \param strElem Element name.
211  */
212  void warnUnknownElem(const std::string &strElem)
213  {
214  setErrorMsg("%s: Element <%s> unknown - ignoring.",
215  m_strXmlFileName.c_str(), strElem.c_str());
216  LOGWARN("%s", m_bufErrMsg);
217  }
218 
219  };
220 
221 } // namespace laelaps
222 
223 #endif // _LAE_XML_CFG_H
virtual int setDOMFromDesc(const LaeDesc &desc)
Set the DOM from the <b><i>Laelaps</i></b> description.
Definition: laeXmlCfg.cxx:427
virtual int setDescFromDOM(LaeDesc &desc)
Set <b><i>Laelaps</i></b> description for DOM.
Definition: laeXmlCfg.cxx:230
std::string m_strMajElemOptions
package options major element name
Definition: laeXmlCfg.h:185
Laelaps robotic mobile platform full description class.
Definition: laeDesc.h:451
virtual int loadFile(const std::string &strXmlFileName=LaeEtcCfg)
Load XML file into DOM.
void warnUnknownElem(const std::string &strElem)
Warn on unknown element.
Definition: laeXmlCfg.h:212
LaeXmlCfg()
Default constructor.
Definition: laeXmlCfg.h:77
virtual int saveFile(const std::string &strXmlFileName=LaeEtcCfg)
Save DOM to XML file.
const char *const LaeEtcCfg
xml configuration file
Definition: laelaps.h:237
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Definition: laeAlarms.h:64
Laelaps robotic base mobile platform description class interface.
const char *const LaeXsiUrl
xml schema instance url
Definition: laelaps.h:275
virtual int createTemplateFile(const std::string &strXmlFileName=LaeEtcCfg)
Create a template <b><i>Laelaps</i></b> XML configuration file. root element.
Definition: laeXmlCfg.cxx:167
const char *const LaeXslUrl
xml stylesheet url
Definition: laelaps.h:264
virtual ~LaeXmlCfg()
Destructor.
Definition: laeXmlCfg.h:88
virtual int setBaseDesc(TiXmlElement *pElemMaj, LaeDesc &desc)
Set <b><i>Laelaps</i></b> robotic base description for DOM.
Definition: laeXmlCfg.cxx:279
virtual int setOptionsDesc(TiXmlElement *pElemMaj, LaeDesc &desc)
Set <b><i>Laelaps</i></b> package options descriptions for DOM.
Definition: laeXmlCfg.cxx:360
virtual int load(LaeDesc &desc, const std::string &strSearchPath, const std::string &strXmlFileName, bool bAllInstances=false)
Load XML file into DOM and set the <b><i>Laelaps</i></b> description.
Definition: laeXmlCfg.cxx:65
std::string m_strMajElemBase
robotic base major element name
Definition: laeXmlCfg.h:184
Top-level package include file.
LaeXmlCfg <b><i>Laelaps</i></b> XML configuration class.
Definition: laeXmlCfg.h:71