]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/serialization/collection_size_type copy.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / serialization / collection_size_type copy.hpp
1 #ifndef BOOST_SERIALIZATION_COLLECTION_SIZE_TYPE_HPP
2 #define BOOST_SERIALIZATION_COLLECTION_SIZE_TYPE_HPP
3
4 // (C) Copyright 2005 Matthias Troyer
5 // (C) Copyright 2020 Robert Ramey
6
7 // Use, modification and distribution is subject to the Boost Software
8 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 #include <cstddef> // size_t
12 #include <boost/assert.hpp>
13 #include <boost/operators.hpp>
14 #include <boost/serialization/level.hpp>
15 #include <boost/serialization/is_bitwise_serializable.hpp>
16
17 namespace boost {
18 namespace serialization {
19
20 template<typename T> // T is the basic type holding the integer
21 struct cardinal_number : private
22 boost::totally_ordered<cardinal_number<T> >,
23 boost::additive<cardinal_number<T> >,
24 boost::unit_steppable<cardinal_number<T> >
25 {
26 private:
27 template<typename CharType, typename Traits>
28 friend std::basic_ostream<CharType, Traits> & operator<<(
29 const std::basic_ostream<CharType, Traits> & bos,
30 const cardinal_number & rhs
31 );
32 template<typename CharType, typename Traits>
33 friend std::basic_istream<CharType, Traits> & operator>>(
34 std::basic_istream<CharType, Traits> & bis,
35 const cardinal_number & rhs
36 );
37 public:
38 T m_t;
39 cardinal_number(T t = 0) :
40 m_t(t)
41 {}
42 cardinal_number(unsigned int t) :
43 m_t(t)
44 {}
45 cardinal_number(int t) :
46 m_t(t)
47 {
48 BOOST_ASSERT(t >= 0);
49 }
50 operator const T (){
51 return m_t;
52 }
53 // assignment operator
54 cardinal_number & operator=(const cardinal_number & rhs){
55 m_t = rhs.m_t;
56 return *this;
57 }
58 // basic operations upon which others depend
59 // totally ordered / less_than_comparable
60 bool operator<(const cardinal_number & rhs) const {
61 return m_t < rhs.m_t;
62 }
63 bool operator==(const cardinal_number & rhs) const {
64 return m_t == rhs.m_t;
65 }
66 // additive
67 cardinal_number & operator+=(const cardinal_number & rhs){
68 m_t += rhs.m_t;
69 return *this;
70 }
71 // subtractive
72 cardinal_number & operator-=(const cardinal_number & rhs){
73 BOOST_ASSERT(m_t >= rhs.m_t);
74 m_t -= rhs.m_t;
75 return *this;
76 }
77 // increment
78 cardinal_number operator++(){
79 ++m_t;
80 return *this;
81 }
82 // decrement
83 cardinal_number operator--(){
84 BOOST_ASSERT(m_t > T(0));
85 --m_t;
86 return *this;
87 }
88 };
89
90 typedef cardinal_number<std::size_t> collection_size_type;
91
92 } } // end namespace boost::serialization
93
94 #include <ostream>
95 #include <istream>
96
97 namespace std {
98
99 template<typename CharType, typename Traits>
100 basic_ostream<CharType, Traits> & operator<<(
101 std::basic_ostream<CharType, Traits> & bos,
102 const boost::serialization::collection_size_type & rhs
103 ){
104 bos << rhs.m_t;
105 return bos;
106 }
107
108 template<typename CharType, typename Traits>
109 basic_istream<CharType, Traits> & operator>>(
110 std::basic_istream<CharType, Traits> & bis,
111 boost::serialization::collection_size_type & rhs
112 ){
113 bis >> rhs.m_t;
114 return bis;
115 }
116
117 } // std
118
119 BOOST_CLASS_IMPLEMENTATION( \
120 boost::serialization::collection_size_type, \
121 primitive_type \
122 )
123 BOOST_IS_BITWISE_SERIALIZABLE(boost::serialization::collection_size_type)
124
125 #endif //BOOST_SERIALIZATION_COLLECTION_SIZE_TYPE_HPP