Turi Create  4.0
serializable_concept.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_SERIALIZABLE
7 #define TURI_SERIALIZABLE
8 #include <boost/concept/assert.hpp>
9 #include <boost/concept/requires.hpp>
10 #include <boost/concept_check.hpp>
11 #include <sstream>
12 #include <core/storage/serialization/serialize.hpp>
13 namespace turi {
14 
15  /**
16  * \brief Concept checks if a type T is serializable.
17  *
18  * This is a concept checking class for boost::concept and can be
19  * used to enforce that a type T is \ref sec_serializable, assignable and
20  * default constructible.
21  *
22  * \tparam T The type to test for serializability.
23  */
24  template <typename T>
25  class Serializable : boost::Assignable<T>, boost::DefaultConstructible<T> {
26  public:
27  BOOST_CONCEPT_USAGE(Serializable) {
28  std::stringstream strm;
29  oarchive oarc(strm);
30  iarchive iarc(strm);
31  const T const_t = T();
32  T t = T();
33  // A compiler error on these lines implies that your type is not
34  // serializable. See the documentaiton on how to make
35  // serializable type.
36  oarc << const_t;
37  iarc >> t;
38  }
39  };
40 
41 } // namespace turi
42 #endif
The serialization input archive object which, provided with a reference to an istream, will read from the istream, providing deserialization capabilities.
Definition: iarchive.hpp:60
Concept checks if a type T is serializable.
The serialization output archive object which, provided with a reference to an ostream, will write to the ostream, providing serialization capabilities.
Definition: oarchive.hpp:80