Kuon  1.1.3
RoadNarrows Robotics Large Outdoor Mobile Robot Project
kuon::KuonXmlCfg Class Reference

KuonXmlCfg Kuon XML configuration class. More...

#include <kuonXmlCfg.h>

Inheritance diagram for kuon::KuonXmlCfg:

Public Member Functions

 KuonXmlCfg ()
 Default constructor.
 
virtual ~KuonXmlCfg ()
 Destructor.
 
virtual int loadFile (const std::string &strXmlFileName=KuonEtcCfg)
 Load XML file into DOM. More...
 
virtual int loadFile (KuonDesc &desc, const std::string &strXmlFileName=KuonEtcCfg)
 Load XML file into DOM and set the Kuon description. More...
 
virtual int saveFile (const std::string &strXmlFileName=KuonEtcCfg)
 Save DOM to XML file. More...
 
virtual int saveFile (const KuonDesc &desc, const std::string &strXmlFileName=KuonEtcCfg)
 Set DOM from Kuon description and save XML file. More...
 
virtual int createTemplateFile (const std::string &strXmlFileName=KuonEtcCfg)
 Create a template Kuon XML configuration file. root element. More...
 
virtual int setKuonDescFromDOM (KuonDesc &desc)
 Set Kuon description for DOM. More...
 
virtual int setDOMFromKuonDesc (const KuonDesc &desc)
 Set the DOM from the Kuon description. More...
 

Protected Member Functions

virtual int setKuonBaseDescFromDOM (TiXmlElement *pElemMaj, KuonDescBase *pDesc)
 Set Kuon robotic base platform description for DOM. More...
 

Protected Attributes

std::string m_strMajElemBase
 robotic base major element name
 
std::string m_strAttrProdId
 product id attribute name
 
std::string m_strElemProdName
 product name element name
 
std::string m_strElemProdBrief
 product brief element name
 
std::string m_strElemProdHwVer
 product hardware version element name
 
std::string m_strElemProdFrontTire
 front tire radius element name
 
std::string m_strElemProdRearTire
 rear tire radius element name
 

Detailed Description

KuonXmlCfg Kuon XML configuration class.

Definition at line 76 of file kuonXmlCfg.h.

Member Function Documentation

int KuonXmlCfg::createTemplateFile ( const std::string &  strXmlFileName = KuonEtcCfg)
virtual

Create a template Kuon XML configuration file. root element.

Any current DOM is not accessed nor altered.

Parameters
strXmlFileNameXML file path name.

Definition at line 72 of file kuonXmlCfg.cxx.

References kuon::KUON_ECODE_XML, and kuon::KUON_OK.

Referenced by saveFile().

