JSBSim Flight Dynamics Model  1.2.0 (05 Nov 2023)
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 FORWARD DECLARATIONS
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 
48 namespace JSBSim {
49 
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 CLASS DOCUMENTATION
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 
136 class Element;
137 typedef SGSharedPtr<Element> Element_ptr;
138 
139 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 CLASS DECLARATION
141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
142 
143 class JSBSIM_API Element : public SGReferenced {
144 public:
148  Element(const std::string& nm);
150  ~Element(void);
151 
155  bool HasAttribute(const std::string& key) {return attributes.find(key) != attributes.end();}
156 
161  std::string GetAttributeValue(const std::string& key);
162 
169  bool SetAttributeValue(const std::string& key, const std::string& value);
170 
175  double GetAttributeValueAsNumber(const std::string& key);
176 
179  const std::string& GetName(void) const {return name;}
180  void ChangeName(const std::string& _name) { name = _name; }
181 
186  std::string GetDataLine(unsigned int i=0);
187 
189  unsigned int GetNumDataLines(void) {return (unsigned int)data_lines.size();}
190 
192  unsigned int GetNumElements(void) {return (unsigned int)children.size();}
193 
195  unsigned int GetNumElements(const std::string& element_name);
196 
202  double GetDataAsNumber(void);
203 
211  Element* GetElement(unsigned int el=0);
212 
221  Element* GetNextElement(void);
222 
225  Element* GetParent(void) {return parent;}
226 
230  int GetLineNumber(void) const { return line_number; }
231 
235  const std::string& GetFileName(void) const { return file_name; }
236 
243  Element* FindElement(const std::string& el="");
244 
254  Element* FindNextElement(const std::string& el="");
255 
264  std::string FindElementValue(const std::string& el="");
265 
274  double FindElementValueAsNumber(const std::string& el="");
275 
284  bool FindElementValueAsBoolean(const std::string& el="");
285 
301  double FindElementValueAsNumberConvertTo(const std::string& el, const std::string& target_units);
302 
320  double FindElementValueAsNumberConvertFromTo( const std::string& el,
321  const std::string& supplied_units,
322  const std::string& target_units);
323 
333  FGColumnVector3 FindElementTripletConvertTo( const std::string& target_units);
334 
335  double DisperseValue(Element *e, double val, const std::string& supplied_units="",
336  const std::string& target_units="");
337 
341  void SetParent(Element* p) {parent = p;}
342 
345  void AddChildElement(Element* el) {children.push_back(el);}
346 
350  void AddAttribute(const std::string& name, const std::string& value);
351 
354  void AddData(std::string d);
355 
359  void Print(unsigned int level=0);
360 
364  void SetLineNumber(int line) { line_number = line; }
365 
369  void SetFileName(const std::string& name) { file_name = name; }
370 
376  std::string ReadFrom(void) const;
377 
385  void MergeAttributes(Element* el);
386 
387 private:
388  std::string name;
389  std::map <std::string, std::string> attributes;
390  std::vector <std::string> data_lines;
391  std::vector <Element_ptr> children;
392  Element *parent;
393  unsigned int element_index;
394  std::string file_name;
395  int line_number;
396  typedef std::map <std::string, std::map <std::string, double> > tMapConvert;
397  static tMapConvert convert;
398  static bool converterIsInitialized;
399 };
400 
401 } // namespace JSBSim
402 
403 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
404 
405 #endif
int GetLineNumber(void) const
Returns the line number at which the element has been defined.
Definition: FGXMLElement.h:230
void SetFileName(const std::string &name)
Set the name of the file in which the element has been read.
Definition: FGXMLElement.h:369
unsigned int GetNumDataLines(void)
Returns the number of lines of data stored.
Definition: FGXMLElement.h:189
const std::string & GetFileName(void) const
Returns the name of the file in which the element has been read.
Definition: FGXMLElement.h:235
unsigned int GetNumElements(void)
Returns the number of child elements for this element.
Definition: FGXMLElement.h:192
Element * GetParent(void)
Returns a pointer to the parent of an element.
Definition: FGXMLElement.h:225
void SetLineNumber(int line)
Set the line number at which the element has been read.
Definition: FGXMLElement.h:364
bool HasAttribute(const std::string &key)
Determines if an element has the supplied attribute.
Definition: FGXMLElement.h:155
void AddChildElement(Element *el)
Adds a child element to the list of children stored for this element.
Definition: FGXMLElement.h:345
void SetParent(Element *p)
This function sets the value of the parent class attribute to the supplied Element pointer.
Definition: FGXMLElement.h:341
const std::string & GetName(void) const
Retrieves the element name.
Definition: FGXMLElement.h:179
This class implements a 3 element column vector.