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