Remote Call Framework 3.0
SerializeArray.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_SERIALIZEARRAY_HPP
20 #define INCLUDE_SF_SERIALIZEARRAY_HPP
21 
22 #include <cstddef>
23 
24 #include <RCF/Exception.hpp>
25 #include <SF/Archive.hpp>
26 
27 namespace SF {
28 
29  class Archive;
30 
31  // Serialization for boost::array<>, std::array<>, etc.
32 
33  template<typename ArrayType>
34  void serialize_array_impl(SF::Archive & ar, ArrayType & a)
35  {
36  if (ar.isRead())
37  {
38  unsigned int count = 0;
39  ar & count;
40 
41  if ( static_cast<std::size_t>(count) != a.size() )
42  {
43  RCF::Exception e(RCF::RcfError_ArraySizeMismatch, a.size(), count);
44  RCF_THROW(e);
45  }
46 
47  for (std::size_t i=0; i<a.size(); ++i)
48  {
49  ar & a[i];
50  }
51  }
52  else if (ar.isWrite())
53  {
54  unsigned int count = static_cast<unsigned int>(a.size());
55  ar & count;
56 
57  for (std::size_t i=0; i<a.size(); ++i)
58  {
59  ar & a[i];
60  }
61  }
62  }
63 
64 } // namespace SF
65 
66 #endif // ! INCLUDE_SF_SERIALIZEARRAY_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.