Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
XOMUnserializer.h
1 /*
2  * XOMUnserializer class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2006, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_SERIAL2_XOM_UNSERIALIZER_H
22 #define ELM_SERIAL2_XOM_UNSERIALIZER_H
23 
24 #include <elm/data/HashMap.h>
25 #include <elm/data/Vector.h>
26 #include <elm/serial2/serial.h>
27 #include <elm/serial2/Unserializer.h>
28 #include <elm/sys/Path.h>
29 #include <elm/util/Pair.h>
30 
31 namespace elm {
32 
33 // Extern classes
34 namespace xom {
35  class Document;
36  class Element;
37 }
38 
39 namespace serial2 {
40 
41 // XOMUnserializer class
43 public:
45 
46  XOMUnserializer(xom::Element *element);
47  XOMUnserializer(const char *path);
50  ~XOMUnserializer(void);
51  inline ExternalSolver& solver(void) const { return *_solver; }
52  inline void setSolver(ExternalSolver& solver) { _solver = &solver; }
53 
54  // XOMUnserializer overload
55  virtual void flush(void);
56  virtual void beginObject(const rtti::Type& clazz, void *object);
57  virtual void endObject(const rtti::Type& clazz, void *object);
58  virtual bool beginField(CString name);
59  virtual void endField(void);
60  virtual void onPointer(const rtti::Type& clazz, void **object);
61  virtual bool beginCompound(void*);
62  virtual int countItems(void);
63  virtual bool nextItem(void);
64  virtual void endCompound(void*);
65  virtual int onEnum(const rtti::Type & clazz);
66  virtual void onValue(bool& v);
67  virtual void onValue(signed int& v);
68  virtual void onValue(unsigned int& v);
69  virtual void onValue(char& v);
70  virtual void onValue(signed char& v);
71  virtual void onValue(unsigned char& v);
72  virtual void onValue(signed short& v);
73  virtual void onValue(unsigned short& v);
74  virtual void onValue(signed long& v);
75  virtual void onValue(unsigned long& v);
76  virtual void onValue(signed long long& v);
77  virtual void onValue(unsigned long long& v);
78  virtual void onValue(float& v);
79  virtual void onValue(double& v);
80  virtual void onValue(long double& v);
81  virtual void onValue(CString& v);
82  virtual void onValue(String& v);
83 
84 private:
85  typedef struct patch_t {
86  struct patch_t *next;
87  void **ptr;
88  inline patch_t(void **_ptr): next(0), ptr(_ptr) { };
89  } patch_t;
90 
91  typedef struct ref_t {
92  const rtti::Type& t;
93  void *ptr;
94  patch_t *patches;
95  inline ref_t(const rtti::Type& type, void *_ptr = 0) : t(type), ptr(_ptr), patches(0) { };
96  void put(void **_ptr);
97  void record(void *_ptr);
98  inline bool isRecorded(void) const { return ptr; }
99  } ref_t;
100 
101  typedef struct context_t {
102  int i;
103  xom::Element *elem;
104  } context_t;
105 
106  xom::Document *doc;
107  bool opened;
108  context_t ctx;
109  elm::io::Input in;
110  HashMap<CString, ref_t *> refs;
113  ExternalSolver *_solver;
114 
115  void init(cstring path);
116  void embed(const rtti::Type& clazz, void **ptr);
117  string xline(xom::Element *element);
118  void lookupID(const rtti::Type& type, void *ptr);
119 };
120 
121 } } // elm::serial2
122 
123 #endif // ELM_SERIAL2_XOM_UNSERIALIZER_H
124 
elm::serial2::XOMUnserializer::onValue
virtual void onValue(bool &v)
Definition: serial2_XOMUnserializer.cpp:422
elm::serial2::XOMUnserializer::countItems
virtual int countItems(void)
Definition: serial2_XOMUnserializer.cpp:392
elm::serial2::XOMUnserializer::beginField
virtual bool beginField(CString name)
Definition: serial2_XOMUnserializer.cpp:334
elm::sys::Path
Definition: Path.h:33
elm::serial2::XOMUnserializer::setSolver
void setSolver(ExternalSolver &solver)
Definition: XOMUnserializer.h:52
elm::serial2::XOMUnserializer::solver
ExternalSolver & solver(void) const
Definition: XOMUnserializer.h:51
elm::serial2::XOMUnserializer::nextItem
virtual bool nextItem(void)
Definition: serial2_XOMUnserializer.cpp:375
elm::serial2::XOMUnserializer::beginCompound
virtual bool beginCompound(void *)
Definition: serial2_XOMUnserializer.cpp:353
elm::cstring
CString cstring
Definition: CString.h:62
elm::serial2::XOMUnserializer::XOMUnserializer
XOMUnserializer(xom::Element *element)
Definition: serial2_XOMUnserializer.cpp:108
elm::CString
Definition: CString.h:17
elm::serial2::XOMUnserializer::onEnum
virtual int onEnum(const rtti::Type &clazz)
Definition: serial2_XOMUnserializer.cpp:406
elm::serial2::XOMUnserializer::null_tag
const static cstring null_tag
Definition: XOMUnserializer.h:44
elm::serial2::ExternalSolver
Definition: serial.h:214
elm::serial2::XOMUnserializer::class_tag
const static cstring class_tag
Definition: XOMUnserializer.h:44
elm
Definition: adapter.h:26
elm::Vector< context_t >
elm::serial2::XOMUnserializer::~XOMUnserializer
~XOMUnserializer(void)
Definition: serial2_XOMUnserializer.cpp:163
elm::serial2::XOMUnserializer::endObject
virtual void endObject(const rtti::Type &clazz, void *object)
Definition: serial2_XOMUnserializer.cpp:328
elm::t::put
void put(var< T > &x, in< T > v)
Definition: type_info.h:287
elm::serial2::XOMUnserializer::endCompound
virtual void endCompound(void *)
Definition: serial2_XOMUnserializer.cpp:369
elm::io::Input
Definition: Input.h:34
elm::serial2::Unserializer
Definition: Unserializer.h:15
elm::serial2::XOMUnserializer::endField
virtual void endField(void)
Definition: serial2_XOMUnserializer.cpp:346
elm::serial2::XOMUnserializer::ref_tag
const static cstring ref_tag
Definition: XOMUnserializer.h:44
elm::serial2::XOMUnserializer::id_tag
const static cstring id_tag
Definition: XOMUnserializer.h:44
elm::String
Definition: String.h:30
elm::serial2::XOMUnserializer::onPointer
virtual void onPointer(const rtti::Type &clazz, void **object)
Definition: serial2_XOMUnserializer.cpp:277
elm::serial2::XOMUnserializer::flush
virtual void flush(void)
Definition: serial2_XOMUnserializer.cpp:186
elm::serial2::XOMUnserializer::beginObject
virtual void beginObject(const rtti::Type &clazz, void *object)
Definition: serial2_XOMUnserializer.cpp:321
elm::xom::Element
Definition: Element.h:21
elm::t::ptr
void * ptr
Definition: types.h:30
elm::serial2::XOMUnserializer
Definition: XOMUnserializer.h:42
elm::rtti::Type
Definition: Type.h:83