73 {
74  FILE *fp;
75 
76  if( strXmlFileName.empty() )
77  {
78  setErrorMsg("No file name.");
79  LOGERROR("%s", m_bufErrMsg);
80  return -KUON_ECODE_XML;
81  }
82 
83  m_strXmlFileName = strXmlFileName;
84 
85  // open file
86  if( (fp = fopen(m_strXmlFileName.c_str(), "w+")) == NULL )
87  {
88  setErrorMsg("%s: %s(errno=%d).",
89  m_strXmlFileName.c_str(), strerror(errno), errno);
90  LOGERROR("%s", m_bufErrMsg);
91  return -KUON_ECODE_XML;
92  }
93 
94  makeXmlHead();
95  makeXmlTail();
96 
97  //
98  // XML head.
99  //
100  fprintf(fp, " <!-- RoadNarrows Kuon Top-Level Configuration -->\n");
101  fprintf(fp, "%s", m_strXmlHead.c_str());
102 
103  //
104  // Robotic base major element.
105  //
106  fprintf(fp, " <!-- Kuon robotic mobile platform -->\n");
107  fprintf(fp, " <%s product_id=\"PRODID\">\n", m_strMajElemBase.c_str());
108 
109  fprintf(fp, " <%s>PRODNAME</%s>\n",
110  m_strElemProdName.c_str(), m_strElemProdName.c_str());
111 
112  fprintf(fp, " <%s>\n PRODBRIEF\n </%s>\n",
113  m_strElemProdBrief.c_str(), m_strElemProdBrief.c_str());
114 
115  fprintf(fp, " <%s>PRODHWVER</%s>\n",
116  m_strElemProdHwVer.c_str(), m_strElemProdHwVer.c_str());
117 
118  fprintf(fp, " <%s>FRONTTIRE</%s>\n",
120 
121  fprintf(fp, " <%s>REARTIRE</%s>\n",
123 
124  fprintf(fp, " </%s>\n\n", m_strMajElemBase.c_str());
125 
126 
127  //
128  // XML tail
129  //
130  fprintf(fp, "%s", m_strXmlTail.c_str());
131 
132  fclose(fp);
133 
134  LOGDIAG3("Created file %s.", m_strXmlFileName.c_str());
135 
136  return KUON_OK;
137 }
static const int KUON_OK
not an error, success
Definition: kuon.h:80
static const int KUON_ECODE_XML
XML error.
Definition: kuon.h:102
std::string m_strElemProdFrontTire
front tire radius element name
Definition: kuonXmlCfg.h:217
std::string m_strElemProdRearTire
rear tire radius element name
Definition: kuonXmlCfg.h:218
std::string m_strElemProdName
product name element name
Definition: kuonXmlCfg.h:214
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_strElemProdHwVer
product hardware version element name
Definition: kuonXmlCfg.h:216
virtual int kuon::KuonXmlCfg::loadFile ( const std::string &  strXmlFileName = KuonEtcCfg)
inlinevirtual

Load XML file into DOM.

Parameters
strXmlFileNameXML file path name.

Definition at line 113 of file kuonXmlCfg.h.

References kuon::KUON_ECODE_XML, and kuon::KUON_OK.

114  {
115  int rc;
116 
117  rc = Xml::loadFile(strXmlFileName);
118 
119  return rc < 0? -KUON_ECODE_XML: KUON_OK;
120  }
static const int KUON_OK
not an error, success
Definition: kuon.h:80
static const int KUON_ECODE_XML
XML error.
Definition: kuon.h:102
virtual int kuon::KuonXmlCfg::loadFile ( KuonDesc desc,
const std::string &  strXmlFileName = KuonEtcCfg 
)
inlinevirtual

Load XML file into DOM and set the Kuon description.

Parameters
desc

Definition at line 130 of file kuonXmlCfg.h.

References kuon::KUON_ECODE_XML, kuon::KUON_OK, and setKuonDescFromDOM().

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  }
static const int KUON_OK
not an error, success
Definition: kuon.h:80
static const int KUON_ECODE_XML
XML error.
Definition: kuon.h:102
virtual int setKuonDescFromDOM(KuonDesc &desc)
Set <b><i>Kuon</i></b> description for DOM.
Definition: kuonXmlCfg.cxx:139
virtual int kuon::KuonXmlCfg::saveFile ( const std::string &  strXmlFileName = KuonEtcCfg)
inlinevirtual

Save DOM to XML file.

Parameters
strXmlFileNameXML file path name.

Definition at line 150 of file kuonXmlCfg.h.

References kuon::KUON_ECODE_XML, and kuon::KUON_OK.

151  {
152  int rc;
153 
154  rc = Xml::saveFile(strXmlFileName);
155 
156  return rc < 0? -KUON_ECODE_XML: KUON_OK;
157  }
static const int KUON_OK
not an error, success
Definition: kuon.h:80
static const int KUON_ECODE_XML
XML error.
Definition: kuon.h:102
virtual int kuon::KuonXmlCfg::saveFile ( const KuonDesc desc,
const std::string &  strXmlFileName = KuonEtcCfg 
)
inlinevirtual

Set DOM from Kuon description and save XML file.

Parameters
desc

Definition at line 167 of file kuonXmlCfg.h.

References createTemplateFile(), kuon::KUON_ECODE_XML, kuon::KUON_OK, setDOMFromKuonDesc(), and setKuonDescFromDOM().

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  }
static const int KUON_OK
not an error, success
Definition: kuon.h:80
static const int KUON_ECODE_XML
XML error.
Definition: kuon.h:102
virtual int setDOMFromKuonDesc(const KuonDesc &desc)
Set the DOM from the <b><i>Kuon</i></b> description.
Definition: kuonXmlCfg.cxx:184
int KuonXmlCfg::setDOMFromKuonDesc ( const KuonDesc desc)
virtual

Set the DOM from the Kuon description.

Parameters
desc

Definition at line 184 of file kuonXmlCfg.cxx.

References kuon::KUON_ECODE_GEN.

Referenced by saveFile().

185 {
186  // TODO
187  return -KUON_ECODE_GEN;
188 }
static const int KUON_ECODE_GEN
general, unspecified error
Definition: kuon.h:82
int KuonXmlCfg::setKuonBaseDescFromDOM ( TiXmlElement *  pElemMaj,
KuonDescBase pDesc 
)
protectedvirtual

Set Kuon robotic base platform description for DOM.

Parameters
pElemMajPointer to major DOM base description element.
pDescPoint to Kuon robotic base description.

Definition at line 190 of file kuonXmlCfg.cxx.

References kuon::KUON_ECODE_XML, and kuon::KUON_OK.

