Graphite  Version 3
An experimental 3D geometry processing program
serializer.h
Go to the documentation of this file.
1 /*
2  * OGF/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000 Bruno Levy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * If you modify this software, you should include a notice giving the
20  * name of the person performing the modification, the date of modification,
21  * and the reason for such modification.
22  *
23  * Contact: Bruno Levy
24  *
25  * levy@loria.fr
26  *
27  * ISA Project
28  * LORIA, INRIA Lorraine,
29  * Campus Scientifique, BP 239
30  * 54506 VANDOEUVRE LES NANCY CEDEX
31  * FRANCE
32  *
33  * Note that the GNU General Public License does not permit incorporating
34  * the Software into proprietary programs.
35  */
36 
37 #ifndef H_OGF_GOM_SERVICES_SERIALIZER_H
38 #define H_OGF_GOM_SERVICES_SERIALIZER_H
39 
40 #include <OGF/gom/common/common.h>
41 #include <OGF/gom/types/arg_list.h>
42 #include <iostream>
43 
50 namespace OGF {
51 
52 //______________________________________________________________________
53 
58  class GOM_API Serializer : public Counted {
59  public:
60 
64  ~Serializer() override;
65 
74  virtual bool serialize_read(
75  std::istream& stream, void* addr
76  ) = 0;
77 
86  virtual bool serialize_write(
87  std::ostream& stream, void* addr
88  ) = 0;
89  };
90 
95 
96 //______________________________________________________________________
97 
101  class GOM_API StringSerializer : public Serializer {
102  public:
107  std::istream& stream, void* addr
108  ) override;
109 
114  std::ostream& stream, void* addr
115  ) override;
116  };
117 
118 //______________________________________________________________________
119 
123  class GOM_API BoolSerializer : public Serializer {
124  public:
129  std::istream& stream, void* addr
130  ) override;
131 
136  std::ostream& stream, void* addr
137  ) override;
138  };
139 
140 //______________________________________________________________________
141 
145  class GOM_API PointerSerializer : public Serializer {
146  public:
147 
152  std::istream& stream, void* addr
153  ) override;
154 
159  std::ostream& stream, void* addr
160  ) override;
161  };
162 
163 //______________________________________________________________________
164 
165  class MetaEnum;
166 
170  class GOM_API EnumSerializer : public Serializer {
171  public:
172 
179  explicit EnumSerializer(MetaEnum* meta_enum) : meta_enum_(meta_enum) {
180  }
181 
186  std::istream& stream, void* addr
187  ) override;
188 
193  std::ostream& stream, void* addr
194  ) override;
195 
196  private:
197  MetaEnum* meta_enum_;
198  };
199 
200 //______________________________________________________________________
201 
206  template <class T> class GenericSerializer : public Serializer {
207  public:
212  std::istream& stream, void* addr
213  ) override {
214  T* object = static_cast<T*>(addr);
215  stream >> (*object);
216  return true;
217  }
218 
223  std::ostream& stream, void* addr
224  ) override {
225  T* object = static_cast<T*>(addr);
226  stream << (*object);
227  return true;
228  }
229  };
230 
236  template <> class GOM_API GenericSerializer<ArgList> : public Serializer {
237 
241  ~GenericSerializer() override;
242 
248  bool serialize_read(
249  std::istream& stream, void* addr
250  ) override;
251 
257  bool serialize_write(
258  std::ostream& stream, void* addr
259  ) override;
260  };
261 
262 //______________________________________________________________________
263 
264 }
265 
266 #endif
Generic arguments and argument lists.
Base class for reference-counted objects.
Definition: counted.h:71
Represents a list of name-value pairs.
Definition: arg_list.h:65
Implementation of Serializer for bool.
Definition: serializer.h:123
bool serialize_read(std::istream &stream, void *addr) override
Reads a value from a stream.
bool serialize_write(std::ostream &stream, void *addr) override
Writes a value to a stream.
Implementation of Serializer for enums.
Definition: serializer.h:170
EnumSerializer(MetaEnum *meta_enum)
EnumSerializer constructor.
Definition: serializer.h:179
bool serialize_read(std::istream &stream, void *addr) override
Reads a value from a stream.
bool serialize_write(std::ostream &stream, void *addr) override
Writes a value to a stream.
Generic implementation of Serializer.
Definition: serializer.h:206
bool serialize_read(std::istream &stream, void *addr) override
Reads a value from a stream.
Definition: serializer.h:211
bool serialize_write(std::ostream &stream, void *addr) override
Writes a value to a stream.
Definition: serializer.h:222
MetaType for enums.
Definition: meta_enum.h:56
Implementation of Serializer for pointers.
Definition: serializer.h:145
bool serialize_write(std::ostream &stream, void *addr) override
Writes a value to a stream.
bool serialize_read(std::istream &stream, void *addr) override
Reads a value from a stream.
Abstract base class for reading and writing values from/to streams.
Definition: serializer.h:58
virtual bool serialize_read(std::istream &stream, void *addr)=0
Reads a value from a stream.
~Serializer() override
Serializer destructor.
virtual bool serialize_write(std::ostream &stream, void *addr)=0
Writes a value to a stream.
Implementation of Serializer for std::string.
Definition: serializer.h:101
bool serialize_read(std::istream &stream, void *addr) override
Reads a value from a stream.
bool serialize_write(std::ostream &stream, void *addr) override
Writes a value to a stream.
Global Graphite namespace.
Definition: common.h:76
SmartPointer< Serializer > Serializer_var
Automatic reference-counted pointer to a Serializer.
Definition: serializer.h:94
Definitions common to all include files in the gom library.