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