Kuon  1.1.3
RoadNarrows Robotics Large Outdoor Mobile Robot Project
kuonXmlCfg.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Kuon
4 //
5 // Library: libkuon
6 //
7 // File: kuonXmlCfg.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2014-04-04 17:05:03 -0600 (Fri, 04 Apr 2014) $
12  * $Rev: 3629 $
13  *
14  * \brief \h_kuon XML configuration class interface.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \copyright
19  * \h_copy 2014-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  *
26  * Permission is hereby granted, without written agreement and without
27  * license or royalty fees, to use, copy, modify, and distribute this
28  * software and its documentation for any purpose, provided that
29  * (1) The above copyright notice and the following two paragraphs
30  * appear in all copies of the source code and (2) redistributions
31  * including binaries reproduces these notices in the supporting
32  * documentation. Substantial modifications to this software may be
33  * copyrighted by their authors and need not follow the licensing terms
34  * described here, provided that the new terms are clearly indicated in
35  * all files where they apply.
36  *
37  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
38  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
39  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
40  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
41  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
42  * THE POSSIBILITY OF SUCH DAMAGE.
43  *
44  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
45  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
46  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
47  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
48  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
49  *
50  * @EulaEnd@
51  */
52 ////////////////////////////////////////////////////////////////////////////////
53 
54 #ifndef _KUON_XML_CFG_H
55 #define _KUON_XML_CFG_H
56 
57 #include <string>
58 
59 #include "rnr/rnrconfig.h"
60 #include "rnr/appkit/Xml.h"
61 #include "rnr/tinyxml/tinyxml.h"
62 
63 #include "Kuon/kuon.h"
64 #include "Kuon/kuonDescBase.h"
65 
66 
67 namespace kuon
68 {
69  //----------------------------------------------------------------------------
70  // KuonXmlCfg Class
71  //----------------------------------------------------------------------------
72 
73  /*!
74  * \brief KuonXmlCfg \h_kuon XML configuration class.
75  */
76  class KuonXmlCfg : public rnr::Xml
77  {
78  public:
79  /*!
80  * \brief Default constructor.
81  */
83  Xml("kuon", KuonXsiUrl, KuonXslUrl),
84  m_strMajElemBase("base"),
85  m_strAttrProdId("product_id"),
86  m_strElemProdName("product_name"),
87  m_strElemProdBrief("product_brief"),
88  m_strElemProdHwVer("hw_version"),
89  m_strElemProdFrontTire("front_tires"),
90  m_strElemProdRearTire("rear_tires")
91  {
92  }
93 
94  /*!
95  * \brief Destructor.
96  */
97  virtual ~KuonXmlCfg()
98  {
99  }
100 
101 
102  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
103  // I/O Methods
104  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
105 
106  /*!
107  * \brief Load XML file into DOM.
108  *
109  * \param strXmlFileName XML file path name.
110  *
111  * \copydoc doc_return_std
112  */
113  virtual int loadFile(const std::string &strXmlFileName=KuonEtcCfg)
114  {
115  int rc;
116 
117  rc = Xml::loadFile(strXmlFileName);
118 
119  return rc < 0? -KUON_ECODE_XML: KUON_OK;
120  }
121 
122  /*!
123  * \brief Load XML file into DOM and set the \h_kuon description.
124  *
125  * \param desc \h_kuon robotic maniputator description.
126  * \param strXmlFileName XML file path name.
127  *
128  * \copydoc doc_return_std
129  */
130  virtual int loadFile(KuonDesc &desc,
131  const std::string &strXmlFileName=KuonEtcCfg)
132  {
133  int rc;
134 
135  if( (rc = Xml::loadFile(strXmlFileName)) == OK )
136  {
137  rc = setKuonDescFromDOM(desc);
138  }
139 
140  return rc < 0? -KUON_ECODE_XML: KUON_OK;
141  }
142 
143  /*!
144  * \brief Save DOM to XML file.
145  *
146  * \param strXmlFileName XML file path name.
147  *
148  * \copydoc doc_return_std
149  */
150  virtual int saveFile(const std::string &strXmlFileName=KuonEtcCfg)
151  {
152  int rc;
153 
154  rc = Xml::saveFile(strXmlFileName);
155 
156  return rc < 0? -KUON_ECODE_XML: KUON_OK;
157  }
158 
159  /*!
160  * \brief Set DOM from \h_kuon description and save XML file.
161  *
162  * \param desc \h_kuon robotic maniputator description.
163  * \param strXmlFileName XML file path name.
164  *
165  * \copydoc doc_return_std
166  */
167  virtual int saveFile(const KuonDesc &desc,
168  const std::string &strXmlFileName=KuonEtcCfg)
169  {
170  int rc;
171 
172  if( (rc = setDOMFromKuonDesc(desc)) == KUON_OK )
173  {
174  rc = Xml::saveFile(strXmlFileName);
175  }
176 
177  return rc < 0? -KUON_ECODE_XML: KUON_OK;
178  }
179 
180  /*!
181  * \brief Create a template \h_kuon XML configuration file.
182  * root element.
183  *
184  * Any current DOM is not accessed nor altered.
185  *
186  * \param strXmlFileName XML file path name.
187  *
188  * \copydoc doc_return_std
189  */
190  virtual int createTemplateFile(
191  const std::string &strXmlFileName=KuonEtcCfg);
192 
193  /*!
194  * \brief Set \h_kuon description for DOM.
195  *
196  * \param desc \h_kuon robotic manipulator description.
197  *
198  * \copydoc doc_return_std
199  */
200  virtual int setKuonDescFromDOM(KuonDesc &desc);
201 
202  /*!
203  * \brief Set the DOM from the \h_kuon description.
204  *
205  * \param desc \h_kuon robotic manipulator description.
206  *
207  * \copydoc doc_return_std
208  */
209  virtual int setDOMFromKuonDesc(const KuonDesc &desc);
210 
211  protected:
212  std::string m_strMajElemBase; ///< robotic base major element name
213  std::string m_strAttrProdId; ///< product id attribute name
214  std::string m_strElemProdName; ///< product name element name
215  std::string m_strElemProdBrief; ///< product brief element name
216  std::string m_strElemProdHwVer; ///< product hardware version element name
217  std::string m_strElemProdFrontTire; ///< front tire radius element name
218  std::string m_strElemProdRearTire; ///< rear tire radius element name
219 
220  /*!
221  * \brief Set \h_kuon robotic base platform description for DOM.
222  *
223  * \param pElemMaj Pointer to major DOM base description element.
224  * \param pDesc Point to \h_kuon robotic base description.
225  *
226  * \copydoc doc_return_std
227  */
228  virtual int setKuonBaseDescFromDOM(TiXmlElement *pElemMaj,
229  KuonDescBase *pDesc);
230  };
231 
232 } // namespace kuon
233 
234 #endif // _KUON_XML_CFG_H
const char *const KuonXsiUrl
xml schema instance url
Definition: kuon.h:248
virtual int setKuonBaseDescFromDOM(TiXmlElement *pElemMaj, KuonDescBase *pDesc)
Set <b><i>Kuon</i></b> robotic base platform description for DOM.
Definition: kuonXmlCfg.cxx:190
static const int KUON_OK
not an error, success
Definition: kuon.h:80
Kuon robotic mobile base escription class.
Definition: kuonDescBase.h:79
static const int KUON_ECODE_XML
XML error.
Definition: kuon.h:102
virtual ~KuonXmlCfg()
Destructor.
Definition: kuonXmlCfg.h:97
virtual int loadFile(KuonDesc &desc, const std::string &strXmlFileName=KuonEtcCfg)
Load XML file into DOM and set the <b><i>Kuon</i></b> description.
Definition: kuonXmlCfg.h:130
Kuon robotic base mobile platform description class interface.
std::string m_strElemProdFrontTire
front tire radius element name
Definition: kuonXmlCfg.h:217
KuonXmlCfg <b><i>Kuon</i></b> XML configuration class.
Definition: kuonXmlCfg.h:76
The <b><i>Kuon</i></b> namespace encapsulates all <b><i>Kuon</i></b> related constructs.
Definition: kuon.h:66
std::string m_strElemProdRearTire
rear tire radius element name
Definition: kuonXmlCfg.h:218
virtual int loadFile(const std::string &strXmlFileName=KuonEtcCfg)
Load XML file into DOM.
Definition: kuonXmlCfg.h:113
virtual int setKuonDescFromDOM(KuonDesc &desc)
Set <b><i>Kuon</i></b> description for DOM.
Definition: kuonXmlCfg.cxx:139
RoadNarrows Kuon robot top-level header file.
virtual int createTemplateFile(const std::string &strXmlFileName=KuonEtcCfg)
Create a template <b><i>Kuon</i></b> XML configuration file. root element.
Definition: kuonXmlCfg.cxx:72
std::string m_strElemProdName
product name element name
Definition: kuonXmlCfg.h:214
const char *const KuonXslUrl
xml configuration file
Definition: kuon.h:237
Kuon robotic manipulator full description class.
Definition: kuonDesc.h:83
std::string m_strMajElemBase
robotic base major element name
Definition: kuonXmlCfg.h:212
std::string m_strElemProdBrief
product brief element name
Definition: kuonXmlCfg.h:215
std::string m_strAttrProdId
product id attribute name
Definition: kuonXmlCfg.h:213
virtual int saveFile(const std::string &strXmlFileName=KuonEtcCfg)
Save DOM to XML file.
Definition: kuonXmlCfg.h:150
virtual int setDOMFromKuonDesc(const KuonDesc &desc)
Set the DOM from the <b><i>Kuon</i></b> description.
Definition: kuonXmlCfg.cxx:184
virtual int saveFile(const KuonDesc &desc, const std::string &strXmlFileName=KuonEtcCfg)
Set DOM from <b><i>Kuon</i></b> description and save XML file.
Definition: kuonXmlCfg.h:167
KuonXmlCfg()
Default constructor.
Definition: kuonXmlCfg.h:82
std::string m_strElemProdHwVer
product hardware version element name
Definition: kuonXmlCfg.h:216