192 {
193  TiXmlElement *pElem;
194  const char *sValue;
195  string str;
196  int eProdId;
197  string strProdName;
198  string strProdBrief;
199  string strHwVer;
200  double fFrontTire = 0.0;
201  double fRearTire = 0.0;
202  int rc;
203 
204  if( (rc = strToInt(elemAttr(pElemMaj, m_strAttrProdId), eProdId)) < 0 )
205  {
206  setErrorMsg("%s: No %s attribute of <%s> found or value not an integer.",
207  m_strXmlFileName.c_str(),
208  m_strAttrProdId.c_str(),
209  m_strMajElemBase.c_str());
210  LOGERROR("%s", m_bufErrMsg);
211  return -KUON_ECODE_XML;
212  }
213 
214  // child elements
215  for(pElem = pElemMaj->FirstChildElement();
216  pElem != NULL;
217  pElem = pElem->NextSiblingElement())
218  {
219  if( (sValue = pElem->Value()) == NULL )
220  {
221  continue;
222  }
223 
224  // product name
225  else if( !strcasecmp(sValue, m_strElemProdName.c_str()) )
226  {
227  strProdName = elemText(pElem);
228  }
229 
230  // product brief
231  else if( !strcasecmp(sValue, m_strElemProdBrief.c_str()) )
232  {
233  strProdBrief = elemText(pElem);
234  }
235 
236  // product hardware version
237  else if( !strcasecmp(sValue, m_strElemProdHwVer.c_str()) )
238  {
239  strHwVer = elemText(pElem);
240  }
241 
242  // front tires radius
243  else if( !strcasecmp(sValue, m_strElemProdFrontTire.c_str()) )
244  {
245  str = elemText(pElem);
246  if( !str.empty() )
247  {
248  if( (rc = strToDouble(str, fFrontTire)) < 0 )
249  {
250  setErrorMsg("%s: Element <%s> text \"%s\" not an number.",
251  m_strXmlFileName.c_str(), m_strElemProdFrontTire.c_str(),
252  str.c_str());
253  LOGERROR("%s", m_bufErrMsg);
254  return -KUON_ECODE_XML;
255  }
256  }
257  }
258 
259  // rear tires radius
260  else if( !strcasecmp(sValue, m_strElemProdRearTire.c_str()) )
261  {
262  str = elemText(pElem);
263  if( !str.empty() )
264  {
265  if( (rc = strToDouble(str, fRearTire)) < 0 )
266  {
267  setErrorMsg("%s: Element <%s> text \"%s\" not an number.",
268  m_strXmlFileName.c_str(), m_strElemProdRearTire.c_str(),
269  str.c_str());
270  LOGERROR("%s", m_bufErrMsg);
271  return -KUON_ECODE_XML;
272  }
273  }
274  }
275  }
276 
277  pDesc->setDesc(eProdId, strProdName, strProdBrief, strHwVer,
278  fFrontTire, fRearTire);
279 
280  LOGDIAG3("%s: Kuon robotic base description set.",
281  m_strXmlFileName.c_str());
282 
283  return KUON_OK;
284 }
static const int KUON_OK
not an error, success
Definition: kuon.h:80
static const int KUON_ECODE_XML
XML error.
Definition: kuon.h:102
std::string m_strElemProdFrontTire
front tire radius element name
Definition: kuonXmlCfg.h:217
std::string m_strElemProdRearTire
rear tire radius element name
Definition: kuonXmlCfg.h:218
std::string m_strElemProdName
product name element name
Definition: kuonXmlCfg.h:214
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
std::string m_strElemProdHwVer
product hardware version element name
Definition: kuonXmlCfg.h:216
int KuonXmlCfg::setKuonDescFromDOM ( KuonDesc desc)
virtual

Set Kuon description for DOM.

Parameters
desc

Definition at line 139 of file kuonXmlCfg.cxx.

References kuon::KuonDesc::getBaseDesc(), kuon::KUON_ECODE_XML, kuon::KUON_OK, and kuon::KuonDescBase::resetDesc().

Referenced by loadFile(), and saveFile().

140 {
141  KuonDescBase *pDescBase;
142  TiXmlElement *pElem;
143  const char *sValue;
144  const char *sAttr;
145  const char *sText;
146  int n;
147  int rc;
148 
149  //
150  // Subsection descriptions.
151  //
152  pDescBase = desc.getBaseDesc();
153 
154  pDescBase->resetDesc();
155 
156  if( m_pElemRoot == NULL )
157  {
158  setErrorMsg("Missing DOM and/or <%s> root element missing.",
159  m_strRootElemName.c_str());
160  LOGERROR("%s", m_bufErrMsg);
161  return -KUON_ECODE_XML;
162  }
163 
164  // search secion elements
165  for(pElem = m_pElemRoot->FirstChildElement();
166  pElem != NULL;
167  pElem = pElem->NextSiblingElement())
168  {
169  if( (sValue = pElem->Value()) == NULL )
170  {
171  continue;
172  }
173 
174  // robotic base description
175  if( !strcasecmp(sValue, m_strMajElemBase.c_str()) )
176  {
177  setKuonBaseDescFromDOM(pElem, pDescBase);
178  }
179  }
180 
181  return KUON_OK;
182 }
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
std::string m_strMajElemBase
robotic base major element name
Definition: kuonXmlCfg.h:212
void resetDesc()
Reset base description to the "unitialized" values.
KuonDescBase * getBaseDesc()
Get the <b><i>Kuon</i></b> base product description.
Definition: kuonDesc.h:156

The documentation for this class was generated from the following files: