Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
XOMSerializer.h
1 /*
2  * XOMSerializer 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_SERIALIZER_H
22 #define ELM_SERIAL2_XOM_SERIALIZER_H
23 
24 #include <elm/data/HashMap.h>
25 #include <elm/data/Vector.h>
26 #include <elm/data/VectorQueue.h>
27 #include <elm/serial2/Serializer.h>
28 #include <elm/util/Pair.h>
29 #include <elm/sys/Path.h>
30 
31 namespace elm {
32 
33 // Extern classes
34 
35 namespace xom {
36  class Document;
37  class Attribute;
38  class Element;
39 }
40 
41 namespace serial2 {
42 
43 
45 public:
47  virtual ~XOMElementSerializer(void);
48  inline ExternalSolver& solver(void) const { return *_solver; }
49  inline void setSolver(ExternalSolver& solver) { _solver = &solver; }
50 
51  // XOMUnserializer overload
52  virtual void flush(void);
53  virtual void beginObject(const rtti::Type& clazz, const void *object);
54  virtual void endObject(const rtti::Type& clazz, const void *object);
55  virtual void beginField(CString name);
56  virtual void endField(void);
57  virtual void onPointer(const rtti::Type& clazz, const void *object);
58  virtual void beginCompound(const void*);
59  virtual void endCompound(const void*);
60  virtual void onEnum(const void *address, int value, const rtti::Type& clazz);
61  virtual void onValue(const bool& v);
62  virtual void onValue(const signed int& v);
63  virtual void onValue(const unsigned int& v);
64  virtual void onValue(const char& v);
65  virtual void onValue(const signed char& v);
66  virtual void onValue(const unsigned char& v);
67  virtual void onValue(const signed short& v);
68  virtual void onValue(const unsigned short& v);
69  virtual void onValue(const signed long& v);
70  virtual void onValue(const unsigned long& v);
71  virtual void onValue(const signed long long& v);
72  virtual void onValue(const unsigned long long& v);
73  virtual void onValue(const float& v);
74  virtual void onValue(const double& v);
75  virtual void onValue(const long double& v);
76  virtual void onValue(const CString& v);
77  virtual void onValue(const String& v);
78  virtual void onItem (void);
79 
80 private:
85 
86  typedef struct context_t {
87  xom::Element *elem;
88  bool firstItem;
89  } context_t;
90  context_t ctx;
92  int ref_current;
93 
94  int refGet(const void* object) {
95  if (!idmap.hasKey(object)) {
96  idmap.put(object, ref_current);
97  ref_current++;
98  }
99  return idmap.get(object, -1);
100  }
101 
102  ExternalSolver *_solver;
103  xom::Element *top;
104 };
105 
107 public:
108  XOMSerializer(const sys::Path& path);
109  ~XOMSerializer(void);
110 
111 private:
112  xom::Element *prepare(void);
113  xom::Document *doc;
114  const sys::Path& _path;
115 };
116 
117 } } // elm::serial2
118 
119 #endif // ELM_SERIAL2_XOM_SERIALIZER_H
120 
elm::sys::Path
Definition: Path.h:33
elm::HashMap< const void *, bool >
elm::serial2::XOMElementSerializer::flush
virtual void flush(void)
Definition: serial2_XOMSerializer.cpp:90
elm::HashMap::put
void put(const K &key, const T &val)
Definition: HashMap.h:133
elm::serial2::XOMSerializer::XOMSerializer
XOMSerializer(const sys::Path &path)
Definition: serial2_XOMSerializer.cpp:401
elm::VectorQueue
Definition: VectorQueue.h:31
elm::HashMap::get
Option< T > get(const K &k) const
Definition: HashMap.h:55
value
elm::CString
Definition: CString.h:17
elm::serial2::XOMElementSerializer::endCompound
virtual void endCompound(const void *)
Definition: serial2_XOMSerializer.cpp:207
elm::serial2::XOMElementSerializer
Definition: XOMSerializer.h:44
elm::serial2::XOMSerializer::~XOMSerializer
~XOMSerializer(void)
Definition: serial2_XOMSerializer.cpp:419
elm::serial2::XOMElementSerializer::onItem
virtual void onItem(void)
Definition: serial2_XOMSerializer.cpp:239
elm::serial2::ExternalSolver
Definition: serial.h:214
elm::serial2::XOMElementSerializer::endObject
virtual void endObject(const rtti::Type &clazz, const void *object)
Definition: serial2_XOMSerializer.cpp:149
elm::serial2::XOMElementSerializer::setSolver
void setSolver(ExternalSolver &solver)
Definition: XOMSerializer.h:49
elm
Definition: adapter.h:26
elm::serial2::Serializer
Definition: Serializer.h:36
elm::Vector< context_t >
elm::HashMap::hasKey
bool hasKey(const K &k) const
Definition: HashMap.h:59
elm::serial2::XOMElementSerializer::solver
ExternalSolver & solver(void) const
Definition: XOMSerializer.h:48
elm::serial2::XOMSerializer
Definition: XOMSerializer.h:106
elm::xom::Document
Definition: Document.h:20
elm::serial2::XOMElementSerializer::onValue
virtual void onValue(const bool &v)
Definition: serial2_XOMSerializer.cpp:221
elm::serial2::XOMElementSerializer::~XOMElementSerializer
virtual ~XOMElementSerializer(void)
Definition: serial2_XOMSerializer.cpp:83
elm::serial2::XOMElementSerializer::XOMElementSerializer
XOMElementSerializer(xom::Element *top)
Definition: serial2_XOMSerializer.cpp:75
elm::String
Definition: String.h:30
elm::serial2::XOMElementSerializer::onPointer
virtual void onPointer(const rtti::Type &clazz, const void *object)
Definition: serial2_XOMSerializer.cpp:173
elm::serial2::XOMElementSerializer::beginObject
virtual void beginObject(const rtti::Type &clazz, const void *object)
Definition: serial2_XOMSerializer.cpp:106
elm::serial2::XOMElementSerializer::endField
virtual void endField(void)
Definition: serial2_XOMSerializer.cpp:166
elm::xom::Element
Definition: Element.h:21
elm::serial2::XOMElementSerializer::beginField
virtual void beginField(CString name)
Definition: serial2_XOMSerializer.cpp:156
elm::serial2::XOMElementSerializer::onEnum
virtual void onEnum(const void *address, int value, const rtti::Type &clazz)
Definition: serial2_XOMSerializer.cpp:214
elm::xom::Attribute
Definition: Attribute.h:30
elm::rtti::Type
Definition: Type.h:83
elm::serial2::XOMElementSerializer::beginCompound
virtual void beginCompound(const void *)
Definition: serial2_XOMSerializer.cpp:191