GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
MergeXML.h
1 #ifndef GEAR_MergeXML_H
2 #define GEAR_MergeXML_H
3 
4 #include <string>
5 #include "gearxml/tinyxml.h"
6 
7 #define NAME_STR "name"
8 
9 namespace gear {
10 
11  class TiXmlDocument ;
12 
18  class MergeXML {
19 
20  public:
21 
25  bool setFile1( const std::string& fileName ) ;
26 
30  bool setFile2( const std::string& fileName ) ;
31 
36  void makeDominant(const int domFileNr )
37  {
38  if (domFileNr==1 || domFileNr==2) {
39  _domFile = domFileNr ;
40  }
41  }
42 
45  bool mergeFiles (const std::string& fileName ) ;
46 
49  MergeXML() :
50  _file1(NULL),
51  _file2(NULL),
52  _fileSwap(NULL),
53  _fileMerged(NULL),
54  _domFile(2),
55  _name(NAME_STR) {
56  }
57 
58 
59  private:
60 
61  //checks whether file can be read in
62  bool checkXML( const std::string& fileName ) ;
63 
64  //get files correct: dominant will be _file2 and recessiv will be _file1
65  void correctDominantFile() ;
66 
67  //compare nodes
68  void mergeNode( TiXmlNode* node, TiXmlNode* domNode ) ;
69 
70  // merge childsNodes where domNode overrules Node
71  void mergeElement( TiXmlNode* node, TiXmlNode* domNode ) ;
72 
73  // merge childElements where domNode overrules Node
74  void mergeAttribute( TiXmlElement* element, TiXmlElement* domElement ) ;
75 
76  // count the number of nodes that look like childNode in parentNode
77  int countNodes( TiXmlNode* childNode, TiXmlNode* domNode ) ;
78 
79  // get chilElement with same Attribute name
80  TiXmlNode* getChildNode( TiXmlNode* node, TiXmlNode* domNode, int getOccurence = 1 ) ;
81 
82  // get the Name of the Node - either as value of the attribute name or as node->Value()
83  std::string getNodeName( TiXmlNode* node ) ;
84 
85  // check if the Node has the required attribute
86  bool hasAttribute( TiXmlNode* node ) ;
87 
88  //file1
89  TiXmlDocument* _file1 ;
90 
91  //file2
92  TiXmlDocument* _file2 ;
93 
94  //fileSwap - if dominant changes
95  TiXmlDocument* _fileSwap ;
96 
97  //fileMerged - final document
98  TiXmlDocument* _fileMerged ;
99 
100  //dominant file - default file2
101  int _domFile ;
102 
103  // unique attribute as identifier for nodes
104  const char* _name ;
105 
106  }; //class
107 
108 } //namespace
109 
110 #endif
bool mergeFiles(const std::string &fileName)
merges files
Definition: MergeXML.cc:36
Always the top level node.
Definition: tinyxml.h:1154
MergeXML()
constructor
Definition: MergeXML.h:49
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:370
void makeDominant(const int domFileNr)
determines what file is dominant.
Definition: MergeXML.h:36
The element is a container class.
Definition: tinyxml.h:827
class to merge two xml files.
Definition: MergeXML.h:18
bool setFile1(const std::string &fileName)
Sets first filename returns true if file can be read.
Definition: MergeXML.cc:9
bool setFile2(const std::string &fileName)
Sets second filename returns true if file can be read.
Definition: MergeXML.cc:17