Remote Call Framework 3.3
SerializePolymorphic.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2022, Delta V Software. All rights reserved.
6 // https://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 under GPL terms.
12 //
13 // Version: 3.3
14 // Contact: support <at> deltavsoft.com
15 //
16 //******************************************************************************
17 
18 #ifndef INCLUDE_SF_SERIALIZEPOLYMORPHIC_HPP
19 #define INCLUDE_SF_SERIALIZEPOLYMORPHIC_HPP
20 
21 namespace SF {
22 
23  class Archive;
24 
25  class I_SerializerPolymorphic
26  {
27  public:
28  virtual ~I_SerializerPolymorphic() {}
29  virtual bool invoke(void **ppvb, Archive &ar) = 0;
30  };
31 
32  template<typename Base, typename Derived>
33  class SerializerPolymorphic : public I_SerializerPolymorphic
34  {
35  public:
36 
37  SerializerPolymorphic()
38  {}
39 
40  virtual bool invoke(void **ppvb, Archive &ar);
41  };
42 
43 }
44 
45 #include <SF/Archive.hpp>
46 #include <SF/Serializer.hpp>
47 
48 namespace SF {
49 
50  template<typename Base, typename Derived>
51  bool SerializerPolymorphic<Base,Derived>::invoke(void **ppvb, Archive &ar)
52  {
53  if (ar.isWrite())
54  {
55  Base *pb = reinterpret_cast<Base *>(*ppvb);
56  Derived *pd = static_cast<Derived *>(pb);
57  ar & pd;
58  }
59  else if (ar.isRead())
60  {
61  if (ar.isFlagSet(Archive::POINTER))
62  {
63  Derived *pd = NULL;
64  ar & pd;
65  Base *pb = static_cast<Base *>(pd);
66  *ppvb = pb;
67  }
68  else
69  {
70  Base *pb = reinterpret_cast<Base *>(*ppvb);
71  Derived *pd = static_cast<Derived *>(pb);
72  ar & *pd;
73  }
74  }
75  return true;
76  }
77 
78 }
79 
80 #endif // ! INCLUDE_SF_SERIALIZEPOLYMORPHIC_HPP
Definition: ByteBuffer.hpp:188