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