Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
XMLBase.hh
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8 
9  BIAS is free software; you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation; either version 2.1 of the License, or
12  (at your option) any later version.
13 
14  BIAS is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with BIAS; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
22 #ifndef __BIAS_XMLBASE_hh__
23 #define __BIAS_XMLBASE_hh__
24 
25 #include "bias_config.h"
26 
27 #ifndef BIAS_HAVE_XML2
28 # error BIAS_HAVE_XML2 required to use XMLIO.hh. Please recompile BIAS with USE_XML2.
29 #endif
30 
31 #ifdef BIAS_HAVE_XML2
32 
33 #include <Base/Common/XMLIO.hh>
34 
35 namespace BIAS {
36 
37  /** @class XMLBase
38  @ingroup g_utils
39  @brief Base class with interface for xml output
40 
41  All classes with xml i/o support should be derived from this class.
42  You can then call XMLWrite to write the object to an XML file or
43  XMLAdd(n) to attach the object to a node n of a given xml structure.
44  For this to work you must:
45  - Override XMLGetTopLevelName such that it returns something identifying
46  the class, e.g. "FeaturePoint". XMLAdd and XMLWrite use this function
47  to generate the toplevel node of you object.
48  - Override XMLFill, such that it fills the XML code of (*this) into a
49  tree, where the top level node is already created
50  Given a valid xml file, you can call XMLRead to read the xml file into
51  the current object, this calls your specialization of XMLReadObject
52 
53  This class is empty if no XML2 support is available.
54 
55  @author koeser 08/2004 */
56  class BIASCommon_EXPORT XMLBase {
57 
58  public:
59  virtual ~XMLBase() {}
60 
61  /** @brief call this to add the class to a node of a given xml tree
62  @attention interface changed 3/2008: return value now nodeptr of
63  added node!*/
64  xmlNodePtr XMLAdd(const xmlNodePtr Node, XMLIO& XMLObject) const;
65 
66  /** @brief call this to add the class to a new xml tree and write it
67  to the file Filename. Calls function XMLOut of derived class
68  @param CompressionLevel 0..9 (0=off, 9=highest compression) */
69  int XMLWrite(const std::string& Filename,
70  int CompressionLevel = 0,
71  bool AutoAddCompressionSuffix = true,
72  std::string encoding="UTF-8") const;
73 
74  /** serialize xml tree to string
75  @author evers*/
76  int XMLWriteToString(std::string &str,
77  std::string encoding="UTF-8") const;
78 
79  /** @brief reconstruct xml tree from string
80  @author evers*/
81  int XMLReadFromString(const std::string& str);
82 
83  /** @brief derived classes must implement this, so that it returns the name
84  of the class for the top level tag in the XML file */
85  virtual int XMLGetClassName(std::string& TopLevelTag,
86  double& Version) const = 0;
87 
88  /** @brief derived classes must implement this to write the code of (*this)
89  into the XML tree. Called by XMLRead of XMLBase.
90  @param node always points to a node with a name given by the function
91  XMLGetTopLevelName */
92  virtual int XMLOut(const xmlNodePtr Node, XMLIO& XMLObject) const = 0;
93 
94  /** @brief derived classes must implement this to read everything in Node
95  into (*this). Called by XMLRead of XMLBase.
96  @return 0 on success, <0 on error */
97  virtual int XMLIn(const xmlNodePtr Node, XMLIO& XMLObject) = 0;
98 
99  /** @brief derived classes must implement the function XMLIn which is called by
100  * this function XMLRead to read everything with name Filename into (*this).
101  * @return 0 on success, <0 on error
102  * */
103  int XMLRead(const std::string& Filename);
104 
105  };
106 
107 } // namespace
108 
109 #endif // BIAS_HAVE_XML2
110 #endif // __BIAS_XMLBASE_hh__
virtual ~XMLBase()
Definition: XMLBase.hh:59
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
Base class with interface for xml output.
Definition: XMLBase.hh:56