1 // Boost.Geometry.Index varray 2 // Unit Test 3 4 // Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland. 5 // Copyright (c) 2012-2013 Andrew Hundt. 6 7 // Use, modification and distribution is subject to the Boost Software License, 8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 // http://www.boost.org/LICENSE_1_0.txt) 10 11 #ifndef BOOST_GEOMETRY_INDEX_TEST_VARRAY_TEST_HPP 12 #define BOOST_GEOMETRY_INDEX_TEST_VARRAY_TEST_HPP 13 14 #include <boost/geometry/index/detail/varray.hpp> 15 16 #include <boost/shared_ptr.hpp> 17 #include "movable.hpp" 18 19 class value_ndc 20 { 21 public: value_ndc(size_t a)22 explicit value_ndc(size_t a) : aa(a) {} ~value_ndc()23 ~value_ndc() {} operator ==(value_ndc const & v) const24 bool operator==(value_ndc const& v) const { return aa == v.aa; } operator <(value_ndc const & v) const25 bool operator<(value_ndc const& v) const { return aa < v.aa; } 26 private: value_ndc(value_ndc const &)27 value_ndc(value_ndc const&) {} operator =(value_ndc const &)28 value_ndc & operator=(value_ndc const&) { return *this; } 29 size_t aa; 30 }; 31 32 class value_nd 33 { 34 public: value_nd(size_t a)35 explicit value_nd(size_t a) : aa(a) {} ~value_nd()36 ~value_nd() {} operator ==(value_nd const & v) const37 bool operator==(value_nd const& v) const { return aa == v.aa; } operator <(value_nd const & v) const38 bool operator<(value_nd const& v) const { return aa < v.aa; } 39 private: 40 size_t aa; 41 }; 42 43 class value_nc 44 { 45 public: value_nc(size_t a=0)46 explicit value_nc(size_t a = 0) : aa(a) {} ~value_nc()47 ~value_nc() {} operator ==(value_nc const & v) const48 bool operator==(value_nc const& v) const { return aa == v.aa; } operator <(value_nc const & v) const49 bool operator<(value_nc const& v) const { return aa < v.aa; } 50 private: value_nc(value_nc const &)51 value_nc(value_nc const&) {} operator =(value_ndc const &)52 value_nc & operator=(value_ndc const&) { return *this; } 53 size_t aa; 54 }; 55 56 class counting_value 57 { 58 BOOST_COPYABLE_AND_MOVABLE(counting_value) 59 60 public: counting_value(size_t a=0,size_t b=0)61 explicit counting_value(size_t a = 0, size_t b = 0) : aa(a), bb(b) { ++c(); } counting_value(counting_value const & v)62 counting_value(counting_value const& v) : aa(v.aa), bb(v.bb) { ++c(); } counting_value(BOOST_RV_REF (counting_value)p)63 counting_value(BOOST_RV_REF(counting_value) p) : aa(p.aa), bb(p.bb) { p.aa = 0; p.bb = 0; ++c(); } // Move constructor operator =(BOOST_RV_REF (counting_value)p)64 counting_value& operator=(BOOST_RV_REF(counting_value) p) { aa = p.aa; p.aa = 0; bb = p.bb; p.bb = 0; return *this; } // Move assignment operator =(BOOST_COPY_ASSIGN_REF (counting_value)p)65 counting_value& operator=(BOOST_COPY_ASSIGN_REF(counting_value) p) { aa = p.aa; bb = p.bb; return *this; } // Copy assignment ~counting_value()66 ~counting_value() { --c(); } operator ==(counting_value const & v) const67 bool operator==(counting_value const& v) const { return aa == v.aa && bb == v.bb; } operator <(counting_value const & v) const68 bool operator<(counting_value const& v) const { return aa < v.aa || ( aa == v.aa && bb < v.bb ); } count()69 static size_t count() { return c(); } 70 71 private: c()72 static size_t & c() { static size_t co = 0; return co; } 73 size_t aa, bb; 74 }; 75 76 namespace boost { 77 78 template <> 79 struct has_nothrow_move<counting_value> 80 { 81 static const bool value = true; 82 }; 83 84 } 85 86 class shptr_value 87 { 88 typedef boost::shared_ptr<size_t> Ptr; 89 public: shptr_value(size_t a=0)90 explicit shptr_value(size_t a = 0) : m_ptr(new size_t(a)) {} operator ==(shptr_value const & v) const91 bool operator==(shptr_value const& v) const { return *m_ptr == *(v.m_ptr); } operator <(shptr_value const & v) const92 bool operator<(shptr_value const& v) const { return *m_ptr < *(v.m_ptr); } 93 private: 94 boost::shared_ptr<size_t> m_ptr; 95 }; 96 97 #endif // BOOST_GEOMETRY_INDEX_TEST_VARRAY_TEST_HPP 98