Remote Call Framework 3.0
SerializeFundamental.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_SERIALIZEFUNDAMENTAL_HPP
20 #define INCLUDE_SF_SERIALIZEFUNDAMENTAL_HPP
21 
22 #include <SF/Archive.hpp>
23 #include <SF/DataPtr.hpp>
24 #include <SF/I_Stream.hpp>
25 #include <SF/Stream.hpp>
26 #include <RCF/Tools.hpp>
27 
28 namespace SF {
29 
30  // serialize fundamental types
31 
32  template<typename T>
33  inline void serializeFundamental(
34  SF::Archive &ar,
35  T &t,
36  unsigned int count = 1)
37  {
38  typedef typename RCF::RemoveCv<T>::type U;
39  static_assert( RCF::IsFundamental<U>::value, "" );
40  U * pt = const_cast<U *>(&t);
41 
42  if (ar.isRead())
43  {
44  I_Encoding &encoding = ar.getIstream()->getEncoding();
45  DataPtr data;
46  ar.getIstream()->get(data);
47  if (count > 1 && count != encoding.getCount(data, pt) )
48  {
49  // static array size mismatch
50  RCF::Exception e(RCF::RcfError_SfDataFormat);
51  RCF_THROW(e);
52  }
53  encoding.toObject(data, pt, count);
54  }
55  else if (ar.isWrite())
56  {
57  I_Encoding &encoding = ar.getOstream()->getEncoding();
58  DataPtr data;
59  encoding.toData(data, pt, count );
60  ar.getOstream()->put(data);
61  }
62  }
63 
64 } // namespace SF
65 
66 #endif // ! INCLUDE_SF_SERIALIZEFUNDAMENTAL_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.
bool isRead() const
Returns true if this archive is being read from.