diff --git a/include/trick/checkpoint_fwd_declare.hh b/include/trick/checkpoint_fwd_declare.hh index c78f2cc3..8fb1fa41 100644 --- a/include/trick/checkpoint_fwd_declare.hh +++ b/include/trick/checkpoint_fwd_declare.hh @@ -129,6 +129,15 @@ template & in_stl , std::string object_name , std::string var_name ) ; +// stack +template ::value>::type* = nullptr > +int checkpoint_stl(std::stack & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::stack & in_stl , std::string object_name , std::string var_name ) ; + /* ===================================================================================================== */ // Restore routines @@ -239,5 +248,14 @@ template & in_stl , std::string object_name , std::string var_name ) ; +// stack +template ::value>::type* = nullptr > +int restore_stl(std::stack & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int restore_stl(std::stack & in_stl , std::string object_name , std::string var_name ) ; + #endif diff --git a/include/trick/checkpoint_is_stl_container.hh b/include/trick/checkpoint_is_stl_container.hh index 50aff438..93b1ad56 100644 --- a/include/trick/checkpoint_is_stl_container.hh +++ b/include/trick/checkpoint_is_stl_container.hh @@ -11,6 +11,7 @@ #include #include #include +#include #include template @@ -63,8 +64,13 @@ struct is_stl_container > { static const bool value = true; }; -template -struct is_stl_container > { +template +struct is_stl_container > { + static const bool value = true; +}; + +template +struct is_stl_container > { static const bool value = true; }; diff --git a/include/trick/checkpoint_queue.hh b/include/trick/checkpoint_queue.hh index b4fd5b28..675bf85d 100644 --- a/include/trick/checkpoint_queue.hh +++ b/include/trick/checkpoint_queue.hh @@ -66,7 +66,7 @@ int checkpoint_stl(std::queue & in_stl , std::string object std::ostringstream var_declare ; int status ; - ITEM_TYPE * items = nullptr ; + std::string * items = nullptr ; std::queue temp_queue(in_stl) ; cont_size = temp_queue.size() ; @@ -75,11 +75,15 @@ int checkpoint_stl(std::queue & in_stl , std::string object if ( cont_size > 0 ) { var_declare << "std::string " << object_name << "_" << var_name << "[" << cont_size << "]" ; - items = (ITEM_TYPE *)TMM_declare_var_s(var_declare.str().c_str()) ; + items = (std::string *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { + std::ostringstream sub_elements ; + sub_elements << object_name << "_" << var_name << "_" << ii ; + items[ii] = sub_elements.str() ; + std::ostringstream index_string ; index_string << ii ; checkpoint_stl (temp_queue.front(), object_name + "_" + var_name, index_string.str()) ; @@ -132,7 +136,7 @@ int checkpoint_stl(std::priority_queue & in_stl std::ostringstream var_declare ; int status ; - ITEM_TYPE * items = nullptr ; + std::string * items = nullptr ; std::priority_queue temp_queue(in_stl) ; cont_size = temp_queue.size() ; @@ -141,14 +145,18 @@ int checkpoint_stl(std::priority_queue & in_stl if ( cont_size > 0 ) { var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " << object_name << "_" << var_name << "[" << cont_size << "]" ; - items = (ITEM_TYPE *)TMM_declare_var_s(var_declare.str().c_str()) ; + items = (std::string *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { + std::ostringstream sub_elements ; + sub_elements << object_name << "_" << var_name << "_" << ii ; + items[ii] = sub_elements.str() ; + std::ostringstream index_string ; index_string << ii ; - checkpoint_stl (temp_queue.top(), object_name + "_" + var_name, index_string.str()) ; + checkpoint_stl (const_cast< ITEM_TYPE &>(temp_queue.top()), object_name + "_" + var_name, index_string.str()) ; temp_queue.pop() ; } } diff --git a/include/trick/checkpoint_stack.hh b/include/trick/checkpoint_stack.hh index 11077748..df9c3864 100644 --- a/include/trick/checkpoint_stack.hh +++ b/include/trick/checkpoint_stack.hh @@ -8,6 +8,9 @@ #include #include +#include +#include +#include #ifdef __GNUC__ #include @@ -17,35 +20,30 @@ #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" -#ifndef TRICK_ICG -template -int delete_stl(std::stack & in_stl , std::string object_name , std::string var_name ) { - return delete_sequence_stl( in_stl , object_name , var_name ) ; -} +/* =================================================================================================*/ -template -int checkpoint_stl(std::stack & in_stl , std::string object_name , std::string var_name ) { +// stack: intrinsic +template ::value>::type* > +int checkpoint_stl(std::stack & in_stl , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; - char var_declare[128] ; + std::ostringstream var_declare ; int status ; ITEM_TYPE * items = nullptr ; - std::stack temp_stack ; + std::stack temp_stack(in_stl) ; - cont_size = in_stl.size() ; + cont_size = temp_stack.size() ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - - sprintf(var_declare, "%s %s_%s[%d]" , - abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; - items = (ITEM_TYPE *)TMM_declare_var_s(var_declare) ; + var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + << object_name << "_" << var_name << "[" << cont_size << "]" ; + items = (ITEM_TYPE *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; - //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; - - temp_stack = in_stl ; + //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { items[ii] = temp_stack.top() ; @@ -56,14 +54,61 @@ int checkpoint_stl(std::stack & in_stl , std::string object_name , st return 0 ; } +// stack: STL +template ::value>::type* > +int checkpoint_stl(std::stack & in_stl , std::string object_name , std::string var_name ) { + + unsigned int ii ; + unsigned int cont_size ; + std::ostringstream var_declare ; + int status ; + + std::string * items = nullptr ; + std::stack temp_stack(in_stl) ; + + cont_size = temp_stack.size() ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + if ( cont_size > 0 ) { + var_declare << "std::string " + << object_name << "_" << var_name << "[" << cont_size << "]" ; + items = (std::string *)TMM_declare_var_s(var_declare.str().c_str()) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; + //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; + + for ( ii = 0 ; ii < cont_size ; ii++ ) { + std::ostringstream sub_elements ; + sub_elements << object_name << "_" << var_name << "_" << ii ; + items[ii] = sub_elements.str() ; + + std::ostringstream index_string ; + index_string << ii ; + checkpoint_stl (temp_stack.top(), object_name + "_" + var_name, index_string.str()) ; + temp_stack.pop() ; + } + } + + return 0 ; +} + +/* =================================================================================================*/ + +template +int delete_stl(std::stack & in_stl , std::string object_name , std::string var_name ) { + return delete_sequence_stl( in_stl , object_name , var_name ) ; +} + +/* =================================================================================================*/ + /* Find the arrays the map data was stored in the checkpoint using ref_attributes From the address of the resulting ref_attributes, we can figure out the number of items that were stored in the checkpoint. Knowing the size, we can restore the map from the 2 arrays. */ -template -int restore_stl(std::stack & in_stl , std::string object_name , std::string var_name ) { - +template ::value>::type* > +int restore_stl(std::stack & in_stl , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -73,7 +118,6 @@ int restore_stl(std::stack & in_stl , std::string object_name , std:: //message_publish(1, "RESTORE_STL_STACK %s_%s\n", object_name.c_str() , var_name.c_str()) ; - items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; if ( items_ref != NULL ) { @@ -93,10 +137,39 @@ int restore_stl(std::stack & in_stl , std::string object_name , std:: return 0 ; } -// Specialized routines for strings. -int checkpoint_stl(std::stack & in_stl , std::string object_name , std::string var_name ) ; -int restore_stl(std::stack & in_stl , std::string object_name , std::string var_name ) ; - -#endif +template ::value>::type* > +int restore_stl(std::stack & in_stl , std::string object_name , std::string var_name ) { + unsigned int ii ; + unsigned int cont_size ; + + REF2 * items_ref ; + std::string * items = nullptr ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + //message_publish(1, "RESTORE_STL_STACK %s_%s\n", object_name.c_str() , var_name.c_str()) ; + + items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; + + if ( items_ref != NULL ) { + cont_size = in_stl.size() ; + for ( ii = 0 ; ii < cont_size ; ii++ ) { + in_stl.pop() ; + } + items = (std::string *)items_ref->address ; + cont_size = get_size((char *)items) ; + + for ( ii = cont_size - 1 ; ii < cont_size ; ii-- ) { + ITEM_TYPE vt ; + std::ostringstream index_string ; + index_string << ii ; + restore_stl( vt , object_name + "_" + var_name , index_string.str()) ; + in_stl.push( vt ) ; + } + delete_stl( in_stl , object_name , var_name ) ; + } + + return 0 ; +} #endif diff --git a/test/SIM_stls/models/STLCheckpoint.cpp b/test/SIM_stls/models/STLCheckpoint.cpp index cba6b943..1fcca9e9 100644 --- a/test/SIM_stls/models/STLCheckpoint.cpp +++ b/test/SIM_stls/models/STLCheckpoint.cpp @@ -5,139 +5,10 @@ /* These 2 constructors add different data to an STLCheckpoint. */ STLCheckpoint::STLCheckpoint() { - - double_map[11.1] = 111.1 ; - double_map[22.2] = 222.2 ; - double_map[33.3] = 333.3 ; - - string_key_map[std::string("one")] = 1 ; - string_key_map[std::string("two")] = 2 ; string_key_map[std::string("three")] = 3 ; - - string_data_map[4] = std::string("vier") ; - string_data_map[5] = std::string("fumf") ; - string_data_map[6] = std::string("sechs") ; - - string_map[std::string("mother")] = std::string("Marge") ; - string_map[std::string("father")] = std::string("Homer") ; - string_map[std::string("son")] = std::string("Bart") ; - - int_multimap.insert(std::pair(11,111)) ; - int_multimap.insert(std::pair(22,222)) ; - int_multimap.insert(std::pair(33,333)) ; - int_multimap.insert(std::pair(11,111)) ; - int_multimap.insert(std::pair(22,222)) ; - int_multimap.insert(std::pair(33,333)) ; - - string_key_multimap.insert(std::pair("one", 1)) ; - string_key_multimap.insert(std::pair("two", 2)) ; - string_key_multimap.insert(std::pair("three", 3)) ; - string_key_multimap.insert(std::pair("one", 1)) ; - string_key_multimap.insert(std::pair("two", 2)) ; - string_key_multimap.insert(std::pair("three", 3)) ; - - string_data_multimap.insert(std::pair(4, "vier")) ; - string_data_multimap.insert(std::pair(5, "fumf")) ; - string_data_multimap.insert(std::pair(6, "sechs")) ; - string_data_multimap.insert(std::pair(4, "four")) ; - string_data_multimap.insert(std::pair(5, "five")) ; - string_data_multimap.insert(std::pair(6, "six")) ; - - string_multimap.insert(std::pair("mother","Marge")) ; - string_multimap.insert(std::pair("father","Homer")) ; - string_multimap.insert(std::pair("mother","Lois")) ; - string_multimap.insert(std::pair("father","Meg")) ; - - double_vector.push_back(1.0) ; - double_vector.push_back(2.0) ; - double_vector.push_back(3.0) ; - - string_vector.push_back("I") ; - string_vector.push_back("was") ; - string_vector.push_back("here") ; - - short_list.push_back(300) ; - short_list.push_back(301) ; - short_list.push_back(302) ; - - string_list.push_back("I") ; - string_list.push_back("was") ; - string_list.push_back("there") ; - - float_deque.push_back(12.3) ; - float_deque.push_back(45.6) ; - float_deque.push_back(78.9) ; - - string_deque.push_back("meow") ; - string_deque.push_back("bark") ; - string_deque.push_back("quack") ; - - int_set.insert(8) ; - int_set.insert(4) ; - int_set.insert(2) ; - int_set.insert(1) ; - - string_set.insert("e") ; - string_set.insert("a") ; - string_set.insert("d") ; - - long_multiset.insert(8) ; - long_multiset.insert(4) ; - long_multiset.insert(4) ; - long_multiset.insert(2) ; - long_multiset.insert(1) ; - - string_multiset.insert("e") ; - string_multiset.insert("a") ; - string_multiset.insert("d") ; - string_multiset.insert("e") ; - string_multiset.insert("a") ; - string_multiset.insert("d") ; - - uint_stack.push(10) ; - uint_stack.push(20) ; - uint_stack.push(30) ; - uint_stack.push(40) ; - - string_stack.push("abc I") ; - string_stack.push("abc want the one") ; - string_stack.push("abc with the bigger") ; - string_stack.push("abc Gee Bees") ; - - int_queue.push(10) ; - int_queue.push(20) ; - int_queue.push(30) ; - int_queue.push(40) ; - - string_queue.push("abc I") ; - string_queue.push("abc want") ; - string_queue.push("abc an") ; - string_queue.push("abc iPhone 4") ; - - int_priority_queue.push(30) ; - int_priority_queue.push(20) ; - int_priority_queue.push(40) ; - int_priority_queue.push(10) ; - - string_priority_queue.push("abc I") ; - string_priority_queue.push("abc want") ; - string_priority_queue.push("abc an") ; - string_priority_queue.push("abc iPhone 4") ; - - int_pair.first = 1 ; - int_pair.second = 2 ; - - string_first_pair.first = "abc string first" ; - string_first_pair.second = 2 ; - - string_second_pair.first = 2 ; - string_second_pair.second = "abc string second" ; - - string_pair.first = "abc pair first string" ; - string_pair.second = "abc pair second string" ; return ; } -STLCheckpoint::STLCheckpoint(std::string in_name) : +STLCheckpoint::STLCheckpoint(std::string in_name) : vector_vector_double(4, std::vector(3)) , vector_vector_vector_double(5, std::vector >(4, std::vector(3))) { @@ -270,6 +141,9 @@ STLCheckpoint::STLCheckpoint(std::string in_name) : string_stack.push("with the bigger") ; string_stack.push("Gee Bees") ; + stack_vector_int.push(v) ; + stack_vector_int.push(v) ; + int_queue.push(1) ; int_queue.push(2) ; int_queue.push(3) ; @@ -290,6 +164,12 @@ STLCheckpoint::STLCheckpoint(std::string in_name) : string_priority_queue.push("an") ; string_priority_queue.push("iPhone 4") ; + queue_vector_int.push(v) ; + queue_vector_int.push(v) ; + + priority_queue_vector_int.push(v) ; + priority_queue_vector_int.push(v) ; + int_pair.first = 10 ; int_pair.second = 20 ; @@ -413,8 +293,12 @@ int STLCheckpoint::speak() { //message_publish(1,"int_pair_int_int.second.second = %d\n", int_pair_int_int.second.second) ; //message_publish(1,"pair_int_int_int.first.second = %d\n", pair_int_int_int.first.second) ; //message_publish(1,"pair_pair_pair.second.first = %d\n", pair_pair_pair.second.first) ; - message_publish(1,"int_queue.front = %d\n", int_queue.front()) ; - message_publish(1,"int_priority_queue.top = %d\n", int_priority_queue.top()) ; + //message_publish(1,"int_queue.front = %d\n", int_queue.front()) ; + //message_publish(1,"int_priority_queue.top = %d\n", int_priority_queue.top()) ; + //message_publish(1,"uint_stack.top = %d\n", uint_stack.top()) ; + //message_publish(1,"queue_vector_int.front()[3] = %d\n", queue_vector_int.front()[3]) ; + //message_publish(1,"priority_queue_vector_int.top()[2] = %d\n", priority_queue_vector_int.top()[2]) ; + message_publish(1,"stack_vector_int.top()[1] = %d\n", stack_vector_int.top()[1]) ; return 0 ; } diff --git a/test/SIM_stls/models/STLCheckpoint.hh b/test/SIM_stls/models/STLCheckpoint.hh index ed81ab2b..98db5205 100644 --- a/test/SIM_stls/models/STLCheckpoint.hh +++ b/test/SIM_stls/models/STLCheckpoint.hh @@ -60,13 +60,16 @@ class STLCheckpoint { std::stack< unsigned int > uint_stack ; std::stack< std::string > string_stack ; + std::stack< std::vector > stack_vector_int ; std::queue< int > int_queue ; std::queue< std::string > string_queue ; + std::queue< std::vector > queue_vector_int ; std::priority_queue< int > int_priority_queue ; std::priority_queue< std::string > string_priority_queue ; std::priority_queue< int , std::vector< int > , std::greater< int > > int_greater_priority_queue ; + std::priority_queue< std::vector > priority_queue_vector_int ; std::pair< int , int > int_pair ; std::pair< std::string , int > string_first_pair ; diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp index b47492b9..757e6e37 100644 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp +++ b/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp @@ -1,65 +1,3 @@ #include "trick/checkpoint_stack.hh" -int checkpoint_stl(std::stack & in_stl , std::string object_name , std::string var_name ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - int status ; - - char ** items = NULL ; - std::stack temp_stack ; - - cont_size = in_stl.size() ; - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - - if ( cont_size > 0 ) { - - sprintf(var_declare, "%s %s_%s[%d]" , - abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; - items = (char **)TMM_declare_var_s(var_declare) ; - TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; - //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; - - temp_stack = in_stl ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - items[ii] = (char *)((temp_stack.top()).c_str()) ; - temp_stack.pop() ; - } - } - - return 0 ; -} - -int restore_stl(std::stack & in_stl , std::string object_name , std::string var_name ) { - - unsigned int ii ; - unsigned int cont_size ; - - REF2 * items_ref ; - char ** items ; - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - - //message_publish(1, "RESTORE_STL_STACK %s_%s\n", object_name.c_str() , var_name.c_str()) ; - - items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; - - if ( items_ref != NULL ) { - cont_size = in_stl.size() ; - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_stl.pop() ; - } - items = (char **)items_ref->address ; - cont_size = get_size((char *)items) ; - - for ( ii = cont_size - 1 ; ii < cont_size ; ii-- ) { - in_stl.push( items[ii] ) ; - } - delete_stl( in_stl , object_name , var_name ) ; - } - - return 0 ; -} -