Remote Call Framework 3.0
SerializePolymorphic.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_SERIALIZEPOLYMORPHIC_HPP
20 #define INCLUDE_SF_SERIALIZEPOLYMORPHIC_HPP
21 
22 namespace SF {
23 
24  class Archive;
25 
26  class I_SerializerPolymorphic
27  {
28  public:
29  virtual ~I_SerializerPolymorphic() {}
30  virtual bool invoke(void **ppvb, Archive &ar) = 0;
31  };
32 
33  template<typename Base, typename Derived>
34  class SerializerPolymorphic : public I_SerializerPolymorphic
35  {
36  public:
37 
38  SerializerPolymorphic()
39  {}
40 
41  virtual bool invoke(void **ppvb, Archive &ar);
42  };
43 
44 }
45 
46 #include <SF/Archive.hpp>
47 #include <SF/Serializer.hpp>
48 
49 namespace SF {
50 
51  template<typename Base, typename Derived>
52  bool SerializerPolymorphic<Base,Derived>::invoke(void **ppvb, Archive &ar)
53  {
54  if (ar.isWrite())
55  {
56  Base *pb = reinterpret_cast<Base *>(*ppvb);
57  Derived *pd = static_cast<Derived *>(pb);
58  ar & pd;
59  }
60  else if (ar.isRead())
61  {
62  if (ar.isFlagSet(Archive::POINTER))
63  {
64  Derived *pd = NULL;
65  ar & pd;
66  Base *pb = static_cast<Base *>(pd);
67  *ppvb = pb;
68  }
69  else
70  {
71  Base *pb = reinterpret_cast<Base *>(*ppvb);
72  Derived *pd = static_cast<Derived *>(pb);
73  ar & *pd;
74  }
75  }
76  return true;
77  }
78 
79 }
80 
81 #endif // ! INCLUDE_SF_SERIALIZEPOLYMORPHIC_HPP
Definition: ByteBuffer.hpp:189