Remote Call Framework 3.1
SF/boost/Any.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2019, 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.1
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_SF_ANY_HPP
20 #define INCLUDE_SF_ANY_HPP
21 
22 #include <string>
23 
24 #include <boost/any.hpp>
25 
26 #include <SF/string.hpp>
27 #include <SF/Registry.hpp>
28 #include <SF/SerializeAny.hpp>
29 
30 namespace SF {
31 
32  class Archive;
33 
34  inline void serialize(SF::Archive &ar, boost::any &a)
35  {
36  if ( ar.isWrite() )
37  {
38  std::string which =
39  SF::Registry::getSingleton().getTypeName(a.type());
40 
41  if ( which.empty() && !a.empty() )
42  {
43  RCF_THROW(RCF::Exception(RCF::RcfError_AnyTypeNotRegistered, a.type().name()));
44  }
45 
46  ar & which;
47 
48  if ( !a.empty() )
49  {
50  RCF_ASSERT(which.size() > 0);
51 
52  SF::I_SerializerAny * serializerAny = SF::Registry::getSingleton().getAnySerializer(which);
53  if ( serializerAny )
54  {
55  serializerAny->serialize(ar, a);
56  }
57  }
58  }
59  else
60  {
61  std::string which;
62  ar & which;
63  if ( which.empty() )
64  {
65  a = boost::any();
66  }
67  else
68  {
69  SF::I_SerializerAny * serializerAny = SF::Registry::getSingleton().getAnySerializer(which);
70  if ( serializerAny )
71  {
72  serializerAny->serialize(ar, a);
73  }
74  }
75  }
76  }
77 
78 
79 } // namespace SF
80 
81 #endif // ! INCLUDE_SF_ANY_HPP
Represents an archive, in which serialized objects are stored.
Definition: Archive.hpp:32
Base class for all RCF exceptions.
Definition: Exception.hpp:64
Definition: ByteBuffer.hpp:189
bool isWrite() const
Returns true if this archive is being written to.