JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGXMLElement.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  File: FGXMLElement.h
4  Author: Jon S. Berndt
5  Date started: 9/28/04
6 
7  ------------- Copyright (C) 2004 Jon S. Berndt (jon@jsbsim.org) -------------
8 
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17  details.
18 
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25 
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 SENTRY
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
29 
30 #ifndef XMLELEMENT_H
31 #define XMLELEMENT_H
32 
33 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 INCLUDES
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36 
37 #include <string>
38 #include <map>
39 #include <vector>
40 
41 #include "simgear/structure/SGSharedPtr.hxx"
42 #include "math/FGColumnVector3.h"
43 
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 DEFINITIONS
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 
48 #define ID_XMLELEMENT "$Id: FGXMLElement.h,v 1.25 2015/07/12 19:34:08 bcoconni Exp $"
49 
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 FORWARD DECLARATIONS
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 
54 namespace JSBSim {
55 
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 CLASS DOCUMENTATION
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 
143 class Element;
144 typedef SGSharedPtr<Element> Element_ptr;
145 
146 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 CLASS DECLARATION
148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
149 
150 class Element : public SGReferenced {
151 public:
155  Element(const std::string& nm);
157  ~Element(void);
158 
162  bool HasAttribute(const std::string& key) {return attributes.find(key) != attributes.end();}
163 
168  std::string GetAttributeValue(const std::string& key);
169 
176  bool SetAttributeValue(const std::string& key, const std::string& value);
177 
182  double GetAttributeValueAsNumber(const std::string& key);
183 
186  const std::string& GetName(void) const {return name;}
187 
192  std::string GetDataLine(unsigned int i=0);
193 
195  unsigned int GetNumDataLines(void) {return (unsigned int)data_lines.size();}
196 
198  unsigned int GetNumElements(void) {return (unsigned int)children.size();}
199 
201  unsigned int GetNumElements(const std::string& element_name);
202 
208  double GetDataAsNumber(void);
209 
217  Element* GetElement(unsigned int el=0);
218 
227  Element* GetNextElement(void);
228 
231  Element* GetParent(void) {return parent;}
232 
236  int GetLineNumber(void) const { return line_number; }
237 
241  const std::string& GetFileName(void) const { return file_name; }
242 
249  Element* FindElement(const std::string& el="");
250 
260  Element* FindNextElement(const std::string& el="");
261 
270  std::string FindElementValue(const std::string& el="");
271 
280  double FindElementValueAsNumber(const std::string& el="");
281 
297  double FindElementValueAsNumberConvertTo(const std::string& el, const std::string& target_units);
298 
316  double FindElementValueAsNumberConvertFromTo( const std::string& el,
317  const std::string& supplied_units,
318  const std::string& target_units);
319 
329  FGColumnVector3 FindElementTripletConvertTo( const std::string& target_units);
330 
331  double DisperseValue(Element *e, double val, const std::string& supplied_units="",
332  const std::string& target_units="");
333 
337  void SetParent(Element* p) {parent = p;}
338 
341  void AddChildElement(Element* el) {children.push_back(el);}
342 
346  void AddAttribute(const std::string& name, const std::string& value);
347 
350  void AddData(std::string d);
351 
355  void Print(unsigned int level=0);
356 
360  void SetLineNumber(int line) { line_number = line; }
361 
365  void SetFileName(const std::string& name) { file_name = name; }
366 
372  std::string ReadFrom(void) const;
373 
381  void MergeAttributes(Element* el);
382 
383 private:
384  std::string name;
385  std::map <std::string, std::string> attributes;
386  std::vector <std::string> data_lines;
387  std::vector <Element_ptr> children;
388  Element *parent;
389  unsigned int element_index;
390  std::string file_name;
391  int line_number;
392  typedef std::map <std::string, std::map <std::string, double> > tMapConvert;
393  static tMapConvert convert;
394  static bool converterIsInitialized;
395 };
396 
397 } // namespace JSBSim
398 
399 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
400 
401 #endif
void AddChildElement(Element *el)
Adds a child element to the list of children stored for this element.
Definition: FGXMLElement.h:341
Element * GetParent(void)
Returns a pointer to the parent of an element.
Definition: FGXMLElement.h:231
const std::string & GetFileName(void) const
Returns the name of the file in which the element has been read.
Definition: FGXMLElement.h:241
void AddAttribute(const std::string &name, const std::string &value)
Stores an attribute belonging to this element.
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
void SetLineNumber(int line)
Set the line number at which the element has been read.
Definition: FGXMLElement.h:360
bool HasAttribute(const std::string &key)
Determines if an element has the supplied attribute.
Definition: FGXMLElement.h:162
double FindElementValueAsNumberConvertTo(const std::string &el, const std::string &target_units)
Searches for the named element and converts and returns the data belonging to it. ...
void SetParent(Element *p)
This function sets the value of the parent class attribute to the supplied Element pointer...
Definition: FGXMLElement.h:337
Element * FindElement(const std::string &el="")
Searches for a specified element.
double FindElementValueAsNumber(const std::string &el="")
Searches for the named element and returns the data belonging to it as a number.
double FindElementValueAsNumberConvertFromTo(const std::string &el, const std::string &supplied_units, const std::string &target_units)
Searches for the named element and converts and returns the data belonging to it. ...
unsigned int GetNumDataLines(void)
Returns the number of lines of data stored.
Definition: FGXMLElement.h:195
~Element(void)
Destructor.
int GetLineNumber(void) const
Returns the line number at which the element has been defined.
Definition: FGXMLElement.h:236
void MergeAttributes(Element *el)
Merges the attributes of the current element with another element.
bool SetAttributeValue(const std::string &key, const std::string &value)
Modifies an attribute.
double GetDataAsNumber(void)
Converts the element data to a number.
double GetAttributeValueAsNumber(const std::string &key)
Retrieves an attribute value as a double precision real number.
const std::string & GetName(void) const
Retrieves the element name.
Definition: FGXMLElement.h:186
void SetFileName(const std::string &name)
Set the name of the file in which the element has been read.
Definition: FGXMLElement.h:365
std::string FindElementValue(const std::string &el="")
Searches for the named element and returns the string data belonging to it.
std::string GetDataLine(unsigned int i=0)
Gets a line of data belonging to an element.
This class implements a 3 element column vector.
unsigned int GetNumElements(void)
Returns the number of child elements for this element.
Definition: FGXMLElement.h:198
void Print(unsigned int level=0)
Prints the element.
std::string ReadFrom(void) const
Return a string that contains a description of the location where the current XML element was read fr...
Element(const std::string &nm)
Constructor.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
Element * GetElement(unsigned int el=0)
Returns a pointer to the element requested by index.
Element * GetNextElement(void)
Returns a pointer to the next element in the list.
FGColumnVector3 FindElementTripletConvertTo(const std::string &target_units)
Composes a 3-element column vector for the supplied location or orientation.
void AddData(std::string d)
Stores data belonging to this element.