/*-----------------------------------------------------------------------------+ Copyright (c) 2008-2009: Joachim Faulhaber +------------------------------------------------------------------------------+ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENCE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +-----------------------------------------------------------------------------*/ #ifndef BOOST_ICL_TEST_VALUE_MAKER_HPP_JOFA_080916 #define BOOST_ICL_TEST_VALUE_MAKER_HPP_JOFA_080916 #include #include namespace boost{ namespace icl { struct mono { mono(){}; mono& operator ++ (){ return *this; } mono& operator -- (){ return *this; } mono& operator += (const mono&){ return *this; } }; bool operator == (const mono&, const mono&){ return true; } bool operator < (const mono&, const mono&){ return false; } template std::basic_ostream& operator << (std::basic_ostream& stream, const mono& object) { return stream << "*"; } template BicrementableT make(int n) { BicrementableT value = identity_element::value(); if(n>=0) for(int i=0; in; i--) --value; return value; } template struct test_value; template<> struct test_value { static std::string make(int n) { std::string value = identity_element::value(); int abs_n = n<0 ? -n : n; for(int i=1; i struct test_value { static bool map_integers(Type values[], int size) { static const int offset = size/2; for(int idx = 0; idx < size; idx++) values[idx] = test_value::make(idx - offset); return true; } static Type* make(int n) { static bool initialized; static const int size = 100; static const int offset = size/2; static Type values[size]; if(!initialized) initialized = map_integers(values, size); Type* value = values + offset; if(n>=0) for(int i=0; in; i--) --value; return value; } }; template struct test_value { static Type make(int n) { Type value = identity_element::value(); if(n>=0) for(int i=0; in; i--) --value; return value; } }; template struct map_val { typedef typename ItvMapT::domain_type domain_type; typedef typename ItvMapT::codomain_type codomain_type; typedef typename ItvMapT::interval_type interval_type; typedef typename ItvMapT::value_type value_type; typedef typename ItvMapT::segment_type segment_type; typedef typename ItvMapT::domain_mapping_type domain_mapping_type; typedef std::pair std_pair_type; static segment_type mk_segment(const interval_type& inter_val, int val) { return segment_type(inter_val, test_value::make(val)); } /*CL? static interval_type interval_(int lower, int upper, int bounds = 2) { return segment_type(inter_val, test_value::make(val)); } static segment_type val_pair(int lower, int upper, int val, int bounds = 2) { return segment_type( interval_(lower, upper, static_cast(bounds)), test_value::make(val) ); } */ static domain_mapping_type map_pair(int key, int val) { return domain_mapping_type(test_value< domain_type>::make(key), test_value::make(val)); } static std_pair_type std_pair(int key, int val) { return std_pair_type(test_value< domain_type>::make(key), test_value::make(val)); } }; // Very short value denotation for intervals // Assumption typename T and IntervalT exists in scope //I_I : [a,b] #define I_I(low,up) icl::interval::closed (test_value::make(low), test_value::make(up)) //I_D : [a,b) #define I_D(low,up) icl::interval::right_open(test_value::make(low), test_value::make(up)) //C_I : (a,b] #define C_I(low,up) icl::interval::left_open (test_value::make(low), test_value::make(up)) //C_D : (a,b) #define C_D(low,up) icl::interval::open (test_value::make(low), test_value::make(up)) #define MK_I(ItvT,low,up) ItvT(test_value::make(low), test_value::make(up)) #define MK_v(key) test_value::make(key) #define MK_u(key) test_value::make(key) // Very short value denotation for interval value pairs // Assumption typename IntervalMapT existes in scope #define IIv(low,up,val) map_val::mk_segment(I_I(low,up), val) #define IDv(low,up,val) map_val::mk_segment(I_D(low,up), val) #define CIv(low,up,val) map_val::mk_segment(C_I(low,up), val) #define CDv(low,up,val) map_val::mk_segment(C_D(low,up), val) #define K_v(key,val) map_val::map_pair(key,val) #define sK_v(key,val) map_val::std_pair(key,val) #define MK_seg(itv,val) map_val::mk_segment(itv, val) }} // namespace boost icl #endif