Remote Call Framework 3.0
SerializeAny.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2018, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 3.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_SF_SERIALIZEANY_HPP
20 #define INCLUDE_SF_SERIALIZEANY_HPP
21 
22 #include <boost/any.hpp>
23 
24 namespace SF {
25 
26  class Archive;
27 
28  class I_SerializerAny
29  {
30  public:
31  virtual ~I_SerializerAny()
32  {}
33 
34  virtual void serialize(
35  SF::Archive &ar,
36  boost::any &a) = 0;
37  };
38 
39  template<typename T>
40  class SerializerAny : public I_SerializerAny
41  {
42  public:
43  void serialize(SF::Archive &ar, boost::any &a);
44  };
45 
46 } // namespace SF
47 
48 #include <SF/Archive.hpp>
49 
50 namespace SF {
51 
52  template<typename T>
53  void SerializerAny<T>::serialize(SF::Archive &ar, boost::any &a)
54  {
55  if (ar.isWrite())
56  {
57  ar & boost::any_cast<T>(a);
58  }
59  else
60  {
61  T t;
62  ar & t;
63  a = t;
64  }
65  }
66 
67 } // namespace SF
68 
69 #endif // ! INCLUDE_SF_SERIALIZEANY_HPP
Represents an archive, in which serialized objects are stored.
Definition: Archive.hpp:32
Definition: ByteBuffer.hpp:189
bool isWrite() const
Returns true if this archive is being written to.