soma-io  5.1.2
minfXML2.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 #ifndef SOMAIO_UTILITIES_MINFXML2_H
35 #define SOMAIO_UTILITIES_MINFXML2_H
36 //--- soma-io ----------------------------------------------------------------
39 //--- cartobase --------------------------------------------------------------
43 //----------------------------------------------------------------------------
44 
45 namespace soma {
46 
47 
48 //----------------------------------------------------------------------------
49 // XML tags and attributes
50 //----------------------------------------------------------------------------
51 
52 
53 extern const std::string minfTag;
54 extern const std::string noneTag;
55 extern const std::string trueTag;
56 extern const std::string falseTag;
57 extern const std::string numberTag;
58 extern const std::string stringTag;
59 extern const std::string listTag;
60 extern const std::string dictionaryTag;
61 extern const std::string factoryTag;
62 extern const std::string xhtmlTag;
63 extern const std::string referenceTag;
64 
65 extern const std::string expanderAttribute;
66 extern const std::string lengthAttribute;
67 extern const std::string nameAttribute;
68 extern const std::string objectTypeAttribute;
69 extern const std::string identifierAttribute;
70 
71 
72 //-----------------------------------------------------------------------------
73 carto::Object readDictionaryMinfXML( const std::string &fileName,
79 void readDictionaryMinfXML( const std::string &fileName,
80  carto::Object &dictionary,
84  carto::Object &dictionary,
90 void init_libXML();
91 
92 
93 //----------------------------------------------------------------------------
94 class ObjectListener : public virtual carto::RCObject
95 {
96 public:
97  virtual ~ObjectListener();
98 
99  virtual void nextObject( const carto::Object & ) = 0;
100  virtual void noMoreObject() = 0;
101 };
102 
103 
104 //----------------------------------------------------------------------------
105 class MinfTreeExpander;
106 class MinfNodeExpander : public virtual carto::RCObject
107 {
108 public:
109  virtual ~MinfNodeExpander();
110 
111  virtual std::string startStructure( MinfTreeExpander &,
112  const std::string &nodeType,
113  const std::string &identifier,
114  carto::Object attributes,
115  const std::string &parentSyntax=std::string(),
116  const std::string &name=std::string() ) = 0;
117  virtual void endStructure( MinfTreeExpander &, const std::string &nodeType ) = 0;
118  virtual void atom( MinfTreeExpander &, carto::Object, const std::string &identifier ) = 0;
119  virtual void reference( MinfTreeExpander &, const std::string &identifier ) = 0;
120 };
121 
122 
123 //----------------------------------------------------------------------------
124 class MinfTreeExpander : public virtual carto::RCObject
125 {
126 public:
128  virtual ~MinfTreeExpander();
129 
132 
133  void addReference( const std::string &identifier, carto::Object value );
134  carto::Object getReferencedObject( const std::string &identifier );
135 
136  virtual std::string startStructure( const std::string &nodeType,
137  const std::string &identifier,
138  carto::Object attributes,
139  const std::string &parentSyntax=std::string(),
140  const std::string &name=std::string() );
141  virtual void endStructure( const std::string &nodeType );
142  virtual void atom( carto::Object, const std::string &identifier );
143  virtual void reference( const std::string &identifier );
144 
145 private:
146  std::list< carto::rc_ptr< MinfNodeExpander > > _stack;
147  std::map< std::string, carto::Object > _references;
148 };
149 
150 
151 //----------------------------------------------------------------------------
153 {
154 public:
161 
162  virtual std::string startStructure( MinfTreeExpander &,
163  const std::string &nodeType,
164  const std::string &identifier,
165  carto::Object attributes,
166  const std::string &parentSyntax=std::string(),
167  const std::string &name=std::string() );
168  virtual void endStructure( MinfTreeExpander &, const std::string &nodeType );
169  virtual void atom( MinfTreeExpander &, carto::Object, const std::string &identifier );
170  virtual void reference( MinfTreeExpander &, const std::string &identifier );
171 
172 private:
173 
174  carto::rc_ptr< ObjectListener > _objectListener;
175 
176 protected:
177 
179 };
180 
181 
182 //----------------------------------------------------------------------------
184 {
185 public:
189 
190  virtual std::string startStructure( MinfTreeExpander &,
191  const std::string &nodeType,
192  const std::string &identifier,
193  carto::Object attributes,
194  const std::string &parentSyntax=std::string(),
195  const std::string &name=std::string() );
196 
197 private:
198 
199  carto::Object _dictionary;
200 };
201 
202 
203 //----------------------------------------------------------------------------
205 {
206 public:
211  virtual ~ListBuilder();
212 
213  virtual void nextObject( const carto::Object & );
214  virtual void noMoreObject();
215 
217 private:
218 
219  carto::rc_ptr< ObjectListener > _objectListener;
220 };
221 
222 
223 //----------------------------------------------------------------------------
225 {
226 public:
232 
233  virtual void nextObject( const carto::Object & );
234  virtual void noMoreObject();
235 
237 
238 private:
239 
240  carto::Object _key;
241  carto::rc_ptr< ObjectListener > _objectListener;
242 };
243 
244 
245 
246 //----------------------------------------------------------------------------
247 class MinfXMLReader : public virtual carto::RCObject
248 {
249 public:
251  void read( const std::string & );
252  void read( DataSource & );
253 
254 private:
255 
256  MinfTreeExpander &_expander;
258 };
259 
260 
261 //----------------------------------------------------------------------------
262 // class TestMinfTreeExpander : public virtual MinfNodeExpander
263 // {
264 // public:
265 // TestMinfTreeExpander();
266 // virtual ~TestMinfTreeExpander();
267 //
268 // virtual void startStructure( MinfTreeExpander &,
269 // const std::string &nodeType,
270 // const std::string &identifier,
271 // carto::Object attributes );
272 // virtual void endStructure( MinfTreeExpander &, const std::string &nodeType );
273 // virtual void atom( MinfTreeExpander &, carto::Object, const std::string &identifier );
274 // virtual void reference( MinfTreeExpander &, const std::string &identifier );
275 //
276 // private:
277 //
278 // int _level;
279 // };
280 
281 } // namespace soma
282 
283 #endif // ifndef SOMAIO_UTILITIES_MINFXML2_H
Abstraction layer for various data sources (file, buffer, socket...).
Definition: datasource.h:65
virtual void reference(MinfTreeExpander &, const std::string &identifier)
DefaultMinfNodeExpander(carto::rc_ptr< ObjectListener > ol=carto::rc_ptr< ObjectListener >(), carto::rc_ptr< carto::SyntaxSet > syntax=carto::rc_ptr< carto::SyntaxSet >())
virtual void endStructure(MinfTreeExpander &, const std::string &nodeType)
virtual std::string startStructure(MinfTreeExpander &, const std::string &nodeType, const std::string &identifier, carto::Object attributes, const std::string &parentSyntax=std::string(), const std::string &name=std::string())
DefaultMinfNodeExpander(carto::rc_ptr< carto::SyntaxSet > syntax)
carto::rc_ptr< carto::SyntaxSet > _syntax
Definition: minfXML2.h:178
virtual void atom(MinfTreeExpander &, carto::Object, const std::string &identifier)
virtual void noMoreObject()
DictionaryBuilder(carto::rc_ptr< ObjectListener >)
carto::Object result
Definition: minfXML2.h:236
DictionaryBuilder(carto::Object, carto::rc_ptr< ObjectListener >)
virtual void nextObject(const carto::Object &)
DictionaryBuilder(carto::Object)
virtual void noMoreObject()
ListBuilder(carto::rc_ptr< ObjectListener >)
ListBuilder(carto::Object, carto::rc_ptr< ObjectListener >)
carto::Object result
Definition: minfXML2.h:216
virtual ~ListBuilder()
virtual void nextObject(const carto::Object &)
ListBuilder(carto::Object)
virtual void reference(MinfTreeExpander &, const std::string &identifier)=0
virtual std::string startStructure(MinfTreeExpander &, const std::string &nodeType, const std::string &identifier, carto::Object attributes, const std::string &parentSyntax=std::string(), const std::string &name=std::string())=0
virtual void atom(MinfTreeExpander &, carto::Object, const std::string &identifier)=0
virtual void endStructure(MinfTreeExpander &, const std::string &nodeType)=0
carto::Object getReferencedObject(const std::string &identifier)
virtual void reference(const std::string &identifier)
void push(carto::rc_ptr< MinfNodeExpander >)
carto::rc_ptr< MinfNodeExpander > pop()
virtual void atom(carto::Object, const std::string &identifier)
virtual void endStructure(const std::string &nodeType)
virtual std::string startStructure(const std::string &nodeType, const std::string &identifier, carto::Object attributes, const std::string &parentSyntax=std::string(), const std::string &name=std::string())
void addReference(const std::string &identifier, carto::Object value)
MinfXMLReader(MinfTreeExpander &, carto::rc_ptr< carto::SyntaxSet > syntax)
void read(DataSource &)
void read(const std::string &)
virtual void nextObject(const carto::Object &)=0
virtual void noMoreObject()=0
virtual ~ObjectListener()
virtual std::string startStructure(MinfTreeExpander &, const std::string &nodeType, const std::string &identifier, carto::Object attributes, const std::string &parentSyntax=std::string(), const std::string &name=std::string())
SingleDictionaryExpander(carto::Object dictionary, carto::rc_ptr< carto::SyntaxSet > syntax)
Definition: allocator.h:49
const std::string factoryTag
const std::string minfTag
const std::string expanderAttribute
const std::string falseTag
const std::string referenceTag
const std::string stringTag
const std::string numberTag
const std::string trueTag
const std::string listTag
const std::string xhtmlTag
const std::string noneTag
const std::string objectTypeAttribute
const std::string lengthAttribute
const std::string identifierAttribute
const std::string nameAttribute
const std::string dictionaryTag
carto::Object readDictionaryMinfXML(const std::string &fileName, carto::rc_ptr< carto::SyntaxSet > syntax=carto::rc_ptr< carto::SyntaxSet >())
void init_libXML()
just to force initializing libxml2, needs to be called once from the main thread in a multi-threaded ...