XmlSerializationContext.h
1/*
2 * Copyright (C) 2008-2013 by Marc Boris Duerner
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * As a special exception, you may use this file as part of a free
10 * software library without restriction. Specifically, if other files
11 * instantiate templates or use macros or inline functions from this
12 * file, or you compile this file and link it with other files to
13 * produce an executable, this file does not by itself cause the
14 * resulting executable to be covered by the GNU General Public
15 * License. This exception does not however invalidate any other
16 * reasons why the executable file might be covered by the GNU Library
17 * General Public License.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29#ifndef Pt_Xml_XmlSerializationContext_h
30#define Pt_Xml_XmlSerializationContext_h
31
32#include <Pt/Xml/Api.h>
33#include <Pt/SerializationContext.h>
34#include <Pt/Types.h>
35#include <map>
36#include <vector>
37#include <string>
38
39namespace Pt {
40
41namespace Xml {
42
46{
47 public:
48 class Fixup;
49
50 public:
53
56
57 protected:
58 // inherit docs
59 virtual void onClear();
60
61 // inherit docs
62 virtual bool onBeginSave(const void* p, const char* name);
63
64 // inherit docs
65 virtual void onFinishSave();
66
67 // inherit docs
68 virtual void onPrepareId(const void* p);
69
70 // inherit docs
71 virtual const char* onGetId(const void* p);
72
73 // inherit docs
74 virtual const char* onMakeId(const void* p);
75
76 protected:
77 // inherit docs
78 virtual void onBeginLoad(void* obj, const std::type_info& fixupInfo,
79 const char* name, const char* id);
80 // inherit docs
81 virtual void onFinishLoad();
82
83 // inherit docs
84 virtual void onRebindTarget(const char* id, void* obj);
85
86 // inherit docs
87 virtual void onRebindFixup(const char* id, void* obj, void* prev);
88
89 // inherit docs
90 virtual void onPrepareFixup(void* obj, const char* id, FixupInfo::FixupHandler, unsigned m);
91
92 // inherit docs
93 virtual void onFixup();
94
95 private:
97 {}
98
100 { return *this; }
101
102 private:
103 std::map<const void*, std::size_t> _idmap;
104 std::map<const void*, std::string> _refmap;
105 std::vector<Fixup*> _targets;
106 std::vector<Fixup*> _pointers;
107 Pt::varint_t _r1;
108 Pt::varint_t _r2;
109};
110
111} // namespace Xml
112
113} // namespace Pt
114
115#endif // Pt_Xml_XmlSerializationContext_h
SerializationContext()
Default Constructor.
Serialization context for XML serialization.
Definition XmlSerializationContext.h:46
virtual const char * onMakeId(const void *p)
Create an ID for a type, if referenced.
virtual bool onBeginSave(const void *p, const char *name)
Begin saving a type.
virtual void onBeginLoad(void *obj, const std::type_info &fixupInfo, const char *name, const char *id)
Begin loading a type.
virtual void onRebindFixup(const char *id, void *obj, void *prev)
Rebind reference to fixup for a ID.
virtual void onPrepareId(const void *p)
Mark a type as being referenced.
virtual void onFixup()
Fixup all prepared references to their targets.
virtual void onFinishLoad()
Finish loading a type.
virtual void onRebindTarget(const char *id, void *obj)
Rebind a ID to a referenced type.
virtual const char * onGetId(const void *p)
Get the ID for a reference.
virtual void onFinishSave()
Finish saving a type.
XmlSerializationContext()
Default Constructor.
virtual void onPrepareFixup(void *obj, const char *id, FixupInfo::FixupHandler, unsigned m)
Prepare a reference to fixup for an ID.
virtual void onClear()
Clears all content.
Read and write XML ducuments.
Core module.
Definition Allocator.h:33