• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2006-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/interprocess for documentation.
8 //
9 ///////////////////////////////////////////////////////////////////////////
10 
11 #ifndef BOOST_INTERPROCESS_TEST_MOVABLE_INT_HEADER
12 #define BOOST_INTERPROCESS_TEST_MOVABLE_INT_HEADER
13 
14 #include <boost/interprocess/detail/config_begin.hpp>
15 #include <boost/interprocess/detail/workaround.hpp>
16 #include <boost/move/utility_core.hpp>
17 
18 namespace boost {
19 namespace interprocess {
20 namespace test {
21 
22 template<class T>
23 struct is_copyable;
24 
25 template<>
26 struct is_copyable<int>
27 {
28    static const bool value = true;
29 };
30 
31 
32 class movable_int
33 {
34    BOOST_MOVABLE_BUT_NOT_COPYABLE(movable_int)
35 
36    public:
movable_int()37    movable_int()
38       :  m_int(0)
39    {}
40 
movable_int(int a)41    explicit movable_int(int a)
42       :  m_int(a)
43    {}
44 
movable_int(BOOST_RV_REF (movable_int)mmi)45    movable_int(BOOST_RV_REF(movable_int) mmi)
46       :  m_int(mmi.m_int)
47    {  mmi.m_int = 0; }
48 
operator =(BOOST_RV_REF (movable_int)mmi)49    movable_int & operator= (BOOST_RV_REF(movable_int) mmi)
50    {  this->m_int = mmi.m_int;   mmi.m_int = 0;  return *this;  }
51 
operator =(int i)52    movable_int & operator= (int i)
53    {  this->m_int = i;  return *this;  }
54 
operator ==(const movable_int & mi) const55    bool operator ==(const movable_int &mi) const
56    {  return this->m_int == mi.m_int;   }
57 
operator !=(const movable_int & mi) const58    bool operator !=(const movable_int &mi) const
59    {  return this->m_int != mi.m_int;   }
60 
operator <(const movable_int & mi) const61    bool operator <(const movable_int &mi) const
62    {  return this->m_int < mi.m_int;   }
63 
operator <=(const movable_int & mi) const64    bool operator <=(const movable_int &mi) const
65    {  return this->m_int <= mi.m_int;   }
66 
operator >=(const movable_int & mi) const67    bool operator >=(const movable_int &mi) const
68    {  return this->m_int >= mi.m_int;   }
69 
operator >(const movable_int & mi) const70    bool operator >(const movable_int &mi) const
71    {  return this->m_int > mi.m_int;   }
72 
get_int() const73    int get_int() const
74    {  return m_int;  }
75 
operator ==(const movable_int & l,int r)76    friend bool operator==(const movable_int &l, int r)
77    {  return l.get_int() == r;   }
78 
operator ==(int l,const movable_int & r)79    friend bool operator==(int l, const movable_int &r)
80    {  return l == r.get_int();   }
81 
82    private:
83    int m_int;
84 };
85 
86 template<class E, class T>
operator <<(std::basic_ostream<E,T> & os,movable_int const & p)87 std::basic_ostream<E, T> & operator<<
88    (std::basic_ostream<E, T> & os, movable_int const & p)
89 
90 {
91     os << p.get_int();
92     return os;
93 }
94 
95 
96 template<>
97 struct is_copyable<movable_int>
98 {
99    static const bool value = false;
100 };
101 
102 class movable_and_copyable_int
103 {
104    BOOST_COPYABLE_AND_MOVABLE(movable_and_copyable_int)
105 
106    public:
movable_and_copyable_int()107    movable_and_copyable_int()
108       :  m_int(0)
109    {}
110 
movable_and_copyable_int(int a)111    explicit movable_and_copyable_int(int a)
112       :  m_int(a)
113    {}
114 
movable_and_copyable_int(const movable_and_copyable_int & mmi)115    movable_and_copyable_int(const movable_and_copyable_int& mmi)
116       :  m_int(mmi.m_int)
117    {}
118 
movable_and_copyable_int(BOOST_RV_REF (movable_and_copyable_int)mmi)119    movable_and_copyable_int(BOOST_RV_REF(movable_and_copyable_int) mmi)
120       :  m_int(mmi.m_int)
121    {  mmi.m_int = 0; }
122 
operator =(BOOST_COPY_ASSIGN_REF (movable_and_copyable_int)mi)123    movable_and_copyable_int &operator= (BOOST_COPY_ASSIGN_REF(movable_and_copyable_int) mi)
124    {  this->m_int = mi.m_int;    return *this;  }
125 
operator =(BOOST_RV_REF (movable_and_copyable_int)mmi)126    movable_and_copyable_int & operator= (BOOST_RV_REF(movable_and_copyable_int) mmi)
127    {  this->m_int = mmi.m_int;   mmi.m_int = 0;    return *this;  }
128 
operator =(int i)129    movable_and_copyable_int & operator= (int i)
130    {  this->m_int = i;  return *this;  }
131 
operator ==(const movable_and_copyable_int & mi) const132    bool operator ==(const movable_and_copyable_int &mi) const
133    {  return this->m_int == mi.m_int;   }
134 
operator !=(const movable_and_copyable_int & mi) const135    bool operator !=(const movable_and_copyable_int &mi) const
136    {  return this->m_int != mi.m_int;   }
137 
operator <(const movable_and_copyable_int & mi) const138    bool operator <(const movable_and_copyable_int &mi) const
139    {  return this->m_int < mi.m_int;   }
140 
operator <=(const movable_and_copyable_int & mi) const141    bool operator <=(const movable_and_copyable_int &mi) const
142    {  return this->m_int <= mi.m_int;   }
143 
operator >=(const movable_and_copyable_int & mi) const144    bool operator >=(const movable_and_copyable_int &mi) const
145    {  return this->m_int >= mi.m_int;   }
146 
operator >(const movable_and_copyable_int & mi) const147    bool operator >(const movable_and_copyable_int &mi) const
148    {  return this->m_int > mi.m_int;   }
149 
get_int() const150    int get_int() const
151    {  return m_int;  }
152 
operator ==(const movable_and_copyable_int & l,int r)153    friend bool operator==(const movable_and_copyable_int &l, int r)
154    {  return l.get_int() == r;   }
155 
operator ==(int l,const movable_and_copyable_int & r)156    friend bool operator==(int l, const movable_and_copyable_int &r)
157    {  return l == r.get_int();   }
158 
159    private:
160    int m_int;
161 };
162 
163 template<class E, class T>
operator <<(std::basic_ostream<E,T> & os,movable_and_copyable_int const & p)164 std::basic_ostream<E, T> & operator<<
165    (std::basic_ostream<E, T> & os, movable_and_copyable_int const & p)
166 
167 {
168     os << p.get_int();
169     return os;
170 }
171 
172 template<>
173 struct is_copyable<movable_and_copyable_int>
174 {
175    static const bool value = true;
176 };
177 
178 class copyable_int
179 {
180    public:
copyable_int()181    copyable_int()
182       :  m_int(0)
183    {}
184 
copyable_int(int a)185    explicit copyable_int(int a)
186       :  m_int(a)
187    {}
188 
copyable_int(const copyable_int & mmi)189    copyable_int(const copyable_int& mmi)
190       :  m_int(mmi.m_int)
191    {}
192 
operator =(int i)193    copyable_int & operator= (int i)
194    {  this->m_int = i;  return *this;  }
195 
operator ==(const copyable_int & mi) const196    bool operator ==(const copyable_int &mi) const
197    {  return this->m_int == mi.m_int;   }
198 
operator !=(const copyable_int & mi) const199    bool operator !=(const copyable_int &mi) const
200    {  return this->m_int != mi.m_int;   }
201 
operator <(const copyable_int & mi) const202    bool operator <(const copyable_int &mi) const
203    {  return this->m_int < mi.m_int;   }
204 
operator <=(const copyable_int & mi) const205    bool operator <=(const copyable_int &mi) const
206    {  return this->m_int <= mi.m_int;   }
207 
operator >=(const copyable_int & mi) const208    bool operator >=(const copyable_int &mi) const
209    {  return this->m_int >= mi.m_int;   }
210 
operator >(const copyable_int & mi) const211    bool operator >(const copyable_int &mi) const
212    {  return this->m_int > mi.m_int;   }
213 
get_int() const214    int get_int() const
215    {  return m_int;  }
216 
operator ==(const copyable_int & l,int r)217    friend bool operator==(const copyable_int &l, int r)
218    {  return l.get_int() == r;   }
219 
operator ==(int l,const copyable_int & r)220    friend bool operator==(int l, const copyable_int &r)
221    {  return l == r.get_int();   }
222 
223    private:
224    int m_int;
225 };
226 
227 template<class E, class T>
operator <<(std::basic_ostream<E,T> & os,copyable_int const & p)228 std::basic_ostream<E, T> & operator<<
229    (std::basic_ostream<E, T> & os, copyable_int const & p)
230 
231 {
232     os << p.get_int();
233     return os;
234 }
235 
236 template<>
237 struct is_copyable<copyable_int>
238 {
239    static const bool value = true;
240 };
241 
242 class non_copymovable_int
243 {
244    non_copymovable_int(const non_copymovable_int& mmi);
245    non_copymovable_int & operator= (const non_copymovable_int &mi);
246 
247    public:
non_copymovable_int()248    non_copymovable_int()
249       :  m_int(0)
250    {}
251 
non_copymovable_int(int a)252    explicit non_copymovable_int(int a)
253       :  m_int(a)
254    {}
255 
operator ==(const non_copymovable_int & mi) const256    bool operator ==(const non_copymovable_int &mi) const
257    {  return this->m_int == mi.m_int;   }
258 
operator !=(const non_copymovable_int & mi) const259    bool operator !=(const non_copymovable_int &mi) const
260    {  return this->m_int != mi.m_int;   }
261 
operator <(const non_copymovable_int & mi) const262    bool operator <(const non_copymovable_int &mi) const
263    {  return this->m_int < mi.m_int;   }
264 
operator <=(const non_copymovable_int & mi) const265    bool operator <=(const non_copymovable_int &mi) const
266    {  return this->m_int <= mi.m_int;   }
267 
operator >=(const non_copymovable_int & mi) const268    bool operator >=(const non_copymovable_int &mi) const
269    {  return this->m_int >= mi.m_int;   }
270 
operator >(const non_copymovable_int & mi) const271    bool operator >(const non_copymovable_int &mi) const
272    {  return this->m_int > mi.m_int;   }
273 
get_int() const274    int get_int() const
275    {  return m_int;  }
276 
operator ==(const non_copymovable_int & l,int r)277    friend bool operator==(const non_copymovable_int &l, int r)
278    {  return l.get_int() == r;   }
279 
operator ==(int l,const non_copymovable_int & r)280    friend bool operator==(int l, const non_copymovable_int &r)
281    {  return l == r.get_int();   }
282 
283    private:
284    int m_int;
285 };
286 
287 }  //namespace test {
288 }  //namespace interprocess {
289 }  //namespace boost {
290 
291 #include <boost/interprocess/detail/config_end.hpp>
292 
293 #endif   //#ifndef BOOST_INTERPROCESS_TEST_MOVABLE_INT_HEADER
294