Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Interface.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program 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 Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OMNI_SERIALIZATION_INTERFACE_H_
21 #define OMNI_SERIALIZATION_INTERFACE_H_
22 
23 #include <omni/TypeIdInterface.h>
24 #include <omni/util.h>
25 
26 namespace omni {
27  namespace serialization {
28  /**@brief Abstract interface for serialization
29  * @detail Holds two member functions for serialization and deserialization
30  */
31  class Interface {
32  public:
33  virtual ~Interface() {}
34 
35  /// Serialize to stream
36  virtual void toStream(QDataStream&) const = 0;
37 
38  /// Deserialize from stream
39  virtual void fromStream(QDataStream&) = 0;
40 
41  /// Optional virtual member method for testing equality of two
42  // interfaces
43  inline virtual bool equal(Interface const *_that) const
44  {
45  return true;
46  }
47  };
48  }
49 
51 }
52 
53 #define OMNI_DECL_STREAM_OPERATORS(CLASS) \
54  inline QDataStream &operator>>(QDataStream & _stream, CLASS & _cls) \
55  { \
56  _cls.fromStream(_stream); \
57  return _stream; \
58  } \
59  inline QDataStream& operator<<(QDataStream& _stream, CLASS const& _cls) \
60  { \
61  _cls.toStream(_stream); \
62  return _stream; \
63  }
64 
65 #define OMNI_DECL_ENUM_STREAM_OPERATORS(ENUM) \
66  inline QDataStream &operator>>(QDataStream & _stream, ENUM & _enum) \
67  { \
68  int _i = 0; \
69  _stream >> _i; \
70  _enum = omni::util::intToEnum<ENUM>(_enum); \
71  return _stream; \
72  } \
73  inline QDataStream& operator<<(QDataStream& _stream, ENUM const& _enum) \
74  { \
75  _stream << omni::util::enumToInt(_enum); \
76  return _stream; \
77  }
78 
79 #endif /* OMNI_SERIALIZATIONINTERFACE_H_ */
virtual bool equal(Interface const *_that) const
Optional virtual member method for testing equality of two.
Definition: Interface.h:43
Abstract interface for serialization Holds two member functions for serialization and deserializatio...
Definition: Interface.h:31
virtual void toStream(QDataStream &) const =0
Serialize to stream.
virtual ~Interface()
Definition: Interface.h:33
virtual void fromStream(QDataStream &)=0
Deserialize from stream.
serialization::Interface SerializationInterface
Definition: Interface.h:50