// ============================================================================ // // Copyright (c) 2001-2006 Max-Planck-Institut Saarbruecken (Germany). // All rights reserved. // // This file is part of EXACUS (http://www.mpi-inf.mpg.de/projects/EXACUS/); // you may redistribute it under the terms of the Q Public License version 1.0. // See the file LICENSE.QPL distributed with EXACUS. // // Licensees holding a valid commercial license may use this file in // accordance with the commercial license agreement provided with the software. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // // ---------------------------------------------------------------------------- // // Library : Support // File : test/Cache.C // SoX_release : $Name: $ // Revision : $Revision$ // Revision_date : $Date$ // // Author(s) : Michael Hemmer // // ============================================================================ #include #include #include #include #include #include #include struct Int_rep { int val; Int_rep( int i = 0) : val(i) {} Int_rep( int i, int j) : val(i+j) {} Int_rep( int i, int j, int k) : val(i+j+k) {} }; template < class Unify> struct Int_t : public CGAL::Handle_with_policy< Int_rep, Unify > { typedef CGAL::Handle_with_policy< Int_rep, Unify > Base; Int_t( int i = 0) : Base( i) {} Int_t( int i, int j) : Base( i, j) {} // test template constructors Int_t( int i, int j, int k) : Base( Base::USE_WITH_INITIALIZE_WITH) { // test initialize_with this->initialize_with( i, j + k); } // This is needed to prevent VC7.1 and VC8 to call // the explicit templated constructor in Base instead of its copy-ctor. Int_t( Int_t const& rhs ) : Base( static_cast(rhs) ) {} int value() const { return this->ptr()->val; } void set_value( int i) { this->copy_on_write(); this->ptr()->val = i; } bool operator==( const Int_t& i) const { bool equal = (value() == i.value()); if ( equal) unify(i); return equal; } }; void test_typedefs(){ typedef CGAL::Cache Cache; BOOST_STATIC_ASSERT(( ::boost::is_same< Cache::Input, int >::value )); BOOST_STATIC_ASSERT(( ::boost::is_same< Cache::Output,double>::value )); typedef CGAL::Creator_1 Creator_double; BOOST_STATIC_ASSERT(( ::boost::is_same::value )); typedef CGAL::Creator_1 Creator_int; BOOST_STATIC_ASSERT(( ::boost::is_same::value )); BOOST_STATIC_ASSERT(( ::boost::is_same >::value )); BOOST_STATIC_ASSERT(( ::boost::is_same >::value )); } int main(){ { test_typedefs(); { typedef CGAL::Cache Cache; double d; Cache cache; CGAL_test_assert(cache.is_empty()); CGAL_test_assert(cache.size()==0); d=cache(3); CGAL_test_assert(d==double(3)); CGAL_test_assert(cache.size()==1); d=cache(4); CGAL_test_assert(d==double(4)); CGAL_test_assert(cache.size()==2); d=cache(3); CGAL_test_assert(d==double(3)); CGAL_test_assert(cache.size()==2); d=cache(2); CGAL_test_assert(d==double(2)); CGAL_test_assert(cache.size()==3); typedef Cache::Iterator Iterator; typedef Cache::Const_iterator Const_iterator; typedef Cache::Reverse_iterator Reverse_iterator; typedef Cache::Const_reverse_iterator Const_reverse_iterator; typedef Cache::Size_type Size_type; Iterator it; d=0; for(it=cache.begin();it!=cache.end();it++){ CGAL_test_assert(d<(*it).second); d=(*it).second; } cache.clear(); CGAL_test_assert(cache.size()==0); } { typedef Int_t< CGAL::Handle_policy_no_union > Int; typedef CGAL::Cache Cache; Int hi,hi2; Cache cache; CGAL_test_assert(cache.is_empty()); CGAL_test_assert(cache.size()==0); hi=cache(3); CGAL_test_assert(hi==Int(3)); CGAL_test_assert(cache.size()==1); hi2=cache(4); CGAL_test_assert(hi2==Int(4)); CGAL_test_assert(cache.size()==2); hi2=cache(3); CGAL_test_assert(hi.id()==hi2.id()); } } return EXIT_SUCCESS; }