16 #include <portability.h>
63 class predicate:
public std::unary_function<T, bool>
101 template <
typename T>
120 template <
typename T>
138 template <
typename T>
175 template <
typename T>
196 std::string temp_str( new_object->get_name() );
197 (*objects)[ temp_str ] = new_object;
205 typename std::map<std::string, T *>::iterator p;
215 T *
get(
const char *name )
217 std::string temp_str( name );
218 typename std::map<std::string, T *>::iterator p =
objects->find( temp_str );
228 typename std::map<std::string, T *>::iterator p;
253 virtual bool set_string(
const char *new_string ) = 0;
261 template <
typename T>
282 std::string temp_str;
283 to_string(
value, temp_str );
284 return strdup( temp_str.c_str() );
290 from_string( new_val, new_string );
306 from_string( new_val, new_string );
351 char *return_val =
new char[
value->length() + 1 ];
352 strcpy( return_val,
value->c_str() );
353 return_val[
value->length() ] =
'\0';
380 return value->c_str();
385 value->assign( new_value );
390 template <
typename T>
410 char *return_val =
new char[
value->length() + 1 ];
411 strcpy( return_val,
value->c_str() );
412 return_val[
value->length() ] =
'\0';
421 return from_string( test_val, new_value );
427 from_string( new_val, new_string );
435 typename std::set< T >::iterator it =
my_set->find( new_val );
436 std::string temp_str;
438 if ( it !=
my_set->end() )
446 to_string( *it, temp_str );
447 value->append( temp_str );
451 if ( it !=
my_set->end() )
452 value->append(
", " );
457 my_set->insert( new_val );
459 if ( !
value->empty() )
460 value->append(
", " );
462 to_string( new_val, temp_str );
463 value->append( temp_str );
481 virtual typename std::set< T >::iterator
set_end()
505 for ( std::set<Symbol *>::iterator p=
my_set->begin(); p!=
my_set->end(); p++ )
517 char *return_val =
new char[
value->length() + 1 ];
518 strcpy( return_val,
value->c_str() );
519 return_val[
value->length() ] =
'\0';
546 bool return_val =
false;
552 Symbol *my_sym = test_sym;
556 std::string temp_str;
560 to_string( my_sym->
ic.
value, temp_str );
564 to_string( my_sym->
fc.
value, temp_str );
570 std::set<Symbol *>::iterator p =
my_set->find( my_sym );
571 return_val = ( p !=
my_set->end() );
573 if ( test_sym != my_sym )
585 std::set<Symbol *>::iterator p =
my_set->find( my_sym );
599 value->append( (*p)->sc.name );
604 value->append(
", " );
611 if ( !
value->empty() )
612 value->append(
", " );
622 template <
typename T>
645 typename std::map<T, const char *>::iterator p;
652 size_t len = strlen( p->second );
653 char *return_val =
new char[ len + 1 ];
655 strcpy( return_val, p->second );
656 return_val[ len ] =
'\0';
664 typename std::map<std::string, T>::iterator p;
665 std::string temp_str( new_string );
682 typename std::map<std::string, T>::iterator p;
683 std::string temp_str( new_string );
706 std::string my_string( str );
709 (*string_to_value)[ my_string ] = val;
712 (*value_to_string)[ val ] = str;
751 virtual void reset() = 0;
757 template <
typename T>
779 std::string temp_str;
780 to_string( my_val, temp_str );
781 return strdup(temp_str.c_str());
820 for ( std::map<std::string, stat *>::iterator p=
objects->begin(); p!=
objects->end(); p++ )
857 double my_value =
value();
859 std::string temp_str;
860 to_string( my_value, temp_str );
861 return strdup(temp_str.c_str());
911 for ( std::map<std::string, timer *>::iterator p=
objects->begin(); p!=
objects->end(); p++ )
921 #define USE_MEM_POOL_ALLOCATORS 1
923 #ifdef USE_MEM_POOL_ALLOCATORS
956 template <
class _other>
1064 template <
class T,
int N>
1114 for (
int i=0; i<N; i++ )
1125 return ( ( current == ( N - 1 ) )?( 0 ):( current + 1 ) );
1130 return ( ( current == 0 )?( N - 1 ):( current - 1 ) );
1145 return &( p->second );
1166 virtual void _init() = 0;
1167 virtual void _down() = 0;
1206 bool return_val =
false;
1215 std::pair< typename object_history_map::iterator, bool > ip =
object_histories.insert( std::make_pair< const T*, object_history >( obj,
object_history( obj ) ) );
1216 assert( ip.second );
1218 h = &( ip.first->second );
1242 typename history_set::iterator h_p;
1305 typename forgetting_map::iterator pq_p =
forgetting_pq.begin();
1310 typename history_set::iterator d_p=pq_p->second.begin();
1311 typename history_set::iterator current_p;
1313 while ( d_p != pq_p->second.end() )
1319 forgotten.insert( (*current_p)->this_object );
1330 pq_p->second.clear();
1337 if ( ( pq_p !=
forgetting_pq.end() ) && pq_p->second.empty() )
1374 f_p->second.erase( h );
1412 template <
class T,
int N,
unsigned int R>
1452 if ( ( new_decay_rate > 0 ) && ( new_decay_rate < 1 ) && !this->
is_initialized() )
1502 double cache_full =
static_cast<double>( exp( (
decay_thresh - log( static_cast<double>( R ) ) ) /
decay_rate ) );
1507 double cache_bound_unit = (
static_cast<unsigned int>(
pow_cache_bound * 1024 * 1024 ) / static_cast<unsigned int>(
sizeof(
double ) ) );
1509 pow_cache_size =
static_cast< unsigned int >( ceil( ( cache_full > cache_bound_unit )?( cache_bound_unit ):( cache_full ) ) );
1528 for (
int i=1; i<R; i++ )
1548 if ( fresh_reference )
1552 unsigned int p = h->
next_p;
1572 return_val += to_add;
1578 if ( return_val == t )
1595 lower_bound = upper_bound;
1599 lower_bound = ( to_add / 2 );
1602 while ( lower_bound != upper_bound )
1604 mid = ( ( lower_bound + upper_bound ) / 2 );
1610 if ( upper_bound - lower_bound <= 1 )
1619 if ( upper_bound - lower_bound <= 1 )
1621 lower_bound = upper_bound;
1626 to_add = upper_bound;
1629 return_val += to_add;
1649 return pow( static_cast<double>( t_diff ),
decay_rate );
1663 unsigned int p = h->
next_p;
1674 assert( t_diff > 0 );
1702 if ( return_val > 0.0 )
1704 return_val = log( return_val );