From 46aec08b801dcb817b6a58aaa4804eb481dd22ef Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Tue, 29 Mar 2016 09:26:49 -0500 Subject: [PATCH 1/9] Add direct STL checkpointing Initial checkin of STL checkpointing. This checkin only covers the sequential STLs, vector, list, deque, set, and multiset. This checkin does include the changes in Trick header files to include/exclude our STLs properly to make a restartable checkpoint. refs #206 --- include/trick/DMTCP.hh | 2 +- include/trick/DataRecordGroup.hh | 4 +- include/trick/EventManager.hh | 4 +- include/trick/Executive.hh | 8 +- include/trick/FrameDataRecordGroup.hh | 2 +- include/trick/FrameLog.hh | 2 +- include/trick/IntegLoopScheduler.hh | 6 +- include/trick/IntegLoopSimObject.hh | 7 +- include/trick/Master.hh | 2 +- include/trick/MemoryManager.hh | 63 ++- include/trick/MonteCarlo.hh | 10 +- include/trick/UnitTest.hh | 2 +- include/trick/VariableServer.hh | 6 +- include/trick/attributes.h | 5 + include/trick/checkpoint_is_stl_container.hh | 44 ++ include/trick/checkpoint_map.hh | 22 +- include/trick/checkpoint_pair.hh | 6 + include/trick/checkpoint_queue.hh | 27 +- include/trick/checkpoint_sequence_stl.hh | 484 ++++++++++++++---- include/trick/checkpoint_stack.hh | 13 +- .../trick/checkpoint_trick_sequence_stl.hh | 4 +- include/trick/memorymanager_c_intf.h | 1 + include/trick/parameter_types.h | 1 + libexec/trick/make_makefile_swig | 3 +- share/trick/makefiles/Makefile.tricklib | 4 +- share/trick/sim_objects/default_trick_sys.sm | 11 +- test/SIM_stls/RUN_test/input.py | 17 +- test/SIM_stls/S_define | 32 +- test/SIM_stls/S_overrides.mk | 1 + .../src => }/STLCheckpoint.cpp | 91 +++- .../include => }/STLCheckpoint.hh | 23 +- .../stl_checkpoint/include/STLCompanion.hh | 42 -- .../src/STLCompanion_checkpoint.cpp | 53 -- .../src/STLCompanion_post_checkpoint.cpp | 55 -- .../src/STLCompanion_restart.cpp | 54 -- .../Interface_Code_Gen/FieldDescription.cpp | 18 + .../Interface_Code_Gen/FieldDescription.hh | 10 + .../Interface_Code_Gen/FieldVisitor.cpp | 130 +++-- .../Interface_Code_Gen/PrintAttributes.cpp | 1 + .../PrintFileContents10.cpp | 160 +++++- .../Interface_Code_Gen/PrintFileContents10.hh | 18 + .../ClassicCheckPointerAgent.cpp | 17 +- .../sim_services/CheckPointRestart/Makefile | 2 + .../CheckPointRestart/checkpoint_pair.cpp | 2 + .../CheckPointRestart/checkpoint_queue.cpp | 2 + .../CheckPointRestart/checkpoint_stack.cpp | 10 +- .../sim_services/Executive/Executive.cpp | 2 - .../Executive/Executive_checkpoint.cpp | 10 +- .../sim_services/Executive/Executive_init.cpp | 4 +- .../Executive/Executive_post_checkpoint.cpp | 8 - .../Executive/Executive_restart.cpp | 11 - .../Integrator/src/IntegLoopSimObject.cpp | 23 +- .../MemoryManager/MemoryManager_C_Intf.cpp | 92 ++-- ...anager_add_checkpoint_alloc_dependency.cpp | 11 + .../MemoryManager_alloc_depends.cpp | 34 +- .../MemoryManager_clear_memory.cpp | 6 + .../MemoryManager_get_stl_dependencies.cpp | 192 +++++++ .../MemoryManager/MemoryManager_restore.cpp | 7 +- .../MemoryManager_restore_stls.cpp | 197 +++++++ .../MemoryManager_write_checkpoint.cpp | 46 +- 60 files changed, 1501 insertions(+), 623 deletions(-) create mode 100644 include/trick/checkpoint_is_stl_container.hh rename test/SIM_stls/models/{stl_checkpoint/src => }/STLCheckpoint.cpp (69%) rename test/SIM_stls/models/{stl_checkpoint/include => }/STLCheckpoint.hh (67%) delete mode 100644 test/SIM_stls/models/stl_checkpoint/include/STLCompanion.hh delete mode 100644 test/SIM_stls/models/stl_checkpoint/src/STLCompanion_checkpoint.cpp delete mode 100644 test/SIM_stls/models/stl_checkpoint/src/STLCompanion_post_checkpoint.cpp delete mode 100644 test/SIM_stls/models/stl_checkpoint/src/STLCompanion_restart.cpp create mode 100644 trick_source/sim_services/MemoryManager/MemoryManager_add_checkpoint_alloc_dependency.cpp create mode 100644 trick_source/sim_services/MemoryManager/MemoryManager_get_stl_dependencies.cpp create mode 100644 trick_source/sim_services/MemoryManager/MemoryManager_restore_stls.cpp diff --git a/include/trick/DMTCP.hh b/include/trick/DMTCP.hh index 79b7ada6..52f92c8e 100644 --- a/include/trick/DMTCP.hh +++ b/include/trick/DMTCP.hh @@ -43,7 +43,7 @@ namespace Trick { std::string splitFilename( const std::string& str ); unsigned int dmtcp_ckpt_complete; - std::priority_queue dmtcp_checkpoint_jobs_queue ; + std::priority_queue dmtcp_checkpoint_jobs_queue ; // ** ignore this for checkpointing virtual int write_s_job_execution( FILE * fp ) ; virtual int instrument_job_before(Trick::JobData * instrument_job) ; diff --git a/include/trick/DataRecordGroup.hh b/include/trick/DataRecordGroup.hh index 2a46cc3b..424d37b7 100644 --- a/include/trick/DataRecordGroup.hh +++ b/include/trick/DataRecordGroup.hh @@ -94,7 +94,7 @@ namespace Trick { char ** variable_alias ; /** trick_units(--) */ /** Vector of buffers - one for every variable added with Trick::DataRecordGroup::add_variable.\n */ - std::vector rec_buffer; /**< trick_io(*io) trick_units(--) */ + std::vector rec_buffer; /**< trick_io(**) trick_units(--) */ /** Number of change variable names to save in a checkpoint.\n */ unsigned int num_change_variable_names ; /** trick_units(--) */ @@ -104,7 +104,7 @@ namespace Trick { char ** change_variable_alias ; /** trick_units(--) */ /** Vector of buffers - one for every change variable added with Trick::DataRecordGroup::add_change_variable.\n */ - std::vector change_buffer; /**< trick_io(*io) trick_units(--) */ + std::vector change_buffer; /**< trick_io(**) trick_units(--) */ /** Maximum records to hold in memory before writing.\n */ unsigned int max_num; /**< trick_io(*io) trick_units(--) */ diff --git a/include/trick/EventManager.hh b/include/trick/EventManager.hh index 68107a00..ee0b3dec 100644 --- a/include/trick/EventManager.hh +++ b/include/trick/EventManager.hh @@ -149,10 +149,10 @@ namespace Trick { unsigned int num_active_events ; /**< trick_io(*io) trick_units(--) */ /** All of the event processors, one per thread. */ - std::vector< Trick::EventProcessor * > event_processors ; + std::vector< Trick::EventProcessor * > event_processors ; /**< trick_io(**) */ /** All of the events that have been attached to jobs */ - std::vector< Trick::EventInstrument * > events_instrumented ; + std::vector< Trick::EventInstrument * > events_instrumented ; /**< trick_io(**) */ /** @brief Add user's event to manager's list of events; don't add it if it's already in list. diff --git a/include/trick/Executive.hh b/include/trick/Executive.hh index c2613826..640e1036 100644 --- a/include/trick/Executive.hh +++ b/include/trick/Executive.hh @@ -244,13 +244,7 @@ namespace Trick { int num_sim_objects ; /**< trick_units(--) */ /** List of all sim_objects that have been added to scheduler through add_sim_object().\n */ - std::vector sim_objects ; /**< trick_io(**) */ - - /** Count of how many sim_objects are written to the checkpoint.\n */ - int num_sim_objects_in_checkpoint ; /**< trick_units(--) */ - - /** Contains same info as the sim_objects vector but in a checkpointable form\n */ - Trick::SimObject ** sim_objects_for_checkpoint ; /**< trick_units(--) */ + std::vector sim_objects ; /**< trick_io(*io) trick_units(--) */ /** List of other schedulers in thes sim.\n */ std::vector other_schedulers ; /**< trick_io(**) */ diff --git a/include/trick/FrameDataRecordGroup.hh b/include/trick/FrameDataRecordGroup.hh index 6495394f..0bfb6763 100644 --- a/include/trick/FrameDataRecordGroup.hh +++ b/include/trick/FrameDataRecordGroup.hh @@ -56,7 +56,7 @@ namespace Trick { unsigned int thread_id ; /** Jobs this group is recording */ - std::vector< Trick::JobData *> rec_jobs ; + std::vector< Trick::JobData *> rec_jobs ; // trick_io(**) /** Time value to record with main frame. The main frame has already incremented time by the time data record is called. We need to record the time of the previous frame. */ diff --git a/include/trick/FrameLog.hh b/include/trick/FrameLog.hh index c4de9de6..7a443ec1 100644 --- a/include/trick/FrameLog.hh +++ b/include/trick/FrameLog.hh @@ -37,7 +37,7 @@ namespace Trick { bool frame_log_flag ; /**< trick_io(*io) trick_units(--) */ /** Data recording groups for logging user jobs.\n */ - std::vector< Trick::FrameDataRecordGroup *> drg_users ; /**< trick_io(*io) trick_units(--) */ + std::vector< Trick::FrameDataRecordGroup *> drg_users ; /**< trick_io(**) trick_units(--) */ /** Data recording group for logging trick jobs.\n */ Trick::FrameDataRecordGroup * drg_trick; /**< trick_io(*io) trick_units(--) */ /** Data recording group for logging frame/overrun time.\n trick_units(--) */ diff --git a/include/trick/IntegLoopScheduler.hh b/include/trick/IntegLoopScheduler.hh index 92df8c82..9cc5e3ea 100644 --- a/include/trick/IntegLoopScheduler.hh +++ b/include/trick/IntegLoopScheduler.hh @@ -107,7 +107,7 @@ namespace Trick { * The sim objects integrated by this IntegLoopScheduler. * This is public so it can be checkpointed and restored. */ - SimObjectVector sim_objects; //!< trick_io(**) + SimObjectVector sim_objects; //!< trick_io(*io) trick_units(--) // Member functions @@ -379,7 +379,7 @@ namespace Trick { /** * Empty a job queue in anticipation of the queue being rebuilt. - */ + */ void clear_queue (Trick::ScheduledJobQueue & job_queue); /** @@ -387,7 +387,7 @@ namespace Trick { * @return Iterator pointing to the object, * or to sim_objects.end() if not found. * @param sim_obj Object to be found. - */ + */ SimObjectVector::iterator find_sim_object ( Trick::SimObject & sim_obj); diff --git a/include/trick/IntegLoopSimObject.hh b/include/trick/IntegLoopSimObject.hh index eb7d6c1c..6d5c966d 100644 --- a/include/trick/IntegLoopSimObject.hh +++ b/include/trick/IntegLoopSimObject.hh @@ -1,3 +1,7 @@ +/* + PURPOSE: + (Trick Integration sim object) +*/ #ifndef INTEG_LOOP_SIMOBJECT_HH #define INTEG_LOOP_SIMOBJECT_HH @@ -15,7 +19,7 @@ class IntegLoopSimObject : public Trick::SimObject { public: - Trick::IntegLoopScheduler integ_sched ; + Trick::IntegLoopScheduler integ_sched ; // trick_io(*io) IntegLoopSimObject() : integ_sched(0.01, this) { add_jobs(0.01, 0) ; @@ -41,7 +45,6 @@ class IntegLoopSimObject : public Trick::SimObject { virtual int call_function( Trick::JobData * curr_job ) ; virtual double call_function_double( Trick::JobData * curr_job ) ; - Trick::Integrator * getIntegrator( Integrator_type Alg, unsigned int State_size ) { return integ_sched.getIntegrator(Alg , State_size) ; } diff --git a/include/trick/Master.hh b/include/trick/Master.hh index 7b43526f..c22ae057 100644 --- a/include/trick/Master.hh +++ b/include/trick/Master.hh @@ -203,7 +203,7 @@ namespace Trick { int num_slaves ; /**< trick_units(--) */ /** Vector of slaves tracked by the master.\n */ - std::vector< Trick::SlaveInfo * > slaves ; /**< trick_units(--) */ + std::vector< Trick::SlaveInfo * > slaves ; /**< trick_io(**) trick_units(--) */ /** @brief @userdesc Command to enable the master/slave synchronization. diff --git a/include/trick/MemoryManager.hh b/include/trick/MemoryManager.hh index 350df233..221a3441 100644 --- a/include/trick/MemoryManager.hh +++ b/include/trick/MemoryManager.hh @@ -1,3 +1,8 @@ +/* + PURPOSE: + (Memory Manager.) +*/ + #ifndef MEMORYMANAGEMENT_HH #define MEMORYMANAGEMENT_HH @@ -533,13 +538,13 @@ namespace Trick { @param addr The Address. */ ALLOC_INFO* get_alloc_info_of( void* addr); - + /** Get information for the allocation starting at the specified address. @param addr The Address. */ ALLOC_INFO* get_alloc_info_at( void* addr); - + /** Names an allocation in the ALLOC_INFO map to the incoming name. @param addr The Address. @@ -547,13 +552,21 @@ namespace Trick { */ int set_name_at( void* addr, const char * name); + /** + Adds a name of an allocation to the dependency list of allocations that are to be checkpointed. + This call is used by standard template library functions that create new allocations and + dependencies during the checkpoint process. + @param name The name of the allocation. + */ + void add_checkpoint_alloc_dependency(const char * name); + /** Opens a handle to the shared library file. The handles are used to look for io_src functions. @param name The name of the file to open. */ int add_shared_library_symbols( const char * file_name ); - + std::vector dlhandles ; /**< ** dynamic loader handle left open for all dl (dlsym) calls */ /** @@ -654,37 +667,61 @@ namespace Trick { bool hexfloat_checkpoint; /**< -- true = Represent floating point values as hexidecimal to preserve precision. false= Normal. */ bool expanded_arrays; /**< -- true = array element values are set in separate assignments. */ - ALLOC_INFO_MAP alloc_info_map; /**< -- Map of key-value pairs for each of the managed allocations. */ - VARIABLE_MAP variable_map; /**< -- Map of key-value pairs for each named-allocations. */ - ENUMERATION_MAP enumeration_map; /**< -- Enumeration map. */ - pthread_mutex_t mm_mutex; /**< -- Mutex to control access to memory manager maps */ + ALLOC_INFO_MAP alloc_info_map; /**< ** Map of key-value pairs for each of the managed allocations. */ + VARIABLE_MAP variable_map; /**< ** Map of key-value pairs for each named-allocations. */ + ENUMERATION_MAP enumeration_map; /**< ** Enumeration map. */ + pthread_mutex_t mm_mutex; /**< ** Mutex to control access to memory manager maps */ int alloc_info_map_counter ; /**< ** counter to assign unique ids to allocations as they are added to map */ int extern_alloc_info_map_counter ; /**< ** counter to assign unique ids to allocations as they are added to map */ + std::vector dependencies; /**< ** list of allocations used in a checkpoint. */ + std::vector stl_dependencies; /**< ** list of allocations known to be STL checkpoint allocations */ - void write_checkpoint( std::ostream& out_s, std::vector& dependencies); + void execute_checkpoint( std::ostream& out_s ); + + /** + Walks through allocation and allocates space for STLs + FIXME: I NEED DOCUMENTATION! + */ + void get_stl_dependencies( ALLOC_INFO* alloc_info ); + void get_stl_dependencies_in_class( std::string name, char* address, ATTRIBUTES* attr) ; + void get_stl_dependencies_in_arrayed_class( std::string name, + char* address, ATTRIBUTES* attr, int curr_dim, int offset) ; + void get_stl_dependencies_in_intrinsic( std::string name, + void* address, ATTRIBUTES* attr, int curr_dim, int offset) ; + + /** + Walks through allocations and restores STLs + FIXME: I NEED DOCUMENTATION! + */ + void restore_stls( ALLOC_INFO* alloc_info ); + void restore_stls_in_class( std::string name, char* address, ATTRIBUTES* attr) ; + void restore_stls_in_arrayed_class( std::string name, + char* address, ATTRIBUTES* attr, int curr_dim, int offset) ; + void restore_stls_in_intrinsic( std::string name, + void* address, ATTRIBUTES* attr, int curr_dim, int offset) ; /** FIXME: I NEED DOCUMENTATION! */ - void get_alloc_deps_in_allocation(std::vector& dependencies, ALLOC_INFO* alloc_info ); + void get_alloc_deps_in_allocation( ALLOC_INFO* alloc_info ); /** FIXME: I NEED DOCUMENTATION! */ - void get_alloc_deps_in_allocation( std::vector& dependencies, const char* var_name ); + void get_alloc_deps_in_allocation( const char* var_name ); /** FIXME: I NEED DOCUMENTATION! */ - void get_alloc_deps_in_class( std::vector& dependencies, char* address, ATTRIBUTES* attr); + void get_alloc_deps_in_class( char* address, ATTRIBUTES* attr); /** FIXME: I NEED DOCUMENTATION! */ - void get_alloc_deps_in_arrayed_class( std::vector& dependencies, char* address, ATTRIBUTES* attr, int curr_dim, int offset); + void get_alloc_deps_in_arrayed_class( char* address, ATTRIBUTES* attr, int curr_dim, int offset); /** FIXME: I NEED DOCUMENTATION! */ - void get_alloc_deps_in_intrinsic( std::vector& dependencies, void* address, ATTRIBUTES* attr, int curr_dim, int offset); + void get_alloc_deps_in_intrinsic( void* address, ATTRIBUTES* attr, int curr_dim, int offset); std::set< std::string > primitive_types ; /**< ** Names of primitive types. Used in add_attr_info */ std::map< std::string , std::string > template_name_map ; /**< ** Templates names => mangled attr names */ diff --git a/include/trick/MonteCarlo.hh b/include/trick/MonteCarlo.hh index bd87593f..b8a47867 100644 --- a/include/trick/MonteCarlo.hh +++ b/include/trick/MonteCarlo.hh @@ -339,19 +339,19 @@ namespace Trick { TCDevice data_connection_device; /**< \n trick_units(--) */ /** Runs to be dispatched. */ - std::deque runs; /**< \n trick_units(--) */ + std::deque runs; /**< \n trick_io(**) trick_units(--) */ /** Failed runs. */ - std::deque failed_runs; /**< \n trick_units(--) */ + std::deque failed_runs; /**< \n trick_io(**) trick_units(--) */ /** Valid ranges. */ - std::vector run_ranges; /**< \n trick_units(--) */ + std::vector run_ranges; /**< \n trick_io(**) trick_units(--) */ /** Variables. */ - std::vector variables; /**< \n trick_units(--) */ + std::vector variables; /**< \n trick_io(**) trick_units(--) */ /** Slaves. */ - std::vector slaves; /**< \n trick_units(--) */ + std::vector slaves; /**< \n trick_io(**) trick_units(--) */ /** Number of slaves. Exists for Variable Server access. */ int num_slaves; /**< \n trick_units(--) */ diff --git a/include/trick/UnitTest.hh b/include/trick/UnitTest.hh index 347e77fa..84cc7d8c 100644 --- a/include/trick/UnitTest.hh +++ b/include/trick/UnitTest.hh @@ -60,7 +60,7 @@ namespace Trick { std::string file_name ; /**< trick_units(--) trick_io(*i) */ /** Keeps lists of test results keyed by test_suite name.\n*/ - std::map< std::string , TestSuite > test_suites ; + std::map< std::string , TestSuite > test_suites ; // ** ignore /** @brief The constructor. diff --git a/include/trick/VariableServer.hh b/include/trick/VariableServer.hh index 479f0722..309ba6c3 100644 --- a/include/trick/VariableServer.hh +++ b/include/trick/VariableServer.hh @@ -276,16 +276,16 @@ namespace Trick { to this map by suspendPreCheckpointReload(). resumePostCheckpointReload() restores the pause state from this map. */ - std::map thread_pause_state_store; + std::map thread_pause_state_store; // ** ignore this /** Map thread id to the VariableServerThread object.\n */ - std::map < pthread_t , VariableServerThread * > var_server_threads ; + std::map < pthread_t , VariableServerThread * > var_server_threads ; /**< trick_io(**) */ /** Mutex to ensure only one thread manipulates the map of var_server_threads\n */ pthread_mutex_t map_mutex ; /**< trick_io(**) */ /** Map of additional listen threads created by create_tcp_socket.\n */ - std::map < pthread_t , VariableServerListenThread * > additional_listen_threads ; + std::map < pthread_t , VariableServerListenThread * > additional_listen_threads ; /**< trick_io(**) */ } ; diff --git a/include/trick/attributes.h b/include/trick/attributes.h index 3d6ead19..03f2b9b7 100644 --- a/include/trick/attributes.h +++ b/include/trick/attributes.h @@ -119,6 +119,11 @@ typedef struct ATTRIBUTES_tag { INDEX index[TRICK_MAX_INDEX]; /**< -- An array of array-index information or bit-field information. Is only meaningful if num_index > 0 or if type is a bit field type. */ + void (*checkpoint_stl)(void * start_address, const char * obj_name , const char * var_name) ; + void (*post_checkpoint_stl)(void * start_address, const char * obj_name , const char * var_name) ; + void (*restore_stl)(void * start_address, const char * obj_name , const char * var_name) ; + void (*clear_stl)(void * start_address) ; + } ATTRIBUTES; typedef struct { diff --git a/include/trick/checkpoint_is_stl_container.hh b/include/trick/checkpoint_is_stl_container.hh new file mode 100644 index 00000000..4b4da6ee --- /dev/null +++ b/include/trick/checkpoint_is_stl_container.hh @@ -0,0 +1,44 @@ +/* + PURPOSE: (Test if item is an STL) +*/ + +#ifndef CHECKPOINT_IS_STL_CONTAINER +#define CHECKPOINT_IS_STL_CONTAINER + +#include +#include +#include +#include + +template +struct is_stl_container { + static const bool value = false; +}; + +template +struct is_stl_container > { + static const bool value = true; +}; + +template +struct is_stl_container > { + static const bool value = true; +}; + +template +struct is_stl_container > { + static const bool value = true; +}; + +template +struct is_stl_container > { + static const bool value = true; +}; + +template +struct is_stl_container > { + static const bool value = true; +}; + +#endif + diff --git a/include/trick/checkpoint_map.hh b/include/trick/checkpoint_map.hh index 2d2691a2..29340207 100644 --- a/include/trick/checkpoint_map.hh +++ b/include/trick/checkpoint_map.hh @@ -47,11 +47,13 @@ int checkpoint_map_stl(STL & in_map , std::string object_name , std::string var_ sprintf(var_declare, "%s %s_%s_keys[%d]" , abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; keys = (typename STL::key_type *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; //message_publish(1, "HERE with %s\n", var_declare) ; sprintf(var_declare, "%s %s_%s_data[%d]" , abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_data").c_str()) ; //message_publish(1, "HERE with %s\n", var_declare) ; /* copy the contents of the map the 2 arrays */ @@ -91,11 +93,13 @@ int checkpoint_map_stl_key_string(STL & in_map , std::string object_name , std:: if ( cont_size > 0 ) { sprintf(var_declare, "char * %s_%s_keys[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; keys = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; sprintf(var_declare, "%s %s_%s_data[%d]" , abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str() , cont_size) ; items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_data").c_str()) ; //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; /* copy the contents of the map the 2 arrays */ @@ -136,10 +140,12 @@ int checkpoint_map_stl_data_string(STL & in_map , std::string object_name , std: sprintf(var_declare, "%s %s_%s_keys[%d]" , abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str() , cont_size) ; keys = (typename STL::key_type *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; sprintf(var_declare, "char * %s_%s_data[%d]" , 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 + "_data").c_str()) ; //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; /* copy the contents of the map the 2 arrays */ @@ -179,10 +185,12 @@ int checkpoint_map_stl_strings(STL & in_map , std::string object_name , std::str if ( cont_size > 0 ) { sprintf(var_declare, "char * %s_%s_keys[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; keys = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; sprintf(var_declare, "char * %s_%s_data[%d]" , 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 + "_data").c_str()) ; //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; /* copy the contents of the map the 2 arrays */ @@ -239,13 +247,13 @@ int restore_map_stl(STL & in_map , std::string object_name , std::string var_nam //message_publish(1, "in regular map template restore\n") ; - in_map.clear() ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; if ( keys_ref != NULL && items_ref != NULL ) { + in_map.clear() ; keys = (typename STL::key_type *)keys_ref->address ; items = (typename STL::mapped_type *)items_ref->address ; cont_size = get_size((char *)keys) ; @@ -255,7 +263,7 @@ int restore_map_stl(STL & in_map , std::string object_name , std::string var_nam } delete_stl( in_map , object_name , var_name ) ; - } + } return 0 ; } @@ -280,13 +288,13 @@ int restore_map_stl_key_string( STL & in_map , std::string object_name , std::st char ** keys ; typename STL::mapped_type * items ; - in_map.clear() ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; if ( keys_ref != NULL && items_ref != NULL ) { + in_map.clear() ; keys = (char **)keys_ref->address ; items = (typename STL::mapped_type *)items_ref->address ; cont_size = get_size((char *)keys) ; @@ -296,7 +304,7 @@ int restore_map_stl_key_string( STL & in_map , std::string object_name , std::st } delete_stl( in_map , object_name , var_name ) ; - } + } return 0 ; } @@ -322,13 +330,13 @@ int restore_map_stl_data_string(STL & in_map , std::string object_name , std::st //message_publish(1, "in specialized map template restore\n") ; - in_map.clear() ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; if ( keys_ref != NULL && items_ref != NULL ) { + in_map.clear() ; keys = (typename STL::key_type *)keys_ref->address ; items = (char **)items_ref->address ; cont_size = get_size((char *)keys) ; @@ -338,7 +346,7 @@ int restore_map_stl_data_string(STL & in_map , std::string object_name , std::st } delete_stl( in_map , object_name , var_name ) ; - } + } return 0 ; } @@ -369,13 +377,13 @@ int restore_map_stl_strings(STL & in_map , std::string object_name , std::string of items that were stored in the checkpoint. Knowing the size, we can restore the map from the 2 arrays. This template only works for string map keys. */ - in_map.clear() ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; if ( keys_ref != NULL && items_ref != NULL ) { + in_map.clear() ; keys = (char **)keys_ref->address ; items = (char **)items_ref->address ; cont_size = get_size((char *)keys) ; diff --git a/include/trick/checkpoint_pair.hh b/include/trick/checkpoint_pair.hh index 0f7b6156..ad75230e 100644 --- a/include/trick/checkpoint_pair.hh +++ b/include/trick/checkpoint_pair.hh @@ -44,10 +44,12 @@ int checkpoint_stl(std::pair & in_stl , std::string obj sprintf(var_declare, "%s %s_%s_first[1]" , abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str()) ; first = (FIRST_TYPE *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; sprintf(var_declare, "%s %s_%s_second[1]" , abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str()) ; second = (SECOND_TYPE *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; first[0] = in_stl.first ; second[0] = in_stl.second ; @@ -68,9 +70,11 @@ int checkpoint_stl(std::pair & in_stl , std::string obj sprintf(var_declare, "%s %s_%s_first[1]" , abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str()) ; first = (FIRST_TYPE *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; sprintf(var_declare, "char * %s_%s_second[1]" , object_name.c_str(), var_name.c_str()) ; second = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; first[0] = in_stl.first ; second[0] = (char *)(in_stl.second.c_str()) ; @@ -90,10 +94,12 @@ int checkpoint_stl(std::pair & in_stl , std::string ob sprintf(var_declare, "char * %s_%s_first[1]", object_name.c_str(), var_name.c_str()) ; first = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; sprintf(var_declare, "%s %s_%s_second[1]" , abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str()) ; second = (SECOND_TYPE *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; first[0] = (char *)(in_stl.first.c_str()) ; second[0] = in_stl.second ; diff --git a/include/trick/checkpoint_queue.hh b/include/trick/checkpoint_queue.hh index e892bdc5..bbdb4626 100644 --- a/include/trick/checkpoint_queue.hh +++ b/include/trick/checkpoint_queue.hh @@ -52,6 +52,7 @@ int checkpoint_stl(std::queue & in_stl , std::string object_name , st 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) ; + 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_queue = in_stl ; @@ -84,6 +85,7 @@ int checkpoint_stl(std::priority_queue & in_stl , std::string object_ 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) ; + 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_queue = in_stl ; @@ -117,6 +119,7 @@ int checkpoint_stl(std::priority_queue, std::g 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) ; + 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_queue = in_stl ; @@ -147,22 +150,22 @@ int restore_queue_stl(STL & in_stl , std::string object_name , std::string var_n //message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; - cont_size = in_stl.size() ; - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_stl.pop() ; - } - 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 = (typename STL::value_type *)items_ref->address ; cont_size = get_size((char *)items) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { in_stl.push( items[ii] ) ; - } + } delete_stl( in_stl , object_name , var_name ) ; - } + } return 0 ; } @@ -179,22 +182,18 @@ int restore_queue_stl_string(STL & in_stl , std::string object_name , std::strin //message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; - cont_size = in_stl.size() ; - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_stl.pop() ; - } - items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; if ( items_ref != NULL ) { + STL().swap(in_stl) ; items = (char **)items_ref->address ; cont_size = get_size((char *)items) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { in_stl.push( items[ii] ) ; - } + } delete_stl( in_stl , object_name , var_name ) ; - } + } return 0 ; } diff --git a/include/trick/checkpoint_sequence_stl.hh b/include/trick/checkpoint_sequence_stl.hh index f6baedf0..a5b61b1f 100644 --- a/include/trick/checkpoint_sequence_stl.hh +++ b/include/trick/checkpoint_sequence_stl.hh @@ -14,14 +14,249 @@ #include #include +#include +#include +#include + #ifdef __GNUC__ #include #endif +#include + #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" +#include "checkpoint_is_stl_container.hh" -#ifndef TRICK_ICG +/* =================================================================================================*/ + +// Forward declare all of the specialized templates that can be used in checkpoint_sequence_stl_stl +template ::value>::type* = nullptr > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; +// End forward declarations. + +template +int checkpoint_sequence_stl_intrinsic(STL & in_stl , std::string object_name , std::string var_name ) { + + unsigned int ii ; + unsigned int cont_size ; + char var_declare[128] ; + int status ; + + typename STL::value_type * items = NULL ; + typename STL::iterator it ; + typename STL::iterator end ; + + message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; + + 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 = (typename STL::value_type *)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; + //message_publish(1, "CHECKPOINT_SEQUENCE_STL with %s\n", var_declare) ; + + /* copy the contents of the stl */ + for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { + items[ii] = *it ; + } + + } + + return 0 ; +} + +template +int checkpoint_sequence_stl_string(STL & in_stl , std::string object_name , std::string var_name ) { + + unsigned int ii ; + unsigned int cont_size ; + char var_declare[128] ; + + const char ** items ; + typename STL::iterator it ; + typename STL::iterator end ; + + + 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, "char * %s_%s[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; + items = (const char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; + //message_publish(1, "CHECKPOINT_SEQUENCE_STL_STRING with %s\n", var_declare) ; + + /* copy the contents of the vector */ + for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { + items[ii] = it->c_str() ; + } + } + + return 0 ; +} + +template +int checkpoint_sequence_stl_stl(STL & in_stl , std::string object_name , std::string var_name ) { + + unsigned int ii ; + unsigned int cont_size ; + char var_declare[128] ; + + const char ** items ; + typename STL::iterator it ; + typename STL::iterator end ; + + + cont_size = in_stl.size() ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; + + if ( cont_size > 0 ) { + + sprintf(var_declare, "char * %s_%s[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; + items = (const char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; + //message_publish(1, "CHECKPOINT_SEQUENCE_STL_STL with %s\n", var_declare) ; + + /* create the names of the sub stl checkpoint names we're going to be using */ + for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { + char sub_elements[128] ; + sprintf(sub_elements, "%s_%s_%d", object_name.c_str(), var_name.c_str() , ii) ; + items[ii] = TMM_strdup(sub_elements) ; + sprintf(sub_elements, "%s_%s_%d_name", object_name.c_str(), var_name.c_str() , ii) ; + set_alloc_name_at((void *)items[ii], sub_elements) ; + TMM_add_checkpoint_alloc_dependency(sub_elements) ; + + char index_string[16] ; + sprintf(index_string, "%d", ii) ; + message_publish(1, "recursive call to checkpoint_stl %s\n", __PRETTY_FUNCTION__) ; + checkpoint_stl( (*it) , object_name + "_" + var_name , std::string(index_string) ) ; + } + } + return 0 ; +} + +// ----------- +// std::vector + +// This template is only enabled if the items in the vector are an STL +template ::value>::type* = nullptr > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the vector are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +// Specialized routines for strings. found in checkpoint_sequence.cpp +int checkpoint_stl(std::vector & in_vector , std::string object_name , std::string var_name ) ; + +// ----------- +// std::list + +template ::value>::type* = nullptr > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the list are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +// Specialized routines for strings. found in checkpoint_sequence.cpp +int checkpoint_stl(std::list & in_list , std::string object_name , std::string var_name ) ; + +// ----------- +// std::deque + +template ::value>::type* = nullptr > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the deque are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +// Specialized routines for strings. found in checkpoint_sequence.cpp +int checkpoint_stl(std::deque & in_vector , std::string object_name , std::string var_name ) ; + +// ----------- +// std::set + +template ::value>::type* = nullptr > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the set are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +// Specialized routines for strings. found in checkpoint_sequence.cpp +int checkpoint_stl(std::set & in_vector , std::string object_name , std::string var_name ) ; + +// ----------- +// std::multiset + +template ::value>::type* = nullptr > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the multiset are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +// Specialized routines for strings. found in checkpoint_sequence.cpp +int checkpoint_stl(std::multiset & in_vector , std::string object_name , std::string var_name ) ; + +/* =================================================================================================*/ template int delete_sequence_stl(STL & in_stl __attribute__ ((unused)), std::string object_name , std::string var_name ) { @@ -60,75 +295,48 @@ int delete_stl(std::multiset & in_stl , std::string object_name , std return delete_sequence_stl( in_stl , object_name , var_name ) ; } -template -int checkpoint_sequence_stl(STL & in_stl , std::string object_name , std::string var_name ) { - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - int status ; +/* =================================================================================================*/ - typename STL::value_type * items = NULL ; - typename STL::iterator it ; - typename STL::iterator end ; +// Forward declare all of the specialized templates that can be used in checkpoint_sequence_stl_stl +template ::value>::type* = nullptr > +int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; - cont_size = in_stl.size() ; - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); +template ::value>::type* = nullptr > +int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; - if ( cont_size > 0 ) { +template ::value>::type* = nullptr > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; - 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 = (typename STL::value_type *)TMM_declare_var_s(var_declare) ; - //message_publish(1, "CHECKPOINT_SEQUENCE_STL with %s\n", var_declare) ; +template ::value>::type* = nullptr > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; - /* copy the contents of the stl */ - for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { - items[ii] = *it ; - } +template ::value>::type* = nullptr > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; - } +template ::value>::type* = nullptr > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; - return 0 ; -} +template ::value>::type* = nullptr > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; -template -int checkpoint_sequence_stl_string(STL & in_stl , std::string object_name , std::string var_name ) { +template ::value>::type* = nullptr > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; +template ::value>::type* = nullptr > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; - const char ** items ; - typename STL::iterator it ; - typename STL::iterator end ; +template ::value>::type* = nullptr > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; +// End forward declarations. - - 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, "char * %s_%s[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; - items = (const char **)TMM_declare_var_s(var_declare) ; - //message_publish(1, "CHECKPOINT_SEQUENCE_STL_STRING with %s\n", var_declare) ; - - /* copy the contents of the vector */ - for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { - items[ii] = it->c_str() ; - } - } - - return 0 ; -} - -/* Find the arrays the map data was stored in the checkpoint using ref_attributes +/* 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. + the map from the 2 arrays. */ template -int restore_sequence_stl(STL & in_stl , std::string object_name , std::string var_name ) { +int restore_sequence_stl_intrinsic(STL & in_stl , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -139,19 +347,19 @@ int restore_sequence_stl(STL & in_stl , std::string object_name , std::string va //message_publish(1, "RESTORE_SEQUENCE_STL %s_%s\n", object_name.c_str() , var_name.c_str()) ; - in_stl.clear() ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; if ( items_ref != NULL ) { + in_stl.clear() ; items = (typename STL::value_type *)items_ref->address ; cont_size = get_size((char *)items) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { in_stl.insert( in_stl.end(), items[ii] ) ; - } + } delete_stl( in_stl , object_name , var_name ) ; - } + } return 0 ; } @@ -168,11 +376,11 @@ int restore_sequence_stl_string(STL & in_stl , std::string object_name , std::st //message_publish(1, "in specialized vector template restore\n") ; - in_stl.clear() ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; if ( items_ref != NULL ) { + in_stl.clear() ; items = (char **)items_ref->address ; cont_size = get_size((char *)items) ; @@ -185,67 +393,123 @@ int restore_sequence_stl_string(STL & in_stl , std::string object_name , std::st return 0 ; } -// General routines for all types but strings -template -int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl( in_stl , object_name , var_name ) ; +template +int restore_sequence_stl_stl(STL & 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, "%s\n", __PRETTY_FUNCTION__) ; + + items_ref = ref_attributes((char *)(object_name + "_" + var_name).c_str()) ; + + if ( items_ref != NULL ) { + in_stl.clear() ; + items = (char **)items_ref->address ; + cont_size = get_size((char *)items) ; + + for ( ii = 0 ; ii < cont_size ; ii++ ) { + typename STL::value_type vt ; + char index_string[16] ; + sprintf(index_string, "%d", ii) ; + restore_stl(vt, object_name + "_" + var_name , std::string(index_string)) ; + in_stl.insert( in_stl.end(), vt ) ; + } + delete_stl( in_stl , object_name , var_name ) ; + } + + return 0 ; } -template -int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl( in_stl , object_name , var_name ) ; -} +// ----------- +// std::vector -template -int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl( in_stl , object_name , var_name ) ; -} - -template -int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl( in_stl , object_name , var_name ) ; -} - -template -int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl( in_stl , object_name , var_name ) ; -} - -template +// This template is only enabled if the items in the vector are an STL +template ::value>::type* = nullptr > int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl( in_stl , object_name , var_name ) ; + return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; } -template -int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl( in_stl , object_name , var_name ) ; +// This template is only enabled if the items in the vector are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } -template -int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl( in_stl , object_name , var_name ) ; -} - -template -int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl( in_stl , object_name , var_name ) ; -} - -template -int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl( in_stl , object_name , var_name ) ; -} // Specialized routines for strings. -int checkpoint_stl(std::vector & in_vector , std::string object_name , std::string var_name ) ; -int checkpoint_stl(std::list & in_vector , std::string object_name , std::string var_name ) ; -int checkpoint_stl(std::deque & in_vector , std::string object_name , std::string var_name ) ; -int checkpoint_stl(std::set & in_vector , std::string object_name , std::string var_name ) ; -int checkpoint_stl(std::multiset & in_vector , std::string object_name , std::string var_name ) ; int restore_stl(std::vector & in_vector , std::string object_name , std::string var_name ) ; -int restore_stl(std::list & in_vector , std::string object_name , std::string var_name ) ; -int restore_stl(std::deque & in_vector , std::string object_name , std::string var_name ) ; -int restore_stl(std::set & in_vector , std::string object_name , std::string var_name ) ; -int restore_stl(std::multiset & in_vector , std::string object_name , std::string var_name ) ; -#endif + +// ----------- +// std::list + +// This template is only enabled if the items in the list are an STL +template ::value>::type* = nullptr > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the list are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +int restore_stl(std::list & in_list , std::string object_name , std::string var_name ) ; + +// ----------- +// std::deque + +// This template is only enabled if the items in the deque are an STL +template ::value>::type* = nullptr > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the deque are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +int restore_stl(std::deque & in_deque , std::string object_name , std::string var_name ) ; + +// ----------- +// std::set + +// This template is only enabled if the items in the set are an STL +template ::value>::type* = nullptr > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the set are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +int restore_stl(std::set & in_set , std::string object_name , std::string var_name ) ; + +// ----------- +// std::multiset + +// This template is only enabled if the items in the multiset are an STL +template ::value>::type* = nullptr > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the multiset are NOT an STL, except for std::string +template ::value>::type* = nullptr > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +} + +// Specialized routines for strings. +int restore_stl(std::multiset & in_multiset , std::string object_name , std::string var_name ) ; #endif diff --git a/include/trick/checkpoint_stack.hh b/include/trick/checkpoint_stack.hh index 5a7c28bb..1699943f 100644 --- a/include/trick/checkpoint_stack.hh +++ b/include/trick/checkpoint_stack.hh @@ -42,6 +42,7 @@ int checkpoint_stl(std::stack & in_stl , std::string object_name , st 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) ; + 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 ; @@ -72,22 +73,22 @@ 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()) ; - cont_size = in_stl.size() ; - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_stl.pop() ; - } 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 = (ITEM_TYPE *)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 ; } diff --git a/include/trick/checkpoint_trick_sequence_stl.hh b/include/trick/checkpoint_trick_sequence_stl.hh index 5d4a1fde..ba13092f 100644 --- a/include/trick/checkpoint_trick_sequence_stl.hh +++ b/include/trick/checkpoint_trick_sequence_stl.hh @@ -11,9 +11,7 @@ #include #include -#ifdef __GNUC__ -#include -#endif +#ifdef __GNUC__ #include #endif #include "trick/STLInterface.hh" #include "trick/memorymanager_c_intf.h" diff --git a/include/trick/memorymanager_c_intf.h b/include/trick/memorymanager_c_intf.h index 2d5ac9c3..0e38c891 100644 --- a/include/trick/memorymanager_c_intf.h +++ b/include/trick/memorymanager_c_intf.h @@ -76,6 +76,7 @@ void ref_free( REF2 *R ) ; int get_enumerated(const char* name, V_DATA* v_data) ; +void TMM_add_checkpoint_alloc_dependency(const char * name) ; #ifdef __cplusplus } #endif diff --git a/include/trick/parameter_types.h b/include/trick/parameter_types.h index 18769e60..de96c954 100644 --- a/include/trick/parameter_types.h +++ b/include/trick/parameter_types.h @@ -34,6 +34,7 @@ extern "C" { TRICK_ENUMERATED = 21, /* User defined type (enumeration) */ TRICK_STRUCTURED = 22, /* User defined type (struct/class) */ TRICK_OPAQUE_TYPE = 23, /* User defined type (where type details are as yet unknown) */ + TRICK_STL = 24, /* Standard template library type */ TRICK_NUMBER_OF_TYPES } TRICK_TYPE ; diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index 3de1a2b6..27e1a0c9 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -87,9 +87,10 @@ sub read_files_to_process() { @defines = $ENV{"TRICK_CFLAGS"} =~ /(-D\S+)/g ; # get defines from TRICK_CFLAGS push @defines , "-DTRICK_VER=$year" ; push @defines , "-DSWIG" ; + push @defines , "-std=c++11" ; # Get the list header files from the compiler to compare to what get_headers processed. - open FILE_LIST, "$cc -MM -DSWIG @include_paths @defines S_source.hh |" ; + open FILE_LIST, "$cc -MM @include_paths @defines S_source.hh |" ; my $dir ; $dir = dirname($s_source_full_path) ; while ( ) { diff --git a/share/trick/makefiles/Makefile.tricklib b/share/trick/makefiles/Makefile.tricklib index 1a11a477..f9162d69 100644 --- a/share/trick/makefiles/Makefile.tricklib +++ b/share/trick/makefiles/Makefile.tricklib @@ -96,7 +96,8 @@ $(TRICK_LIB_DIR): $(IO_C_OBJS): $(OBJ_DIR)/%.o : $(IO_SRC_DIR)%.c | $(OBJ_DIR) $(TRICK_CC) $(TRICK_CFLAGS) $(TRICK_SYSTEM_CFLAGS) -c $< -o $@ -$(IO_CPP_OBJS): TRICK_CXXFLAGS += -Wno-invalid-offsetof +$(IO_CPP_OBJS): TRICK_SYSTEM_CXXFLAGS += -std=c++11 +$(IO_CPP_OBJS): TRICK_SYSTEM_CXXFLAGS += -Wno-invalid-offsetof ifeq ($(IS_CC_CLANG), 0) # cannot get an "expr" command to work on all platforms. Falling back to reliable perl. :) GCCVERSIONGTEQ48 := $(shell perl -e 'printf "%d\n", ($(GCC_MAJOR)>4)||(($(GCC_MAJOR)==4)&&($(GCC_MINOR)>=8)) ;' ) @@ -105,7 +106,6 @@ ifeq ($(IS_CC_CLANG), 0) endif endif - $(IO_CPP_OBJS): $(OBJ_DIR)/%.o : $(IO_SRC_DIR)%.cpp | $(OBJ_DIR) $(TRICK_CPPC) $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) -c $< -o $@ diff --git a/share/trick/sim_objects/default_trick_sys.sm b/share/trick/sim_objects/default_trick_sys.sm index 9680eda1..17bf71bd 100644 --- a/share/trick/sim_objects/default_trick_sys.sm +++ b/share/trick/sim_objects/default_trick_sys.sm @@ -93,12 +93,6 @@ a replacement SimObject will create an uncompilable sim. ##include "trick/RtiStager.hh" ##include "trick/RtiExec.hh" -// TODO: move users away from this STL checkpoint method -##include "trick/checkpoint_stl.hh" - -// TODO: move users away from this STL checkpoint method -#include "trick/stl_s_define_macro.hh" - // This is a user header block. Code here is copied without processing to S_source.hh %header{ @@ -382,7 +376,7 @@ class EventManagerSimObject : public Trick::SimObject { public: Trick::EventManager em ; Trick::EventProcessor ep ; - std::vector< ThreadProcessEventSimObject * > thread_process_event_so ; + std::vector< ThreadProcessEventSimObject * > thread_process_event_so ; // ** ignore for checkpointing void create_thread_process_event() { unsigned int ii ; @@ -748,7 +742,7 @@ class InjectorSimObject : public Trick::SimObject { public: Trick::RtiStager rtis ; - std::vector< InjectorExecSimObject * > injector_executor_so ; + std::vector< InjectorExecSimObject * > injector_executor_so ; // trick_io(**) void create_injector_executors() { unsigned int ii ; @@ -801,6 +795,5 @@ UnitTestSimObject trick_utest ; // Include optional external clocks #include "sim_objects/TPROClock.sm" #include "sim_objects/BC635Clock.sm" -#include "sim_objects/STL.sm" #endif diff --git a/test/SIM_stls/RUN_test/input.py b/test/SIM_stls/RUN_test/input.py index 0ae88b83..d49bbf77 100644 --- a/test/SIM_stls/RUN_test/input.py +++ b/test/SIM_stls/RUN_test/input.py @@ -2,21 +2,18 @@ def main(): #trick.echo_jobs_on() - simControlPanel = trick.SimControlPanel() - simControlPanel.thisown = 0 - trick.add_external_application(simControlPanel) + trick.sim_control_panel_set_enabled(True) trick.real_time_enable() - #trick.itimer_enable() + trick.itimer_enable() - trick.checkpoint_post_init(True) - trick.checkpoint_end(True) + trick.checkpoint_pre_init(True) + #trick.checkpoint_post_init(True) + #trick.checkpoint_end(True) - trick.freeze(2.0) + #trick.freeze(2.0) - the_object.stlc2.name = "Daisy" - - # Data recording HDF5 test + trick.exec_set_software_frame(0.10) trick.exec_set_freeze_frame(0.10) trick.stop(5.0) diff --git a/test/SIM_stls/S_define b/test/SIM_stls/S_define index f0a2aee1..908cbe15 100644 --- a/test/SIM_stls/S_define +++ b/test/SIM_stls/S_define @@ -1,46 +1,18 @@ #include "sim_objects/default_trick_sys.sm" -##include "stl_checkpoint/include/STLCheckpoint.hh" -##include "stl_checkpoint/include/STLCompanion.hh" - -/* This object tests having 2 of the same type of object containing STLs in the same sim_object. - The checkpoints use the name of the objects to give the STLs unique and identifiable names - in the checkpoint. */ +##include "STLCheckpoint.hh" class theSimObject : public Trick::SimObject { public: STLCheckpoint stlc ; - STLCheckpoint stlc2 ; - STLCompanion gc ; /** Constructor to add the jobs */ - theSimObject() : stlc(std::string("Petunia")) , stlc2() { - + theSimObject() : stlc("Petunia") { (1.0, "scheduled") stlc.speak() ; - - ("checkpoint") gc.checkpoint(&stlc, name + std::string("_stlc")) ; - ("checkpoint") gc.checkpoint(&stlc2, name + std::string("_stlc2")) ; - - ("post_checkpoint") gc.post_checkpoint(&stlc, name + std::string("_stlc")) ; - ("post_checkpoint") gc.post_checkpoint(&stlc2, name + std::string("_stlc2")) ; - - ("restart") gc.restart(&stlc, name + std::string("_stlc")) ; - ("restart") gc.restart(&stlc2, name + std::string("_stlc2")) ; } } ; -// Multiple simobjects theSimObject the_object ; -theSimObject the_object2 ; - -// Connect objects -void create_connections() { - - // Set the default termination time - trick_sys.sched.set_terminate_time(10.0) ; - trick_sys.sched.set_freeze_frame(0.10) ; - -} diff --git a/test/SIM_stls/S_overrides.mk b/test/SIM_stls/S_overrides.mk index 27536a3b..c4c9b818 100644 --- a/test/SIM_stls/S_overrides.mk +++ b/test/SIM_stls/S_overrides.mk @@ -2,3 +2,4 @@ TRICK_CFLAGS += -I./models TRICK_CXXFLAGS += -I./models +#TRICK_CXXFLAGS += -std=c++11 diff --git a/test/SIM_stls/models/stl_checkpoint/src/STLCheckpoint.cpp b/test/SIM_stls/models/STLCheckpoint.cpp similarity index 69% rename from test/SIM_stls/models/stl_checkpoint/src/STLCheckpoint.cpp rename to test/SIM_stls/models/STLCheckpoint.cpp index c8472d15..73a2bd35 100644 --- a/test/SIM_stls/models/stl_checkpoint/src/STLCheckpoint.cpp +++ b/test/SIM_stls/models/STLCheckpoint.cpp @@ -138,7 +138,10 @@ STLCheckpoint::STLCheckpoint() { return ; } -STLCheckpoint::STLCheckpoint(std::string in_name) { +STLCheckpoint::STLCheckpoint(std::string in_name) : + my_vector_vector_double(4, std::vector(3)) , + my_vector_vector_vector_double(5, std::vector >(4, std::vector(3))) +{ name = in_name ; @@ -271,11 +274,95 @@ STLCheckpoint::STLCheckpoint(std::string in_name) { my_string_pair.first = "pair first string" ; my_string_pair.second = "pair second string" ; + + my_vector_vector_double[0][0] = 100 ; + my_vector_vector_double[0][1] = 101 ; + my_vector_vector_double[0][2] = 102 ; + my_vector_vector_double[1][0] = 103 ; + my_vector_vector_double[1][1] = 104 ; + my_vector_vector_double[1][2] = 105 ; + my_vector_vector_double[2][0] = 106 ; + my_vector_vector_double[2][1] = 107 ; + my_vector_vector_double[2][2] = 108 ; + my_vector_vector_double[3][0] = 109 ; + my_vector_vector_double[3][1] = 110 ; + my_vector_vector_double[3][2] = 111 ; + + my_vector_vector_vector_double[0][0][0] = 0 ; + my_vector_vector_vector_double[0][0][1] = 1 ; + my_vector_vector_vector_double[0][0][2] = 2 ; + my_vector_vector_vector_double[0][1][0] = 3 ; + my_vector_vector_vector_double[0][1][1] = 4 ; + my_vector_vector_vector_double[0][1][2] = 5 ; + my_vector_vector_vector_double[0][2][0] = 6 ; + my_vector_vector_vector_double[0][2][1] = 7 ; + my_vector_vector_vector_double[0][2][2] = 8 ; + my_vector_vector_vector_double[0][3][0] = 9 ; + my_vector_vector_vector_double[0][3][1] = 10 ; + my_vector_vector_vector_double[0][3][2] = 11 ; + + my_vector_vector_vector_double[1][0][0] = 1000 ; + my_vector_vector_vector_double[1][0][1] = 1001 ; + my_vector_vector_vector_double[1][0][2] = 1002 ; + my_vector_vector_vector_double[1][1][0] = 1003 ; + my_vector_vector_vector_double[1][1][1] = 1004 ; + my_vector_vector_vector_double[1][1][2] = 1005 ; + my_vector_vector_vector_double[1][2][0] = 1006 ; + my_vector_vector_vector_double[1][2][1] = 1007 ; + my_vector_vector_vector_double[1][2][2] = 1008 ; + my_vector_vector_vector_double[1][3][0] = 1009 ; + my_vector_vector_vector_double[1][3][1] = 1010 ; + my_vector_vector_vector_double[1][3][2] = 1011 ; + + my_vector_vector_vector_double[2][0][0] = 2000 ; + my_vector_vector_vector_double[2][0][1] = 2001 ; + my_vector_vector_vector_double[2][0][2] = 2002 ; + my_vector_vector_vector_double[2][1][0] = 2003 ; + my_vector_vector_vector_double[2][1][1] = 2004 ; + my_vector_vector_vector_double[2][1][2] = 2005 ; + my_vector_vector_vector_double[2][2][0] = 2006 ; + my_vector_vector_vector_double[2][2][1] = 2007 ; + my_vector_vector_vector_double[2][2][2] = 2008 ; + my_vector_vector_vector_double[2][3][0] = 2009 ; + my_vector_vector_vector_double[2][3][1] = 2010 ; + my_vector_vector_vector_double[2][3][2] = 2011 ; + + my_vector_vector_vector_double[3][0][0] = 3000 ; + my_vector_vector_vector_double[3][0][1] = 3001 ; + my_vector_vector_vector_double[3][0][2] = 3002 ; + my_vector_vector_vector_double[3][1][0] = 3003 ; + my_vector_vector_vector_double[3][1][1] = 3004 ; + my_vector_vector_vector_double[3][1][2] = 3005 ; + my_vector_vector_vector_double[3][2][0] = 3006 ; + my_vector_vector_vector_double[3][2][1] = 3007 ; + my_vector_vector_vector_double[3][2][2] = 3008 ; + my_vector_vector_vector_double[3][3][0] = 3009 ; + my_vector_vector_vector_double[3][3][1] = 3010 ; + my_vector_vector_vector_double[3][3][2] = 3011 ; + + my_vector_vector_vector_double[4][0][0] = 4000 ; + my_vector_vector_vector_double[4][0][1] = 4001 ; + my_vector_vector_vector_double[4][0][2] = 4002 ; + my_vector_vector_vector_double[4][1][0] = 4003 ; + my_vector_vector_vector_double[4][1][1] = 4004 ; + my_vector_vector_vector_double[4][1][2] = 4005 ; + my_vector_vector_vector_double[4][2][0] = 4006 ; + my_vector_vector_vector_double[4][2][1] = 4007 ; + my_vector_vector_vector_double[4][2][2] = 4008 ; + my_vector_vector_vector_double[4][3][0] = 4009 ; + my_vector_vector_vector_double[4][3][1] = 4010 ; + my_vector_vector_vector_double[4][3][2] = 4011 ; + return ; } int STLCheckpoint::speak() { - message_publish(1,"Quack!\n") ; + //message_publish(1,"Quack!\n") ; + //message_publish(1,"my_double_vector: %f %f %f\n", my_double_vector[0], my_double_vector[1], my_double_vector[2]) ; + message_publish(1,"my_vector_vector_double[1]: %f %f %f\n", + my_vector_vector_double[1][0], my_vector_vector_double[1][1], my_vector_vector_double[1][2]) ; + message_publish(1,"my_vector_vector_vector_double[4][2]: %f %f %f\n", + my_vector_vector_vector_double[4][2][0], my_vector_vector_vector_double[4][2][1], my_vector_vector_vector_double[4][2][2]) ; return 0 ; } diff --git a/test/SIM_stls/models/stl_checkpoint/include/STLCheckpoint.hh b/test/SIM_stls/models/STLCheckpoint.hh similarity index 67% rename from test/SIM_stls/models/stl_checkpoint/include/STLCheckpoint.hh rename to test/SIM_stls/models/STLCheckpoint.hh index 8a4b4031..45c89b34 100644 --- a/test/SIM_stls/models/stl_checkpoint/include/STLCheckpoint.hh +++ b/test/SIM_stls/models/STLCheckpoint.hh @@ -18,26 +18,8 @@ #include #include -/* This shows the most difficult case in checkpointing STLs where all - STLs are private. There are no accessor routines to get individual - items out of the STLs. (In fact getting to all items in some of the - STLs forces changes in the contents, such as stacks and queues.) Anyways - in this case we need to specify a friend that carries out the checkpoint. - There are 2 methods one can use to call the Trick stl checkpoint routines: - 1) Provide a companion class that calls the Trick routines for each STL - (STLCompanion in this example). - -- OR -- - 2) Invoke Trick's CHECKPOINT_STL macro in the sim object class for each STL - (theSimObject in this example). - Whichever method is chosen, make that class a friend of the class with STLs - (STLCheckpoint in this example). - Public STLs can be checkpointed in the same way (but no need to specify friend). -*/ class STLCheckpoint { - friend class STLCompanion ; // method 1 - friend class theSimObject ; // method 2 - public: STLCheckpoint() ; @@ -46,8 +28,6 @@ class STLCheckpoint { std::string name ; - private: - std::map< double , double > my_double_map ; std::map< std::string , int > my_string_key_map ; std::map< int , std::string > my_string_data_map ; @@ -87,6 +67,9 @@ class STLCheckpoint { std::pair< int , std::string > my_string_second_pair ; std::pair< std::string , std::string > my_string_pair ; + std::vector< std::vector< double > > my_vector_vector_double ; + std::vector< std::vector< std::vector< double > > > my_vector_vector_vector_double ; + //std::vector< std::list< double > > my_vector_list_double ; } ; #endif diff --git a/test/SIM_stls/models/stl_checkpoint/include/STLCompanion.hh b/test/SIM_stls/models/stl_checkpoint/include/STLCompanion.hh deleted file mode 100644 index bc2c987b..00000000 --- a/test/SIM_stls/models/stl_checkpoint/include/STLCompanion.hh +++ /dev/null @@ -1,42 +0,0 @@ -/* - PURPOSE: (Illustrate how to checkpoint STLs) - LIBRARY_DEPENDENCIES: ( - (STLCompanion_checkpoint.o) - (STLCompanion_post_checkpoint.o) - (STLCompanion_restart.o) - ) -*/ - -#ifndef STLCOMPANION_HH -#define STLCOMPANION_HH - -#include - -#include "STLCheckpoint.hh" - -/* STLCheckpoint's friend - -This class's sole purpose in life is to keep up the STLs in the STLCheckpoint class. -Since this is a friend to the STLCheckpoint class, the methods of this class work -with the STLs in STLCheckpoint directly. -*/ - -class STLCompanion { - - public: - - STLCompanion() {} ; - - /* writes out the STL data in arrays in the memory manager */ - int checkpoint(STLCheckpoint * in_stlc, std::string var_name) ; - - /* deletes the STL data in arrays from the memory manager */ - int post_checkpoint(STLCheckpoint * in_stlc, std::string var_name) ; - - /* restores memory from a checkpoint. the data resides in memory - manager. deletes the STL data in arrays after restoration */ - int restart(STLCheckpoint * in_stlc, std::string var_name) ; -} ; - -#endif - diff --git a/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_checkpoint.cpp b/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_checkpoint.cpp deleted file mode 100644 index 4355dbc5..00000000 --- a/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_checkpoint.cpp +++ /dev/null @@ -1,53 +0,0 @@ - -#include - -#include "STLCompanion.hh" -#include "sim_services/CheckPointRestart/include/checkpoint_stl.hh" - -/* All STLs are checkpointed through the same templated function checkpoint_stl. The - second and third arguments to the call give each set of STL data a unique name. In - this example the unique name is the concatenation of the object instance and the variable name - */ -int STLCompanion::checkpoint(STLCheckpoint * stlc, std::string object_name ) { - - checkpoint_stl(stlc->my_double_map , object_name , std::string("my_double_map")) ; - checkpoint_stl(stlc->my_string_key_map , object_name , std::string("my_string_key_map")) ; - checkpoint_stl(stlc->my_string_data_map , object_name , std::string("my_string_data_map")) ; - checkpoint_stl(stlc->my_string_map , object_name , std::string("my_string_map")) ; - - checkpoint_stl(stlc->my_int_multimap , object_name , std::string("my_int_multimap")) ; - checkpoint_stl(stlc->my_string_key_multimap , object_name , std::string("my_string_key_multimap")) ; - checkpoint_stl(stlc->my_string_data_multimap , object_name , std::string("my_string_data_multimap")) ; - checkpoint_stl(stlc->my_string_multimap , object_name , std::string("my_string_multimap")) ; - - checkpoint_stl(stlc->my_double_vector , object_name , std::string("my_double_vector")) ; - checkpoint_stl(stlc->my_string_vector , object_name , std::string("my_string_vector")) ; - - checkpoint_stl(stlc->my_short_list , object_name , std::string("my_short_list")) ; - checkpoint_stl(stlc->my_string_list , object_name , std::string("my_string_list")) ; - - checkpoint_stl(stlc->my_float_deque , object_name , std::string("my_float_deque")) ; - checkpoint_stl(stlc->my_string_deque , object_name , std::string("my_string_deque")) ; - - checkpoint_stl(stlc->my_int_set , object_name , std::string("my_int_set")) ; - checkpoint_stl(stlc->my_string_set , object_name , std::string("my_string_set")) ; - - checkpoint_stl(stlc->my_long_multiset , object_name , std::string("my_long_multiset")) ; - checkpoint_stl(stlc->my_string_multiset , object_name , std::string("my_string_multiset")) ; - - checkpoint_stl(stlc->my_uint_stack , object_name , std::string("my_uint_stack")) ; - checkpoint_stl(stlc->my_string_stack , object_name , std::string("my_string_stack")) ; - - checkpoint_stl(stlc->my_int_queue , object_name , std::string("my_int_queue")) ; - checkpoint_stl(stlc->my_string_queue , object_name , std::string("my_string_queue")) ; - - checkpoint_stl(stlc->my_int_priority_queue , object_name , std::string("my_int_priority_queue")) ; - checkpoint_stl(stlc->my_string_priority_queue , object_name , std::string("my_string_priority_queue")) ; - - checkpoint_stl(stlc->my_int_pair , object_name , std::string("my_int_pair")) ; - checkpoint_stl(stlc->my_string_first_pair , object_name , std::string("my_string_first_pair")) ; - checkpoint_stl(stlc->my_string_second_pair , object_name , std::string("my_string_second_pair")) ; - checkpoint_stl(stlc->my_string_pair , object_name , std::string("my_stringpair")) ; - - return 0 ; -} diff --git a/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_post_checkpoint.cpp b/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_post_checkpoint.cpp deleted file mode 100644 index c531e65e..00000000 --- a/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_post_checkpoint.cpp +++ /dev/null @@ -1,55 +0,0 @@ - -#include - -#include "STLCompanion.hh" -#include "sim_services/CheckPointRestart/include/checkpoint_stl.hh" - -/* All STLs are deleted through the same templated function delete_stl. The - second and third arguments give the unique name to delete. In - this example the unique name is the concatenation of the object instance and the variable name. - Currently the first argument is unused. - */ -int STLCompanion::post_checkpoint(STLCheckpoint * stlc, std::string object_name ) { - - delete_stl(stlc->my_double_map , object_name , std::string("my_double_map")) ; - delete_stl(stlc->my_string_key_map , object_name , std::string("my_string_key_map")) ; - delete_stl(stlc->my_string_data_map , object_name , std::string("my_string_data_map")) ; - delete_stl(stlc->my_string_map , object_name , std::string("my_string_map")) ; - - delete_stl(stlc->my_int_multimap , object_name , std::string("my_int_multimap")) ; - delete_stl(stlc->my_string_key_multimap , object_name , std::string("my_string_key_multimap")) ; - delete_stl(stlc->my_string_data_multimap , object_name , std::string("my_string_data_multimap")) ; - delete_stl(stlc->my_string_multimap , object_name , std::string("my_string_multimap")) ; - - delete_stl(stlc->my_double_vector , object_name , std::string("my_double_vector")) ; - delete_stl(stlc->my_string_vector , object_name , std::string("my_string_vector")) ; - - delete_stl(stlc->my_short_list , object_name , std::string("my_short_list")) ; - delete_stl(stlc->my_string_list , object_name , std::string("my_string_list")) ; - - delete_stl(stlc->my_float_deque , object_name , std::string("my_float_deque")) ; - delete_stl(stlc->my_string_deque , object_name , std::string("my_string_deque")) ; - - delete_stl(stlc->my_int_set , object_name , std::string("my_int_set")) ; - delete_stl(stlc->my_string_set , object_name , std::string("my_string_set")) ; - - delete_stl(stlc->my_long_multiset , object_name , std::string("my_long_multiset")) ; - delete_stl(stlc->my_string_multiset , object_name , std::string("my_string_multiset")) ; - - delete_stl(stlc->my_uint_stack , object_name , std::string("my_uint_stack")) ; - delete_stl(stlc->my_string_stack , object_name , std::string("my_string_stack")) ; - - delete_stl(stlc->my_int_queue , object_name , std::string("my_int_queue")) ; - delete_stl(stlc->my_string_queue , object_name , std::string("my_string_queue")) ; - - delete_stl(stlc->my_int_priority_queue , object_name , std::string("my_int_priority_queue")) ; - delete_stl(stlc->my_string_priority_queue , object_name , std::string("my_string_priority_queue")) ; - - delete_stl(stlc->my_int_pair , object_name , std::string("my_int_pair")) ; - delete_stl(stlc->my_string_first_pair , object_name , std::string("my_string_first_pair")) ; - delete_stl(stlc->my_string_second_pair , object_name , std::string("my_string_second_pair")) ; - delete_stl(stlc->my_string_pair , object_name , std::string("my_stringpair")) ; - - return 0 ; -} - diff --git a/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_restart.cpp b/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_restart.cpp deleted file mode 100644 index c23166bf..00000000 --- a/test/SIM_stls/models/stl_checkpoint/src/STLCompanion_restart.cpp +++ /dev/null @@ -1,54 +0,0 @@ - -#include - -#include "STLCompanion.hh" -#include "sim_services/CheckPointRestart/include/checkpoint_stl.hh" - -/* All STLs are restored through the same templated function restore_stl. The - second and third arguments give the unique name to delete. In - this example the unique name is the concatenation of the object instance and the variable name. - retore_stl will delete the memory manager arrays. - */ -int STLCompanion::restart(STLCheckpoint * stlc, std::string object_name ) { - - restore_stl(stlc->my_double_map , object_name , std::string("my_double_map")) ; - restore_stl(stlc->my_string_key_map , object_name , std::string("my_string_key_map")) ; - restore_stl(stlc->my_string_data_map , object_name , std::string("my_string_data_map")) ; - restore_stl(stlc->my_string_map , object_name , std::string("my_string_map")) ; - - restore_stl(stlc->my_int_multimap , object_name , std::string("my_int_multimap")) ; - restore_stl(stlc->my_string_key_multimap , object_name , std::string("my_string_key_multimap")) ; - restore_stl(stlc->my_string_data_multimap , object_name , std::string("my_string_data_multimap")) ; - restore_stl(stlc->my_string_multimap , object_name , std::string("my_string_multimap")) ; - - restore_stl(stlc->my_double_vector , object_name , std::string("my_double_vector")) ; - restore_stl(stlc->my_string_vector , object_name , std::string("my_string_vector")) ; - - restore_stl(stlc->my_short_list , object_name , std::string("my_short_list")) ; - restore_stl(stlc->my_string_list , object_name , std::string("my_string_list")) ; - - restore_stl(stlc->my_float_deque , object_name , std::string("my_float_deque")) ; - restore_stl(stlc->my_string_deque , object_name , std::string("my_string_deque")) ; - - restore_stl(stlc->my_int_set , object_name , std::string("my_int_set")) ; - restore_stl(stlc->my_string_set , object_name , std::string("my_string_set")) ; - - restore_stl(stlc->my_long_multiset , object_name , std::string("my_long_multiset")) ; - restore_stl(stlc->my_string_multiset , object_name , std::string("my_string_multiset")) ; - - restore_stl(stlc->my_uint_stack , object_name , std::string("my_uint_stack")) ; - restore_stl(stlc->my_string_stack , object_name , std::string("my_string_stack")) ; - - restore_stl(stlc->my_int_queue , object_name , std::string("my_int_queue")) ; - restore_stl(stlc->my_string_queue , object_name , std::string("my_string_queue")) ; - - restore_stl(stlc->my_int_priority_queue , object_name , std::string("my_int_priority_queue")) ; - restore_stl(stlc->my_string_priority_queue , object_name , std::string("my_string_priority_queue")) ; - - restore_stl(stlc->my_int_pair , object_name , std::string("my_int_pair")) ; - restore_stl(stlc->my_string_first_pair , object_name , std::string("my_string_first_pair")) ; - restore_stl(stlc->my_string_second_pair , object_name , std::string("my_string_second_pair")) ; - restore_stl(stlc->my_string_pair , object_name , std::string("my_stringpair")) ; - - return 0 ; -} diff --git a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp index 6ef6910d..7704b8cd 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp @@ -35,6 +35,8 @@ FieldDescription::FieldDescription( bitfield_word_offset(0) , is_enum(0) , is_record(0) , + is_stl(0) , + has_stl_clear(1) , is_static(0) , num_dims(0) , array_sizes() {} ; @@ -368,6 +370,22 @@ bool FieldDescription::isRecord() { return is_record ; } +void FieldDescription::setSTL(bool yes_no) { + is_stl = yes_no ; +} + +bool FieldDescription::isSTL() { + return is_stl ; +} + +void FieldDescription::setSTLClear(bool yes_no) { + has_stl_clear = yes_no ; +} + +bool FieldDescription::hasSTLClear() { + return has_stl_clear ; +} + void FieldDescription::setStatic(bool yes_no) { is_static = yes_no ; } diff --git a/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh b/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh index 9914697a..5335d68f 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh +++ b/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh @@ -70,6 +70,10 @@ class FieldDescription : public ConstructValues { bool isEnum() ; void setRecord( bool yes_no ) ; bool isRecord() ; + void setSTL( bool yes_no ) ; + bool isSTL() ; + void setSTLClear( bool yes_no ) ; + bool hasSTLClear() ; void setStatic( bool yes_no ) ; bool isStatic() ; bool getAccessSpecFound() ; @@ -150,6 +154,12 @@ class FieldDescription : public ConstructValues { /** is a record class */ bool is_record ; + /** is an stl */ + bool is_stl ; + + /** does this stl have a clear */ + bool has_stl_clear ; + /** is this field declared static */ bool is_static ; diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp index 28aa6978..719776b7 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp @@ -5,6 +5,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/AST/RecordLayout.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/Comment.h" #include "FieldVisitor.hh" #include "FieldDescription.hh" @@ -143,27 +144,28 @@ bool FieldVisitor::VisitDeclaratorDecl( clang::DeclaratorDecl *dd ) { /* Get the source location of this field. */ clang::SourceRange dd_range = dd->getSourceRange() ; - std::string file_name = ci.getSourceManager().getBufferName(dd_range.getEnd()) ; - char * resolved_path = almostRealPath( file_name.c_str() ) ; - if ( resolved_path ) { + std::string file_name = getFileName(ci, dd_range.getEnd(), hsd) ; + if ( ! file_name.empty() ) { if ( isInUserOrTrickCode( ci , dd_range.getEnd() , hsd ) ) { fdes->setLineNo(ci.getSourceManager().getSpellingLineNumber(dd_range.getEnd())) ; /* process comment if neither ICG:(No) or ICG:(NoComment) is present */ - if ( cs.hasTrickHeader(resolved_path) and - !cs.hasICGNoComment(resolved_path) and - !hsd.isPathInICGNoComment(resolved_path) ) { + if ( cs.hasTrickHeader(file_name) and + !cs.hasICGNoComment(file_name) and + !hsd.isPathInICGNoComment(file_name) ) { /* Get the possible comment on this line and parse it */ - fdes->parseComment(cs.getComment(resolved_path , fdes->getLineNo())) ; + fdes->parseComment(cs.getComment(file_name , fdes->getLineNo())) ; } } - free(resolved_path) ; } if ( debug_level >= 3 ) { if ( ! ci.getSourceManager().isInSystemHeader(dd_range.getEnd()) ) { std::cout << "FieldVisitor VisitDeclaratorDecl" << std::endl ; - //dd->dump() ; + std::cout << " file_name = " << file_name << std::endl ; + std::cout << " line num = " << fdes->getLineNo() << std::endl ; + std::cout << " comment = " << cs.getComment(file_name , fdes->getLineNo()) << std::endl ; std::cout << " public/private = " << fdes->getAccess() << std::endl ; + std::cout << " io = " << fdes->getIO() << std::endl ; } } @@ -217,19 +219,12 @@ bool FieldVisitor::VisitFieldDecl( clang::FieldDecl *field ) { if ( !qt.isCanonical() ) { clang::QualType ct = qt.getCanonicalType() ; std::string tst_string = ct.getAsString() ; - // If we have a standard template library specializations other than std::string, don't process it. - if ( (! tst_string.compare( 0 , 9 , "class std") or ! tst_string.compare( 0 , 10 , "struct std")) and - tst_string.compare( 0, 23 , "class std::basic_string") ) { - // This is a standard template library type. don't process any further. - fdes->setIO(0) ; - } else { - if ( debug_level >= 3 ) { - std::cout << "\033[33mFieldVisitor VisitFieldDecl: Processing canonical type\033[00m" << std::endl ; - ct.dump() ; - } - TraverseType(ct) ; + if ( debug_level >= 3 ) { + std::cout << "\033[33mFieldVisitor VisitFieldDecl: Processing canonical type\033[00m" << std::endl ; + ct.dump() ; } - // We have either skipped a std template or extracted the canonical type and everything else we need + TraverseType(ct) ; + // We have extracted the canonical type and everything else we need // return false so we cut off processing of this AST branch return false ; } @@ -242,6 +237,19 @@ bool FieldVisitor::VisitPointerType(clang::PointerType *p) { return true; } +static std::string mangle_string( std::string in_name ) { + // convert characters not valid in a function name to underscores + std::string mangled_name = in_name ; + // Create a mangled type name, some characters have to converted to underscores. + std::replace( mangled_name.begin(), mangled_name.end(), '<', '_') ; + std::replace( mangled_name.begin(), mangled_name.end(), '>', '_') ; + std::replace( mangled_name.begin(), mangled_name.end(), ' ', '_') ; + std::replace( mangled_name.begin(), mangled_name.end(), ',', '_') ; + std::replace( mangled_name.begin(), mangled_name.end(), ':', '_') ; + std::replace( mangled_name.begin(), mangled_name.end(), '*', '_') ; + return mangled_name ; +} + std::map < std::string , std::string > FieldVisitor::processed_templates ; bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl * crd ) { @@ -251,6 +259,7 @@ bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl * size_t pos ; +/* if ((pos = in_name.find("class ")) != std::string::npos ) { in_name.erase(pos , 6) ; } @@ -261,20 +270,13 @@ bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl * while ((pos = in_name.find(" _Bool")) != std::string::npos ) { in_name.replace(pos , 6, " bool") ; } +*/ // NOTE: clang also changes FILE * to struct _SFILE *. We may need to change that too. // Check to see if we've processed this template before // If not we need to create attributes for this template if ( processed_templates.find(in_name) == processed_templates.end() ) { - // convert characters not valid in a function name to underscores - std::string mangled_name = in_name ; - // Create a mangled type name, some characters have to converted to underscores. - std::replace( mangled_name.begin(), mangled_name.end(), '<', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), '>', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), ' ', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), ',', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), ':', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), '*', '_') ; + std::string mangled_name = mangle_string(in_name) ; // save off the mangled name of this template to be used if another variable is the same template type processed_templates[in_name] = fdes->getContainerClass() + "_" + @@ -305,6 +307,42 @@ bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl * return false ; } +static std::map init_stl_classes() { + std::map my_map ; + my_map.insert(std::pair("std::deque", 1)) ; + my_map.insert(std::pair("std::list", 1)) ; + my_map.insert(std::pair("std::map", 1)) ; + my_map.insert(std::pair("std::multiset", 1)) ; + my_map.insert(std::pair("std::multimap", 1)) ; + my_map.insert(std::pair("std::pair", 1)) ; + my_map.insert(std::pair("std::priority_queue", 0)) ; + my_map.insert(std::pair("std::queue", 0)) ; + my_map.insert(std::pair("std::set", 1)) ; + my_map.insert(std::pair("std::stack", 0)) ; + my_map.insert(std::pair("std::vector", 1)) ; + return my_map ; +} + +static std::map stl_classes = init_stl_classes() ; + +#if 0 +// C++ 11 style initialization +// list of handled STL types and if they have a clear function. +static std::map stl_classes = { + {"std::deque", 1}, + {"std::list", 1}, + {"std::map", 1}, + {"std::multiset", 1}, + {"std::multimap", 1}, + {"std::pair", 0}, + {"std::priority_queue", 0}, + {"std::queue", 0}, + {"std::set", 1}, + {"std::stack", 0}, + {"std::vector", 1} +}; +#endif + bool FieldVisitor::VisitRecordType(clang::RecordType *rt) { if ( debug_level >= 3 ) { std::cout << "FieldVisitor VisitRecordType" << std::endl ; @@ -320,12 +358,42 @@ bool FieldVisitor::VisitRecordType(clang::RecordType *rt) { return false ; } + std::string tst_string = rt->desugar().getAsString() ; + // remove class keyword if it exists + size_t pos ; + while ((pos = tst_string.find("class ")) != std::string::npos ) { + tst_string.erase(pos , 6) ; + } + // clang changes bool to _Bool. We need to change it back + if ((pos = tst_string.find("<_Bool")) != std::string::npos ) { + tst_string.replace(pos , 6, "::iterator it = stl_classes.begin() ; it != stl_classes.end() ; it++ ) { + /* Mark STL types that are not strings and exit */ + //if (!tst_string.compare( 0 , 11 , "class std::") or !tst_string.compare( 0 , 12 , "struct std::")) { + if (!tst_string.compare( 0 , (*it).first.size() , (*it).first)) { + fdes->setEnumString("TRICK_STL") ; + fdes->setSTL(true) ; + fdes->setTypeName(tst_string) ; + fdes->setSTLClear((*it).second) ; + fdes->setMangledTypeName(mangle_string(tst_string)) ; + return false ; + } + } + } + /* Template specialization types will be processed here because the canonical type will be typed as a record. We test if we have a template specialization type. If so process the template type and return */ clang::RecordDecl * rd = rt->getDecl()->getDefinition() ; if ( rd != NULL and clang::ClassTemplateSpecializationDecl::classof(rd) ) { - std::string tst_string = rt->desugar().getAsString() ; if ( debug_level >= 3 ) { rd->dump() ; std::cout << " tst_string = " << tst_string << std::endl ; diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp index 2c35973f..2c5da9c3 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp @@ -417,6 +417,7 @@ void PrintAttributes::printIOMakefile() { std::cout << "Creating/updating io_src Makefile" << std::endl ; makefile_io_src.open("build/Makefile_io_src") ; + makefile_io_src << "TRICK_SYSTEM_CXXFLAGS += -std=c++11" << std::endl ; makefile_io_src << "TRICK_SYSTEM_CXXFLAGS += \\" << std::endl ; makefile_io_src << " -Wno-invalid-offsetof \\" << std::endl ; makefile_io_src << " -Wno-old-style-cast \\" << std::endl ; diff --git a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp index 3557c94e..30895f16 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp @@ -45,6 +45,7 @@ void PrintFileContents10::printIOHeader(std::ofstream & outfile , std::string he "#include \"trick/attributes.h\"\n" "#include \"trick/parameter_types.h\"\n" "#include \"trick/UnitsMap.hh\"\n\n" +"#include \"trick/checkpoint_stl.hh\"\n\n" "#include \"" << header_file_name << "\"\n\n" ; @@ -103,7 +104,9 @@ void PrintFileContents10::print_field_attr(std::ofstream & outfile , FieldDescr if ( array_dim < 0 ) array_dim = 0 ; outfile << ",{" << array_dim << ",0}" ; // indexes 1 through 7 } - outfile << "} }" ; + outfile << "}," << std::endl ; + outfile << " NULL, NULL, NULL, NULL" ; + outfile << "}" ; } /** Prints class attributes */ @@ -186,7 +189,7 @@ void PrintFileContents10::print_field_init_attr_stmts( std::ofstream & outfile , outfile << cv->getMangledTypeName() << "," << fdes->getName() << ") ;\n" ; } - if ( !fdes->isRecord() and !fdes->isEnum() and !fdes->isBitField() ) { + if ( !fdes->isRecord() and !fdes->isEnum() and !fdes->isBitField() and !fdes->isSTL()) { outfile << " attr" ; printNamespaces( outfile, cv , "__" ) ; printContainerClasses( outfile, cv , "__" ) ; @@ -196,6 +199,46 @@ void PrintFileContents10::print_field_init_attr_stmts( std::ofstream & outfile , outfile << fdes->getTypeName() << ") ;\n" ; } + if ( fdes->isSTL()) { + outfile << " attr" ; + printNamespaces( outfile, cv , "__" ) ; + printContainerClasses( outfile, cv , "__" ) ; + outfile << cv->getMangledTypeName() << "[i].checkpoint_stl = checkpoint_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << " ;\n" ; + + outfile << " attr" ; + printNamespaces( outfile, cv , "__" ) ; + printContainerClasses( outfile, cv , "__" ) ; + outfile << cv->getMangledTypeName() << "[i].post_checkpoint_stl = post_checkpoint_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << " ;\n" ; + + outfile << " attr" ; + printNamespaces( outfile, cv , "__" ) ; + printContainerClasses( outfile, cv , "__" ) ; + outfile << cv->getMangledTypeName() << "[i].restore_stl = restore_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << " ;\n" ; + + if (fdes->hasSTLClear()) { + outfile << " attr" ; + printNamespaces( outfile, cv , "__" ) ; + printContainerClasses( outfile, cv , "__" ) ; + outfile << cv->getMangledTypeName() << "[i].clear_stl = clear_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << " ;\n" ; + } + } + if ( fdes->isRecord() or fdes->isEnum()) { outfile << " next_attr = std::string(attr" ; printNamespaces( outfile, cv , "__" ) ; @@ -425,8 +468,121 @@ void PrintFileContents10::print_io_src_delete( std::ofstream & outfile , ClassVa } } +void PrintFileContents10::print_stl_helper_proto(std::ofstream & outfile , ClassValues * cv ) { + + unsigned int ii ; + ClassValues::FieldIterator fit ; + + print_open_extern_c(outfile) ; + + for ( fit = cv->field_begin() ; fit != cv->field_end() ; fit++ ) { + if ( (*fit)->isSTL() and determinePrintAttr(cv , *fit) ) { + outfile << "void checkpoint_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << (*fit)->getName() ; + outfile << "(void * start_address, const char * obj_name , const char * var_name) ;" << std::endl ; + + outfile << "void post_checkpoint_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << (*fit)->getName() ; + outfile << "(void * start_address, const char * obj_name , const char * var_name) ;" << std::endl ; + + outfile << "void restore_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << (*fit)->getName() ; + outfile << "(void * start_address, const char * obj_name , const char * var_name) ;" << std::endl ; + + if ((*fit)->hasSTLClear()) { + outfile << "void clear_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << (*fit)->getName() ; + outfile << "(void * start_address) ;" << std::endl ; + } + } + } + print_close_extern_c(outfile) ; +} + +void PrintFileContents10::print_checkpoint_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * cv ) { + outfile << "void checkpoint_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << "(void * start_address, const char * obj_name , const char * var_name) {" << std::endl ; + + outfile << " " << fdes->getTypeName() << " * stl = reinterpret_cast<" << fdes->getTypeName() << " * >(start_address) ;" << std::endl ; + outfile << " " << "checkpoint_stl(*stl , obj_name , var_name) ;" << std::endl ; + + outfile << "}" << std::endl ; +} + +void PrintFileContents10::print_post_checkpoint_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * cv ) { + outfile << "void post_checkpoint_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << "(void * start_address, const char * obj_name , const char * var_name) {" << std::endl ; + + outfile << " " << fdes->getTypeName() << " * stl = reinterpret_cast<" << fdes->getTypeName() << " * >(start_address) ;" << std::endl ; + outfile << " " << "delete_stl(*stl , obj_name , var_name) ;" << std::endl ; + + outfile << "}" << std::endl ; +} + +void PrintFileContents10::print_restore_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * cv ) { + outfile << "void restore_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << "(void * start_address, const char * obj_name , const char * var_name) {" << std::endl ; + + outfile << " " << fdes->getTypeName() << " * stl = reinterpret_cast<" << fdes->getTypeName() << " * >(start_address) ;" << std::endl ; + outfile << " " << "restore_stl(*stl , obj_name , var_name) ;" << std::endl ; + + outfile << "}" << std::endl ; +} + +void PrintFileContents10::print_clear_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * cv ) { + outfile << "void clear_stl_" ; + outfile << cv->getMangledTypeName() ; + outfile << "_" ; + outfile << fdes->getName() ; + outfile << "(void * start_address) {" << std::endl ; + + outfile << " " << fdes->getTypeName() << " * stl = reinterpret_cast<" << fdes->getTypeName() << " * >(start_address) ;" << std::endl ; + outfile << " " << "stl->clear() ;" << std::endl ; + + outfile << "}" << std::endl ; +} + +void PrintFileContents10::print_stl_helper(std::ofstream & outfile , ClassValues * cv ) { + + unsigned int ii ; + ClassValues::FieldIterator fit ; + + print_open_extern_c(outfile) ; + + for ( fit = cv->field_begin() ; fit != cv->field_end() ; fit++ ) { + if ( (*fit)->isSTL() and determinePrintAttr(cv , *fit) ) { + print_checkpoint_stl(outfile , *fit, cv) ; + print_post_checkpoint_stl(outfile , *fit, cv) ; + print_restore_stl(outfile , *fit, cv) ; + if ((*fit)->hasSTLClear()) { + print_clear_stl(outfile , *fit, cv) ; + } + } + } + print_close_extern_c(outfile) ; +} + void PrintFileContents10::printClass( std::ofstream & outfile , ClassValues * cv ) { + print_stl_helper_proto(outfile, cv) ; print_class_attr(outfile, cv) ; + print_stl_helper(outfile, cv) ; print_init_attr_func(outfile, cv) ; print_open_extern_c(outfile) ; print_init_attr_c_intf(outfile, cv) ; diff --git a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.hh b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.hh index 09ca274c..53f91047 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.hh +++ b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.hh @@ -83,6 +83,24 @@ class PrintFileContents10 : public PrintFileContentsBase { /** Prints the io_src_delete function */ void print_io_src_delete(std::ofstream & outfile , ClassValues * cv ) ; + + /** Prints stl helper function prototypes */ + void print_stl_helper_proto(std::ofstream & outfile , ClassValues * in_class) ; + + /** Prints stl helper function */ + void print_stl_helper(std::ofstream & outfile , ClassValues * in_class) ; + + /** Prints stl checkpoint function */ + void print_checkpoint_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * in_class) ; + + /** Prints stl post_checkpoint function */ + void print_post_checkpoint_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * in_class) ; + + /** Prints stl restart function */ + void print_restore_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * in_class) ; + + /** Prints stl clear function */ + void print_clear_stl(std::ofstream & outfile , FieldDescription * fdes , ClassValues * in_class) ; } ; #endif diff --git a/trick_source/sim_services/CheckPointAgent/ClassicCheckPointerAgent.cpp b/trick_source/sim_services/CheckPointAgent/ClassicCheckPointerAgent.cpp index cdb9e718..8ea6a738 100644 --- a/trick_source/sim_services/CheckPointAgent/ClassicCheckPointerAgent.cpp +++ b/trick_source/sim_services/CheckPointAgent/ClassicCheckPointerAgent.cpp @@ -40,7 +40,8 @@ const int Trick::ClassicCheckPointAgent::array_elements_per_line[TRICK_NUMBER_OF 5, /** TRICK_VOID_PTR */ 10, /** TRICK_ENUMERATED */ 5, /** TRICK_STRUCTURED (for pointers) */ - 5 /** TRICK_OPAQUE_TYPE */ + 5, /** TRICK_OPAQUE_TYPE */ + 1 /** TRICK_STL */ }; // MEMBER FUNCTION @@ -489,6 +490,10 @@ int Trick::ClassicCheckPointAgent::is_nil_valued( void* address, test_addr = (char*)address + offset * sizeof(void*); if (*(std::string*)test_addr == "") return(1); break; + case TRICK_STL : + // Can't test properly, always return 0 to indicate the STL is not empty. + return(0); + break; default : message_publish(MSG_ERROR, "Checkpoint Agent file %s: Unhandled Type (%d).\n", __FILE__, attr->type) ; return(-1); @@ -1059,9 +1064,13 @@ void Trick::ClassicCheckPointAgent::assign_rvalue(std::ostream& chkpnt_os, void* if (!input_perm_check(attr)) { chkpnt_os << "/* OUTPUT-ONLY: "; } - chkpnt_os << lname << " = "; - write_rvalue( chkpnt_os, (void*)address, attr, curr_dim, offset); - chkpnt_os << ";"; + if ( attr->type == TRICK_STL ) { + chkpnt_os << "// STL: " << lname ; + } else { + chkpnt_os << lname << " = "; + write_rvalue( chkpnt_os, (void*)address, attr, curr_dim, offset); + chkpnt_os << ";"; + } if (!input_perm_check(attr)) { chkpnt_os << "*/"; } diff --git a/trick_source/sim_services/CheckPointRestart/Makefile b/trick_source/sim_services/CheckPointRestart/Makefile index 7261c8c1..2d680508 100644 --- a/trick_source/sim_services/CheckPointRestart/Makefile +++ b/trick_source/sim_services/CheckPointRestart/Makefile @@ -7,3 +7,5 @@ ifneq ($(DMTCP),) TRICK_CXXFLAGS += -D_DMTCP -I$(DMTCP)/dmtcpaware endif +TRICK_CXXFLAGS += -std=c++11 + diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp index 31ba0c1b..f9512944 100644 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp +++ b/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp @@ -13,9 +13,11 @@ int checkpoint_stl(std::pair & in_stl , std::string ob sprintf(var_declare, "char * %s_%s_first[1]", object_name.c_str(), var_name.c_str()) ; first = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; sprintf(var_declare, "char * %s_%s_second[1]" , object_name.c_str(), var_name.c_str()) ; second = (char **)TMM_declare_var_s(var_declare) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; first[0] = (char *)(in_stl.first.c_str()) ; second[0] = (char *)(in_stl.second.c_str()) ; diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp index 9b528b47..ee97277c 100644 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp +++ b/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp @@ -19,6 +19,7 @@ int checkpoint_stl(std::queue & in_stl , std::string object_name , 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_queue = in_stl ; @@ -50,6 +51,7 @@ int checkpoint_stl(std::priority_queue & in_stl , std::string objec 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_queue = in_stl ; diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp index 42d0ff8b..b47492b9 100644 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp +++ b/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp @@ -19,6 +19,7 @@ int checkpoint_stl(std::stack & in_stl , std::string object_name , 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 ; @@ -43,14 +44,13 @@ 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()) ; - cont_size = in_stl.size() ; - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_stl.pop() ; - } - 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) ; diff --git a/trick_source/sim_services/Executive/Executive.cpp b/trick_source/sim_services/Executive/Executive.cpp index e858898e..d46d9dae 100644 --- a/trick_source/sim_services/Executive/Executive.cpp +++ b/trick_source/sim_services/Executive/Executive.cpp @@ -64,8 +64,6 @@ Trick::Executive::Executive() { num_all_jobs = 0 ; all_jobs_for_checkpoint = NULL ; - num_sim_objects_in_checkpoint = 0 ; - sim_objects_for_checkpoint = NULL ; software_frame_tics = (long long)(software_frame * time_tic_value) ; next_frame_check_tics = software_frame_tics ; diff --git a/trick_source/sim_services/Executive/Executive_checkpoint.cpp b/trick_source/sim_services/Executive/Executive_checkpoint.cpp index 7a335f55..a7e9669c 100644 --- a/trick_source/sim_services/Executive/Executive_checkpoint.cpp +++ b/trick_source/sim_services/Executive/Executive_checkpoint.cpp @@ -4,19 +4,20 @@ #include "trick/Executive.hh" #include "trick/exec_proto.h" #include "trick/memorymanager_c_intf.h" -#include "trick/checkpoint_stl.hh" /** @details -# Save the number of jobs in the scheduler -# Copy all of the job information in a checkpointable array --# Save the number of sim_objects in the scheduler --# Copy all of the sim_objects in a checkpointable array */ int Trick::Executive::checkpoint() { unsigned int ii ; + /* + The all_jobs_vector contains memory that is not known to the memory manager. We need to + copy the information into memory that is declared to the memory manager. + */ /* save the number of jobs in the scheduler */ num_all_jobs = all_jobs_vector.size() ; @@ -29,9 +30,6 @@ int Trick::Executive::checkpoint() { } } - checkpoint_stl(sim_objects , std::string("trick_sys") , std::string("sim_objects")) ; - checkpoint_stl(freeze_times , std::string("trick_sys") , std::string("freeze_times")) ; - return(0) ; } diff --git a/trick_source/sim_services/Executive/Executive_init.cpp b/trick_source/sim_services/Executive/Executive_init.cpp index ee71c8f5..6b959c6c 100644 --- a/trick_source/sim_services/Executive/Executive_init.cpp +++ b/trick_source/sim_services/Executive/Executive_init.cpp @@ -68,7 +68,7 @@ int Trick::Executive::init() { } else { except_file = "somewhere in Executive::init" ; } - fprintf(stderr, "\nExecutive::loop terminated with std::exception\n ROUTINE: %s\n DIAGNOSTIC: %s\n", + fprintf(stderr, "\nExecutive::init terminated with std::exception\n ROUTINE: %s\n DIAGNOSTIC: %s\n", except_file.c_str(), ex.what()) ; exit(-1) ; } catch (...) { @@ -78,7 +78,7 @@ int Trick::Executive::init() { except_file = "somewhere in Executive::init" ; } except_message = "unknown error" ; - fprintf(stderr, "\nExecutive::loop terminated with unknown exception\n ROUTINE: %s\n DIAGNOSTIC: %s\n", + fprintf(stderr, "\nExecutive::init terminated with unknown exception\n ROUTINE: %s\n DIAGNOSTIC: %s\n", except_file.c_str() , except_message.c_str()) ; exit(-1) ; } diff --git a/trick_source/sim_services/Executive/Executive_post_checkpoint.cpp b/trick_source/sim_services/Executive/Executive_post_checkpoint.cpp index 4b6e6054..91fcb1ba 100644 --- a/trick_source/sim_services/Executive/Executive_post_checkpoint.cpp +++ b/trick_source/sim_services/Executive/Executive_post_checkpoint.cpp @@ -4,19 +4,11 @@ #include "trick/Executive.hh" #include "trick/exec_proto.h" #include "trick/memorymanager_c_intf.h" -#include "trick/checkpoint_stl.hh" int Trick::Executive::post_checkpoint() { TMM_delete_var_a(all_jobs_for_checkpoint) ; - all_jobs_for_checkpoint = NULL ; - delete_stl(sim_objects , std::string("trick_sys") , std::string("sim_objects")) ; - - if ( ! freeze_times.empty() ) { - delete_stl(freeze_times , std::string("trick_sys") , std::string("freeze_times")) ; - } - return(0) ; } diff --git a/trick_source/sim_services/Executive/Executive_restart.cpp b/trick_source/sim_services/Executive/Executive_restart.cpp index 1572f436..7cd6fec3 100644 --- a/trick_source/sim_services/Executive/Executive_restart.cpp +++ b/trick_source/sim_services/Executive/Executive_restart.cpp @@ -7,7 +7,6 @@ #include "trick/message_proto.h" #include "trick/message_type.h" #include "trick/memorymanager_c_intf.h" -#include "trick/checkpoint_stl.hh" #include "trick/ScheduledJobQueue.hh" #include "trick/Threads.hh" @@ -44,13 +43,6 @@ int Trick::Executive::restart() { all_jobs_vector.clear() ; all_tagged_jobs.clear() ; - /* clear all sim_object information in scheduler */ - num_sim_objects = 0 ; - sim_objects.clear() ; - - /* restore the list of sim_objects from the checkpoint. */ - restore_stl(sim_objects , std::string("trick_sys") , std::string("sim_objects")) ; - /* Create a temporary all_jobs map to use to restore job data from all_jobs_for_checkpoint */ for ( sit = sim_objects.begin() ; sit != sim_objects.end() ; sit++ ) { for ( jit = (*sit)->jobs.begin() ; jit != (*sit)->jobs.end() ; jit++ ) { @@ -107,9 +99,6 @@ int Trick::Executive::restart() { TMM_delete_var_a(all_jobs_for_checkpoint) ; all_jobs_for_checkpoint = NULL ; - // restore the vector of freeze times - restore_stl(freeze_times , std::string("trick_sys") , std::string("freeze_times")) ; - /* Set the main thread current time to the simulation time tics value, used with Executive::get_sim_time() */ threads[0]->curr_time_tics = time_tics ; diff --git a/trick_source/sim_services/Integrator/src/IntegLoopSimObject.cpp b/trick_source/sim_services/Integrator/src/IntegLoopSimObject.cpp index 36473cf4..f450b4ae 100644 --- a/trick_source/sim_services/Integrator/src/IntegLoopSimObject.cpp +++ b/trick_source/sim_services/Integrator/src/IntegLoopSimObject.cpp @@ -1,7 +1,6 @@ #include "trick/IntegLoopSimObject.hh" #include "trick/exec_proto.hh" -#include "trick/checkpoint_stl.hh" void IntegLoopSimObject::add_jobs(double in_cycle, unsigned int child) { Trick::JobData * job ; @@ -15,14 +14,11 @@ void IntegLoopSimObject::add_jobs(double in_cycle, unsigned int child) { job->add_tag("TRK") ; job = add_job(child, 3, "integ_loop", NULL, in_cycle, "integ_sched.integrate", "", 60000) ; job->add_tag("TRK") ; - job = add_job(0, 4, "checkpoint", NULL, 1, "checkpoint_stl", "", 60000) ; - job = add_job(0, 5, "post_checkpoint", NULL, 1, "delete_stl", "", 60000) ; - job = add_job(0, 6, "restart", NULL, 1, "restore_stl", "", 60000) ; - job = add_job(0, 7, "preload_checkpoint", NULL, 1, "integ_sched.restart_checkpoint", "", 0) ; + job = add_job(0, 4, "preload_checkpoint", NULL, 1, "integ_sched.restart_checkpoint", "", 0) ; job->add_tag("TRK") ; - job = add_job(0, 8, "restart", NULL, 1, "integ_sched.rebuild_jobs", "", 60000) ; + job = add_job(0, 5, "restart", NULL, 1, "integ_sched.rebuild_jobs", "", 60000) ; job->add_tag("TRK") ; - job = add_job(0, 9, "restart", NULL, 1, "integ_sched.get_first_step_deriv_from_integrator", "", 65535) ; + job = add_job(0, 6, "restart", NULL, 1, "integ_sched.get_first_step_deriv_from_integrator", "", 65535) ; job->add_tag("TRK") ; } @@ -45,21 +41,12 @@ int IntegLoopSimObject::call_function ( Trick::JobData * curr_job ) { integ_sched.integrate() ; break ; case 4: - checkpoint_stl(integ_sched.sim_objects, name + std::string("_") + std::string("integ_sched.sim_objects"), std::string("")) ; - break ; - case 5: - delete_stl (integ_sched.sim_objects, name + std::string("_") + std::string("integ_sched.sim_objects"), std::string("")) ; - break ; - case 6: - restore_stl (integ_sched.sim_objects, name + std::string("_") + std::string("integ_sched.sim_objects"), std::string("")) ; - break ; - case 7: integ_sched.restart_checkpoint() ; break ; - case 8: + case 5: integ_sched.rebuild_jobs() ; break ; - case 9: + case 6: integ_sched.get_first_step_deriv_from_integrator() ; break ; default: diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_C_Intf.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_C_Intf.cpp index cba47da7..7a76921d 100644 --- a/trick_source/sim_services/MemoryManager/MemoryManager_C_Intf.cpp +++ b/trick_source/sim_services/MemoryManager/MemoryManager_C_Intf.cpp @@ -17,7 +17,7 @@ extern "C" void* TMM_declare_var( TRICK_TYPE type, const char*class_name, int n_ std::string svar_name = var_name; return ( trick_MM->declare_var( type, sclass_name, n_stars, svar_name, n_cdims, cdims)); } else { - Trick::MemoryManager::emitError("TMM_declare_var() called before MemoryManager instantiation. Returning NULL.") ; + Trick::MemoryManager::emitError("TMM_declare_var() called before MemoryManager instantiation. Returning NULL.") ; return ( (void*)NULL); } } @@ -31,7 +31,7 @@ extern "C" void* TMM_declare_var_1d( const char* enh_type_spec, int e_elems) { if (trick_MM != NULL) { return ( trick_MM->declare_var( enh_type_spec, e_elems)); } else { - Trick::MemoryManager::emitError("TMM_declare_var_1d() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_declare_var_1d() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -45,7 +45,7 @@ extern "C" void* TMM_declare_var_s( const char* declaration) { if (trick_MM != NULL) { return ( trick_MM->declare_var( declaration)); } else { - Trick::MemoryManager::emitError("TMM_declare_var_s() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_declare_var_s() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -61,7 +61,7 @@ extern "C" void* alloc_type( int e_elems, const char* enh_type_spec) { if (trick_MM != NULL) { return ( trick_MM->declare_var( enh_type_spec, e_elems)); } else { - Trick::MemoryManager::emitError("alloc_type() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("alloc_type() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -75,7 +75,7 @@ extern "C" void* TMM_declare_operatornew_var( const char * class_name, unsigned if (trick_MM != NULL) { return trick_MM->declare_operatornew_var( std::string(class_name), alloc_size, element_size ) ; } else { - Trick::MemoryManager::emitError("TMM_declare_var() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_declare_var() called before MemoryManager instantiation. Returning NULL.\n") ; return (void*)NULL ; } } @@ -91,7 +91,7 @@ extern "C" void* TMM_declare_ext_var( void* addr, TRICK_TYPE type, const char*cl std::string svar_name = var_name; return ( trick_MM->declare_extern_var( addr, type, sclass_name, n_stars, svar_name, n_cdims, cdims)); } else { - Trick::MemoryManager::emitError("TMM_declare_ext_var() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_declare_ext_var() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -105,7 +105,7 @@ extern "C" void* TMM_declare_ext_var_1d( void* addr, const char* elem_decl, int if (trick_MM != NULL) { return ( trick_MM->declare_extern_var( addr, elem_decl, n_elems)); } else { - Trick::MemoryManager::emitError("TMM_declare_ext_var_1d() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_declare_ext_var_1d() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -119,7 +119,7 @@ extern "C" void* TMM_declare_ext_var_s( void* addr, const char* declaration) { if (trick_MM != NULL) { return ( trick_MM->declare_extern_var(addr, declaration)); } else { - Trick::MemoryManager::emitError("TMM_declare_ext_var_s() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_declare_ext_var_s() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -135,7 +135,7 @@ void* TMM_resize_array_a(void *address, int n_cdims, int *cdims){ if (trick_MM != NULL) { return ( trick_MM->resize_array(address, n_cdims, cdims)); } else { - Trick::MemoryManager::emitError("TMM_resize_array_a() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_resize_array_a() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -151,7 +151,7 @@ void* TMM_resize_array_n(const char *name, int n_cdims, int *cdims){ if (trick_MM != NULL) { return ( trick_MM->resize_array(name, n_cdims, cdims)); } else { - Trick::MemoryManager::emitError("TMM_resize_array_n() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_resize_array_n() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -165,7 +165,7 @@ void* TMM_resize_array_1d_a(void* address, int num){ if (trick_MM != NULL) { return ( trick_MM->resize_array(address, num)); } else { - Trick::MemoryManager::emitError("TMM_resize_array_1d_a() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_resize_array_1d_a() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -179,7 +179,7 @@ void* TMM_resize_array_1d_n(const char *name, int num){ if (trick_MM != NULL) { return ( trick_MM->resize_array(name, num)); } else { - Trick::MemoryManager::emitError("TMM_resize_array_1d_n() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_resize_array_1d_n() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (void*)NULL); } } @@ -193,7 +193,7 @@ extern "C" char* TMM_strdup(char *str) { if (trick_MM != NULL) { return ( trick_MM->mm_strdup( str)); } else { - Trick::MemoryManager::emitError("TMM_strdup called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("TMM_strdup called before MemoryManager instantiation. Returning NULL.\n") ; return( (char*)NULL); } } @@ -208,7 +208,7 @@ extern "C" int TMM_var_exists( const char* var_name) { std::string svar_name = var_name; return ( trick_MM->var_exists( svar_name)); } else { - Trick::MemoryManager::emitError("TMM_var_exists() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_var_exists() called before MemoryManager instantiation.\n") ; return (0); } } @@ -222,7 +222,7 @@ extern "C" int TMM_is_alloced(char *addr) { if (trick_MM != NULL) { return ( trick_MM->is_alloced( addr)); } else { - Trick::MemoryManager::emitError("TMM_is_alloced() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_is_alloced() called before MemoryManager instantiation.\n") ; return (0); } } @@ -236,7 +236,7 @@ extern "C" void TMM_set_debug_level(int level) { if (trick_MM != NULL) { trick_MM->set_debug_level( level); } else { - Trick::MemoryManager::emitError("TMM_set_debug_level() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_set_debug_level() called before MemoryManager instantiation.\n") ; } } @@ -248,7 +248,7 @@ extern "C" void TMM_reduced_checkpoint(int yesno) { if (trick_MM != NULL) { trick_MM->set_reduced_checkpoint( yesno!=0 ); } else { - Trick::MemoryManager::emitError("TMM_reduced_checkpoint() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_reduced_checkpoint() called before MemoryManager instantiation.\n") ; } } @@ -260,7 +260,7 @@ extern "C" void TMM_hexfloat_checkpoint(int yesno) { if (trick_MM != NULL) { trick_MM->set_hexfloat_checkpoint( yesno!=0 ); } else { - Trick::MemoryManager::emitError("TMM_hexfloat_checkpoint() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_hexfloat_checkpoint() called before MemoryManager instantiation.\n") ; } } @@ -275,7 +275,7 @@ extern "C" void TMM_clear_var_a(void *addr) { if (trick_MM != NULL) { trick_MM->clear_var( addr); } else { - Trick::MemoryManager::emitError("TMM_clear_var_a() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_clear_var_a() called before MemoryManager instantiation.\n") ; return; } } @@ -288,7 +288,7 @@ extern "C" void TMM_clear_var_n( const char* name) { if (trick_MM != NULL) { trick_MM->clear_var( name); } else { - Trick::MemoryManager::emitError("TMM_clear_var_n() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_clear_var_n() called before MemoryManager instantiation.\n") ; return; } } @@ -301,7 +301,7 @@ extern "C" void TMM_delete_var_a(void *addr) { if (trick_MM != NULL) { trick_MM->delete_var( addr); } else { - Trick::MemoryManager::emitError("TMM_delete_var_a() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_delete_var_a() called before MemoryManager instantiation.\n") ; return; } } @@ -314,7 +314,7 @@ extern "C" void TMM_delete_var_n( const char* name) { if (trick_MM != NULL) { trick_MM->delete_var( name); } else { - Trick::MemoryManager::emitError("TMM_delete_var_n() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_delete_var_n() called before MemoryManager instantiation.\n") ; return; } } @@ -327,7 +327,7 @@ extern "C" void TMM_delete_extern_var_a(void *addr) { if (trick_MM != NULL) { trick_MM->delete_extern_var( addr); } else { - Trick::MemoryManager::emitError("TMM_delete_extern_var_a() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_delete_extern_var_a() called before MemoryManager instantiation.\n") ; return; } } @@ -340,7 +340,7 @@ extern "C" void TMM_delete_extern_var_n( const char* name) { if (trick_MM != NULL) { trick_MM->delete_extern_var( name); } else { - Trick::MemoryManager::emitError("TMM_delete_extern_var_n() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_delete_extern_var_n() called before MemoryManager instantiation.\n") ; return; } } @@ -353,7 +353,7 @@ extern "C" void TMM_write_checkpoint(const char* filename) { if (trick_MM != NULL) { return ( trick_MM->write_checkpoint( filename)); } else { - Trick::MemoryManager::emitError("TMM_write_checkpoint_fn() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_write_checkpoint_fn() called before MemoryManager instantiation.\n") ; return; } } @@ -366,7 +366,7 @@ extern "C" int TMM_read_checkpoint(const char* filename) { if (trick_MM != NULL) { return ( trick_MM->read_checkpoint( filename)); } else { - Trick::MemoryManager::emitError("TMM_read_checkpoint() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_read_checkpoint() called before MemoryManager instantiation.\n") ; return(1); } } @@ -379,7 +379,7 @@ extern "C" int TMM_read_checkpoint_from_string(const char* str) { if (trick_MM != NULL) { return ( trick_MM->read_checkpoint_from_string( str)); } else { - Trick::MemoryManager::emitError("TMM_read_checkpoint_from_string() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_read_checkpoint_from_string() called before MemoryManager instantiation.\n") ; return(1); } } @@ -392,7 +392,7 @@ extern "C" int TMM_init_from_checkpoint(const char* filename) { if (trick_MM != NULL) { return ( trick_MM->init_from_checkpoint( filename)); } else { - Trick::MemoryManager::emitError("TMM_init_from_checkpoint() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_init_from_checkpoint() called before MemoryManager instantiation.\n") ; return(1); } } @@ -405,7 +405,7 @@ extern "C" int TMM_add_shared_library_symbols(const char* filename) { if (trick_MM != NULL) { return ( trick_MM->add_shared_library_symbols( filename)); } else { - Trick::MemoryManager::emitError("TMM_add_shared_library_symbols() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("TMM_add_shared_library_symbols() called before MemoryManager instantiation.\n") ; return(1); } } @@ -418,7 +418,7 @@ extern "C" void* add_var( TRICK_TYPE type, const char* stype, VAR_DECLARE* var_d if (trick_MM != NULL) { return( trick_MM->add_var(type, stype, var_declare, units )); } else { - Trick::MemoryManager::emitError("add_var() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("add_var() called before MemoryManager instantiation. Returning NULL.\n") ; return ((void*)NULL); } } @@ -431,7 +431,7 @@ extern "C" int add_vars( TRICK_TYPE type, const char* stype, VAR_LIST* var_list, if (trick_MM != NULL) { return( trick_MM->add_vars(type, stype, var_list, units )); } else { - Trick::MemoryManager::emitError("add_vars() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("add_vars() called before MemoryManager instantiation.\n") ; return (1); } } @@ -444,7 +444,7 @@ extern "C" int ref_allocate(REF2 *R, int num) { if (trick_MM != NULL) { return( trick_MM->ref_allocate( R, num)); } else { - Trick::MemoryManager::emitError("ref_allocate() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("ref_allocate() called before MemoryManager instantiation.\n") ; return (1); } } @@ -457,7 +457,7 @@ extern "C" REF2* ref_attributes( char* name) { if (trick_MM != NULL) { return( trick_MM->ref_attributes( name)); } else { - Trick::MemoryManager::emitError("ref_attributes() called before MemoryManager instantiation. Returning NULL.\n") ; + Trick::MemoryManager::emitError("ref_attributes() called before MemoryManager instantiation. Returning NULL.\n") ; return ( (REF2*)NULL); } } @@ -470,7 +470,7 @@ extern "C" int ref_assignment(REF2* R, V_TREE* V) { if (trick_MM != NULL) { return( trick_MM->ref_assignment( R, V)); } else { - Trick::MemoryManager::emitError("ref_assignment() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("ref_assignment() called before MemoryManager instantiation.\n") ; return (1); } } @@ -483,7 +483,7 @@ extern "C" int ref_var(REF2 *R, char* name) { if (trick_MM != NULL) { return( trick_MM->ref_var( R, name)); } else { - Trick::MemoryManager::emitError("ref_var() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("ref_var() called before MemoryManager instantiation.\n") ; return (1); } } @@ -496,7 +496,7 @@ extern "C" int get_size(void *addr) { if (trick_MM != NULL) { return( trick_MM->get_size( addr)); } else { - Trick::MemoryManager::emitError("get_size() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("get_size() called before MemoryManager instantiation.\n") ; return (0); } } @@ -509,7 +509,7 @@ extern "C" int get_truncated_size(void *addr) { if (trick_MM != NULL) { return( trick_MM->get_truncated_size( addr)); } else { - Trick::MemoryManager::emitError("get_truncated_size() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("get_truncated_size() called before MemoryManager instantiation.\n") ; return (0); } } @@ -523,7 +523,7 @@ extern "C" int io_get_fixed_truncated_size(char *ptr __attribute__ ((unused)), char *str __attribute__ ((unused)), int dims __attribute__ ((unused)), ATTRIBUTES * left_type __attribute__ ((unused))) { - Trick::MemoryManager::emitError("io_get_fixed_truncated_size() is not implemented yet.\n") ; + Trick::MemoryManager::emitError("io_get_fixed_truncated_size() is not implemented yet.\n") ; return(0); } @@ -535,7 +535,7 @@ extern "C" ALLOC_INFO* get_alloc_info_of(void * addr) { if (trick_MM != NULL) { return( trick_MM->get_alloc_info_of( addr)); } else { - Trick::MemoryManager::emitError("get_alloc_info_of() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("get_alloc_info_of() called before MemoryManager instantiation.\n") ; return ( (ALLOC_INFO*)NULL); } } @@ -548,7 +548,7 @@ extern "C" ALLOC_INFO* get_alloc_info_at(void * addr) { if (trick_MM != NULL) { return( trick_MM->get_alloc_info_at( addr)); } else { - Trick::MemoryManager::emitError("get_alloc_info_at() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("get_alloc_info_at() called before MemoryManager instantiation.\n") ; return ( (ALLOC_INFO*)NULL); } } @@ -557,7 +557,7 @@ extern "C" int set_alloc_name_at(void * addr, const char * name ) { if (trick_MM != NULL) { return( trick_MM->set_name_at(addr, name)); } else { - Trick::MemoryManager::emitError("get_alloc_info_at() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("get_alloc_info_at() called before MemoryManager instantiation.\n") ; return ( -1 ); } } @@ -570,7 +570,15 @@ extern "C" int get_enumerated(const char* name, V_DATA* v_data) { if (trick_MM != NULL) { return( trick_MM->get_enumerated(name, v_data )); } else { - Trick::MemoryManager::emitError("get_enumerated() called before MemoryManager instantiation.\n") ; + Trick::MemoryManager::emitError("get_enumerated() called before MemoryManager instantiation.\n") ; return 1 ; } } + +extern "C" void TMM_add_checkpoint_alloc_dependency(const char * name) { + if (trick_MM != NULL) { + trick_MM->add_checkpoint_alloc_dependency(name) ; + } + return ; +} + diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_add_checkpoint_alloc_dependency.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_add_checkpoint_alloc_dependency.cpp new file mode 100644 index 00000000..e461b754 --- /dev/null +++ b/trick_source/sim_services/MemoryManager/MemoryManager_add_checkpoint_alloc_dependency.cpp @@ -0,0 +1,11 @@ +#include "trick/MemoryManager.hh" + +// MEMBER FUNCTION: +void Trick::MemoryManager::add_checkpoint_alloc_dependency(const char *name) { + VARIABLE_MAP_ITER it = variable_map.find(name) ; + if ( it != variable_map.end() ) { + dependencies.push_back(it->second) ; + stl_dependencies.push_back(it->second) ; + } +} + diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_alloc_depends.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_alloc_depends.cpp index 7dfe9e40..5a4d9509 100644 --- a/trick_source/sim_services/MemoryManager/MemoryManager_alloc_depends.cpp +++ b/trick_source/sim_services/MemoryManager/MemoryManager_alloc_depends.cpp @@ -2,7 +2,7 @@ #include "trick/attributes.h" // MEMBER FUNCTION -void Trick::MemoryManager::get_alloc_deps_in_allocation(std::vector& dependencies, ALLOC_INFO* alloc_info ) { +void Trick::MemoryManager::get_alloc_deps_in_allocation(ALLOC_INFO* alloc_info ) { ATTRIBUTES* reference_attr; @@ -58,12 +58,12 @@ void Trick::MemoryManager::get_alloc_deps_in_allocation(std::vector // Get the dependencies of the allocation if (alloc_info->type == TRICK_STRUCTURED) { if (reference_attr->num_index > 0) { - get_alloc_deps_in_arrayed_class( dependencies, (char*)(alloc_info->start), reference_attr, 0, 0) ; + get_alloc_deps_in_arrayed_class( (char*)(alloc_info->start), reference_attr, 0, 0) ; } else { - get_alloc_deps_in_class( dependencies, (char*)(alloc_info->start), alloc_info->attr) ; + get_alloc_deps_in_class( (char*)(alloc_info->start), alloc_info->attr) ; } } else { - get_alloc_deps_in_intrinsic( dependencies, alloc_info->start, reference_attr, 0, 0 ); + get_alloc_deps_in_intrinsic( alloc_info->start, reference_attr, 0, 0 ); } if (debug_level) { @@ -76,7 +76,7 @@ void Trick::MemoryManager::get_alloc_deps_in_allocation(std::vector } // MEMBER FUNCTION -void Trick::MemoryManager::get_alloc_deps_in_allocation( std::vector& dependencies, const char* var_name ) { +void Trick::MemoryManager::get_alloc_deps_in_allocation( const char* var_name ) { VARIABLE_MAP::iterator pos; ALLOC_INFO *alloc_info; @@ -89,7 +89,7 @@ void Trick::MemoryManager::get_alloc_deps_in_allocation( std::vectorsecond; - get_alloc_deps_in_allocation( dependencies, alloc_info ); + get_alloc_deps_in_allocation( alloc_info ); } else { std::cerr << "ERROR: get_alloc_deps_in_allocation(\""<< var_name <<"\") failed because the given name is'nt known by the MemoryManager." @@ -100,7 +100,7 @@ void Trick::MemoryManager::get_alloc_deps_in_allocation( std::vector& dependencies, char* address, ATTRIBUTES* attr) { +void Trick::MemoryManager::get_alloc_deps_in_class( char* address, ATTRIBUTES* attr) { int ii; if (debug_level > 1) { @@ -123,19 +123,19 @@ void Trick::MemoryManager::get_alloc_deps_in_class( std::vector& de if (attr[ii].type == TRICK_STRUCTURED) { if (attr[ii].num_index != 0) { - get_alloc_deps_in_arrayed_class( dependencies, elem_addr, &attr[ii], 0, 0); + get_alloc_deps_in_arrayed_class( elem_addr, &attr[ii], 0, 0); } else { - get_alloc_deps_in_class( dependencies, elem_addr, (ATTRIBUTES*)(attr[ii].attr)); + get_alloc_deps_in_class( elem_addr, (ATTRIBUTES*)(attr[ii].attr)); } } else { - get_alloc_deps_in_intrinsic( dependencies, elem_addr, &(attr[ii]), 0, 0); + get_alloc_deps_in_intrinsic( elem_addr, &(attr[ii]), 0, 0); } } } } // MEMBER FUNCTION -void Trick::MemoryManager::get_alloc_deps_in_arrayed_class( std::vector& dependencies, +void Trick::MemoryManager::get_alloc_deps_in_arrayed_class( char* address, ATTRIBUTES* attr, int curr_dim, @@ -163,7 +163,7 @@ void Trick::MemoryManager::get_alloc_deps_in_arrayed_class( std::vectorname << "[" << offset << "] points to @" << (void*)pointer << std::endl; } - get_alloc_deps_in_allocation(dependencies, alloc_info); + get_alloc_deps_in_allocation(alloc_info); } else { if (debug_level) { std::cout << __FUNCTION__ << ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl; @@ -182,11 +182,11 @@ void Trick::MemoryManager::get_alloc_deps_in_arrayed_class( std::vectorindex[curr_dim].size; for (ii = 0; ii < curr_dim_size; ii++) { if (curr_dim < attr->num_index - 1) { - get_alloc_deps_in_arrayed_class( dependencies, address, attr, curr_dim + 1, offset * curr_dim_size + ii); + get_alloc_deps_in_arrayed_class( address, attr, curr_dim + 1, offset * curr_dim_size + ii); } else { char* elem_addr; elem_addr = address + (offset * curr_dim + ii) * attr->size ; - get_alloc_deps_in_class( dependencies, elem_addr, (ATTRIBUTES*)attr->attr ); + get_alloc_deps_in_class( elem_addr, (ATTRIBUTES*)attr->attr ); } } } @@ -194,7 +194,7 @@ void Trick::MemoryManager::get_alloc_deps_in_arrayed_class( std::vector& dependencies, void* address, ATTRIBUTES* attr, int curr_dim, int offset) { +void Trick::MemoryManager::get_alloc_deps_in_intrinsic( void* address, ATTRIBUTES* attr, int curr_dim, int offset) { if (debug_level > 1) { std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; @@ -215,7 +215,7 @@ void Trick::MemoryManager::get_alloc_deps_in_intrinsic( std::vector if (debug_level) { std::cout << __FUNCTION__ << ": @" << (void*)address << "." << attr->name << "[" << offset << "] points to @" << (void*)pointer << std::endl; } - get_alloc_deps_in_allocation(dependencies, alloc_info); + get_alloc_deps_in_allocation(alloc_info); } else { if (debug_level) { std::cout << __FUNCTION__ << ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl; @@ -232,7 +232,7 @@ void Trick::MemoryManager::get_alloc_deps_in_intrinsic( std::vector } else { // otherwise its a constrained array. int ii; for (ii=0 ; ii< attr->index[curr_dim].size ; ii++) { - get_alloc_deps_in_intrinsic( dependencies, address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii); + get_alloc_deps_in_intrinsic( address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii); } } } diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_clear_memory.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_clear_memory.cpp index fb778b60..460d42d2 100644 --- a/trick_source/sim_services/MemoryManager/MemoryManager_clear_memory.cpp +++ b/trick_source/sim_services/MemoryManager/MemoryManager_clear_memory.cpp @@ -95,6 +95,12 @@ void Trick::MemoryManager::clear_rvalue( void* base_address, ATTRIBUTES* attr, i final_address = (char*)base_address + offset * sizeof(void*); *(std::string*)final_address = ""; break; + case TRICK_STL : + final_address = (char*)base_address + offset * attr->size ; + if ( attr->clear_stl ) { + (*attr->clear_stl)(final_address) ; + } + break; default : std::stringstream message; message << "Unhandled Type (" << (int)attr->type << ")."; diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_get_stl_dependencies.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_get_stl_dependencies.cpp new file mode 100644 index 00000000..3cfc3ce9 --- /dev/null +++ b/trick_source/sim_services/MemoryManager/MemoryManager_get_stl_dependencies.cpp @@ -0,0 +1,192 @@ + +#include + +#include "trick/MemoryManager.hh" +#include "trick/attributes.h" + +// MEMBER FUNCTION +void Trick::MemoryManager::get_stl_dependencies( ALLOC_INFO* alloc_info ) { + + ATTRIBUTES* reference_attr; + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + if (alloc_info == NULL) { + std::cout << "ERROR: Trick::MemoryManager::get_stl_dependencies called with alloc_info == NULL." << std::endl; + std::cout.flush(); + return; + } + + if (debug_level) { + std::cout << __FUNCTION__ << ": Begin scan of allocation @" << (void*)alloc_info->start << " for dependencies." << std::endl; + } + + reference_attr = make_reference_attr( alloc_info ); + + // Get the dependencies of the allocation + if (alloc_info->type == TRICK_STRUCTURED) { + if (reference_attr->num_index > 0) { + get_stl_dependencies_in_arrayed_class(alloc_info->name, (char*)(alloc_info->start), reference_attr, 0, 0) ; + } else { + get_stl_dependencies_in_class(alloc_info->name, (char*)(alloc_info->start), alloc_info->attr) ; + } + } else { + get_stl_dependencies_in_intrinsic(alloc_info->name, alloc_info->start, reference_attr, 0, 0 ); + } + + if (debug_level) { + std::cout << __FUNCTION__ << ": End scan of allocation @" << (void*)alloc_info->start << "." << std::endl; + } + + free_reference_attr( reference_attr ); + +} + +// MEMBER FUNCTION +void Trick::MemoryManager::get_stl_dependencies_in_class( std::string name, char* address, ATTRIBUTES* attr) { + int ii; + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + if (attr == NULL) { + std::cerr << "ERROR: Trick::MemoryManager::get_stl_dependencies_in_class called with attr = NULL." << std::endl; + return; + } + + for (ii = 0; attr[ii].name[0] != '\0'; ii++) { + if (currentCheckPointAgent->output_perm_check(&attr[ii])) { + char *elem_addr; + if (attr[ii].mods & 2) { + elem_addr = (char *) attr[ii].offset; + } else { + elem_addr = address + attr[ii].offset; + } + + if (attr[ii].type == TRICK_STRUCTURED) { + if (attr[ii].num_index != 0) { + get_stl_dependencies_in_arrayed_class( name + "." + attr[ii].name, elem_addr, &attr[ii], 0, 0); + } else { + get_stl_dependencies_in_class( name + "." + attr[ii].name, elem_addr, (ATTRIBUTES*)(attr[ii].attr)); + } + } else if (attr[ii].type == TRICK_STL) { + (*attr[ii].checkpoint_stl)(elem_addr, name.c_str(), attr[ii].name) ; + } else { + get_stl_dependencies_in_intrinsic( name + "." + attr[ii].name , elem_addr, &(attr[ii]), 0, 0); + } + } + } +} + +// MEMBER FUNCTION +void Trick::MemoryManager::get_stl_dependencies_in_arrayed_class( + std::string name, + char* address, + ATTRIBUTES* attr, + int curr_dim, + int offset) { + int ii; + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + if (attr == NULL) { + std::cerr << "Trick::MemoryManager::get_stl_dependencies_in_arrayed_class: ERROR: attr = NULL." << std::endl; + return; + } + + if (attr->index[curr_dim].size == 0) { + + void* pointer = *(void**)((char*)address + offset * sizeof(void*)); + + if (pointer != NULL) { + ALLOC_INFO *alloc_info; + alloc_info = get_alloc_info_of( pointer); + if (alloc_info != NULL) { + + if (debug_level) { + std::cout << __FUNCTION__ << ": @" << (void*)address << "." << attr->name << "[" << offset << "] points to @" << (void*)pointer << std::endl; + } + //get_stl_dependencies(alloc_info); + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl; + std::cout.flush(); + } + } + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Allocation reference is NULL." << std::endl; + std::cout.flush(); + } + } + + } else { + int curr_dim_size; + curr_dim_size = attr->index[curr_dim].size; + for (ii = 0; ii < curr_dim_size; ii++) { + char index[16] ; + sprintf(index, "[%d]", ii) ; + if (curr_dim < attr->num_index - 1) { + get_stl_dependencies_in_arrayed_class( name + index, address, attr, curr_dim + 1, offset * curr_dim_size + ii); + } else { + char* elem_addr; + elem_addr = address + (offset * curr_dim + ii) * attr->size ; + get_stl_dependencies_in_class( name + index, elem_addr, (ATTRIBUTES*)attr->attr ); + } + } + } +} + + +// MEMBER FUNCTION +void Trick::MemoryManager::get_stl_dependencies_in_intrinsic( std::string name , void* address, ATTRIBUTES* attr, int curr_dim, int offset) { + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + // If the variable that we are pointing to is an arrayed + if (curr_dim < attr->num_index) { + + // If it is an unconstrained array (a pointer) + if (attr->index[curr_dim].size == 0) { + + void* pointer = *(void**)((char*)address + offset * sizeof(void*)); + + if (pointer != NULL) { + ALLOC_INFO *alloc_info; + alloc_info = get_alloc_info_of( pointer); + if (alloc_info != NULL) { + if (debug_level) { + std::cout << __FUNCTION__ << ": @" << (void*)address << "." << attr->name << "[" << offset << "] points to @" << (void*)pointer << std::endl; + } + //get_stl_dependencies(alloc_info); + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl; + std::cout.flush(); + } + } + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Allocation reference is NULL." << std::endl; + std::cout.flush(); + } + } + + } else { // otherwise its a constrained array. + int ii; + for (ii=0 ; ii< attr->index[curr_dim].size ; ii++) { + char index[16] ; + sprintf(index, "[%d]", ii) ; + //get_stl_dependencies_in_intrinsic( name + index , address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii); + } + } + } +} + diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_restore.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_restore.cpp index ea763ef5..805e360f 100644 --- a/trick_source/sim_services/MemoryManager/MemoryManager_restore.cpp +++ b/trick_source/sim_services/MemoryManager/MemoryManager_restore.cpp @@ -20,14 +20,19 @@ int Trick::MemoryManager::read_checkpoint( std::istream *is) { emitError("Checkpoint restore failed.") ; } + // Search for stls and restore them + for ( pos=alloc_info_map.begin() ; pos!=alloc_info_map.end() ; pos++ ) { + restore_stls(pos->second) ; + } + // Go through all of the allocations that have been created looking // for those whose names start with the temporary-variable prefix and: - pthread_mutex_lock(&mm_mutex); for ( pos=alloc_info_map.begin() ; pos!=alloc_info_map.end() ; pos++ ) { alloc_info = pos->second; + if ( alloc_info->stcl == TRICK_LOCAL) { // If the temporary-variable prefix occurs at the beginning of the name ... diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_restore_stls.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_restore_stls.cpp new file mode 100644 index 00000000..0aba1563 --- /dev/null +++ b/trick_source/sim_services/MemoryManager/MemoryManager_restore_stls.cpp @@ -0,0 +1,197 @@ + +#include + +#include "trick/MemoryManager.hh" +#include "trick/attributes.h" + +// MEMBER FUNCTION +void Trick::MemoryManager::restore_stls( ALLOC_INFO* alloc_info ) { + + ATTRIBUTES* reference_attr; + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + if (alloc_info == NULL) { + std::cout << "ERROR: Trick::MemoryManager::restore_stls called with alloc_info == NULL." << std::endl; + std::cout.flush(); + return; + } + + // If there is no name associated with this alloc_info, we won't be able to find any stls associated with it. + if (alloc_info->name == NULL) { + return; + } + + if (debug_level) { + std::cout << __FUNCTION__ << ": Begin scan of allocation @" << (void*)alloc_info->start << " for dependencies." << std::endl; + } + + reference_attr = make_reference_attr( alloc_info ); + + // Get the dependencies of the allocation + if (alloc_info->type == TRICK_STRUCTURED) { + if (reference_attr->num_index > 0) { + restore_stls_in_arrayed_class(alloc_info->name, (char*)(alloc_info->start), reference_attr, 0, 0) ; + } else { + restore_stls_in_class(alloc_info->name, (char*)(alloc_info->start), alloc_info->attr) ; + } + } else { + restore_stls_in_intrinsic(alloc_info->name, alloc_info->start, reference_attr, 0, 0 ); + } + + if (debug_level) { + std::cout << __FUNCTION__ << ": End scan of allocation @" << (void*)alloc_info->start << "." << std::endl; + } + + free_reference_attr( reference_attr ); + +} + +// MEMBER FUNCTION +void Trick::MemoryManager::restore_stls_in_class( std::string name, char* address, ATTRIBUTES* attr) { + int ii; + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + if (attr == NULL) { + std::cerr << "ERROR: Trick::MemoryManager::restore_stls called with attr = NULL." << std::endl; + return; + } + + for (ii = 0; attr[ii].name[0] != '\0'; ii++) { + if (currentCheckPointAgent->input_perm_check(&attr[ii])) { + char *elem_addr; + if (attr[ii].mods & 2) { + elem_addr = (char *) attr[ii].offset; + } else { + elem_addr = address + attr[ii].offset; + } + + if (attr[ii].type == TRICK_STRUCTURED) { + if (attr[ii].num_index != 0) { + restore_stls_in_arrayed_class( name + "." + attr[ii].name, elem_addr, &attr[ii], 0, 0); + } else { + restore_stls_in_class( name + "." + attr[ii].name, elem_addr, (ATTRIBUTES*)(attr[ii].attr)); + } + } else if (attr[ii].type == TRICK_STL) { + (*attr[ii].restore_stl)(elem_addr, name.c_str(), attr[ii].name) ; + } else { + restore_stls_in_intrinsic( name + "." + attr[ii].name , elem_addr, &(attr[ii]), 0, 0); + } + } + } +} + +// MEMBER FUNCTION +void Trick::MemoryManager::restore_stls_in_arrayed_class( + std::string name, + char* address, + ATTRIBUTES* attr, + int curr_dim, + int offset) { + int ii; + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + if (attr == NULL) { + std::cerr << "Trick::MemoryManager::restore_stls_in_arrayed_class: ERROR: attr = NULL." << std::endl; + return; + } + + if (attr->index[curr_dim].size == 0) { + + void* pointer = *(void**)((char*)address + offset * sizeof(void*)); + + if (pointer != NULL) { + ALLOC_INFO *alloc_info; + alloc_info = get_alloc_info_of( pointer); + if (alloc_info != NULL) { + + if (debug_level) { + std::cout << __FUNCTION__ << ": @" << (void*)address << "." << attr->name << "[" << offset << "] points to @" << (void*)pointer << std::endl; + } + //restore_stls(alloc_info); + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl; + std::cout.flush(); + } + } + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Allocation reference is NULL." << std::endl; + std::cout.flush(); + } + } + + } else { + int curr_dim_size; + curr_dim_size = attr->index[curr_dim].size; + for (ii = 0; ii < curr_dim_size; ii++) { + char index[16] ; + sprintf(index, "[%d]", ii) ; + if (curr_dim < attr->num_index - 1) { + restore_stls_in_arrayed_class( name + index, address, attr, curr_dim + 1, offset * curr_dim_size + ii); + } else { + char* elem_addr; + elem_addr = address + (offset * curr_dim + ii) * attr->size ; + restore_stls_in_class( name + index, elem_addr, (ATTRIBUTES*)attr->attr ); + } + } + } +} + + +// MEMBER FUNCTION +void Trick::MemoryManager::restore_stls_in_intrinsic( std::string name , void* address, ATTRIBUTES* attr, int curr_dim, int offset) { + + if (debug_level > 1) { + std::cout << "DEBUG: Entered function:" << __FUNCTION__ << std::endl; + } + + // If the variable that we are pointing to is an arrayed + if (curr_dim < attr->num_index) { + + // If it is an unconstrained array (a pointer) + if (attr->index[curr_dim].size == 0) { + + void* pointer = *(void**)((char*)address + offset * sizeof(void*)); + + if (pointer != NULL) { + ALLOC_INFO *alloc_info; + alloc_info = get_alloc_info_of( pointer); + if (alloc_info != NULL) { + if (debug_level) { + std::cout << __FUNCTION__ << ": @" << (void*)address << "." << attr->name << "[" << offset << "] points to @" << (void*)pointer << std::endl; + } + //restore_stls(alloc_info); + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl; + std::cout.flush(); + } + } + } else { + if (debug_level) { + std::cout << __FUNCTION__ << ": Allocation reference is NULL." << std::endl; + std::cout.flush(); + } + } + + } else { // otherwise its a constrained array. + int ii; + for (ii=0 ; ii< attr->index[curr_dim].size ; ii++) { + char index[16] ; + sprintf(index, "[%d]", ii) ; + //restore_stls_in_intrinsic( name + index , address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii); + } + } + } +} + diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_write_checkpoint.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_write_checkpoint.cpp index 4464bc5a..141ba0ba 100644 --- a/trick_source/sim_services/MemoryManager/MemoryManager_write_checkpoint.cpp +++ b/trick_source/sim_services/MemoryManager/MemoryManager_write_checkpoint.cpp @@ -11,7 +11,7 @@ #endif // MEMBER FUNCTION -void Trick::MemoryManager::write_checkpoint( std::ostream& out_s, std::vector& dependencies) { +void Trick::MemoryManager::execute_checkpoint( std::ostream& out_s ) { ALLOC_INFO_MAP::iterator pos; ALLOC_INFO* alloc_info; @@ -26,16 +26,17 @@ void Trick::MemoryManager::write_checkpoint( std::ostream& out_s, std::vectorname == NULL) { if ( alloc_info->stcl == TRICK_LOCAL) { sprintf( name, "%s%d", local_anon_var_prefix, local_anon_var_number++); alloc_info->name = strdup( name); - currentCheckPointAgent->write_decl( out_s, alloc_info); } else if (alloc_info->stcl == TRICK_EXTERN) { sprintf( name, "%s%d", extern_anon_var_prefix, extern_anon_var_number++); alloc_info->name = strdup( name); @@ -44,7 +45,15 @@ void Trick::MemoryManager::write_checkpoint( std::ostream& out_s, std::vectorstcl == TRICK_LOCAL) { currentCheckPointAgent->write_decl( out_s, alloc_info); } } @@ -77,6 +86,12 @@ void Trick::MemoryManager::write_checkpoint( std::ostream& out_s, std::vectorname = NULL; } } + + // Delete the variables created by STLs. Remove memory in reverse order. + std::vector::reverse_iterator it ; + for ( it = stl_dependencies.rbegin() ; it != stl_dependencies.rend() ; it++ ) { + delete_var((*it)->start) ; + } } // Local sort function used in write_checkpoint. @@ -87,7 +102,8 @@ void Trick::MemoryManager::write_checkpoint( std::ostream& out_s) { ALLOC_INFO_MAP::iterator pos; ALLOC_INFO* alloc_info; - std::vector dependencies; + dependencies.clear(); + stl_dependencies.clear(); pthread_mutex_lock(&mm_mutex); for ( pos=alloc_info_map.begin() ; pos!=alloc_info_map.end() ; pos++ ) { @@ -98,7 +114,8 @@ void Trick::MemoryManager::write_checkpoint( std::ostream& out_s) { // Sort the dependencies by ALLOC_INFO.id. std::sort( dependencies.begin() , dependencies.end() , alloc_info_id_compare) ; pthread_mutex_unlock(&mm_mutex); - write_checkpoint( out_s, dependencies); + + execute_checkpoint( out_s ); } @@ -119,21 +136,20 @@ void Trick::MemoryManager::write_checkpoint(const char* filename) { // MEMBER FUNCTION void Trick::MemoryManager::write_checkpoint( std::ostream& out_s, const char* var_name) { - std::vector dependencies; + dependencies.clear(); + stl_dependencies.clear(); pthread_mutex_lock(&mm_mutex); - get_alloc_deps_in_allocation( dependencies, var_name); + get_alloc_deps_in_allocation( var_name); pthread_mutex_unlock(&mm_mutex); - write_checkpoint( out_s, dependencies); + execute_checkpoint( out_s ); } // MEMBER FUNCTION void Trick::MemoryManager::write_checkpoint(const char* filename, const char* var_name) { - std::vector dependencies; std::ofstream out_s( filename, std::ios::out); - if (out_s.is_open()) { write_checkpoint( out_s, var_name); } else { @@ -146,19 +162,21 @@ void Trick::MemoryManager::write_checkpoint(const char* filename, const char* va // MEMBER FUNCTION void Trick::MemoryManager::write_checkpoint( std::ostream& out_s, std::vector& var_name_list) { - std::vector dependencies; const char* var_name; int n_names; + dependencies.clear(); + stl_dependencies.clear(); + n_names = var_name_list.size(); for (int ii=0; ii< n_names; ii++) { var_name = var_name_list[ii]; pthread_mutex_lock(&mm_mutex); - get_alloc_deps_in_allocation(dependencies, var_name); + get_alloc_deps_in_allocation(var_name); pthread_mutex_unlock(&mm_mutex); } - write_checkpoint( out_s, dependencies); + execute_checkpoint( out_s ); } // MEMBER FUNCTION From c57c10edcd27dabe68b1deeb4b9e240a205805a9 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Tue, 29 Mar 2016 09:59:49 -0500 Subject: [PATCH 2/9] Add direct STL checkpointing Made adjustments to template default arguments to avoid clang compiler errors. Also added an irnore warning during python glue code compilation refs #206 --- include/trick/checkpoint_map.hh | 8 ++--- include/trick/checkpoint_queue.hh | 4 +-- include/trick/checkpoint_sequence_stl.hh | 40 ++++++++++++------------ include/trick/checkpoint_stack.hh | 4 +-- libexec/trick/make_makefile_swig | 2 +- test/SIM_stls/RUN_test/input.py | 6 ++-- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/include/trick/checkpoint_map.hh b/include/trick/checkpoint_map.hh index 29340207..52fceb9a 100644 --- a/include/trick/checkpoint_map.hh +++ b/include/trick/checkpoint_map.hh @@ -37,8 +37,8 @@ int checkpoint_map_stl(STL & in_map , std::string object_name , std::string var_ typename STL::iterator iter ; int status ; - typename STL::key_type * keys ; - typename STL::mapped_type * items ; + typename STL::key_type * keys = nullptr ; + typename STL::mapped_type * items = nullptr ; cont_size = in_map.size() ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); @@ -85,7 +85,7 @@ int checkpoint_map_stl_key_string(STL & in_map , std::string object_name , std:: int status ; char ** keys ; - typename STL::mapped_type * items ; + typename STL::mapped_type * items = nullptr ; cont_size = in_map.size() ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); @@ -130,7 +130,7 @@ int checkpoint_map_stl_data_string(STL & in_map , std::string object_name , std: typename STL::iterator iter ; int status ; - typename STL::key_type * keys ; + typename STL::key_type * keys = nullptr ; char ** items ; cont_size = in_map.size() ; diff --git a/include/trick/checkpoint_queue.hh b/include/trick/checkpoint_queue.hh index bbdb4626..a5e781d9 100644 --- a/include/trick/checkpoint_queue.hh +++ b/include/trick/checkpoint_queue.hh @@ -41,7 +41,7 @@ int checkpoint_stl(std::queue & in_stl , std::string object_name , st char var_declare[128] ; int status ; - ITEM_TYPE * items ; + ITEM_TYPE * items = nullptr ; std::queue temp_queue ; cont_size = in_stl.size() ; @@ -74,7 +74,7 @@ int checkpoint_stl(std::priority_queue & in_stl , std::string object_ char var_declare[128] ; int status ; - ITEM_TYPE * items ; + ITEM_TYPE * items = nullptr ; std::priority_queue temp_queue ; cont_size = in_stl.size() ; diff --git a/include/trick/checkpoint_sequence_stl.hh b/include/trick/checkpoint_sequence_stl.hh index a5b61b1f..6e353daa 100644 --- a/include/trick/checkpoint_sequence_stl.hh +++ b/include/trick/checkpoint_sequence_stl.hh @@ -174,13 +174,13 @@ int checkpoint_sequence_stl_stl(STL & in_stl , std::string object_name , std::st // std::vector // This template is only enabled if the items in the vector are an STL -template ::value>::type* = nullptr > +template ::value>::type* > int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the vector are NOT an STL, except for std::string -template ::value>::type* = nullptr > +template ::value>::type* > int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } @@ -191,13 +191,13 @@ int checkpoint_stl(std::vector & in_vector , std::string object_nam // ----------- // std::list -template ::value>::type* = nullptr > +template ::value>::type* > int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) { return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the list are NOT an STL, except for std::string -template ::value>::type* = nullptr > +template ::value>::type* > int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) { return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } @@ -208,13 +208,13 @@ int checkpoint_stl(std::list & in_list , std::string object_name , // ----------- // std::deque -template ::value>::type* = nullptr > +template ::value>::type* > int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the deque are NOT an STL, except for std::string -template ::value>::type* = nullptr > +template ::value>::type* > int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } @@ -225,13 +225,13 @@ int checkpoint_stl(std::deque & in_vector , std::string object_name // ----------- // std::set -template ::value>::type* = nullptr > +template ::value>::type* > int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) { return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the set are NOT an STL, except for std::string -template ::value>::type* = nullptr > +template ::value>::type* > int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) { return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } @@ -242,13 +242,13 @@ int checkpoint_stl(std::set & in_vector , std::string object_name , // ----------- // std::multiset -template ::value>::type* = nullptr > +template ::value>::type* > int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the multiset are NOT an STL, except for std::string -template ::value>::type* = nullptr > +template ::value>::type* > int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } @@ -429,13 +429,13 @@ int restore_sequence_stl_stl(STL & in_stl , std::string object_name , std::strin // std::vector // This template is only enabled if the items in the vector are an STL -template ::value>::type* = nullptr > +template ::value>::type* > int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the vector are NOT an STL, except for std::string -template ::value>::type* = nullptr > +template ::value>::type* > int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } @@ -447,13 +447,13 @@ int restore_stl(std::vector & in_vector , std::string object_name , // std::list // This template is only enabled if the items in the list are an STL -template ::value>::type* = nullptr > +template ::value>::type* > int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) { return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the list are NOT an STL, except for std::string -template ::value>::type* = nullptr > +template ::value>::type* > int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) { return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } @@ -464,13 +464,13 @@ int restore_stl(std::list & in_list , std::string object_name , std // std::deque // This template is only enabled if the items in the deque are an STL -template ::value>::type* = nullptr > +template ::value>::type* > int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the deque are NOT an STL, except for std::string -template ::value>::type* = nullptr > +template ::value>::type* > int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } @@ -481,13 +481,13 @@ int restore_stl(std::deque & in_deque , std::string object_name , s // std::set // This template is only enabled if the items in the set are an STL -template ::value>::type* = nullptr > +template ::value>::type* > int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) { return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the set are NOT an STL, except for std::string -template ::value>::type* = nullptr > +template ::value>::type* > int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) { return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } @@ -498,13 +498,13 @@ int restore_stl(std::set & in_set , std::string object_name , std:: // std::multiset // This template is only enabled if the items in the multiset are an STL -template ::value>::type* = nullptr > +template ::value>::type* > int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the multiset are NOT an STL, except for std::string -template ::value>::type* = nullptr > +template ::value>::type* > int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } diff --git a/include/trick/checkpoint_stack.hh b/include/trick/checkpoint_stack.hh index 1699943f..11077748 100644 --- a/include/trick/checkpoint_stack.hh +++ b/include/trick/checkpoint_stack.hh @@ -31,7 +31,7 @@ int checkpoint_stl(std::stack & in_stl , std::string object_name , st char var_declare[128] ; int status ; - ITEM_TYPE * items ; + ITEM_TYPE * items = nullptr ; std::stack temp_stack ; cont_size = in_stl.size() ; @@ -68,7 +68,7 @@ int restore_stl(std::stack & in_stl , std::string object_name , std:: unsigned int cont_size ; REF2 * items_ref ; - ITEM_TYPE * items ; + ITEM_TYPE * 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()) ; diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index 27e1a0c9..c6462c3c 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -173,7 +173,7 @@ sub make_swig_makefile() { SWIG_FLAGS ?= SWIG_CFLAGS := -I../include \${PYTHON_INCLUDES} -Wno-shadow -Wno-missing-field-initializers ifeq (\$(IS_CC_CLANG), 1) - SWIG_CFLAGS += -Wno-self-assign -Wno-sometimes-uninitialized + SWIG_CFLAGS += -Wno-self-assign -Wno-sometimes-uninitialized -Wno-deprecated-register endif ifdef TRICK_VERBOSE_BUILD diff --git a/test/SIM_stls/RUN_test/input.py b/test/SIM_stls/RUN_test/input.py index d49bbf77..458f7730 100644 --- a/test/SIM_stls/RUN_test/input.py +++ b/test/SIM_stls/RUN_test/input.py @@ -3,9 +3,9 @@ def main(): #trick.echo_jobs_on() - trick.sim_control_panel_set_enabled(True) - trick.real_time_enable() - trick.itimer_enable() + #trick.sim_control_panel_set_enabled(True) + #trick.real_time_enable() + #trick.itimer_enable() trick.checkpoint_pre_init(True) #trick.checkpoint_post_init(True) From f7c74d7872e0a965d4f897537ee1f5ba124c4944 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Tue, 29 Mar 2016 11:01:03 -0500 Subject: [PATCH 3/9] Add direct STL checkpointing Removed saving the namespace of a variable it is in the std namespace. Added a check for STLs residing in std::__1 as they do on Macs. refs #206 --- .../Interface_Code_Gen/ConstructValues.cpp | 5 ++- .../Interface_Code_Gen/FieldVisitor.cpp | 45 +++++-------------- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/trick_source/codegen/Interface_Code_Gen/ConstructValues.cpp b/trick_source/codegen/Interface_Code_Gen/ConstructValues.cpp index 1cd91114..28d856e9 100644 --- a/trick_source/codegen/Interface_Code_Gen/ConstructValues.cpp +++ b/trick_source/codegen/Interface_Code_Gen/ConstructValues.cpp @@ -40,7 +40,10 @@ void ConstructValues::getNamespacesAndClasses( const clang::DeclContext * Ctx ) if (const clang::NamespaceDecl *nd = clang::dyn_cast(*I)) { if (! nd->isAnonymousNamespace()) { //std::cout << "namespace " << nd->getIdentifier()->getName().str() << std::endl ; - addNamespace(nd->getIdentifier()->getName().str()) ; + std::string temp_name = nd->getIdentifier()->getName().str() ; + if ( temp_name.compare("std") and temp_name.compare("__1")) { + addNamespace(nd->getIdentifier()->getName().str()) ; + } } } else if (const clang::RecordDecl *rd = clang::dyn_cast(*I)) { if (rd->getIdentifier()) { diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp index 719776b7..cf7ae26d 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp @@ -259,20 +259,6 @@ bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl * size_t pos ; -/* - if ((pos = in_name.find("class ")) != std::string::npos ) { - in_name.erase(pos , 6) ; - } - // clang changes bool to _Bool. We need to change it back - if ((pos = in_name.find("<_Bool")) != std::string::npos ) { - in_name.replace(pos , 6, " init_stl_classes() { my_map.insert(std::pair("std::set", 1)) ; my_map.insert(std::pair("std::stack", 0)) ; my_map.insert(std::pair("std::vector", 1)) ; + my_map.insert(std::pair("std::__1::deque", 1)) ; + my_map.insert(std::pair("std::__1::list", 1)) ; + my_map.insert(std::pair("std::__1::map", 1)) ; + my_map.insert(std::pair("std::__1::multiset", 1)) ; + my_map.insert(std::pair("std::__1::multimap", 1)) ; + my_map.insert(std::pair("std::__1::pair", 1)) ; + my_map.insert(std::pair("std::__1::priority_queue", 0)) ; + my_map.insert(std::pair("std::__1::queue", 0)) ; + my_map.insert(std::pair("std::__1::set", 1)) ; + my_map.insert(std::pair("std::__1::stack", 0)) ; + my_map.insert(std::pair("std::__1::vector", 1)) ; return my_map ; } static std::map stl_classes = init_stl_classes() ; -#if 0 -// C++ 11 style initialization -// list of handled STL types and if they have a clear function. -static std::map stl_classes = { - {"std::deque", 1}, - {"std::list", 1}, - {"std::map", 1}, - {"std::multiset", 1}, - {"std::multimap", 1}, - {"std::pair", 0}, - {"std::priority_queue", 0}, - {"std::queue", 0}, - {"std::set", 1}, - {"std::stack", 0}, - {"std::vector", 1} -}; -#endif - bool FieldVisitor::VisitRecordType(clang::RecordType *rt) { if ( debug_level >= 3 ) { std::cout << "FieldVisitor VisitRecordType" << std::endl ; @@ -371,13 +350,13 @@ bool FieldVisitor::VisitRecordType(clang::RecordType *rt) { while ((pos = tst_string.find(" _Bool")) != std::string::npos ) { tst_string.replace(pos , 6, " bool") ; } + // NOTE: clang also changes FILE * to struct _SFILE *. We may need to change that too. // Test if we have some type from std. if (!tst_string.compare( 0 , 5 , "std::")) { // If we have some type from std, figure out if it is one we support. for ( std::map::iterator it = stl_classes.begin() ; it != stl_classes.end() ; it++ ) { /* Mark STL types that are not strings and exit */ - //if (!tst_string.compare( 0 , 11 , "class std::") or !tst_string.compare( 0 , 12 , "struct std::")) { if (!tst_string.compare( 0 , (*it).first.size() , (*it).first)) { fdes->setEnumString("TRICK_STL") ; fdes->setSTL(true) ; From 94febe62f29bcbf9d463a5ed2f4dcf44b8833a5b Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Wed, 30 Mar 2016 16:57:45 -0500 Subject: [PATCH 4/9] Add direct STL checkpointing Added the templates required for maps, multimaps, and pairs. refs #206 --- include/trick/checkpoint_fwd_declare.hh | 203 ++++++ include/trick/checkpoint_is_stl_container.hh | 17 + include/trick/checkpoint_map.hh | 453 ++++++++----- include/trick/checkpoint_pair.hh | 356 ++++++---- include/trick/checkpoint_sequence_stl.hh | 213 +----- test/SIM_stls/RUN_test/input.py | 6 +- test/SIM_stls/models/STLCheckpoint.cpp | 616 ++++++++++-------- test/SIM_stls/models/STLCheckpoint.hh | 72 +- .../Interface_Code_Gen/FieldVisitor.cpp | 7 +- .../CheckPointRestart/checkpoint_map.cpp | 3 +- .../CheckPointRestart/checkpoint_pair.cpp | 46 -- .../checkpoint_sequence_stl.cpp | 3 +- 12 files changed, 1142 insertions(+), 853 deletions(-) create mode 100644 include/trick/checkpoint_fwd_declare.hh diff --git a/include/trick/checkpoint_fwd_declare.hh b/include/trick/checkpoint_fwd_declare.hh new file mode 100644 index 00000000..b5789640 --- /dev/null +++ b/include/trick/checkpoint_fwd_declare.hh @@ -0,0 +1,203 @@ +/* + PURPOSE: (Foward declare all the checkpoint_stl routines that are used in other template routines.) +*/ + +#ifndef CHECKPOINT_FWD_DECLARE +#define CHECKPOINT_FWD_DECLARE + +#include +#include +#include +#include +#include + +#include +#include + +#include "checkpoint_is_stl_container.hh" + +// This file declares all of the variants of the checkpoint_stl function. +// Many of the checkpoint_stl templates are recursive, calling cechkpoint_stl again with their +// template argument type. This header makes all of the variants available +// to the recursive templates. + +// Checkpoint routines + +// vector +template ::value>::type* = nullptr > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; + +// list +template ::value>::type* = nullptr > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; + +// deque +template ::value>::type* = nullptr > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; + +// set +template ::value>::type* = nullptr > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; + +// multiset +template ::value>::type* = nullptr > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; + +// map +template ::value && + !is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) ; + +template ::value && + is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) ; + +template ::value && + !is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) ; + +template ::value && + is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) ; + +// multimap +template ::value && + !is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; + +template ::value && + is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; + +template ::value && + !is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; + +template ::value && + is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; + +// pair +template ::value && + !is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; + +template ::value && + is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; + +template ::value && + !is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; + +template ::value && + is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; + +/* ===================================================================================================== */ + +// Restore routines + +// vector +template ::value>::type* = nullptr > +int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; + +// list +template ::value>::type* = nullptr > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; + +// deque +template ::value>::type* = nullptr > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; + +// set +template ::value>::type* = nullptr > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; + +// multiset +template ::value>::type* = nullptr > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; + +// map +template ::value && + !is_stl_container::value >::type* = nullptr > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) ; + +template ::value && + is_stl_container::value >::type* = nullptr > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) ; + +template ::value && + !is_stl_container::value >::type* = nullptr > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) ; + +template ::value && + is_stl_container::value >::type* = nullptr > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) ; + +// multimap +template ::value && + !is_stl_container::value >::type* = nullptr > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; + +template ::value && + is_stl_container::value >::type* = nullptr > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; + +template ::value && + !is_stl_container::value >::type* = nullptr > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; + +template ::value && + is_stl_container::value >::type* = nullptr > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; + +// pair +template ::value && + !is_stl_container::value >::type* = nullptr > +int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; + +template ::value && + is_stl_container::value >::type* = nullptr > +int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; + +template ::value && + !is_stl_container::value >::type* = nullptr > +int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; + +template ::value && + is_stl_container::value >::type* = nullptr > +int restore_stl(std::pair & in_pair , 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 4b4da6ee..b70c0a2f 100644 --- a/include/trick/checkpoint_is_stl_container.hh +++ b/include/trick/checkpoint_is_stl_container.hh @@ -9,6 +9,8 @@ #include #include #include +#include +#include template struct is_stl_container { @@ -40,5 +42,20 @@ struct is_stl_container > { static const bool value = true; }; +template +struct is_stl_container > { + static const bool value = true; +}; + +template +struct is_stl_container > { + static const bool value = true; +}; + +template +struct is_stl_container > { + static const bool value = true; +}; + #endif diff --git a/include/trick/checkpoint_map.hh b/include/trick/checkpoint_map.hh index 52fceb9a..8b958853 100644 --- a/include/trick/checkpoint_map.hh +++ b/include/trick/checkpoint_map.hh @@ -11,15 +11,19 @@ #include #include #include +#include #include +#include #ifdef __GNUC__ #include #endif +#include "checkpoint_is_stl_container.hh" +#include "checkpoint_fwd_declare.hh" #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" -#ifndef TRICK_ICG +/* =================================================================================================*/ /* For all of the checkpoint_map_stl variations. Declare 2 memory manager arrays to hold the contents of the map. No simulation variable actually points to these arrays. Only the @@ -28,12 +32,14 @@ the STL requires a unique name to be saved correctly. The incoming "object_name" and "var_name" gives that unique name. */ + +// intrinsic key, intrinsic data template -int checkpoint_map_stl(STL & in_map , std::string object_name , std::string var_name ) { +int checkpoint_map_stl_ik_id(STL & in_map , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; - char var_declare[128] ; + std::ostringstream var_declare ; typename STL::iterator iter ; int status ; @@ -44,17 +50,19 @@ int checkpoint_map_stl(STL & in_map , std::string object_name , std::string var_ std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - sprintf(var_declare, "%s %s_%s_keys[%d]" , - abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; - keys = (typename STL::key_type *)TMM_declare_var_s(var_declare) ; + var_declare << abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ) << " " + << object_name << "_" << var_name << "_keys[" << cont_size << "]" ; + keys = (typename STL::key_type *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; - //message_publish(1, "HERE with %s\n", var_declare) ; + //message_publish(1, "HERE with %s\n", var_declare) ; - sprintf(var_declare, "%s %s_%s_data[%d]" , - abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; - items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare) ; + var_declare.str("") ; + var_declare.clear() ; + var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + << object_name << "_" << var_name << "_data[" << cont_size << "]" ; + items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_data").c_str()) ; - //message_publish(1, "HERE with %s\n", var_declare) ; + //message_publish(1, "HERE with %s\n", var_declare) ; /* copy the contents of the map the 2 arrays */ for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { @@ -65,146 +73,202 @@ int checkpoint_map_stl(STL & in_map , std::string object_name , std::string var_ return 0 ; } -template -int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl( in_map , object_name , var_name ) ; +template ::value && + !is_stl_container::value >::type* > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_stl_ik_id( in_map , object_name , var_name ) ; } -template -int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl( in_map , object_name , var_name ) ; +template ::value && + !is_stl_container::value >::type*> +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_stl_ik_id( in_map , object_name , var_name ) ; } +// intrinsic key, STL data template -int checkpoint_map_stl_key_string(STL & in_map , std::string object_name , std::string var_name ) { +int checkpoint_map_stl_ik_sd(STL & in_map , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; - char var_declare[128] ; + std::ostringstream var_declare ; typename STL::iterator iter ; int status ; - char ** keys ; + typename STL::key_type * keys = nullptr ; + std::string * items = nullptr ; + + cont_size = in_map.size() ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + if ( cont_size > 0 ) { + var_declare << abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ) << " " + << object_name << "_" << var_name << "_keys[" << cont_size << "]" ; + keys = (typename STL::key_type *)TMM_declare_var_s(var_declare.str().c_str()) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; + //message_publish(1, "HERE with %s\n", var_declare) ; + + var_declare.str("") ; + var_declare.clear() ; + var_declare << "std::string " + << object_name << "_" << var_name << "_data[" << 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 + "_data").c_str()) ; + //message_publish(1, "HERE with %s\n", var_declare) ; + + /* copy the contents of the map the 2 arrays */ + for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { + keys[ii] = iter->first ; + + std::ostringstream sub_elements ; + sub_elements << object_name << "_" << var_name << "_data_" << ii ; + items[ii] = sub_elements.str() ; + + std::ostringstream index_string ; + index_string << ii ; + //message_publish(1, "recursive call to checkpoint_stl %s\n", __PRETTY_FUNCTION__) ; + checkpoint_stl( iter->second , object_name + "_" + var_name + "_data" , index_string.str() ) ; + } + } + return 0 ; +} + +template ::value && + is_stl_container::value >::type* > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_stl_ik_sd( in_map , object_name , var_name ) ; +} + +template ::value && + is_stl_container::value >::type*> +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_stl_ik_sd( in_map , object_name , var_name ) ; +} + +// STL key, intrinsic data +template +int checkpoint_map_stl_sk_id(STL & in_map , std::string object_name , std::string var_name ) { + + unsigned int ii ; + unsigned int cont_size ; + std::ostringstream var_declare ; + typename STL::iterator iter ; + int status ; + + std::string * keys = nullptr ; typename STL::mapped_type * items = nullptr ; cont_size = in_map.size() ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - sprintf(var_declare, "char * %s_%s_keys[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; - keys = (char **)TMM_declare_var_s(var_declare) ; + var_declare << "std::string " + << object_name << "_" << var_name << "_keys[" << cont_size << "]" ; + keys = (std::string *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; - //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; + //message_publish(1, "HERE with %s\n", var_declare) ; - sprintf(var_declare, "%s %s_%s_data[%d]" , - abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str() , cont_size) ; - items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare) ; + var_declare.str("") ; + var_declare.clear() ; + var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + << object_name << "_" << var_name << "_data[" << cont_size << "]" ; + items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_data").c_str()) ; - //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; + //message_publish(1, "HERE with %s\n", var_declare) ; /* copy the contents of the map the 2 arrays */ for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { - keys[ii] = (char *)((iter->first).c_str()) ; + std::ostringstream sub_elements ; + sub_elements << object_name << "_" << var_name << "_keys_" << ii ; + keys[ii] = sub_elements.str() ; + + std::ostringstream index_string ; + index_string << ii ; + checkpoint_stl( const_cast(iter->first) , + object_name + "_" + var_name + "_keys", index_string.str() ) ; + items[ii] = iter->second ; } } return 0 ; } -template -int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl_key_string( in_map , object_name , var_name ) ; +template ::value && + !is_stl_container::value >::type* > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_stl_sk_id( in_map , object_name , var_name ) ; } -template -int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl_key_string( in_map , object_name , var_name ) ; +template ::value && + !is_stl_container::value >::type*> +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_stl_sk_id( in_map , object_name , var_name ) ; } +// STL key, STL data template -int checkpoint_map_stl_data_string(STL & in_map , std::string object_name , std::string var_name ) { +int checkpoint_map_stl_sk_sd(STL & in_map , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; - char var_declare[128] ; + std::ostringstream var_declare ; typename STL::iterator iter ; int status ; - typename STL::key_type * keys = nullptr ; - char ** items ; + std::string * keys = nullptr ; + std::string * items = nullptr ; cont_size = in_map.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_keys[%d]" , - abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str() , cont_size) ; - keys = (typename STL::key_type *)TMM_declare_var_s(var_declare) ; + var_declare << "std::string " + << object_name << "_" << var_name << "_keys[" << cont_size << "]" ; + keys = (std::string *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; - //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; + //message_publish(1, "HERE with %s\n", var_declare) ; - sprintf(var_declare, "char * %s_%s_data[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; - items = (char **)TMM_declare_var_s(var_declare) ; + var_declare.str("") ; + var_declare.clear() ; + var_declare << "std::string " + << object_name << "_" << var_name << "_data[" << 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 + "_data").c_str()) ; - //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; + //message_publish(1, "HERE with %s\n", var_declare) ; /* copy the contents of the map the 2 arrays */ for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { - keys[ii] = iter->first ; - items[ii] = (char *)((iter->second).c_str()) ; + std::ostringstream sub_elements ; + sub_elements << object_name << "_" << var_name << "_keys_" << ii ; + keys[ii] = sub_elements.str() ; + + std::ostringstream index_string ; + index_string << ii ; + checkpoint_stl( const_cast(iter->first) , + object_name + "_" + var_name + "_keys", index_string.str() ) ; + + sub_elements << object_name << "_" << var_name << "_data_" << ii ; + items[ii] = sub_elements.str() ; + + checkpoint_stl( iter->second , + object_name + "_" + var_name + "_data", index_string.str() ) ; } } return 0 ; } - -template -int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl_data_string( in_map , object_name , var_name ) ; +template ::value && + is_stl_container::value >::type* > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_stl_sk_sd( in_map , object_name , var_name ) ; } -template -int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl_data_string( in_map , object_name , var_name ) ; +template ::value && + is_stl_container::value >::type*> +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_stl_sk_sd( in_map , object_name , var_name ) ; } - -template -int checkpoint_map_stl_strings(STL & in_map , std::string object_name , std::string var_name ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - typename STL::iterator iter ; - - char ** keys ; - char ** items ; - - cont_size = in_map.size() ; - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - - if ( cont_size > 0 ) { - sprintf(var_declare, "char * %s_%s_keys[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; - keys = (char **)TMM_declare_var_s(var_declare) ; - TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; - //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; - - sprintf(var_declare, "char * %s_%s_data[%d]" , 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 + "_data").c_str()) ; - //message_publish(1, "STRING KEY HERE with %s\n", var_declare) ; - - /* copy the contents of the map the 2 arrays */ - - for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { - keys[ii] = (char *)((iter->first).c_str()) ; - items[ii] = (char *)((iter->second).c_str()) ; - } - } - return 0 ; -} - -int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) ; -int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; +/* =================================================================================================*/ template int delete_map_stl(STL & in_map __attribute__ ((unused)), std::string object_name , std::string var_name ) { @@ -219,24 +283,26 @@ int delete_map_stl(STL & in_map __attribute__ ((unused)), std::string object_nam return 0 ; } -template -int delete_stl(std::map & in_map , std::string object_name , std::string var_name ) { +template +int delete_stl(std::map & in_map , std::string object_name , std::string var_name ) { return delete_map_stl(in_map , object_name , var_name) ; } -template -int delete_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { +template +int delete_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { return delete_map_stl(in_map , object_name , var_name) ; } +/* =================================================================================================*/ + /* For all restore_map_stl varieties. - Find the arrays the map data was stored in the checkpoint using ref_attributes + 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. + the map from the 2 arrays. */ template -int restore_map_stl(STL & in_map , std::string object_name , std::string var_name ) { +int restore_map_stl_ik_id(STL & in_map , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -249,8 +315,8 @@ int restore_map_stl(STL & in_map , std::string object_name , std::string var_nam std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; - items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; + keys_ref = ref_attributes((char *)(object_name + "_" + var_name + "_keys").c_str()) ; + items_ref = ref_attributes((char *)(object_name + "_" + var_name + "_data").c_str()) ; if ( keys_ref != NULL && items_ref != NULL ) { in_map.clear() ; @@ -267,139 +333,164 @@ int restore_map_stl(STL & in_map , std::string object_name , std::string var_nam return 0 ; } -template -int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl(in_map , object_name , var_name) ; - return 0 ; +template ::value && + !is_stl_container::value >::type* > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return restore_map_stl_ik_id(in_map , object_name , var_name) ; } -template -int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl(in_map , object_name , var_name) ; +template ::value && + !is_stl_container::value >::type* > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return restore_map_stl_ik_id(in_map , object_name , var_name) ; } template -int restore_map_stl_key_string( STL & in_map , std::string object_name , std::string var_name ) { - - unsigned int ii ; - unsigned int cont_size ; - - REF2 * keys_ref , * items_ref ; - char ** keys ; - typename STL::mapped_type * items ; - - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - - keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; - items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - in_map.clear() ; - keys = (char **)keys_ref->address ; - items = (typename STL::mapped_type *)items_ref->address ; - cont_size = get_size((char *)keys) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_map.insert( std::pair(std::string(keys[ii]), items[ii])) ; - } - - delete_stl( in_map , object_name , var_name ) ; - } - return 0 ; -} - -template -int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_key_string(in_map , object_name , var_name) ; -} - -template -int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_key_string(in_map , object_name , var_name) ; -} - -template -int restore_map_stl_data_string(STL & in_map , std::string object_name , std::string var_name ) { +int restore_map_stl_ik_sd(STL & in_map , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; REF2 * keys_ref , * items_ref ; typename STL::key_type * keys ; - char ** items ; + std::string * items ; - //message_publish(1, "in specialized map template restore\n") ; + //message_publish(1, "in regular map template restore\n") ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; - items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; + keys_ref = ref_attributes((char *)(object_name + "_" + var_name + "_keys").c_str()) ; + items_ref = ref_attributes((char *)(object_name + "_" + var_name + "_data").c_str()) ; if ( keys_ref != NULL && items_ref != NULL ) { in_map.clear() ; keys = (typename STL::key_type *)keys_ref->address ; - items = (char **)items_ref->address ; + items = (std::string *)items_ref->address ; cont_size = get_size((char *)keys) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_map.insert( std::pair(keys[ii] , std::string(items[ii]))) ; - } + std::ostringstream index_string ; + index_string << ii ; + typename STL::mapped_type mt ; + restore_stl(mt, object_name + "_" + var_name + "_data", index_string.str()) ; + in_map.insert( std::pair(keys[ii], mt)) ; + } delete_stl( in_map , object_name , var_name ) ; } return 0 ; } -template -int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_data_string(in_map , object_name , var_name) ; +template ::value && + is_stl_container::value >::type* > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return restore_map_stl_ik_sd(in_map , object_name , var_name) ; } -template -int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_data_string(in_map , object_name , var_name) ; +template ::value && + is_stl_container::value >::type* > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return restore_map_stl_ik_sd(in_map , object_name , var_name) ; } template -int restore_map_stl_strings(STL & in_map , std::string object_name , std::string var_name ) { +int restore_map_stl_sk_id(STL & in_map , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; REF2 * keys_ref , * items_ref ; - char ** keys ; - char ** items ; + std::string * keys ; + typename STL::mapped_type * items ; - //message_publish(1, "in specialized map template restore\n") ; + //message_publish(1, "in regular map template restore\n") ; - /* 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. This template only works for string map keys. - */ std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; - items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; + keys_ref = ref_attributes((char *)(object_name + "_" + var_name + "_keys").c_str()) ; + items_ref = ref_attributes((char *)(object_name + "_" + var_name + "_data").c_str()) ; if ( keys_ref != NULL && items_ref != NULL ) { in_map.clear() ; - keys = (char **)keys_ref->address ; - items = (char **)items_ref->address ; + keys = (std::string *)keys_ref->address ; + items = (typename STL::mapped_type *)items_ref->address ; cont_size = get_size((char *)keys) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_map.insert( std::pair(std::string(keys[ii]) , std::string(items[ii]))) ; - } + std::ostringstream index_string ; + index_string << ii ; + typename STL::key_type kt ; + restore_stl(kt, object_name + "_" + var_name + "_keys", index_string.str()) ; + in_map.insert( std::pair(kt, items[ii])) ; + } delete_stl( in_map , object_name , var_name ) ; } return 0 ; } -int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) ; -int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; - -#endif +template ::value && + !is_stl_container::value >::type* > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return restore_map_stl_sk_id(in_map , object_name , var_name) ; +} + +template ::value && + !is_stl_container::value >::type* > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return restore_map_stl_sk_id(in_map , object_name , var_name) ; +} + +template +int restore_map_stl_sk_sd(STL & in_map , std::string object_name , std::string var_name ) { + + unsigned int ii ; + unsigned int cont_size ; + + REF2 * keys_ref , * items_ref ; + std::string * keys ; + std::string * items ; + + //message_publish(1, "in regular map template restore\n") ; + + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + keys_ref = ref_attributes((char *)(object_name + "_" + var_name + "_keys").c_str()) ; + items_ref = ref_attributes((char *)(object_name + "_" + var_name + "_data").c_str()) ; + + if ( keys_ref != NULL && items_ref != NULL ) { + in_map.clear() ; + keys = (std::string *)keys_ref->address ; + items = (std::string *)items_ref->address ; + cont_size = get_size((char *)keys) ; + + for ( ii = 0 ; ii < cont_size ; ii++ ) { + std::ostringstream index_string ; + index_string << ii ; + + typename STL::key_type kt ; + restore_stl(kt, object_name + "_" + var_name + "_keys", index_string.str()) ; + + typename STL::mapped_type mt ; + restore_stl(mt, object_name + "_" + var_name + "_data", index_string.str()) ; + + in_map.insert( std::pair(kt, mt)) ; + } + delete_stl( in_map , object_name , var_name ) ; + } + return 0 ; +} + +template ::value && + is_stl_container::value >::type* > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return restore_map_stl_sk_sd(in_map , object_name , var_name) ; +} + +template ::value && + is_stl_container::value >::type* > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return restore_map_stl_sk_sd(in_map , object_name , var_name) ; +} #endif diff --git a/include/trick/checkpoint_pair.hh b/include/trick/checkpoint_pair.hh index ad75230e..a6b8b0a5 100644 --- a/include/trick/checkpoint_pair.hh +++ b/include/trick/checkpoint_pair.hh @@ -7,193 +7,311 @@ #define CHECKPOINT_PAIR_HH #include +#include #include #include #include +#include +#include #ifdef __GNUC__ #include #endif +#include "checkpoint_is_stl_container.hh" +#include "checkpoint_fwd_declare.hh" #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" -#ifndef TRICK_ICG -template -int delete_stl(std::pair & in_stl __attribute__ ((unused)) , std::string object_name , std::string var_name ) { +// intrinsic first , intrinsic second +template +int checkpoint_pair_if_is(std::pair & in_stl , std::string object_name , std::string var_name ) { + + std::ostringstream var_declare ; + int status ; + + FIRST * first = nullptr ; + SECOND * second = nullptr ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + var_declare << abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status ) << " " + << object_name << "_" << var_name << "_first[1]" ; + first = (FIRST *)TMM_declare_var_s(var_declare.str().c_str()) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; + first[0] = in_stl.first ; + + var_declare.str("") ; + var_declare.clear() ; + var_declare << abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status ) << " " + << object_name << "_" << var_name << "_second[1]" ; + second = (SECOND *)TMM_declare_var_s(var_declare.str().c_str()) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; + second[0] = in_stl.second ; + + return 0 ; +} + +template ::value && + !is_stl_container::value >::type* > +int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { + return checkpoint_pair_if_is( in_pair, object_name, var_name ) ; +} + +// intrinsic first , STL second +template +int checkpoint_pair_if_ss(std::pair & in_stl , std::string object_name , std::string var_name ) { + + std::ostringstream var_declare ; + int status ; + + FIRST * first = nullptr ; + std::string * second = nullptr ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + var_declare << abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status ) << " " + << object_name << "_" << var_name << "_first[1]" ; + first = (FIRST *)TMM_declare_var_s(var_declare.str().c_str()) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; + first[0] = in_stl.first ; + + var_declare.str("") ; + var_declare.clear() ; + var_declare << "std::string " + << object_name << "_" << var_name << "_second[1]" ; + second = (std::string *)TMM_declare_var_s(var_declare.str().c_str()) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; + checkpoint_stl( in_stl.second , object_name + "_" + var_name , "second" ) ; + + return 0 ; +} + +template ::value && + is_stl_container::value >::type* > +int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { + return checkpoint_pair_if_ss( in_pair, object_name, var_name ) ; +} + +// STL first , intrinsic second +template +int checkpoint_pair_sf_is(std::pair & in_stl , std::string object_name , std::string var_name ) { + + std::ostringstream var_declare ; + int status ; + + std::string * first = nullptr ; + SECOND * second = nullptr ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + var_declare << "std::string " + << object_name << "_" << var_name << "_first[1]" ; + first = (std::string *)TMM_declare_var_s(var_declare.str().c_str()) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; + checkpoint_stl( in_stl.first , object_name + "_" + var_name , "first" ) ; + + var_declare.str("") ; + var_declare.clear() ; + var_declare << abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status ) << " " + << object_name << "_" << var_name << "_second[1]" ; + second = (SECOND *)TMM_declare_var_s(var_declare.str().c_str()) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; + second[0] = in_stl.second ; + + return 0 ; +} + +template ::value && + !is_stl_container::value >::type* > +int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { + return checkpoint_pair_sf_is( in_pair, object_name, var_name ) ; +} + +// STL first , STL second +template +int checkpoint_pair_sf_ss(std::pair & in_stl , std::string object_name , std::string var_name ) { + + std::ostringstream var_declare ; + int status ; + + std::string * first = nullptr ; + std::string * second = nullptr ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + var_declare << "std::string " + << object_name << "_" << var_name << "_first[1]" ; + first = (std::string *)TMM_declare_var_s(var_declare.str().c_str()) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; + checkpoint_stl( in_stl.first , object_name + "_" + var_name , "first" ) ; + + var_declare.str("") ; + var_declare.clear() ; + var_declare << "std::string " + << object_name << "_" << var_name << "_second[1]" ; + second = (std::string *)TMM_declare_var_s(var_declare.str().c_str()) ; + TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; + checkpoint_stl( in_stl.second , object_name + "_" + var_name , "second" ) ; + + return 0 ; +} + +template ::value && + is_stl_container::value >::type* > +int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { + return checkpoint_pair_sf_ss( in_pair, object_name, var_name ) ; +} + +/* =================================================================================================*/ + +template +int delete_stl(std::pair & in_stl __attribute__ ((unused)) , std::string object_name , std::string var_name ) { std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); REF2 * items_ref ; - items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_first")).c_str()) ; + items_ref = ref_attributes((char *)(object_name + "_" + var_name + "_first").c_str()) ; if ( items_ref != NULL ) { - TMM_delete_var_n((object_name + std::string("_") + var_name + std::string("_first")).c_str() ) ; - TMM_delete_var_n((object_name + std::string("_") + var_name + std::string("_second")).c_str() ) ; + TMM_delete_var_n((object_name + "_" + var_name + "_first").c_str() ) ; + TMM_delete_var_n((object_name + "_" + var_name + "_second").c_str() ) ; free(items_ref) ; } return 0 ; } -template -int checkpoint_stl(std::pair & in_stl , std::string object_name , std::string var_name ) { - - char var_declare[128] ; - int status ; - - FIRST_TYPE * first ; - SECOND_TYPE * second ; - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - - sprintf(var_declare, "%s %s_%s_first[1]" , - abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str()) ; - first = (FIRST_TYPE *)TMM_declare_var_s(var_declare) ; - TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; - - sprintf(var_declare, "%s %s_%s_second[1]" , - abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str()) ; - second = (SECOND_TYPE *)TMM_declare_var_s(var_declare) ; - TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; - - first[0] = in_stl.first ; - second[0] = in_stl.second ; - - return 0 ; -} - -template -int checkpoint_stl(std::pair & in_stl , std::string object_name , std::string var_name ) { - - char var_declare[128] ; - int status ; - - FIRST_TYPE * first ; - char ** second ; - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - - sprintf(var_declare, "%s %s_%s_first[1]" , - abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str()) ; - first = (FIRST_TYPE *)TMM_declare_var_s(var_declare) ; - TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; - - sprintf(var_declare, "char * %s_%s_second[1]" , object_name.c_str(), var_name.c_str()) ; - second = (char **)TMM_declare_var_s(var_declare) ; - TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; - - first[0] = in_stl.first ; - second[0] = (char *)(in_stl.second.c_str()) ; - - return 0 ; -} - -template -int checkpoint_stl(std::pair & in_stl , std::string object_name , std::string var_name ) { - - char var_declare[128] ; - int status ; - - char ** first ; - SECOND_TYPE * second ; - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - - sprintf(var_declare, "char * %s_%s_first[1]", object_name.c_str(), var_name.c_str()) ; - first = (char **)TMM_declare_var_s(var_declare) ; - TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; - - sprintf(var_declare, "%s %s_%s_second[1]" , - abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str()) ; - second = (SECOND_TYPE *)TMM_declare_var_s(var_declare) ; - TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; - - first[0] = (char *)(in_stl.first.c_str()) ; - second[0] = in_stl.second ; - - return 0 ; -} - -template -int restore_stl(std::pair & in_stl , std::string object_name , std::string var_name ) { +/* =================================================================================================*/ +// intrinsic first, intrinsic second +template +int restore_pair_if_is(std::pair & in_stl , std::string object_name , std::string var_name ) { REF2 * first_ref ; REF2 * second_ref ; - FIRST_TYPE * first ; - SECOND_TYPE * second ; + FIRST * first ; + SECOND * second ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); //message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; - first_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_first")).c_str()) ; - second_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_second")).c_str()) ; + first_ref = ref_attributes((char *)(object_name + "_" + var_name + "_first").c_str()) ; + second_ref = ref_attributes((char *)(object_name + "_" + var_name + "_second").c_str()) ; if ( first_ref != NULL && second_ref != NULL ) { - first = (FIRST_TYPE *)first_ref->address ; - second = (SECOND_TYPE *)second_ref->address ; + first = (FIRST *)first_ref->address ; + second = (SECOND *)second_ref->address ; in_stl.first = first[0] ; in_stl.second = second[0] ; delete_stl( in_stl , object_name , var_name ) ; - } + } return 0 ; } -template -int restore_stl(std::pair & in_stl , std::string object_name , std::string var_name ) { +template ::value && + !is_stl_container::value >::type* > +int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { + return restore_pair_if_is( in_pair, object_name, var_name ) ; +} + +// intrinsic first, STL second +template +int restore_pair_if_ss(std::pair & in_stl , std::string object_name , std::string var_name ) { REF2 * first_ref ; REF2 * second_ref ; - FIRST_TYPE * first ; - char ** second ; - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + FIRST * first ; + std::string * second ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); //message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; - first_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_first")).c_str()) ; - second_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_second")).c_str()) ; + first_ref = ref_attributes((char *)(object_name + "_" + var_name + "_first").c_str()) ; + second_ref = ref_attributes((char *)(object_name + "_" + var_name + "_second").c_str()) ; if ( first_ref != NULL && second_ref != NULL ) { - first = (FIRST_TYPE *)first_ref->address ; - second = (char **)second_ref->address ; + first = (FIRST *)first_ref->address ; + second = (std::string *)second_ref->address ; in_stl.first = first[0] ; - in_stl.second = std::string(second[0]) ; + restore_stl( in_stl.second , object_name + "_" + var_name , "second" ) ; delete_stl( in_stl , object_name , var_name ) ; - } + } return 0 ; } -template -int restore_stl(std::pair & in_stl , std::string object_name , std::string var_name ) { +template ::value && + is_stl_container::value >::type* > +int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { + return restore_pair_if_ss( in_pair, object_name, var_name ) ; +} + +// STL first, intrinsic second +template +int restore_pair_sf_is(std::pair & in_stl , std::string object_name , std::string var_name ) { REF2 * first_ref ; REF2 * second_ref ; - char ** first ; - SECOND_TYPE * second ; - //message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + std::string * first ; + SECOND * second ; - first_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_first")).c_str()) ; - second_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_second")).c_str()) ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + //message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; + + first_ref = ref_attributes((char *)(object_name + "_" + var_name + "_first").c_str()) ; + second_ref = ref_attributes((char *)(object_name + "_" + var_name + "_second").c_str()) ; if ( first_ref != NULL && second_ref != NULL ) { - first = (char **)first_ref->address ; - second = (SECOND_TYPE *)second_ref->address ; + first = (std::string *)first_ref->address ; + second = (SECOND *)second_ref->address ; - in_stl.first = std::string(first[0]) ; + restore_stl( in_stl.first , object_name + "_" + var_name , "first" ) ; in_stl.second = second[0] ; delete_stl( in_stl , object_name , var_name ) ; - } + } return 0 ; } -// Specialized routines for strings. -int checkpoint_stl(std::pair & in_stl , std::string object_name , std::string var_name ) ; -int restore_stl(std::pair & in_stl , std::string object_name , std::string var_name ) ; - -#endif +template ::value && + !is_stl_container::value >::type* > +int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { + return restore_pair_sf_is( in_pair, object_name, var_name ) ; +} + +// STL first, STL second +template +int restore_pair_sf_ss(std::pair & in_stl , std::string object_name , std::string var_name ) { + + REF2 * first_ref ; + REF2 * second_ref ; + + std::string * first ; + std::string * second ; + + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + //message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; + + first_ref = ref_attributes((char *)(object_name + "_" + var_name + "_first").c_str()) ; + second_ref = ref_attributes((char *)(object_name + "_" + var_name + "_second").c_str()) ; + + if ( first_ref != NULL && second_ref != NULL ) { + first = (std::string *)first_ref->address ; + second = (std::string *)second_ref->address ; + + restore_stl( in_stl.first , object_name + "_" + var_name , "first" ) ; + restore_stl( in_stl.second , object_name + "_" + var_name , "second" ) ; + + delete_stl( in_stl , object_name , var_name ) ; + } + + return 0 ; +} + +template ::value && + is_stl_container::value >::type* > +int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { + return restore_pair_sf_ss( in_pair, object_name, var_name ) ; +} #endif diff --git a/include/trick/checkpoint_sequence_stl.hh b/include/trick/checkpoint_sequence_stl.hh index 6e353daa..ba29e618 100644 --- a/include/trick/checkpoint_sequence_stl.hh +++ b/include/trick/checkpoint_sequence_stl.hh @@ -13,77 +13,41 @@ #include #include #include - -#include -#include -#include - +#include +#include #ifdef __GNUC__ #include #endif -#include - +#include "checkpoint_is_stl_container.hh" +#include "checkpoint_fwd_declare.hh" #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" -#include "checkpoint_is_stl_container.hh" /* =================================================================================================*/ -// Forward declare all of the specialized templates that can be used in checkpoint_sequence_stl_stl -template ::value>::type* = nullptr > -int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; -// End forward declarations. - template int checkpoint_sequence_stl_intrinsic(STL & 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 ; typename STL::value_type * items = NULL ; typename STL::iterator it ; typename STL::iterator end ; - message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; + //message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; 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 = (typename STL::value_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 = (typename STL::value_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_SEQUENCE_STL with %s\n", var_declare) ; @@ -97,45 +61,14 @@ int checkpoint_sequence_stl_intrinsic(STL & in_stl , std::string object_name , s return 0 ; } -template -int checkpoint_sequence_stl_string(STL & in_stl , std::string object_name , std::string var_name ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - const char ** items ; - typename STL::iterator it ; - typename STL::iterator end ; - - - 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, "char * %s_%s[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; - items = (const char **)TMM_declare_var_s(var_declare) ; - TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; - //message_publish(1, "CHECKPOINT_SEQUENCE_STL_STRING with %s\n", var_declare) ; - - /* copy the contents of the vector */ - for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { - items[ii] = it->c_str() ; - } - } - - return 0 ; -} - template int checkpoint_sequence_stl_stl(STL & 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 ; - const char ** items ; + std::string * items ; typename STL::iterator it ; typename STL::iterator end ; @@ -143,28 +76,25 @@ int checkpoint_sequence_stl_stl(STL & in_stl , std::string object_name , std::st cont_size = in_stl.size() ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; + //message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; if ( cont_size > 0 ) { - sprintf(var_declare, "char * %s_%s[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; - items = (const char **)TMM_declare_var_s(var_declare) ; + 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_SEQUENCE_STL_STL with %s\n", var_declare) ; + //message_publish(1, "CHECKPOINT_SEQUENCE_STL_STL with %s\n", var_declare.str().c_str()) ; /* create the names of the sub stl checkpoint names we're going to be using */ for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { - char sub_elements[128] ; - sprintf(sub_elements, "%s_%s_%d", object_name.c_str(), var_name.c_str() , ii) ; - items[ii] = TMM_strdup(sub_elements) ; - sprintf(sub_elements, "%s_%s_%d_name", object_name.c_str(), var_name.c_str() , ii) ; - set_alloc_name_at((void *)items[ii], sub_elements) ; - TMM_add_checkpoint_alloc_dependency(sub_elements) ; + std::ostringstream sub_elements ; + sub_elements << object_name << "_" << var_name << "_" << ii ; + items[ii] = sub_elements.str() ; - char index_string[16] ; - sprintf(index_string, "%d", ii) ; - message_publish(1, "recursive call to checkpoint_stl %s\n", __PRETTY_FUNCTION__) ; - checkpoint_stl( (*it) , object_name + "_" + var_name , std::string(index_string) ) ; + std::ostringstream index_string ; + index_string << ii ; + //message_publish(1, "recursive call to checkpoint_stl %s\n", __PRETTY_FUNCTION__) ; + checkpoint_stl( (*it) , object_name + "_" + var_name , index_string.str() ) ; } } return 0 ; @@ -185,9 +115,6 @@ int checkpoint_stl(std::vector & in_stl , std::string object_name , s return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } -// Specialized routines for strings. found in checkpoint_sequence.cpp -int checkpoint_stl(std::vector & in_vector , std::string object_name , std::string var_name ) ; - // ----------- // std::list @@ -202,9 +129,6 @@ int checkpoint_stl(std::list & in_stl , std::string object_name , std return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } -// Specialized routines for strings. found in checkpoint_sequence.cpp -int checkpoint_stl(std::list & in_list , std::string object_name , std::string var_name ) ; - // ----------- // std::deque @@ -219,9 +143,6 @@ int checkpoint_stl(std::deque & in_stl , std::string object_name , st return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } -// Specialized routines for strings. found in checkpoint_sequence.cpp -int checkpoint_stl(std::deque & in_vector , std::string object_name , std::string var_name ) ; - // ----------- // std::set @@ -236,9 +157,6 @@ int checkpoint_stl(std::set & in_stl , std::string object_name , std: return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } -// Specialized routines for strings. found in checkpoint_sequence.cpp -int checkpoint_stl(std::set & in_vector , std::string object_name , std::string var_name ) ; - // ----------- // std::multiset @@ -253,9 +171,6 @@ int checkpoint_stl(std::multiset & in_stl , std::string object_name , return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } -// Specialized routines for strings. found in checkpoint_sequence.cpp -int checkpoint_stl(std::multiset & in_vector , std::string object_name , std::string var_name ) ; - /* =================================================================================================*/ template @@ -298,38 +213,6 @@ int delete_stl(std::multiset & in_stl , std::string object_name , std /* =================================================================================================*/ -// Forward declare all of the specialized templates that can be used in checkpoint_sequence_stl_stl -template ::value>::type* = nullptr > -int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; - -template ::value>::type* = nullptr > -int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; -// End forward declarations. - /* 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 @@ -347,7 +230,6 @@ int restore_sequence_stl_intrinsic(STL & in_stl , std::string object_name , std: //message_publish(1, "RESTORE_SEQUENCE_STL %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 ) { @@ -364,35 +246,6 @@ int restore_sequence_stl_intrinsic(STL & in_stl , std::string object_name , std: return 0 ; } -template -int restore_sequence_stl_string(STL & 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, "in specialized vector template restore\n") ; - - - items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; - - if ( items_ref != NULL ) { - in_stl.clear() ; - items = (char **)items_ref->address ; - cont_size = get_size((char *)items) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_stl.insert( in_stl.end(), items[ii] ) ; - } - delete_stl( in_stl , object_name , var_name ) ; - } - - return 0 ; -} - template int restore_sequence_stl_stl(STL & in_stl , std::string object_name , std::string var_name ) { @@ -400,7 +253,7 @@ int restore_sequence_stl_stl(STL & in_stl , std::string object_name , std::strin unsigned int cont_size ; REF2 * items_ref ; - char ** items ; + std::string * items ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); //message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; @@ -409,14 +262,14 @@ int restore_sequence_stl_stl(STL & in_stl , std::string object_name , std::strin if ( items_ref != NULL ) { in_stl.clear() ; - items = (char **)items_ref->address ; + items = (std::string *)items_ref->address ; cont_size = get_size((char *)items) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { typename STL::value_type vt ; - char index_string[16] ; - sprintf(index_string, "%d", ii) ; - restore_stl(vt, object_name + "_" + var_name , std::string(index_string)) ; + std::ostringstream index_string ; + index_string << ii ; + restore_stl(vt, object_name + "_" + var_name , index_string.str()) ; in_stl.insert( in_stl.end(), vt ) ; } delete_stl( in_stl , object_name , var_name ) ; @@ -440,9 +293,6 @@ int restore_stl(std::vector & in_stl , std::string object_name , std: return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } -// Specialized routines for strings. -int restore_stl(std::vector & in_vector , std::string object_name , std::string var_name ) ; - // ----------- // std::list @@ -458,8 +308,6 @@ int restore_stl(std::list & in_stl , std::string object_name , std::s return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } -int restore_stl(std::list & in_list , std::string object_name , std::string var_name ) ; - // ----------- // std::deque @@ -475,8 +323,6 @@ int restore_stl(std::deque & in_stl , std::string object_name , std:: return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } -int restore_stl(std::deque & in_deque , std::string object_name , std::string var_name ) ; - // ----------- // std::set @@ -492,8 +338,6 @@ int restore_stl(std::set & in_stl , std::string object_name , std::st return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } -int restore_stl(std::set & in_set , std::string object_name , std::string var_name ) ; - // ----------- // std::multiset @@ -509,7 +353,4 @@ int restore_stl(std::multiset & in_stl , std::string object_name , st return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; } -// Specialized routines for strings. -int restore_stl(std::multiset & in_multiset , std::string object_name , std::string var_name ) ; - #endif diff --git a/test/SIM_stls/RUN_test/input.py b/test/SIM_stls/RUN_test/input.py index 458f7730..d49bbf77 100644 --- a/test/SIM_stls/RUN_test/input.py +++ b/test/SIM_stls/RUN_test/input.py @@ -3,9 +3,9 @@ def main(): #trick.echo_jobs_on() - #trick.sim_control_panel_set_enabled(True) - #trick.real_time_enable() - #trick.itimer_enable() + trick.sim_control_panel_set_enabled(True) + trick.real_time_enable() + trick.itimer_enable() trick.checkpoint_pre_init(True) #trick.checkpoint_post_init(True) diff --git a/test/SIM_stls/models/STLCheckpoint.cpp b/test/SIM_stls/models/STLCheckpoint.cpp index 73a2bd35..84c3fff3 100644 --- a/test/SIM_stls/models/STLCheckpoint.cpp +++ b/test/SIM_stls/models/STLCheckpoint.cpp @@ -6,363 +6,413 @@ STLCheckpoint::STLCheckpoint() { - my_double_map[11.1] = 111.1 ; - my_double_map[22.2] = 222.2 ; - my_double_map[33.3] = 333.3 ; + double_map[11.1] = 111.1 ; + double_map[22.2] = 222.2 ; + double_map[33.3] = 333.3 ; - my_string_key_map[std::string("one")] = 1 ; - my_string_key_map[std::string("two")] = 2 ; - my_string_key_map[std::string("three")] = 3 ; + string_key_map[std::string("one")] = 1 ; + string_key_map[std::string("two")] = 2 ; string_key_map[std::string("three")] = 3 ; - my_string_data_map[4] = std::string("vier") ; - my_string_data_map[5] = std::string("fumf") ; - my_string_data_map[6] = std::string("sechs") ; + string_data_map[4] = std::string("vier") ; + string_data_map[5] = std::string("fumf") ; + string_data_map[6] = std::string("sechs") ; - my_string_map[std::string("mother")] = std::string("Marge") ; - my_string_map[std::string("father")] = std::string("Homer") ; - my_string_map[std::string("son")] = std::string("Bart") ; + string_map[std::string("mother")] = std::string("Marge") ; + string_map[std::string("father")] = std::string("Homer") ; + string_map[std::string("son")] = std::string("Bart") ; - my_int_multimap.insert(std::pair(11,111)) ; - my_int_multimap.insert(std::pair(22,222)) ; - my_int_multimap.insert(std::pair(33,333)) ; - my_int_multimap.insert(std::pair(11,111)) ; - my_int_multimap.insert(std::pair(22,222)) ; - my_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)) ; + int_multimap.insert(std::pair(11,111)) ; + int_multimap.insert(std::pair(22,222)) ; + int_multimap.insert(std::pair(33,333)) ; - my_string_key_multimap.insert(std::pair("one", 1)) ; - my_string_key_multimap.insert(std::pair("two", 2)) ; - my_string_key_multimap.insert(std::pair("three", 3)) ; - my_string_key_multimap.insert(std::pair("one", 1)) ; - my_string_key_multimap.insert(std::pair("two", 2)) ; - my_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_key_multimap.insert(std::pair("one", 1)) ; + string_key_multimap.insert(std::pair("two", 2)) ; + string_key_multimap.insert(std::pair("three", 3)) ; - my_string_data_multimap.insert(std::pair(4, "vier")) ; - my_string_data_multimap.insert(std::pair(5, "fumf")) ; - my_string_data_multimap.insert(std::pair(6, "sechs")) ; - my_string_data_multimap.insert(std::pair(4, "four")) ; - my_string_data_multimap.insert(std::pair(5, "five")) ; - my_string_data_multimap.insert(std::pair(6, "six")) ; + 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")) ; - my_string_multimap.insert(std::pair("mother","Marge")) ; - my_string_multimap.insert(std::pair("father","Homer")) ; - my_string_multimap.insert(std::pair("mother","Lois")) ; - my_string_multimap.insert(std::pair("father","Meg")) ; + 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")) ; - my_double_vector.push_back(1.0) ; - my_double_vector.push_back(2.0) ; - my_double_vector.push_back(3.0) ; + double_vector.push_back(1.0) ; + double_vector.push_back(2.0) ; + double_vector.push_back(3.0) ; - my_string_vector.push_back("I") ; - my_string_vector.push_back("was") ; - my_string_vector.push_back("here") ; + string_vector.push_back("I") ; + string_vector.push_back("was") ; + string_vector.push_back("here") ; - my_short_list.push_back(300) ; - my_short_list.push_back(301) ; - my_short_list.push_back(302) ; + short_list.push_back(300) ; + short_list.push_back(301) ; + short_list.push_back(302) ; - my_string_list.push_back("I") ; - my_string_list.push_back("was") ; - my_string_list.push_back("there") ; + string_list.push_back("I") ; + string_list.push_back("was") ; + string_list.push_back("there") ; - my_float_deque.push_back(12.3) ; - my_float_deque.push_back(45.6) ; - my_float_deque.push_back(78.9) ; + float_deque.push_back(12.3) ; + float_deque.push_back(45.6) ; + float_deque.push_back(78.9) ; - my_string_deque.push_back("meow") ; - my_string_deque.push_back("bark") ; - my_string_deque.push_back("quack") ; + string_deque.push_back("meow") ; + string_deque.push_back("bark") ; + string_deque.push_back("quack") ; - my_int_set.insert(8) ; - my_int_set.insert(4) ; - my_int_set.insert(2) ; - my_int_set.insert(1) ; + int_set.insert(8) ; + int_set.insert(4) ; + int_set.insert(2) ; + int_set.insert(1) ; - my_string_set.insert("e") ; - my_string_set.insert("a") ; - my_string_set.insert("d") ; + string_set.insert("e") ; + string_set.insert("a") ; + string_set.insert("d") ; - my_long_multiset.insert(8) ; - my_long_multiset.insert(4) ; - my_long_multiset.insert(4) ; - my_long_multiset.insert(2) ; - my_long_multiset.insert(1) ; + long_multiset.insert(8) ; + long_multiset.insert(4) ; + long_multiset.insert(4) ; + long_multiset.insert(2) ; + long_multiset.insert(1) ; - my_string_multiset.insert("e") ; - my_string_multiset.insert("a") ; - my_string_multiset.insert("d") ; - my_string_multiset.insert("e") ; - my_string_multiset.insert("a") ; - my_string_multiset.insert("d") ; + string_multiset.insert("e") ; + string_multiset.insert("a") ; + string_multiset.insert("d") ; + string_multiset.insert("e") ; + string_multiset.insert("a") ; + string_multiset.insert("d") ; - my_uint_stack.push(10) ; - my_uint_stack.push(20) ; - my_uint_stack.push(30) ; - my_uint_stack.push(40) ; + uint_stack.push(10) ; + uint_stack.push(20) ; + uint_stack.push(30) ; + uint_stack.push(40) ; - my_string_stack.push("abc I") ; - my_string_stack.push("abc want the one") ; - my_string_stack.push("abc with the bigger") ; - my_string_stack.push("abc Gee Bees") ; + 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") ; - my_int_queue.push(10) ; - my_int_queue.push(20) ; - my_int_queue.push(30) ; - my_int_queue.push(40) ; + int_queue.push(10) ; + int_queue.push(20) ; + int_queue.push(30) ; + int_queue.push(40) ; - my_string_queue.push("abc I") ; - my_string_queue.push("abc want") ; - my_string_queue.push("abc an") ; - my_string_queue.push("abc iPhone 4") ; + string_queue.push("abc I") ; + string_queue.push("abc want") ; + string_queue.push("abc an") ; + string_queue.push("abc iPhone 4") ; - my_int_priority_queue.push(30) ; - my_int_priority_queue.push(20) ; - my_int_priority_queue.push(40) ; - my_int_priority_queue.push(10) ; + int_priority_queue.push(30) ; + int_priority_queue.push(20) ; + int_priority_queue.push(40) ; + int_priority_queue.push(10) ; - my_string_priority_queue.push("abc I") ; - my_string_priority_queue.push("abc want") ; - my_string_priority_queue.push("abc an") ; - my_string_priority_queue.push("abc iPhone 4") ; + 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") ; - my_int_pair.first = 1 ; - my_int_pair.second = 2 ; + int_pair.first = 1 ; + int_pair.second = 2 ; - my_string_first_pair.first = "abc string first" ; - my_string_first_pair.second = 2 ; + string_first_pair.first = "abc string first" ; + string_first_pair.second = 2 ; - my_string_second_pair.first = 2 ; - my_string_second_pair.second = "abc string second" ; + string_second_pair.first = 2 ; + string_second_pair.second = "abc string second" ; - my_string_pair.first = "abc pair first string" ; - my_string_pair.second = "abc pair second string" ; + string_pair.first = "abc pair first string" ; + string_pair.second = "abc pair second string" ; return ; } STLCheckpoint::STLCheckpoint(std::string in_name) : - my_vector_vector_double(4, std::vector(3)) , - my_vector_vector_vector_double(5, std::vector >(4, std::vector(3))) + vector_vector_double(4, std::vector(3)) , + vector_vector_vector_double(5, std::vector >(4, std::vector(3))) { name = in_name ; - my_double_map[44.4] = 444.4 ; - my_double_map[55.5] = 555.5 ; - my_double_map[66.6] = 666.6 ; + double_map[44.4] = 444.4 ; + double_map[55.5] = 555.5 ; + double_map[66.6] = 666.6 ; - my_string_key_map[std::string("four")] = 4 ; - my_string_key_map[std::string("five")] = 5 ; - my_string_key_map[std::string("six")] = 6 ; + string_key_map[std::string("four")] = 4 ; + string_key_map[std::string("five")] = 5 ; + string_key_map[std::string("six")] = 6 ; - my_string_data_map[7] = std::string("seiben") ; - my_string_data_map[8] = std::string("acht") ; - my_string_data_map[9] = std::string("neun") ; + string_data_map[7] = std::string("seiben") ; + string_data_map[8] = std::string("acht") ; + string_data_map[9] = std::string("neun") ; - my_string_map[std::string("sister")] = std::string("Lisa") ; - my_string_map[std::string("dog")] = std::string("Santa's Little Helper") ; + std::vector< int > v ; + v.push_back(2) ; + v.push_back(4) ; + v.push_back(6) ; + v.push_back(8) ; + map_int_vector_int[1] = v ; - my_int_multimap.insert(std::pair(44,444)) ; - my_int_multimap.insert(std::pair(55,555)) ; - my_int_multimap.insert(std::pair(66,666)) ; - my_int_multimap.insert(std::pair(44,444)) ; - my_int_multimap.insert(std::pair(55,555)) ; - my_int_multimap.insert(std::pair(66,666)) ; + std::pair< int , int > p ; + p.first = 24 ; + p.second = 30 ; + gcd[p] = 6 ; - my_string_key_multimap.insert(std::pair("four", 4)) ; - my_string_key_multimap.insert(std::pair("five", 5)) ; - my_string_key_multimap.insert(std::pair("six", 6)) ; - my_string_key_multimap.insert(std::pair("four", 44)) ; - my_string_key_multimap.insert(std::pair("five", 55)) ; - my_string_key_multimap.insert(std::pair("six", 66)) ; + p.first = 50 ; + p.second = 60 ; + std::pair< int , int > q ; + q.first = 70 ; + q.second = 80 ; + map_pair_pair[p] = q ; - my_string_data_multimap.insert(std::pair(7, "seiben")) ; - my_string_data_multimap.insert(std::pair(8, "acht")) ; - my_string_data_multimap.insert(std::pair(9, "neun")) ; - my_string_data_multimap.insert(std::pair(7, "seven")) ; - my_string_data_multimap.insert(std::pair(8, "eight")) ; - my_string_data_multimap.insert(std::pair(9, "nine")) ; + p.first = 3 ; + p.second = 5 ; + v.clear() ; + v.push_back(15) ; + v.push_back(30) ; + v.push_back(45) ; + v.push_back(60) ; + common_multiples.insert(std::pair< std::pair< int, int >, std::vector< int > >(p,v)) ; - my_string_multimap.insert(std::pair("sister","Lisa")) ; - my_string_multimap.insert(std::pair("dog","Santa's Little Helper")) ; - my_string_multimap.insert(std::pair("sister","Meg")) ; - my_string_multimap.insert(std::pair("dog","Brian")) ; + string_map[std::string("sister")] = std::string("Lisa") ; + string_map[std::string("dog")] = std::string("Santa's Little Helper") ; - my_double_vector.push_back(4.0) ; - my_double_vector.push_back(5.0) ; - my_double_vector.push_back(6.0) ; + int_multimap.insert(std::pair(44,444)) ; + int_multimap.insert(std::pair(55,555)) ; + int_multimap.insert(std::pair(66,666)) ; + int_multimap.insert(std::pair(44,444)) ; + int_multimap.insert(std::pair(55,555)) ; + int_multimap.insert(std::pair(66,666)) ; - my_string_vector.push_back("It") ; - my_string_vector.push_back("has") ; - my_string_vector.push_back("the") ; - my_string_vector.push_back("Wi-Fies") ; + string_key_multimap.insert(std::pair("four", 4)) ; + string_key_multimap.insert(std::pair("five", 5)) ; + string_key_multimap.insert(std::pair("six", 6)) ; + string_key_multimap.insert(std::pair("four", 44)) ; + string_key_multimap.insert(std::pair("five", 55)) ; + string_key_multimap.insert(std::pair("six", 66)) ; - my_short_list.push_back(400) ; - my_short_list.push_back(401) ; - my_short_list.push_back(402) ; + string_data_multimap.insert(std::pair(7, "seiben")) ; + string_data_multimap.insert(std::pair(8, "acht")) ; + string_data_multimap.insert(std::pair(9, "neun")) ; + string_data_multimap.insert(std::pair(7, "seven")) ; + string_data_multimap.insert(std::pair(8, "eight")) ; + string_data_multimap.insert(std::pair(9, "nine")) ; - my_string_list.push_back("I") ; - my_string_list.push_back("don't") ; - my_string_list.push_back("care") ; + string_multimap.insert(std::pair("sister","Lisa")) ; + string_multimap.insert(std::pair("dog","Santa's Little Helper")) ; + string_multimap.insert(std::pair("sister","Meg")) ; + string_multimap.insert(std::pair("dog","Brian")) ; - my_float_deque.push_back(98.7) ; - my_float_deque.push_back(65.4) ; - my_float_deque.push_back(32.1) ; + double_vector.push_back(4.0) ; + double_vector.push_back(5.0) ; + double_vector.push_back(6.0) ; - my_string_deque.push_back("Welcome") ; - my_string_deque.push_back("to") ; - my_string_deque.push_back("PhoneMart") ; + string_vector.push_back("It") ; + string_vector.push_back("has") ; + string_vector.push_back("the") ; + string_vector.push_back("Wi-Fies") ; - my_int_set.insert(8000) ; - my_int_set.insert(4000) ; - my_int_set.insert(2000) ; - my_int_set.insert(1000) ; + short_list.push_back(400) ; + short_list.push_back(401) ; + short_list.push_back(402) ; - my_string_set.insert("efg") ; - my_string_set.insert("abc") ; - my_string_set.insert("def") ; + string_list.push_back("I") ; + string_list.push_back("don't") ; + string_list.push_back("care") ; - my_long_multiset.insert(8000) ; - my_long_multiset.insert(4000) ; - my_long_multiset.insert(4000) ; - my_long_multiset.insert(2000) ; - my_long_multiset.insert(1000) ; + float_deque.push_back(98.7) ; + float_deque.push_back(65.4) ; + float_deque.push_back(32.1) ; - my_string_multiset.insert("efg") ; - my_string_multiset.insert("abc") ; - my_string_multiset.insert("def") ; - my_string_multiset.insert("efg") ; - my_string_multiset.insert("abc") ; - my_string_multiset.insert("def") ; + string_deque.push_back("Welcome") ; + string_deque.push_back("to") ; + string_deque.push_back("PhoneMart") ; - my_uint_stack.push(1) ; - my_uint_stack.push(2) ; - my_uint_stack.push(3) ; - my_uint_stack.push(4) ; + int_set.insert(8000) ; + int_set.insert(4000) ; + int_set.insert(2000) ; + int_set.insert(1000) ; - my_string_stack.push("I") ; - my_string_stack.push("want the one") ; - my_string_stack.push("with the bigger") ; - my_string_stack.push("Gee Bees") ; + string_set.insert("efg") ; + string_set.insert("abc") ; + string_set.insert("def") ; - my_int_queue.push(1) ; - my_int_queue.push(2) ; - my_int_queue.push(3) ; - my_int_queue.push(4) ; + long_multiset.insert(8000) ; + long_multiset.insert(4000) ; + long_multiset.insert(4000) ; + long_multiset.insert(2000) ; + long_multiset.insert(1000) ; - my_string_queue.push("I") ; - my_string_queue.push("want") ; - my_string_queue.push("an") ; - my_string_queue.push("iPhone 4") ; + string_multiset.insert("efg") ; + string_multiset.insert("abc") ; + string_multiset.insert("def") ; + string_multiset.insert("efg") ; + string_multiset.insert("abc") ; + string_multiset.insert("def") ; - my_int_priority_queue.push(3) ; - my_int_priority_queue.push(2) ; - my_int_priority_queue.push(4) ; - my_int_priority_queue.push(1) ; + uint_stack.push(1) ; + uint_stack.push(2) ; + uint_stack.push(3) ; + uint_stack.push(4) ; - my_string_priority_queue.push("I") ; - my_string_priority_queue.push("want") ; - my_string_priority_queue.push("an") ; - my_string_priority_queue.push("iPhone 4") ; + string_stack.push("I") ; + string_stack.push("want the one") ; + string_stack.push("with the bigger") ; + string_stack.push("Gee Bees") ; - my_int_pair.first = 10 ; - my_int_pair.second = 20 ; + int_queue.push(1) ; + int_queue.push(2) ; + int_queue.push(3) ; + int_queue.push(4) ; - my_string_first_pair.first = "string first" ; - my_string_first_pair.second = 25 ; + string_queue.push("I") ; + string_queue.push("want") ; + string_queue.push("an") ; + string_queue.push("iPhone 4") ; - my_string_second_pair.first = 25 ; - my_string_second_pair.second = "string second" ; + int_priority_queue.push(3) ; + int_priority_queue.push(2) ; + int_priority_queue.push(4) ; + int_priority_queue.push(1) ; - my_string_pair.first = "pair first string" ; - my_string_pair.second = "pair second string" ; + string_priority_queue.push("I") ; + string_priority_queue.push("want") ; + string_priority_queue.push("an") ; + string_priority_queue.push("iPhone 4") ; - my_vector_vector_double[0][0] = 100 ; - my_vector_vector_double[0][1] = 101 ; - my_vector_vector_double[0][2] = 102 ; - my_vector_vector_double[1][0] = 103 ; - my_vector_vector_double[1][1] = 104 ; - my_vector_vector_double[1][2] = 105 ; - my_vector_vector_double[2][0] = 106 ; - my_vector_vector_double[2][1] = 107 ; - my_vector_vector_double[2][2] = 108 ; - my_vector_vector_double[3][0] = 109 ; - my_vector_vector_double[3][1] = 110 ; - my_vector_vector_double[3][2] = 111 ; + int_pair.first = 10 ; + int_pair.second = 20 ; - my_vector_vector_vector_double[0][0][0] = 0 ; - my_vector_vector_vector_double[0][0][1] = 1 ; - my_vector_vector_vector_double[0][0][2] = 2 ; - my_vector_vector_vector_double[0][1][0] = 3 ; - my_vector_vector_vector_double[0][1][1] = 4 ; - my_vector_vector_vector_double[0][1][2] = 5 ; - my_vector_vector_vector_double[0][2][0] = 6 ; - my_vector_vector_vector_double[0][2][1] = 7 ; - my_vector_vector_vector_double[0][2][2] = 8 ; - my_vector_vector_vector_double[0][3][0] = 9 ; - my_vector_vector_vector_double[0][3][1] = 10 ; - my_vector_vector_vector_double[0][3][2] = 11 ; + string_first_pair.first = "string first" ; + string_first_pair.second = 25 ; - my_vector_vector_vector_double[1][0][0] = 1000 ; - my_vector_vector_vector_double[1][0][1] = 1001 ; - my_vector_vector_vector_double[1][0][2] = 1002 ; - my_vector_vector_vector_double[1][1][0] = 1003 ; - my_vector_vector_vector_double[1][1][1] = 1004 ; - my_vector_vector_vector_double[1][1][2] = 1005 ; - my_vector_vector_vector_double[1][2][0] = 1006 ; - my_vector_vector_vector_double[1][2][1] = 1007 ; - my_vector_vector_vector_double[1][2][2] = 1008 ; - my_vector_vector_vector_double[1][3][0] = 1009 ; - my_vector_vector_vector_double[1][3][1] = 1010 ; - my_vector_vector_vector_double[1][3][2] = 1011 ; + string_second_pair.first = 25 ; + string_second_pair.second = "string second" ; - my_vector_vector_vector_double[2][0][0] = 2000 ; - my_vector_vector_vector_double[2][0][1] = 2001 ; - my_vector_vector_vector_double[2][0][2] = 2002 ; - my_vector_vector_vector_double[2][1][0] = 2003 ; - my_vector_vector_vector_double[2][1][1] = 2004 ; - my_vector_vector_vector_double[2][1][2] = 2005 ; - my_vector_vector_vector_double[2][2][0] = 2006 ; - my_vector_vector_vector_double[2][2][1] = 2007 ; - my_vector_vector_vector_double[2][2][2] = 2008 ; - my_vector_vector_vector_double[2][3][0] = 2009 ; - my_vector_vector_vector_double[2][3][1] = 2010 ; - my_vector_vector_vector_double[2][3][2] = 2011 ; + string_pair.first = "pair first string" ; + string_pair.second = "pair second string" ; - my_vector_vector_vector_double[3][0][0] = 3000 ; - my_vector_vector_vector_double[3][0][1] = 3001 ; - my_vector_vector_vector_double[3][0][2] = 3002 ; - my_vector_vector_vector_double[3][1][0] = 3003 ; - my_vector_vector_vector_double[3][1][1] = 3004 ; - my_vector_vector_vector_double[3][1][2] = 3005 ; - my_vector_vector_vector_double[3][2][0] = 3006 ; - my_vector_vector_vector_double[3][2][1] = 3007 ; - my_vector_vector_vector_double[3][2][2] = 3008 ; - my_vector_vector_vector_double[3][3][0] = 3009 ; - my_vector_vector_vector_double[3][3][1] = 3010 ; - my_vector_vector_vector_double[3][3][2] = 3011 ; + int_pair_int_int.first = 200 ; + p.first = 10 ; + p.second = 20 ; + int_pair_int_int.second = p ; - my_vector_vector_vector_double[4][0][0] = 4000 ; - my_vector_vector_vector_double[4][0][1] = 4001 ; - my_vector_vector_vector_double[4][0][2] = 4002 ; - my_vector_vector_vector_double[4][1][0] = 4003 ; - my_vector_vector_vector_double[4][1][1] = 4004 ; - my_vector_vector_vector_double[4][1][2] = 4005 ; - my_vector_vector_vector_double[4][2][0] = 4006 ; - my_vector_vector_vector_double[4][2][1] = 4007 ; - my_vector_vector_vector_double[4][2][2] = 4008 ; - my_vector_vector_vector_double[4][3][0] = 4009 ; - my_vector_vector_vector_double[4][3][1] = 4010 ; - my_vector_vector_vector_double[4][3][2] = 4011 ; + p.first = 15 ; + p.second = 12 ; + pair_int_int_int.first = p ; + pair_int_int_int.second = 180 ; + + pair_pair_pair.first.first = 51 ; + pair_pair_pair.first.second = 52 ; + pair_pair_pair.second.first = 53 ; + pair_pair_pair.second.second = 54 ; + + vector_vector_double[0][0] = 100 ; + vector_vector_double[0][1] = 101 ; + vector_vector_double[0][2] = 102 ; + vector_vector_double[1][0] = 103 ; + vector_vector_double[1][1] = 104 ; + vector_vector_double[1][2] = 105 ; + vector_vector_double[2][0] = 106 ; + vector_vector_double[2][1] = 107 ; + vector_vector_double[2][2] = 108 ; + vector_vector_double[3][0] = 109 ; + vector_vector_double[3][1] = 110 ; + vector_vector_double[3][2] = 111 ; + + vector_vector_vector_double[0][0][0] = 0 ; + vector_vector_vector_double[0][0][1] = 1 ; + vector_vector_vector_double[0][0][2] = 2 ; + vector_vector_vector_double[0][1][0] = 3 ; + vector_vector_vector_double[0][1][1] = 4 ; + vector_vector_vector_double[0][1][2] = 5 ; + vector_vector_vector_double[0][2][0] = 6 ; + vector_vector_vector_double[0][2][1] = 7 ; + vector_vector_vector_double[0][2][2] = 8 ; + vector_vector_vector_double[0][3][0] = 9 ; + vector_vector_vector_double[0][3][1] = 10 ; + vector_vector_vector_double[0][3][2] = 11 ; + + vector_vector_vector_double[1][0][0] = 1000 ; + vector_vector_vector_double[1][0][1] = 1001 ; + vector_vector_vector_double[1][0][2] = 1002 ; + vector_vector_vector_double[1][1][0] = 1003 ; + vector_vector_vector_double[1][1][1] = 1004 ; + vector_vector_vector_double[1][1][2] = 1005 ; + vector_vector_vector_double[1][2][0] = 1006 ; + vector_vector_vector_double[1][2][1] = 1007 ; + vector_vector_vector_double[1][2][2] = 1008 ; + vector_vector_vector_double[1][3][0] = 1009 ; + vector_vector_vector_double[1][3][1] = 1010 ; + vector_vector_vector_double[1][3][2] = 1011 ; + + vector_vector_vector_double[2][0][0] = 2000 ; + vector_vector_vector_double[2][0][1] = 2001 ; + vector_vector_vector_double[2][0][2] = 2002 ; + vector_vector_vector_double[2][1][0] = 2003 ; + vector_vector_vector_double[2][1][1] = 2004 ; + vector_vector_vector_double[2][1][2] = 2005 ; + vector_vector_vector_double[2][2][0] = 2006 ; + vector_vector_vector_double[2][2][1] = 2007 ; + vector_vector_vector_double[2][2][2] = 2008 ; + vector_vector_vector_double[2][3][0] = 2009 ; + vector_vector_vector_double[2][3][1] = 2010 ; + vector_vector_vector_double[2][3][2] = 2011 ; + + vector_vector_vector_double[3][0][0] = 3000 ; + vector_vector_vector_double[3][0][1] = 3001 ; + vector_vector_vector_double[3][0][2] = 3002 ; + vector_vector_vector_double[3][1][0] = 3003 ; + vector_vector_vector_double[3][1][1] = 3004 ; + vector_vector_vector_double[3][1][2] = 3005 ; + vector_vector_vector_double[3][2][0] = 3006 ; + vector_vector_vector_double[3][2][1] = 3007 ; + vector_vector_vector_double[3][2][2] = 3008 ; + vector_vector_vector_double[3][3][0] = 3009 ; + vector_vector_vector_double[3][3][1] = 3010 ; + vector_vector_vector_double[3][3][2] = 3011 ; + + vector_vector_vector_double[4][0][0] = 4000 ; + vector_vector_vector_double[4][0][1] = 4001 ; + vector_vector_vector_double[4][0][2] = 4002 ; + vector_vector_vector_double[4][1][0] = 4003 ; + vector_vector_vector_double[4][1][1] = 4004 ; + vector_vector_vector_double[4][1][2] = 4005 ; + vector_vector_vector_double[4][2][0] = 4006 ; + vector_vector_vector_double[4][2][1] = 4007 ; + vector_vector_vector_double[4][2][2] = 4008 ; + vector_vector_vector_double[4][3][0] = 4009 ; + vector_vector_vector_double[4][3][1] = 4010 ; + vector_vector_vector_double[4][3][2] = 4011 ; return ; } int STLCheckpoint::speak() { //message_publish(1,"Quack!\n") ; - //message_publish(1,"my_double_vector: %f %f %f\n", my_double_vector[0], my_double_vector[1], my_double_vector[2]) ; - message_publish(1,"my_vector_vector_double[1]: %f %f %f\n", - my_vector_vector_double[1][0], my_vector_vector_double[1][1], my_vector_vector_double[1][2]) ; - message_publish(1,"my_vector_vector_vector_double[4][2]: %f %f %f\n", - my_vector_vector_vector_double[4][2][0], my_vector_vector_vector_double[4][2][1], my_vector_vector_vector_double[4][2][2]) ; + //message_publish(1,"double_vector: %f %f %f\n", double_vector[0], double_vector[1], double_vector[2]) ; + //message_publish(1,"vector_vector_double[1]: %f %f %f\n", + // vector_vector_double[1][0], vector_vector_double[1][1], vector_vector_double[1][2]) ; + //message_publish(1,"vector_vector_vector_double[4][2]: %f %f %f\n", + // vector_vector_vector_double[4][2][0], vector_vector_vector_double[4][2][1], vector_vector_vector_double[4][2][2]) ; + //message_publish(1,"string_vector[0]: %s\n", string_vector[0].c_str()) ; + //message_publish(1,"map_int_vector_int[1][1] = %d\n", map_int_vector_int[1][1]) ; + //message_publish(1,"gcd = %d\n", gcd[std::pair(24,30)]) ; + //message_publish(1,"common_multiples = %d\n", common_multiples[std::pair(3,5)][1]) ; + //message_publish(1,"common_multiples = %d\n", common_multiples[std::pair(3,5)][1]) ; + //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) ; return 0 ; } diff --git a/test/SIM_stls/models/STLCheckpoint.hh b/test/SIM_stls/models/STLCheckpoint.hh index 45c89b34..5680928d 100644 --- a/test/SIM_stls/models/STLCheckpoint.hh +++ b/test/SIM_stls/models/STLCheckpoint.hh @@ -28,48 +28,58 @@ class STLCheckpoint { std::string name ; - std::map< double , double > my_double_map ; - std::map< std::string , int > my_string_key_map ; - std::map< int , std::string > my_string_data_map ; - std::map< std::string , std::string > my_string_map ; + std::map< double , double > double_map ; + std::map< std::string , int > string_key_map ; + std::map< int , std::string > string_data_map ; + std::map< std::string , std::string > string_map ; - std::multimap< int , int > my_int_multimap ; - std::multimap< std::string , int > my_string_key_multimap ; - std::multimap< int , std::string > my_string_data_multimap ; - std::multimap< std::string , std::string > my_string_multimap ; + std::map< int , std::vector< int > > map_int_vector_int ; + std::map< std::pair< int , int > , int > gcd ; + std::map< std::pair< int , int > , std::pair< int , int > > map_pair_pair ; + std::map< std::pair< int , int > , std::vector< int > > common_multiples ; - std::vector< double > my_double_vector ; - std::vector< std::string > my_string_vector ; + std::multimap< int , int > int_multimap ; + std::multimap< std::string , int > string_key_multimap ; + std::multimap< int , std::string > string_data_multimap ; + std::multimap< std::string , std::string > string_multimap ; - std::list< short > my_short_list ; - std::list< std::string > my_string_list ; + std::vector< double > double_vector ; + std::vector< std::string > string_vector ; - std::deque< float > my_float_deque ; - std::deque< std::string > my_string_deque ; + std::list< short > short_list ; + std::list< std::string > string_list ; - std::set< int > my_int_set ; - std::set< std::string > my_string_set ; + std::deque< float > float_deque ; + std::deque< std::string > string_deque ; - std::multiset< long > my_long_multiset ; - std::multiset< std::string > my_string_multiset ; + std::set< int > int_set ; + std::set< std::string > string_set ; - std::stack< unsigned int > my_uint_stack ; - std::stack< std::string > my_string_stack ; + std::multiset< long > long_multiset ; + std::multiset< std::string > string_multiset ; - std::queue< int > my_int_queue ; - std::queue< std::string > my_string_queue ; + std::stack< unsigned int > uint_stack ; + std::stack< std::string > string_stack ; - std::priority_queue< int > my_int_priority_queue ; - std::priority_queue< std::string > my_string_priority_queue ; + std::queue< int > int_queue ; + std::queue< std::string > string_queue ; - std::pair< int , int > my_int_pair ; - std::pair< std::string , int > my_string_first_pair ; - std::pair< int , std::string > my_string_second_pair ; - std::pair< std::string , std::string > my_string_pair ; + std::priority_queue< int > int_priority_queue ; + std::priority_queue< std::string > string_priority_queue ; - std::vector< std::vector< double > > my_vector_vector_double ; - std::vector< std::vector< std::vector< double > > > my_vector_vector_vector_double ; - //std::vector< std::list< double > > my_vector_list_double ; + std::pair< int , int > int_pair ; + std::pair< std::string , int > string_first_pair ; + std::pair< int , std::string > string_second_pair ; + std::pair< std::string , std::string > string_pair ; + + std::pair< int , std::pair< int, int > > int_pair_int_int ; + std::pair< std::pair< int, int > , int > pair_int_int_int ; + + std::pair< std::pair< int, int > , std::pair< int, int > > pair_pair_pair ; + + std::vector< std::vector< double > > vector_vector_double ; + std::vector< std::vector< std::vector< double > > > vector_vector_vector_double ; + //std::vector< std::list< double > > vector_list_double ; } ; #endif diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp index cf7ae26d..81a2ef28 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp @@ -300,7 +300,7 @@ static std::map init_stl_classes() { my_map.insert(std::pair("std::map", 1)) ; my_map.insert(std::pair("std::multiset", 1)) ; my_map.insert(std::pair("std::multimap", 1)) ; - my_map.insert(std::pair("std::pair", 1)) ; + my_map.insert(std::pair("std::pair", 0)) ; my_map.insert(std::pair("std::priority_queue", 0)) ; my_map.insert(std::pair("std::queue", 0)) ; my_map.insert(std::pair("std::set", 1)) ; @@ -311,7 +311,7 @@ static std::map init_stl_classes() { my_map.insert(std::pair("std::__1::map", 1)) ; my_map.insert(std::pair("std::__1::multiset", 1)) ; my_map.insert(std::pair("std::__1::multimap", 1)) ; - my_map.insert(std::pair("std::__1::pair", 1)) ; + my_map.insert(std::pair("std::__1::pair", 0)) ; my_map.insert(std::pair("std::__1::priority_queue", 0)) ; my_map.insert(std::pair("std::__1::queue", 0)) ; my_map.insert(std::pair("std::__1::set", 1)) ; @@ -343,6 +343,9 @@ bool FieldVisitor::VisitRecordType(clang::RecordType *rt) { while ((pos = tst_string.find("class ")) != std::string::npos ) { tst_string.erase(pos , 6) ; } + while ((pos = tst_string.find("struct ")) != std::string::npos ) { + tst_string.erase(pos , 7) ; + } // clang changes bool to _Bool. We need to change it back if ((pos = tst_string.find("<_Bool")) != std::string::npos ) { tst_string.replace(pos , 6, " & in_map , std::string object_name , std::string var_name ) { return checkpoint_map_stl_strings( in_map , object_name , var_name ) ; } @@ -19,4 +20,4 @@ int restore_stl(std::map & in_map , std::string objec int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { return restore_map_stl_strings( in_map , object_name , var_name ) ; } - +#endif diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp index f9512944..208ae9be 100644 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp +++ b/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp @@ -4,50 +4,4 @@ #include "trick/checkpoint_pair.hh" -int checkpoint_stl(std::pair & in_stl , std::string object_name , std::string var_name ) { - - char var_declare[128] ; - char ** first ; - char ** second ; - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - - sprintf(var_declare, "char * %s_%s_first[1]", object_name.c_str(), var_name.c_str()) ; - first = (char **)TMM_declare_var_s(var_declare) ; - TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; - - sprintf(var_declare, "char * %s_%s_second[1]" , object_name.c_str(), var_name.c_str()) ; - second = (char **)TMM_declare_var_s(var_declare) ; - TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; - - first[0] = (char *)(in_stl.first.c_str()) ; - second[0] = (char *)(in_stl.second.c_str()) ; - - return 0 ; -} - -int restore_stl(std::pair & in_stl , std::string object_name , std::string var_name ) { - - REF2 * first_ref ; - REF2 * second_ref ; - - char ** first ; - char ** second ; - std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - //message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; - - first_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_first")).c_str()) ; - second_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_second")).c_str()) ; - - if ( first_ref != NULL && second_ref != NULL ) { - first = (char **)first_ref->address ; - second = (char **)second_ref->address ; - - in_stl.first = std::string(first[0]) ; - in_stl.second = std::string(second[0]) ; - - delete_stl( in_stl , object_name , var_name ) ; - } - - return 0 ; -} diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_sequence_stl.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_sequence_stl.cpp index 9f94c80e..ae64143f 100644 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_sequence_stl.cpp +++ b/trick_source/sim_services/CheckPointRestart/checkpoint_sequence_stl.cpp @@ -1,6 +1,7 @@ #include "trick/checkpoint_sequence_stl.hh" +/* int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { return checkpoint_sequence_stl_string( in_stl , object_name , var_name ) ; } @@ -40,4 +41,4 @@ int restore_stl(std::set & in_stl , std::string object_name , std:: int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { return restore_sequence_stl_string( in_stl , object_name , var_name ) ; } - +*/ From 536810872358e55a6b95764d2940a0c285ce351b Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Thu, 31 Mar 2016 09:22:45 -0500 Subject: [PATCH 5/9] Add direct STL checkpointing Added queue and priority queue handling. refs #206 --- include/trick/checkpoint_fwd_declare.hh | 40 +++ include/trick/checkpoint_is_stl_container.hh | 11 + include/trick/checkpoint_queue.hh | 270 ++++++++++++------ test/SIM_stls/models/STLCheckpoint.cpp | 4 +- test/SIM_stls/models/STLCheckpoint.hh | 1 + .../CheckPointRestart/checkpoint_queue.cpp | 72 ----- .../checkpoint_sequence_stl.cpp | 41 --- 7 files changed, 237 insertions(+), 202 deletions(-) diff --git a/include/trick/checkpoint_fwd_declare.hh b/include/trick/checkpoint_fwd_declare.hh index b5789640..c78f2cc3 100644 --- a/include/trick/checkpoint_fwd_declare.hh +++ b/include/trick/checkpoint_fwd_declare.hh @@ -109,6 +109,26 @@ template ::value >::type* = nullptr > int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; +// queue +template ::value>::type* = nullptr > +int checkpoint_stl(std::queue & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::queue & in_stl , std::string object_name , std::string var_name ) ; + +// priority queue +template ::value>::type* = nullptr > +int checkpoint_stl(std::priority_queue & in_stl , + std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::priority_queue & in_stl , + std::string object_name , std::string var_name ) ; + /* ===================================================================================================== */ // Restore routines @@ -199,5 +219,25 @@ template ::value >::type* = nullptr > int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; +// queue +template ::value>::type* = nullptr > +int restore_stl(std::queue & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int restore_stl(std::queue & in_stl , std::string object_name , std::string var_name ) ; + +// priority queue +template ::value>::type* = nullptr > +int restore_stl(std::priority_queue & in_stl , + std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int restore_stl(std::priority_queue & 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 b70c0a2f..50aff438 100644 --- a/include/trick/checkpoint_is_stl_container.hh +++ b/include/trick/checkpoint_is_stl_container.hh @@ -10,6 +10,7 @@ #include #include #include +#include #include template @@ -57,5 +58,15 @@ struct is_stl_container > { static const bool value = true; }; +template +struct is_stl_container > { + static const bool value = true; +}; + +template +struct is_stl_container > { + static const bool value = true; +}; + #endif diff --git a/include/trick/checkpoint_queue.hh b/include/trick/checkpoint_queue.hh index a5e781d9..b4fd5b28 100644 --- a/include/trick/checkpoint_queue.hh +++ b/include/trick/checkpoint_queue.hh @@ -8,54 +8,44 @@ #include #include +#include +#include +#include #ifdef __GNUC__ #include #endif -#include "trick/checkpoint_sequence_stl.hh" +#include "checkpoint_is_stl_container.hh" +#include "checkpoint_fwd_declare.hh" #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" -#ifndef TRICK_ICG -template -int delete_stl(std::queue & in_stl , std::string object_name , std::string var_name ) { - return delete_sequence_stl( in_stl , object_name , var_name ) ; -} +/* =================================================================================================*/ -template -int delete_stl(std::priority_queue & in_stl , std::string object_name , std::string var_name ) { - return delete_sequence_stl( in_stl , object_name , var_name ) ; -} -template -int delete_stl(std::priority_queue, std::greater > & 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::queue & in_stl , std::string object_name , std::string var_name ) { +// queue: intrinsic +template ::value>::type* > +int checkpoint_stl(std::queue & 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::queue temp_queue ; + std::queue temp_queue(in_stl) ; - cont_size = in_stl.size() ; + cont_size = temp_queue.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_queue = in_stl ; + //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { items[ii] = temp_queue.front() ; @@ -66,29 +56,61 @@ int checkpoint_stl(std::queue & in_stl , std::string object_name , st return 0 ; } -template -int checkpoint_stl(std::priority_queue & in_stl , std::string object_name , std::string var_name ) { +// queue: STL +template ::value>::type* > +int checkpoint_stl(std::queue & 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::priority_queue temp_queue ; + std::queue temp_queue(in_stl) ; - cont_size = in_stl.size() ; + cont_size = temp_queue.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 << "std::string " + << 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) ; + //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; - temp_queue = in_stl ; + for ( ii = 0 ; ii < cont_size ; ii++ ) { + std::ostringstream index_string ; + index_string << ii ; + checkpoint_stl (temp_queue.front(), object_name + "_" + var_name, index_string.str()) ; + temp_queue.pop() ; + } + } + return 0 ; +} + +// priority queue: intrinsic +template ::value>::type* > +int checkpoint_stl(std::priority_queue & in_stl , + std::string object_name , std::string var_name ) { + unsigned int ii ; + unsigned int cont_size ; + std::ostringstream var_declare ; + int status ; + + ITEM_TYPE * items = nullptr ; + std::priority_queue temp_queue(in_stl) ; + + cont_size = temp_queue.size() ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + 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()) ; + 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++ ) { items[ii] = temp_queue.top() ; @@ -99,33 +121,34 @@ int checkpoint_stl(std::priority_queue & in_stl , std::string object_ return 0 ; } -// template for priority queues using greater comparator -template -int checkpoint_stl(std::priority_queue, std::greater > & in_stl , std::string object_name , std::string var_name ) { +// priority queue: STL +template ::value>::type* > +int checkpoint_stl(std::priority_queue & 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 = NULL ; - std::priority_queue, std::greater > temp_queue ; + ITEM_TYPE * items = nullptr ; + std::priority_queue temp_queue(in_stl) ; - cont_size = in_stl.size() ; + cont_size = temp_queue.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_queue = in_stl ; + //message_publish(1, "CHECKPOINT_STL_STACK with %s\n", var_declare) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { - items[ii] = temp_queue.top() ; + std::ostringstream index_string ; + index_string << ii ; + checkpoint_stl (temp_queue.top(), object_name + "_" + var_name, index_string.str()) ; temp_queue.pop() ; } } @@ -133,24 +156,41 @@ int checkpoint_stl(std::priority_queue, std::g return 0 ; } -/* Find the arrays the map data was stored in the checkpoint using ref_attributes +/* =================================================================================================*/ + +template +int delete_stl(std::queue & in_stl , std::string object_name , std::string var_name ) { + return delete_sequence_stl( in_stl , object_name , var_name ) ; +} + +template +int delete_stl(std::priority_queue & 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. + the map from the 2 arrays. */ -template -int restore_queue_stl(STL & in_stl , std::string object_name , std::string var_name ) { +// queue: intrinsic +template ::value>::type* > +int restore_stl(std::queue & in_stl , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; REF2 * items_ref ; - typename STL::value_type * items ; + ITEM_TYPE * items ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); //message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; - items_ref = ref_attributes((char *)(object_name + std::string("_") + 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() ; @@ -158,7 +198,7 @@ int restore_queue_stl(STL & in_stl , std::string object_name , std::string var_n in_stl.pop() ; } - items = (typename STL::value_type *)items_ref->address ; + items = (ITEM_TYPE *)items_ref->address ; cont_size = get_size((char *)items) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { @@ -166,27 +206,68 @@ int restore_queue_stl(STL & in_stl , std::string object_name , std::string var_n } delete_stl( in_stl , object_name , var_name ) ; } - return 0 ; } -template -int restore_queue_stl_string(STL & in_stl , std::string object_name , std::string var_name ) { - +// queue: STL +template ::value>::type* > +int restore_stl(std::queue & in_stl , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; REF2 * items_ref ; - char ** items ; + std::string * items ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); //message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; - items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; + items_ref = ref_attributes((char *)(object_name + "_" + var_name).c_str()) ; if ( items_ref != NULL ) { - STL().swap(in_stl) ; - items = (char **)items_ref->address ; + 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 = 0 ; 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 ; +} + +// priority_queue: intrinsic +template ::value>::type* > +int restore_stl(std::priority_queue & in_stl , + std::string object_name , std::string var_name ) { + unsigned int ii ; + unsigned int cont_size ; + + REF2 * items_ref ; + ITEM_TYPE * items ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + //message_publish(1, "RESTORE_STL_queue %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 = (ITEM_TYPE *)items_ref->address ; cont_size = get_size((char *)items) ; for ( ii = 0 ; ii < cont_size ; ii++ ) { @@ -194,31 +275,44 @@ int restore_queue_stl_string(STL & in_stl , std::string object_name , std::strin } delete_stl( in_stl , object_name , var_name ) ; } - return 0 ; } -template -int restore_stl(std::queue & in_stl , std::string object_name , std::string var_name ) { - return restore_queue_stl( in_stl , object_name , var_name ) ; -} +// priority_queue: STL +template ::value>::type* > +int restore_stl(std::priority_queue & in_stl , + std::string object_name , std::string var_name ) { + unsigned int ii ; + unsigned int cont_size ; -template -int restore_stl(std::priority_queue & in_stl , std::string object_name , std::string var_name ) { - return restore_queue_stl( in_stl , object_name , var_name ) ; -} + REF2 * items_ref ; + std::string * items ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); -template -int restore_stl(std::priority_queue, std::greater > & in_stl , std::string object_name , std::string var_name ) { - return restore_queue_stl( in_stl , object_name , var_name ) ; -} + //message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; -// Specialized routines for strings. -int checkpoint_stl(std::queue & in_stl , std::string object_name , std::string var_name ) ; -int checkpoint_stl(std::priority_queue & in_stl , std::string object_name , std::string var_name ) ; -int restore_stl(std::queue & in_stl , std::string object_name , std::string var_name ) ; -int restore_stl(std::priority_queue & in_stl , std::string object_name , std::string var_name ) ; - -#endif + items_ref = ref_attributes((char *)(object_name + "_" + 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 = 0 ; 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 84c3fff3..cba6b943 100644 --- a/test/SIM_stls/models/STLCheckpoint.cpp +++ b/test/SIM_stls/models/STLCheckpoint.cpp @@ -412,7 +412,9 @@ int STLCheckpoint::speak() { //message_publish(1,"common_multiples = %d\n", common_multiples[std::pair(3,5)][1]) ; //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,"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()) ; return 0 ; } diff --git a/test/SIM_stls/models/STLCheckpoint.hh b/test/SIM_stls/models/STLCheckpoint.hh index 5680928d..ed81ab2b 100644 --- a/test/SIM_stls/models/STLCheckpoint.hh +++ b/test/SIM_stls/models/STLCheckpoint.hh @@ -66,6 +66,7 @@ class STLCheckpoint { 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::pair< int , int > int_pair ; std::pair< std::string , int > string_first_pair ; diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp index ee97277c..8cc281ea 100644 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp +++ b/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp @@ -1,76 +1,4 @@ #include "trick/checkpoint_queue.hh" -int checkpoint_stl(std::queue & 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::queue temp_queue ; - - 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_queue = in_stl ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - items[ii] = (char *)((temp_queue.front()).c_str()) ; - temp_queue.pop() ; - } - } - - return 0 ; -} - -int checkpoint_stl(std::priority_queue & 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::priority_queue temp_queue ; - - 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_queue = in_stl ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - items[ii] = (char *)((temp_queue.top()).c_str()) ; - temp_queue.pop() ; - } - } - - return 0 ; -} - -int restore_stl(std::queue & in_stl , std::string object_name , std::string var_name ) { - return restore_queue_stl_string(in_stl , object_name , var_name) ; -} - -int restore_stl(std::priority_queue & in_stl , std::string object_name , std::string var_name ) { - return restore_queue_stl_string(in_stl , object_name , var_name) ; -} - diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_sequence_stl.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_sequence_stl.cpp index ae64143f..d169b858 100644 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_sequence_stl.cpp +++ b/trick_source/sim_services/CheckPointRestart/checkpoint_sequence_stl.cpp @@ -1,44 +1,3 @@ #include "trick/checkpoint_sequence_stl.hh" -/* -int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_string( in_stl , object_name , var_name ) ; -} - -int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_string( in_stl , object_name , var_name ) ; -} - -int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_string( in_stl , object_name , var_name ) ; -} - -int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_string( in_stl , object_name , var_name ) ; -} - -int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_string( in_stl , object_name , var_name ) ; -} - -int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_string( in_stl , object_name , var_name ) ; -} - -int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_string( in_stl , object_name , var_name ) ; -} - -int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_string( in_stl , object_name , var_name ) ; -} - -int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_string( in_stl , object_name , var_name ) ; -} - -int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_string( in_stl , object_name , var_name ) ; -} -*/ From 06a405ef35e4bacae64f8b408da86bd682b1eaa7 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Thu, 31 Mar 2016 10:32:13 -0500 Subject: [PATCH 6/9] Add direct STL checkpointing stl::stack code completed. refs #206 --- include/trick/checkpoint_fwd_declare.hh | 18 +++ include/trick/checkpoint_is_stl_container.hh | 10 +- include/trick/checkpoint_queue.hh | 18 ++- include/trick/checkpoint_stack.hh | 125 ++++++++++++--- test/SIM_stls/models/STLCheckpoint.cpp | 148 ++---------------- test/SIM_stls/models/STLCheckpoint.hh | 3 + .../CheckPointRestart/checkpoint_stack.cpp | 62 -------- 7 files changed, 157 insertions(+), 227 deletions(-) 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 ; -} - From c8a39f4a445c2b4f39e9ec198f9d30cb124f19ea Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Thu, 31 Mar 2016 14:50:27 -0500 Subject: [PATCH 7/9] Add direct STL checkpointing Removed the previous attempts at STL checkpointing. Removed the header files and sims. Also simplified the names of some of the templates. refs #206 --- include/trick/CheckPointRestart.hh | 18 - include/trick/checkpoint_fwd_declare.hh | 252 +++--- include/trick/checkpoint_is_stl_container.hh | 20 +- include/trick/checkpoint_map.hh | 169 ++-- include/trick/checkpoint_pair.hh | 131 +-- include/trick/checkpoint_queue.hh | 11 +- include/trick/checkpoint_sequence_stl.hh | 180 ++-- include/trick/checkpoint_stack.hh | 13 +- include/trick/checkpoint_trick_map_stl.hh | 594 ------------ include/trick/checkpoint_trick_pair_stl.hh | 459 ---------- .../trick/checkpoint_trick_sequence_stl.hh | 199 ---- include/trick/trick_deque.hh | 131 --- include/trick/trick_list.hh | 131 --- include/trick/trick_map.hh | 851 ------------------ include/trick/trick_pair.hh | 382 -------- include/trick/trick_queue.hh | 160 ---- include/trick/trick_set.hh | 256 ------ include/trick/trick_stack.hh | 83 -- include/trick/trick_vector.hh | 133 --- share/trick/sim_objects/default_trick_sys.sm | 5 - test/SIM_stls/RUN_test/input.py | 6 +- test/SIM_stls2/RUN_test/input.py | 24 - test/SIM_stls2/RUN_test/unit_test.py | 15 - test/SIM_stls2/S_define | 37 - test/SIM_stls2/S_overrides.mk | 4 - .../models/stl_checkpoint/STLCheckpoint.cpp | 281 ------ .../models/stl_checkpoint/STLCheckpoint.hh | 93 -- test/SIM_stls2/stl_checkpoints.sm | 57 -- test/SIM_stls3/RUN_test/input.py | 8 - test/SIM_stls3/RUN_test/realtime.py | 9 - test/SIM_stls3/S_define | 23 - test/SIM_stls3/S_overrides.mk | 4 - .../TrickSTL/include/TrickSTLCheckpoint.hh | 167 ---- .../TrickSTL/src/TrickSTLCheckpoint.cpp | 504 ----------- test/makefile | 2 - .../CheckPointRestart/CheckPointRestart.cpp | 19 - .../sim_services/CheckPointRestart/Makefile | 2 - .../CheckPointRestart/Makefile_deps | 69 +- .../CheckPointRestart/checkpoint_map.cpp | 23 - .../CheckPointRestart/checkpoint_pair.cpp | 7 - .../CheckPointRestart/checkpoint_queue.cpp | 4 - .../checkpoint_sequence_stl.cpp | 3 - .../CheckPointRestart/checkpoint_stack.cpp | 3 - 43 files changed, 413 insertions(+), 5129 deletions(-) delete mode 100644 include/trick/checkpoint_trick_map_stl.hh delete mode 100644 include/trick/checkpoint_trick_pair_stl.hh delete mode 100644 include/trick/checkpoint_trick_sequence_stl.hh delete mode 100644 include/trick/trick_deque.hh delete mode 100644 include/trick/trick_list.hh delete mode 100644 include/trick/trick_map.hh delete mode 100644 include/trick/trick_pair.hh delete mode 100644 include/trick/trick_queue.hh delete mode 100644 include/trick/trick_set.hh delete mode 100644 include/trick/trick_stack.hh delete mode 100644 include/trick/trick_vector.hh delete mode 100644 test/SIM_stls2/RUN_test/input.py delete mode 100644 test/SIM_stls2/RUN_test/unit_test.py delete mode 100644 test/SIM_stls2/S_define delete mode 100644 test/SIM_stls2/S_overrides.mk delete mode 100644 test/SIM_stls2/models/stl_checkpoint/STLCheckpoint.cpp delete mode 100644 test/SIM_stls2/models/stl_checkpoint/STLCheckpoint.hh delete mode 100644 test/SIM_stls2/stl_checkpoints.sm delete mode 100644 test/SIM_stls3/RUN_test/input.py delete mode 100644 test/SIM_stls3/RUN_test/realtime.py delete mode 100644 test/SIM_stls3/S_define delete mode 100644 test/SIM_stls3/S_overrides.mk delete mode 100644 test/SIM_stls3/models/TrickSTL/include/TrickSTLCheckpoint.hh delete mode 100644 test/SIM_stls3/models/TrickSTL/src/TrickSTLCheckpoint.cpp delete mode 100644 trick_source/sim_services/CheckPointRestart/checkpoint_map.cpp delete mode 100644 trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp delete mode 100644 trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp delete mode 100644 trick_source/sim_services/CheckPointRestart/checkpoint_sequence_stl.cpp delete mode 100644 trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp diff --git a/include/trick/CheckPointRestart.hh b/include/trick/CheckPointRestart.hh index 2b496b47..d08f869d 100644 --- a/include/trick/CheckPointRestart.hh +++ b/include/trick/CheckPointRestart.hh @@ -332,24 +332,6 @@ namespace Trick { */ virtual int load_default_data() ; - /** - * Our own pre_checkpoint job to save off our STLs - * @return always 0 - */ - virtual int pre_checkpoint() ; - - /** - * Our own pre_checkpoint job to remove extra memory when checkpoining STLs - * @return always 0 - */ - virtual int post_checkpoint() ; - - /** - * Our own restart job to restore STLs - * @return always 0 - */ - virtual int restart() ; - // Removed all doxygen documents for functions that have documents in the parent class since // Doxygen inherits the documents from the parent class automatically. diff --git a/include/trick/checkpoint_fwd_declare.hh b/include/trick/checkpoint_fwd_declare.hh index 8fb1fa41..3dbce509 100644 --- a/include/trick/checkpoint_fwd_declare.hh +++ b/include/trick/checkpoint_fwd_declare.hh @@ -24,89 +24,111 @@ // Checkpoint routines // vector -template ::value>::type* = nullptr > -int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; -template ::value>::type* = nullptr > -int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; // list -template ::value>::type* = nullptr > -int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; -template ::value>::type* = nullptr > -int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; // deque -template ::value>::type* = nullptr > -int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; -template ::value>::type* = nullptr > -int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; // set -template ::value>::type* = nullptr > -int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; -template ::value>::type* = nullptr > -int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; // multiset -template ::value>::type* = nullptr > -int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; -template ::value>::type* = nullptr > -int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; // map -template ::value && - !is_stl_container::value >::type* = nullptr > -int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) ; +template ::value && + !is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) ; -template ::value && - is_stl_container::value >::type* = nullptr > -int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) ; +template ::value && + is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) ; -template ::value && - !is_stl_container::value >::type* = nullptr > -int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) ; +template ::value && + !is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) ; -template ::value && - is_stl_container::value >::type* = nullptr > -int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) ; +template ::value && + is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) ; // multimap -template ::value && - !is_stl_container::value >::type* = nullptr > -int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; +template ::value && + !is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; -template ::value && - is_stl_container::value >::type* = nullptr > -int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; +template ::value && + is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; -template ::value && - !is_stl_container::value >::type* = nullptr > -int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; +template ::value && + !is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; -template ::value && - is_stl_container::value >::type* = nullptr > -int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; +template ::value && + is_stl_container::value >::type* = nullptr > +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; // pair -template ::value && - !is_stl_container::value >::type* = nullptr > +template ::value && + !is_stl_container::value >::type* = nullptr > int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; -template ::value && - is_stl_container::value >::type* = nullptr > +template ::value && + is_stl_container::value >::type* = nullptr > int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; -template ::value && - !is_stl_container::value >::type* = nullptr > +template ::value && + !is_stl_container::value >::type* = nullptr > int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; -template ::value && - is_stl_container::value >::type* = nullptr > +template ::value && + is_stl_container::value >::type* = nullptr > int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; // queue @@ -143,89 +165,111 @@ int checkpoint_stl(std::stack & in_stl , std::string objec // Restore routines // vector -template ::value>::type* = nullptr > -int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; -template ::value>::type* = nullptr > -int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) ; // list -template ::value>::type* = nullptr > -int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; -template ::value>::type* = nullptr > -int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) ; // deque -template ::value>::type* = nullptr > -int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; -template ::value>::type* = nullptr > -int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) ; // set -template ::value>::type* = nullptr > -int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; -template ::value>::type* = nullptr > -int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) ; // multiset -template ::value>::type* = nullptr > -int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; -template ::value>::type* = nullptr > -int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; +template ::value>::type* = nullptr > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) ; // map -template ::value && - !is_stl_container::value >::type* = nullptr > -int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) ; +template ::value && + !is_stl_container::value >::type* = nullptr > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) ; -template ::value && - is_stl_container::value >::type* = nullptr > -int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) ; +template ::value && + is_stl_container::value >::type* = nullptr > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) ; -template ::value && - !is_stl_container::value >::type* = nullptr > -int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) ; +template ::value && + !is_stl_container::value >::type* = nullptr > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) ; -template ::value && - is_stl_container::value >::type* = nullptr > -int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) ; +template ::value && + is_stl_container::value >::type* = nullptr > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) ; // multimap -template ::value && - !is_stl_container::value >::type* = nullptr > -int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; +template ::value && + !is_stl_container::value >::type* = nullptr > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; -template ::value && - is_stl_container::value >::type* = nullptr > -int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; +template ::value && + is_stl_container::value >::type* = nullptr > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; -template ::value && - !is_stl_container::value >::type* = nullptr > -int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; +template ::value && + !is_stl_container::value >::type* = nullptr > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; -template ::value && - is_stl_container::value >::type* = nullptr > -int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; +template ::value && + is_stl_container::value >::type* = nullptr > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) ; // pair -template ::value && - !is_stl_container::value >::type* = nullptr > +template ::value && + !is_stl_container::value >::type* = nullptr > int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; -template ::value && - is_stl_container::value >::type* = nullptr > +template ::value && + is_stl_container::value >::type* = nullptr > int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; -template ::value && - !is_stl_container::value >::type* = nullptr > +template ::value && + !is_stl_container::value >::type* = nullptr > int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; -template ::value && - is_stl_container::value >::type* = nullptr > +template ::value && + is_stl_container::value >::type* = nullptr > int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) ; // queue diff --git a/include/trick/checkpoint_is_stl_container.hh b/include/trick/checkpoint_is_stl_container.hh index 93b1ad56..71b8d13a 100644 --- a/include/trick/checkpoint_is_stl_container.hh +++ b/include/trick/checkpoint_is_stl_container.hh @@ -19,28 +19,28 @@ struct is_stl_container { static const bool value = false; }; -template -struct is_stl_container > { +template +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 > { +template +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 > { +template +struct is_stl_container > { static const bool value = true; }; diff --git a/include/trick/checkpoint_map.hh b/include/trick/checkpoint_map.hh index 8b958853..661e66b2 100644 --- a/include/trick/checkpoint_map.hh +++ b/include/trick/checkpoint_map.hh @@ -35,7 +35,7 @@ // intrinsic key, intrinsic data template -int checkpoint_map_stl_ik_id(STL & in_map , std::string object_name , std::string var_name ) { +int checkpoint_map_ik_id(STL & in_map , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -73,21 +73,23 @@ int checkpoint_map_stl_ik_id(STL & in_map , std::string object_name , std::strin return 0 ; } -template ::value && - !is_stl_container::value >::type* > -int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl_ik_id( in_map , object_name , var_name ) ; +template ::value && + !is_stl_container::value >::type* > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_ik_id( in_map , object_name , var_name ) ; } -template ::value && - !is_stl_container::value >::type*> -int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl_ik_id( in_map , object_name , var_name ) ; +template ::value && + !is_stl_container::value >::type*> +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_ik_id( in_map , object_name , var_name ) ; } // intrinsic key, STL data template -int checkpoint_map_stl_ik_sd(STL & in_map , std::string object_name , std::string var_name ) { +int checkpoint_map_ik_sd(STL & in_map , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -133,21 +135,23 @@ int checkpoint_map_stl_ik_sd(STL & in_map , std::string object_name , std::strin return 0 ; } -template ::value && - is_stl_container::value >::type* > -int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl_ik_sd( in_map , object_name , var_name ) ; +template ::value && + is_stl_container::value >::type* > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_ik_sd( in_map , object_name , var_name ) ; } -template ::value && - is_stl_container::value >::type*> -int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl_ik_sd( in_map , object_name , var_name ) ; +template ::value && + is_stl_container::value >::type*> +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_ik_sd( in_map , object_name , var_name ) ; } // STL key, intrinsic data template -int checkpoint_map_stl_sk_id(STL & in_map , std::string object_name , std::string var_name ) { +int checkpoint_map_sk_id(STL & in_map , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -193,16 +197,18 @@ int checkpoint_map_stl_sk_id(STL & in_map , std::string object_name , std::strin return 0 ; } -template ::value && - !is_stl_container::value >::type* > -int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl_sk_id( in_map , object_name , var_name ) ; +template ::value && + !is_stl_container::value >::type* > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_sk_id( in_map , object_name , var_name ) ; } -template ::value && - !is_stl_container::value >::type*> -int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl_sk_id( in_map , object_name , var_name ) ; +template ::value && + !is_stl_container::value >::type*> +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return checkpoint_map_sk_id( in_map , object_name , var_name ) ; } // STL key, STL data @@ -213,7 +219,6 @@ int checkpoint_map_stl_sk_sd(STL & in_map , std::string object_name , std::strin unsigned int cont_size ; std::ostringstream var_declare ; typename STL::iterator iter ; - int status ; std::string * keys = nullptr ; std::string * items = nullptr ; @@ -257,21 +262,23 @@ int checkpoint_map_stl_sk_sd(STL & in_map , std::string object_name , std::strin return 0 ; } -template ::value && - is_stl_container::value >::type* > -int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { +template ::value && + is_stl_container::value >::type* > +int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { return checkpoint_map_stl_sk_sd( in_map , object_name , var_name ) ; } -template ::value && - is_stl_container::value >::type*> -int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { +template ::value && + is_stl_container::value >::type*> +int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { return checkpoint_map_stl_sk_sd( in_map , object_name , var_name ) ; } /* =================================================================================================*/ template -int delete_map_stl(STL & in_map __attribute__ ((unused)), std::string object_name , std::string var_name ) { +int delete_map_allocs(STL & in_map __attribute__ ((unused)), std::string object_name , std::string var_name ) { std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); REF2 * items_ref ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; @@ -283,14 +290,14 @@ int delete_map_stl(STL & in_map __attribute__ ((unused)), std::string object_nam return 0 ; } -template -int delete_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return delete_map_stl(in_map , object_name , var_name) ; +template +int delete_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return delete_map_allocs(in_map , object_name , var_name) ; } -template -int delete_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return delete_map_stl(in_map , object_name , var_name) ; +template +int delete_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return delete_map_allocs(in_map , object_name , var_name) ; } /* =================================================================================================*/ @@ -302,7 +309,7 @@ int delete_stl(std::multimap & in_map , std::string object_name , st the map from the 2 arrays. */ template -int restore_map_stl_ik_id(STL & in_map , std::string object_name , std::string var_name ) { +int restore_map_ik_id(STL & in_map , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -333,20 +340,22 @@ int restore_map_stl_ik_id(STL & in_map , std::string object_name , std::string v return 0 ; } -template ::value && - !is_stl_container::value >::type* > -int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_ik_id(in_map , object_name , var_name) ; +template ::value && + !is_stl_container::value >::type* > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return restore_map_ik_id(in_map , object_name , var_name) ; } -template ::value && - !is_stl_container::value >::type* > -int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_ik_id(in_map , object_name , var_name) ; +template ::value && + !is_stl_container::value >::type* > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return restore_map_ik_id(in_map , object_name , var_name) ; } template -int restore_map_stl_ik_sd(STL & in_map , std::string object_name , std::string var_name ) { +int restore_map_ik_sd(STL & in_map , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -381,20 +390,22 @@ int restore_map_stl_ik_sd(STL & in_map , std::string object_name , std::string v return 0 ; } -template ::value && - is_stl_container::value >::type* > -int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_ik_sd(in_map , object_name , var_name) ; +template ::value && + is_stl_container::value >::type* > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return restore_map_ik_sd(in_map , object_name , var_name) ; } -template ::value && - is_stl_container::value >::type* > -int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_ik_sd(in_map , object_name , var_name) ; +template ::value && + is_stl_container::value >::type* > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return restore_map_ik_sd(in_map , object_name , var_name) ; } template -int restore_map_stl_sk_id(STL & in_map , std::string object_name , std::string var_name ) { +int restore_map_sk_id(STL & in_map , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -429,20 +440,22 @@ int restore_map_stl_sk_id(STL & in_map , std::string object_name , std::string v return 0 ; } -template ::value && - !is_stl_container::value >::type* > -int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_sk_id(in_map , object_name , var_name) ; +template ::value && + !is_stl_container::value >::type* > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return restore_map_sk_id(in_map , object_name , var_name) ; } -template ::value && - !is_stl_container::value >::type* > -int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_sk_id(in_map , object_name , var_name) ; +template ::value && + !is_stl_container::value >::type* > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return restore_map_sk_id(in_map , object_name , var_name) ; } template -int restore_map_stl_sk_sd(STL & in_map , std::string object_name , std::string var_name ) { +int restore_map_sk_sd(STL & in_map , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -481,16 +494,18 @@ int restore_map_stl_sk_sd(STL & in_map , std::string object_name , std::string v return 0 ; } -template ::value && - is_stl_container::value >::type* > -int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_sk_sd(in_map , object_name , var_name) ; +template ::value && + is_stl_container::value >::type* > +int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { + return restore_map_sk_sd(in_map , object_name , var_name) ; } -template ::value && - is_stl_container::value >::type* > -int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_sk_sd(in_map , object_name , var_name) ; +template ::value && + is_stl_container::value >::type* > +int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { + return restore_map_sk_sd(in_map , object_name , var_name) ; } #endif diff --git a/include/trick/checkpoint_pair.hh b/include/trick/checkpoint_pair.hh index a6b8b0a5..f4580bee 100644 --- a/include/trick/checkpoint_pair.hh +++ b/include/trick/checkpoint_pair.hh @@ -23,9 +23,9 @@ #include "trick/message_proto.h" // intrinsic first , intrinsic second -template -int checkpoint_pair_if_is(std::pair & in_stl , std::string object_name , std::string var_name ) { - +template ::value && + !is_stl_container::value >::type* > +int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { std::ostringstream var_declare ; int status ; @@ -37,7 +37,7 @@ int checkpoint_pair_if_is(std::pair & in_stl , std::string object << object_name << "_" << var_name << "_first[1]" ; first = (FIRST *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; - first[0] = in_stl.first ; + first[0] = in_pair.first ; var_declare.str("") ; var_declare.clear() ; @@ -45,20 +45,15 @@ int checkpoint_pair_if_is(std::pair & in_stl , std::string object << object_name << "_" << var_name << "_second[1]" ; second = (SECOND *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; - second[0] = in_stl.second ; + second[0] = in_pair.second ; return 0 ; } -template ::value && - !is_stl_container::value >::type* > -int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { - return checkpoint_pair_if_is( in_pair, object_name, var_name ) ; -} - // intrinsic first , STL second -template -int checkpoint_pair_if_ss(std::pair & in_stl , std::string object_name , std::string var_name ) { +template ::value && + is_stl_container::value >::type* > +int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { std::ostringstream var_declare ; int status ; @@ -71,7 +66,7 @@ int checkpoint_pair_if_ss(std::pair & in_stl , std::string object << object_name << "_" << var_name << "_first[1]" ; first = (FIRST *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; - first[0] = in_stl.first ; + first[0] = in_pair.first ; var_declare.str("") ; var_declare.clear() ; @@ -79,20 +74,15 @@ int checkpoint_pair_if_ss(std::pair & in_stl , std::string object << object_name << "_" << var_name << "_second[1]" ; second = (std::string *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; - checkpoint_stl( in_stl.second , object_name + "_" + var_name , "second" ) ; + checkpoint_stl( in_pair.second , object_name + "_" + var_name , "second" ) ; return 0 ; } -template ::value && - is_stl_container::value >::type* > -int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { - return checkpoint_pair_if_ss( in_pair, object_name, var_name ) ; -} - // STL first , intrinsic second -template -int checkpoint_pair_sf_is(std::pair & in_stl , std::string object_name , std::string var_name ) { +template ::value && + !is_stl_container::value >::type* > +int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { std::ostringstream var_declare ; int status ; @@ -105,7 +95,7 @@ int checkpoint_pair_sf_is(std::pair & in_stl , std::string object << object_name << "_" << var_name << "_first[1]" ; first = (std::string *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; - checkpoint_stl( in_stl.first , object_name + "_" + var_name , "first" ) ; + checkpoint_stl( in_pair.first , object_name + "_" + var_name , "first" ) ; var_declare.str("") ; var_declare.clear() ; @@ -113,23 +103,17 @@ int checkpoint_pair_sf_is(std::pair & in_stl , std::string object << object_name << "_" << var_name << "_second[1]" ; second = (SECOND *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; - second[0] = in_stl.second ; + second[0] = in_pair.second ; return 0 ; } -template ::value && - !is_stl_container::value >::type* > -int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { - return checkpoint_pair_sf_is( in_pair, object_name, var_name ) ; -} - // STL first , STL second -template -int checkpoint_pair_sf_ss(std::pair & in_stl , std::string object_name , std::string var_name ) { +template ::value && + is_stl_container::value >::type* > +int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { std::ostringstream var_declare ; - int status ; std::string * first = nullptr ; std::string * second = nullptr ; @@ -139,7 +123,7 @@ int checkpoint_pair_sf_ss(std::pair & in_stl , std::string object << object_name << "_" << var_name << "_first[1]" ; first = (std::string *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; - checkpoint_stl( in_stl.first , object_name + "_" + var_name , "first" ) ; + checkpoint_stl( in_pair.first , object_name + "_" + var_name , "first" ) ; var_declare.str("") ; var_declare.clear() ; @@ -147,17 +131,11 @@ int checkpoint_pair_sf_ss(std::pair & in_stl , std::string object << object_name << "_" << var_name << "_second[1]" ; second = (std::string *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; - checkpoint_stl( in_stl.second , object_name + "_" + var_name , "second" ) ; + checkpoint_stl( in_pair.second , object_name + "_" + var_name , "second" ) ; return 0 ; } -template ::value && - is_stl_container::value >::type* > -int checkpoint_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { - return checkpoint_pair_sf_ss( in_pair, object_name, var_name ) ; -} - /* =================================================================================================*/ template @@ -176,8 +154,9 @@ int delete_stl(std::pair & in_stl __attribute__ ((unused)) , std: /* =================================================================================================*/ // intrinsic first, intrinsic second -template -int restore_pair_if_is(std::pair & in_stl , std::string object_name , std::string var_name ) { +template ::value && + !is_stl_container::value >::type* > +int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { REF2 * first_ref ; REF2 * second_ref ; @@ -194,24 +173,19 @@ int restore_pair_if_is(std::pair & in_stl , std::string object_na first = (FIRST *)first_ref->address ; second = (SECOND *)second_ref->address ; - in_stl.first = first[0] ; - in_stl.second = second[0] ; + in_pair.first = first[0] ; + in_pair.second = second[0] ; - delete_stl( in_stl , object_name , var_name ) ; + delete_stl( in_pair , object_name , var_name ) ; } return 0 ; } -template ::value && - !is_stl_container::value >::type* > -int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { - return restore_pair_if_is( in_pair, object_name, var_name ) ; -} - // intrinsic first, STL second -template -int restore_pair_if_ss(std::pair & in_stl , std::string object_name , std::string var_name ) { +template ::value && + is_stl_container::value >::type* > +int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { REF2 * first_ref ; REF2 * second_ref ; @@ -229,24 +203,19 @@ int restore_pair_if_ss(std::pair & in_stl , std::string object_na first = (FIRST *)first_ref->address ; second = (std::string *)second_ref->address ; - in_stl.first = first[0] ; - restore_stl( in_stl.second , object_name + "_" + var_name , "second" ) ; + in_pair.first = first[0] ; + restore_stl( in_pair.second , object_name + "_" + var_name , "second" ) ; - delete_stl( in_stl , object_name , var_name ) ; + delete_stl( in_pair , object_name , var_name ) ; } return 0 ; } -template ::value && - is_stl_container::value >::type* > -int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { - return restore_pair_if_ss( in_pair, object_name, var_name ) ; -} - // STL first, intrinsic second -template -int restore_pair_sf_is(std::pair & in_stl , std::string object_name , std::string var_name ) { +template ::value && + !is_stl_container::value >::type* > +int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { REF2 * first_ref ; REF2 * second_ref ; @@ -264,25 +233,19 @@ int restore_pair_sf_is(std::pair & in_stl , std::string object_na first = (std::string *)first_ref->address ; second = (SECOND *)second_ref->address ; - restore_stl( in_stl.first , object_name + "_" + var_name , "first" ) ; - in_stl.second = second[0] ; + restore_stl( in_pair.first , object_name + "_" + var_name , "first" ) ; + in_pair.second = second[0] ; - delete_stl( in_stl , object_name , var_name ) ; + delete_stl( in_pair , object_name , var_name ) ; } return 0 ; } -template ::value && - !is_stl_container::value >::type* > -int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { - return restore_pair_sf_is( in_pair, object_name, var_name ) ; -} - // STL first, STL second -template -int restore_pair_sf_ss(std::pair & in_stl , std::string object_name , std::string var_name ) { - +template ::value && + is_stl_container::value >::type* > +int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { REF2 * first_ref ; REF2 * second_ref ; @@ -299,19 +262,13 @@ int restore_pair_sf_ss(std::pair & in_stl , std::string object_na first = (std::string *)first_ref->address ; second = (std::string *)second_ref->address ; - restore_stl( in_stl.first , object_name + "_" + var_name , "first" ) ; - restore_stl( in_stl.second , object_name + "_" + var_name , "second" ) ; + restore_stl( in_pair.first , object_name + "_" + var_name , "first" ) ; + restore_stl( in_pair.second , object_name + "_" + var_name , "second" ) ; - delete_stl( in_stl , object_name , var_name ) ; + delete_stl( in_pair , object_name , var_name ) ; } return 0 ; } -template ::value && - is_stl_container::value >::type* > -int restore_stl(std::pair & in_pair , std::string object_name , std::string var_name ) { - return restore_pair_sf_ss( in_pair, object_name, var_name ) ; -} - #endif diff --git a/include/trick/checkpoint_queue.hh b/include/trick/checkpoint_queue.hh index 675bf85d..c784424d 100644 --- a/include/trick/checkpoint_queue.hh +++ b/include/trick/checkpoint_queue.hh @@ -18,6 +18,7 @@ #include "checkpoint_is_stl_container.hh" #include "checkpoint_fwd_declare.hh" +#include "checkpoint_sequence_stl.hh" #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" @@ -64,7 +65,6 @@ int checkpoint_stl(std::queue & in_stl , std::string object unsigned int ii ; unsigned int cont_size ; std::ostringstream var_declare ; - int status ; std::string * items = nullptr ; std::queue temp_queue(in_stl) ; @@ -134,7 +134,6 @@ int checkpoint_stl(std::priority_queue & in_stl unsigned int ii ; unsigned int cont_size ; std::ostringstream var_declare ; - int status ; std::string * items = nullptr ; std::priority_queue temp_queue(in_stl) ; @@ -143,7 +142,7 @@ int checkpoint_stl(std::priority_queue & in_stl std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + 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()) ; @@ -166,15 +165,17 @@ int checkpoint_stl(std::priority_queue & in_stl /* =================================================================================================*/ +// The delete routines use the same method as the sequence types + template int delete_stl(std::queue & in_stl , std::string object_name , std::string var_name ) { - return delete_sequence_stl( in_stl , object_name , var_name ) ; + return delete_sequence_alloc( in_stl , object_name , var_name ) ; } template int delete_stl(std::priority_queue & in_stl , std::string object_name , std::string var_name ) { - return delete_sequence_stl( in_stl , object_name , var_name ) ; + return delete_sequence_alloc( in_stl , object_name , var_name ) ; } /* =================================================================================================*/ diff --git a/include/trick/checkpoint_sequence_stl.hh b/include/trick/checkpoint_sequence_stl.hh index ba29e618..cbdf9b50 100644 --- a/include/trick/checkpoint_sequence_stl.hh +++ b/include/trick/checkpoint_sequence_stl.hh @@ -27,7 +27,7 @@ /* =================================================================================================*/ template -int checkpoint_sequence_stl_intrinsic(STL & in_stl , std::string object_name , std::string var_name ) { +int checkpoint_sequence_i(STL & in_stl , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -62,7 +62,7 @@ int checkpoint_sequence_stl_intrinsic(STL & in_stl , std::string object_name , s } template -int checkpoint_sequence_stl_stl(STL & in_stl , std::string object_name , std::string var_name ) { +int checkpoint_sequence_s(STL & in_stl , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -104,77 +104,87 @@ int checkpoint_sequence_stl_stl(STL & in_stl , std::string object_name , std::st // std::vector // This template is only enabled if the items in the vector are an STL -template ::value>::type* > -int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +template ::value>::type* > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_s( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the vector are NOT an STL, except for std::string -template ::value>::type* > -int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +template ::value>::type* > +int checkpoint_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_i( in_stl , object_name , var_name ) ; } // ----------- // std::list -template ::value>::type* > -int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +template ::value>::type* > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_s( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the list are NOT an STL, except for std::string -template ::value>::type* > -int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +template ::value>::type* > +int checkpoint_stl(std::list & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_i( in_stl , object_name , var_name ) ; } // ----------- // std::deque -template ::value>::type* > -int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +template ::value>::type* > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_s( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the deque are NOT an STL, except for std::string -template ::value>::type* > -int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +template ::value>::type* > +int checkpoint_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_i( in_stl , object_name , var_name ) ; } // ----------- // std::set -template ::value>::type* > -int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +template ::value>::type* > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_s( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the set are NOT an STL, except for std::string -template ::value>::type* > -int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +template ::value>::type* > +int checkpoint_stl(std::set & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_i( in_stl , object_name , var_name ) ; } // ----------- // std::multiset -template ::value>::type* > -int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_stl( in_stl , object_name , var_name ) ; +template ::value>::type* > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_s( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the multiset are NOT an STL, except for std::string -template ::value>::type* > -int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { - return checkpoint_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +template ::value>::type* > +int checkpoint_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_i( in_stl , object_name , var_name ) ; } /* =================================================================================================*/ template -int delete_sequence_stl(STL & in_stl __attribute__ ((unused)), std::string object_name , std::string var_name ) { +int delete_sequence_alloc(STL & in_stl __attribute__ ((unused)), std::string object_name , std::string var_name ) { std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); REF2 * items_ref ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; @@ -185,29 +195,29 @@ int delete_sequence_stl(STL & in_stl __attribute__ ((unused)), std::string objec return 0 ; } -template -int delete_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { - return delete_sequence_stl( in_stl , object_name , var_name ) ; +template +int delete_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { + return delete_sequence_alloc( in_stl , object_name , var_name ) ; } -template -int delete_stl(std::list & in_stl , std::string object_name , std::string var_name ) { - return delete_sequence_stl( in_stl , object_name , var_name ) ; +template +int delete_stl(std::list & in_stl , std::string object_name , std::string var_name ) { + return delete_sequence_alloc( in_stl , object_name , var_name ) ; } -template -int delete_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { - return delete_sequence_stl( in_stl , object_name , var_name ) ; +template +int delete_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { + return delete_sequence_alloc( in_stl , object_name , var_name ) ; } -template -int delete_stl(std::set & in_stl , std::string object_name , std::string var_name ) { - return delete_sequence_stl( in_stl , object_name , var_name ) ; +template +int delete_stl(std::set & in_stl , std::string object_name , std::string var_name ) { + return delete_sequence_alloc( in_stl , object_name , var_name ) ; } -template -int delete_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { - return delete_sequence_stl( in_stl , object_name , var_name ) ; +template +int delete_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { + return delete_sequence_alloc( in_stl , object_name , var_name ) ; } @@ -219,7 +229,7 @@ int delete_stl(std::multiset & in_stl , std::string object_name , std the map from the 2 arrays. */ template -int restore_sequence_stl_intrinsic(STL & in_stl , std::string object_name , std::string var_name ) { +int restore_sequence_i(STL & in_stl , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -247,7 +257,7 @@ int restore_sequence_stl_intrinsic(STL & in_stl , std::string object_name , std: } template -int restore_sequence_stl_stl(STL & in_stl , std::string object_name , std::string var_name ) { +int restore_sequence_s(STL & in_stl , std::string object_name , std::string var_name ) { unsigned int ii ; unsigned int cont_size ; @@ -282,75 +292,85 @@ int restore_sequence_stl_stl(STL & in_stl , std::string object_name , std::strin // std::vector // This template is only enabled if the items in the vector are an STL -template ::value>::type* > -int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; +template ::value>::type* > +int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_s( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the vector are NOT an STL, except for std::string -template ::value>::type* > -int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +template ::value>::type* > +int restore_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_i( in_stl , object_name , var_name ) ; } // ----------- // std::list // This template is only enabled if the items in the list are an STL -template ::value>::type* > -int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; +template ::value>::type* > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_s( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the list are NOT an STL, except for std::string -template ::value>::type* > -int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +template ::value>::type* > +int restore_stl(std::list & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_i( in_stl , object_name , var_name ) ; } // ----------- // std::deque // This template is only enabled if the items in the deque are an STL -template ::value>::type* > -int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; +template ::value>::type* > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_s( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the deque are NOT an STL, except for std::string -template ::value>::type* > -int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +template ::value>::type* > +int restore_stl(std::deque & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_i( in_stl , object_name , var_name ) ; } // ----------- // std::set // This template is only enabled if the items in the set are an STL -template ::value>::type* > -int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; +template ::value>::type* > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_s( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the set are NOT an STL, except for std::string -template ::value>::type* > -int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +template ::value>::type* > +int restore_stl(std::set & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_i( in_stl , object_name , var_name ) ; } // ----------- // std::multiset // This template is only enabled if the items in the multiset are an STL -template ::value>::type* > -int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_stl( in_stl , object_name , var_name ) ; +template ::value>::type* > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_s( in_stl , object_name , var_name ) ; } // This template is only enabled if the items in the multiset are NOT an STL, except for std::string -template ::value>::type* > -int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { - return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; +template ::value>::type* > +int restore_stl(std::multiset & in_stl , std::string object_name , std::string var_name ) { + return restore_sequence_i( in_stl , object_name , var_name ) ; } #endif diff --git a/include/trick/checkpoint_stack.hh b/include/trick/checkpoint_stack.hh index df9c3864..116930fc 100644 --- a/include/trick/checkpoint_stack.hh +++ b/include/trick/checkpoint_stack.hh @@ -62,7 +62,6 @@ int checkpoint_stl(std::stack & in_stl , std::string object unsigned int ii ; unsigned int cont_size ; std::ostringstream var_declare ; - int status ; std::string * items = nullptr ; std::stack temp_stack(in_stl) ; @@ -94,17 +93,19 @@ int checkpoint_stl(std::stack & in_stl , std::string object /* =================================================================================================*/ +// The delete routine uses the same method as the sequence types + 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 ) ; + return delete_sequence_alloc( in_stl , object_name , var_name ) ; } /* =================================================================================================*/ -/* Find the arrays the map data was stored in the checkpoint using ref_attributes +/* 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. + the map from the 2 arrays. */ template ::value>::type* > @@ -118,7 +119,7 @@ int restore_stl(std::stack & in_stl , std::string object_na //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()) ; + items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; if ( items_ref != NULL ) { cont_size = in_stl.size() ; @@ -149,7 +150,7 @@ int restore_stl(std::stack & in_stl , std::string object_na //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()) ; + items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; if ( items_ref != NULL ) { cont_size = in_stl.size() ; diff --git a/include/trick/checkpoint_trick_map_stl.hh b/include/trick/checkpoint_trick_map_stl.hh deleted file mode 100644 index 5cf8003b..00000000 --- a/include/trick/checkpoint_trick_map_stl.hh +++ /dev/null @@ -1,594 +0,0 @@ -/* - PURPOSE: (Illustrate how to checkpoint STLs) -*/ - -#ifndef CHECKPOINT_TRICK_MAP_HH -#define CHECKPOINT_TRICK_MAP_HH - -#include -#include -#include -#ifdef __GNUC__ -#include -#endif - -#include "trick/STLInterface.hh" -#include "trick/memorymanager_c_intf.h" -#include "trick/message_proto.h" - -/* For all of the checkpoint_map_stl variations. Declare 2 memory manager arrays to hold - the contents of the map. No simulation variable actually points to these arrays. Only the - user knows they are there and how they are stored. The restart function knows how to - "retrieve" and restore the data. The name of the declaration is important. Each instance of - the STL requires a unique name to be saved correctly. The incoming "object_name" and "var_name" - gives that unique name. - */ -template -int checkpoint_trick_map_nkey_ndata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - typename STL::iterator iter ; - int status ; - - typename STL::key_type * keys ; - typename STL::mapped_type * items ; - - cont_size = in_map.size() ; - - if ( cont_size > 0 ) { - sprintf(var_declare, "%s %s_%06d_keys[%d]" , - abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), id, cont_size) ; - keys = (typename STL::key_type *)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "%s %s_%06d_data[%d]" , - abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), id, cont_size) ; - items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the map the 2 arrays */ - for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { - keys[ii] = iter->first ; - items[ii] = iter->second ; - } - } - return 0 ; -} - -template -int checkpoint_trick_map_nkey_sdata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - typename STL::iterator iter ; - int status ; - - typename STL::key_type * keys ; - char ** items ; - - cont_size = in_map.size() ; - - if ( cont_size > 0 ) { - sprintf(var_declare, "%s %s_%06d_keys[%d]" , - abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), id , cont_size) ; - keys = (typename STL::key_type *)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "char * %s_%06d_data[%d]" , object_name.c_str(), id , cont_size) ; - items = (char **)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the map the 2 arrays */ - for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { - keys[ii] = iter->first ; - items[ii] = (char *)((iter->second).c_str()) ; - } - } - return 0 ; -} - -template -int checkpoint_trick_map_nkey_stldata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - typename STL::iterator iter ; - int status ; - - typename STL::key_type * keys ; - unsigned int * items = NULL ; - - cont_size = in_map.size() ; - - if ( cont_size > 0 ) { - sprintf(var_declare, "%s %s_%06d_keys[%d]" , - abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), id , cont_size) ; - keys = (typename STL::key_type *)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "unsigned int %s_%06d_data[%d]" , object_name.c_str(), id , cont_size) ; - items = (unsigned int*)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the map the 2 arrays */ - for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { - keys[ii] = iter->first ; - items[ii] = (iter->second).stl_id ; - } - } - return 0 ; -} - -template -int checkpoint_trick_map_skey_ndata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - typename STL::iterator iter ; - int status ; - - char ** keys ; - typename STL::mapped_type * items ; - - cont_size = in_map.size() ; - - if ( cont_size > 0 ) { - sprintf(var_declare, "char * %s_%06d_keys[%d]" , object_name.c_str(), id , cont_size) ; - keys = (char **)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "%s %s_%06d_data[%d]" , - abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), id , cont_size) ; - items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the map the 2 arrays */ - for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { - keys[ii] = (char *)((iter->first).c_str()) ; - items[ii] = iter->second ; - } - } - return 0 ; -} - -template -int checkpoint_trick_map_skey_sdata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - typename STL::iterator iter ; - - char ** keys ; - char ** items ; - - cont_size = in_map.size() ; - - if ( cont_size > 0 ) { - sprintf(var_declare, "char * %s_%06d_keys[%d]" , object_name.c_str(), id , cont_size) ; - keys = (char **)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "char * %s_%06d_data[%d]" , object_name.c_str(), id , cont_size) ; - items = (char **)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the map the 2 arrays */ - - for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { - keys[ii] = (char *)((iter->first).c_str()) ; - items[ii] = (char *)((iter->second).c_str()) ; - } - } - return 0 ; -} - -template -int checkpoint_trick_map_skey_stldata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - typename STL::iterator iter ; - - char ** keys ; - unsigned int * items = NULL ; - - cont_size = in_map.size() ; - - if ( cont_size > 0 ) { - sprintf(var_declare, "char * %s_%06d_keys[%d]" , object_name.c_str(), id , cont_size) ; - keys = (char **)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "unsigned int %s_%06d_data[%d]" , object_name.c_str(), id , cont_size) ; - items = (unsigned int*)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the map the 2 arrays */ - for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { - keys[ii] = (char *)((iter->first).c_str()) ; - items[ii] = (iter->second).stl_id ; - } - } - return 0 ; -} - - -template -int checkpoint_trick_map_stlkey_ndata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - typename STL::iterator iter ; - int status ; - - unsigned int * keys = NULL ; - typename STL::mapped_type * items ; - - cont_size = in_map.size() ; - - if ( cont_size > 0 ) { - sprintf(var_declare, "unsigned int %s_%06d_keys[%d]" , object_name.c_str(), id , cont_size) ; - keys = (unsigned int*)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "%s %s_%06d_data[%d]" , - abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), id , cont_size) ; - items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the map the 2 arrays */ - for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { - keys[ii] = (iter->first).stl_id ; - items[ii] = iter->second ; - } - } - return 0 ; -} - -template -int checkpoint_trick_map_stlkey_sdata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - typename STL::iterator iter ; - - unsigned int * keys = NULL ; - char ** items ; - - cont_size = in_map.size() ; - - if ( cont_size > 0 ) { - sprintf(var_declare, "unsigned int %s_%06d_keys[%d]" , object_name.c_str(), id , cont_size) ; - keys = (unsigned int*)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "char * %s_%06d_data[%d]" , object_name.c_str(), id , cont_size) ; - items = (char **)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the map the 2 arrays */ - for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { - keys[ii] = (iter->first).stl_id ; - items[ii] = (char *)((iter->second).c_str()) ; - } - } - return 0 ; -} - -template -int checkpoint_trick_map_stlkey_stldata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - typename STL::iterator iter ; - - unsigned int * keys = NULL ; - unsigned int * items = NULL ; - - cont_size = in_map.size() ; - - if ( cont_size > 0 ) { - sprintf(var_declare, "unsigned int %s_%06d_keys[%d]" , object_name.c_str(), id , cont_size) ; - keys = (unsigned int*)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "unsigned int %s_%06d_data[%d]" , object_name.c_str(), id , cont_size) ; - items = (unsigned int*)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the map the 2 arrays */ - for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { - keys[ii] = (iter->first).stl_id ; - items[ii] = (iter->second).stl_id ; - } - } - return 0 ; -} - -/* For all restore_map_stl varieties. - 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_trick_map_nkey_ndata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - typename STL::key_type * keys ; - typename STL::mapped_type * items ; - - in_map.clear() ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (typename STL::key_type *)keys_ref->address ; - items = (typename STL::mapped_type *)items_ref->address ; - cont_size = get_size((char *)keys) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_map.insert( std::pair(keys[ii], items[ii])) ; - } - } - return 0 ; -} - -template -int restore_trick_map_nkey_sdata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - typename STL::key_type * keys ; - char ** items ; - - in_map.clear() ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (typename STL::key_type *)keys_ref->address ; - items = (char **)items_ref->address ; - cont_size = get_size((char *)keys) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_map.insert( std::pair(keys[ii] , std::string(items[ii]))) ; - } - } - return 0 ; -} - -template -int restore_trick_map_nkey_stldata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - typename STL::key_type * keys ; - unsigned int * items ; - - in_map.clear() ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (typename STL::key_type *)keys_ref->address ; - items = (unsigned int *)items_ref->address ; - cont_size = get_size((char *)keys) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - typename STL::mapped_type mt ; - mt.stl_id = items[ii] ; - mt.restart( object_name ) ; - in_map.insert( std::pair(keys[ii] , mt)) ; - } - } - return 0 ; -} - -template -int restore_trick_map_skey_ndata( STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - char ** keys ; - typename STL::mapped_type * items ; - - in_map.clear() ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (char **)keys_ref->address ; - items = (typename STL::mapped_type *)items_ref->address ; - cont_size = get_size((char *)keys) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_map.insert( std::pair(std::string(keys[ii]), items[ii])) ; - } - } - return 0 ; -} - -template -int restore_trick_map_skey_sdata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - char ** keys ; - char ** items ; - - in_map.clear() ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (char **)keys_ref->address ; - items = (char **)items_ref->address ; - cont_size = get_size((char *)keys) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_map.insert( std::pair(std::string(keys[ii]) , std::string(items[ii]))) ; - } - } - return 0 ; -} - -template -int restore_trick_map_skey_stldata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - char ** keys ; - unsigned int * items ; - - in_map.clear() ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (char **)keys_ref->address ; - items = (unsigned int *)items_ref->address ; - cont_size = get_size((char *)keys) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - typename STL::mapped_type mt ; - mt.stl_id = items[ii] ; - mt.restart( object_name ) ; - in_map.insert( std::pair(std::string(keys[ii]) , mt)) ; - } - } - return 0 ; -} - -template -int restore_trick_map_stlkey_ndata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - unsigned int * keys ; - typename STL::mapped_type * items ; - - in_map.clear() ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (unsigned int *)keys_ref->address ; - items = (typename STL::mapped_type *)items_ref->address ; - cont_size = get_size((char *)keys) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - typename STL::key_type kt ; - kt.stl_id = keys[ii] ; - kt.restart( object_name ) ; - in_map.insert( std::pair(kt , items[ii])) ; - } - } - return 0 ; -} - -template -int restore_trick_map_stlkey_sdata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - unsigned int * keys ; - char ** items ; - - in_map.clear() ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (unsigned int *)keys_ref->address ; - items = (char **)items_ref->address ; - cont_size = get_size((char *)keys) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - typename STL::key_type kt ; - kt.stl_id = keys[ii] ; - kt.restart( object_name ) ; - in_map.insert( std::pair(kt , std::string(items[ii]))) ; - } - } - return 0 ; -} - -template -int restore_trick_map_stlkey_stldata(STL & in_map , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - unsigned int * keys ; - unsigned int * items ; - - in_map.clear() ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (unsigned int *)keys_ref->address ; - items = (unsigned int *)items_ref->address ; - cont_size = get_size((char *)keys) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - typename STL::key_type kt ; - kt.stl_id = keys[ii] ; - kt.restart( object_name ) ; - typename STL::mapped_type mt ; - mt.stl_id = items[ii] ; - mt.restart( object_name ) ; - in_map.insert( std::pair(kt , mt)) ; - } - } - return 0 ; -} - -#endif diff --git a/include/trick/checkpoint_trick_pair_stl.hh b/include/trick/checkpoint_trick_pair_stl.hh deleted file mode 100644 index 9cf0ba04..00000000 --- a/include/trick/checkpoint_trick_pair_stl.hh +++ /dev/null @@ -1,459 +0,0 @@ -/* - PURPOSE: (Illustrate how to checkpoint STLs) -*/ - -#ifndef CHECKPOINT_TRICK_PAIR_HH -#define CHECKPOINT_TRICK_PAIR_HH - -#include -#include -#include -#ifdef __GNUC__ -#include -#endif - -#include "trick/STLInterface.hh" -#include "trick/memorymanager_c_intf.h" -#include "trick/message_proto.h" - -template -int checkpoint_trick_pair_nkey_ndata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - int status ; - - typename STL::first_type * keys ; - typename STL::second_type * items ; - - sprintf(var_declare, "%s %s_%06d_keys[1]" , - abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), id) ; - keys = (typename STL::first_type *)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "%s %s_%06d_data[1]" , - abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), id) ; - items = (typename STL::second_type *)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the pair the 2 arrays */ - keys[0] = in_pair.first ; - items[0] = in_pair.second ; - - return 0 ; -} - -template -int checkpoint_trick_pair_nkey_sdata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - int status ; - - typename STL::first_type * keys ; - char ** items ; - - sprintf(var_declare, "%s %s_%06d_keys[1]" , - abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), id ) ; - keys = (typename STL::first_type *)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "char * %s_%06d_data[1]" , object_name.c_str(), id ) ; - items = (char **)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the pair the 2 arrays */ - keys[0] = in_pair.first ; - items[0] = (char *)((in_pair.second).c_str()) ; - - return 0 ; -} - -template -int checkpoint_trick_pair_nkey_stldata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - int status ; - - typename STL::first_type * keys ; - unsigned int * items = NULL ; - - sprintf(var_declare, "%s %s_%06d_keys[1]" , - abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), id ) ; - keys = (typename STL::first_type *)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "unsigned int %s_%06d_data[1]" , object_name.c_str(), id ) ; - items = (unsigned int*)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the pair the 2 arrays */ - keys[0] = in_pair.first ; - items[0] = (in_pair.second).stl_id ; - - return 0 ; -} - -template -int checkpoint_trick_pair_skey_ndata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - int status ; - - char ** keys ; - typename STL::second_type * items ; - - sprintf(var_declare, "char * %s_%06d_keys[1]" , object_name.c_str(), id ) ; - keys = (char **)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "%s %s_%06d_data[1]" , - abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), id ) ; - items = (typename STL::second_type *)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the pair the 2 arrays */ - keys[0] = (char *)((in_pair.first).c_str()) ; - items[0] = in_pair.second ; - - return 0 ; -} - -template -int checkpoint_trick_pair_skey_sdata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - - char ** keys ; - char ** items ; - - sprintf(var_declare, "char * %s_%06d_keys[1]" , object_name.c_str(), id ) ; - keys = (char **)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "char * %s_%06d_data[1]" , object_name.c_str(), id ) ; - items = (char **)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the pair the 2 arrays */ - keys[0] = (char *)((in_pair.first).c_str()) ; - items[0] = (char *)((in_pair.second).c_str()) ; - - return 0 ; -} - -template -int checkpoint_trick_pair_skey_stldata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - - char ** keys ; - unsigned int * items = NULL ; - - sprintf(var_declare, "char * %s_%06d_keys[1]" , object_name.c_str(), id ) ; - keys = (char **)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "unsigned int %s_%06d_data[1]" , object_name.c_str(), id ) ; - items = (unsigned int*)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the pair the 2 arrays */ - keys[0] = (char *)((in_pair.first).c_str()) ; - items[0] = (in_pair.second).stl_id ; - - return 0 ; -} - - -template -int checkpoint_trick_pair_stlkey_ndata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - int status ; - - unsigned int * keys = NULL ; - typename STL::second_type * items ; - - sprintf(var_declare, "unsigned int %s_%06d_keys[1]" , object_name.c_str(), id ) ; - keys = (unsigned int*)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "%s %s_%06d_data[1]" , - abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), id ) ; - items = (typename STL::second_type *)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the pair the 2 arrays */ - keys[0] = (in_pair.first).stl_id ; - items[0] = in_pair.second ; - - return 0 ; -} - -template -int checkpoint_trick_pair_stlkey_sdata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - - unsigned int * keys = NULL ; - char ** items ; - - sprintf(var_declare, "unsigned int %s_%06d_keys[1]" , object_name.c_str(), id ) ; - keys = (unsigned int*)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "char * %s_%06d_data[1]" , object_name.c_str(), id ) ; - items = (char **)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the pair the 2 arrays */ - keys[0] = (in_pair.first).stl_id ; - items[0] = (char *)((in_pair.second).c_str()) ; - return 0 ; -} - -template -int checkpoint_trick_pair_stlkey_stldata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - - unsigned int * keys = NULL ; - unsigned int * items = NULL ; - - sprintf(var_declare, "unsigned int %s_%06d_keys[1]" , object_name.c_str(), id ) ; - keys = (unsigned int*)TMM_declare_var_s(var_declare) ; - - sprintf(var_declare, "unsigned int %s_%06d_data[1]" , object_name.c_str(), id ) ; - items = (unsigned int*)TMM_declare_var_s(var_declare) ; - - /* copy the contents of the pair the 2 arrays */ - keys[0] = (in_pair.first).stl_id ; - items[0] = (in_pair.second).stl_id ; - return 0 ; -} - -/* RESTORE */ - -template -int restore_trick_pair_nkey_ndata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - typename STL::first_type * keys ; - typename STL::second_type * items ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (typename STL::first_type *)keys_ref->address ; - items = (typename STL::second_type *)items_ref->address ; - - in_pair.first = keys[0] ; - in_pair.second = items[0] ; - } - return 0 ; -} - -template -int restore_trick_pair_nkey_sdata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - typename STL::first_type * keys ; - char ** items ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (typename STL::first_type *)keys_ref->address ; - items = (char **)items_ref->address ; - - in_pair.first = keys[0] ; - in_pair.second = items[0] ; - } - return 0 ; -} - -template -int restore_trick_pair_nkey_stldata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - typename STL::first_type * keys ; - unsigned int * items ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (typename STL::first_type *)keys_ref->address ; - items = (unsigned int *)items_ref->address ; - - typename STL::second_type mt ; - mt.stl_id = items[0] ; - mt.restart( object_name ) ; - - in_pair.first = keys[0] ; - in_pair.second = mt ; - } - return 0 ; -} - -template -int restore_trick_pair_skey_ndata( STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - char ** keys ; - typename STL::second_type * items ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (char **)keys_ref->address ; - items = (typename STL::second_type *)items_ref->address ; - - in_pair.first = keys[0] ; - in_pair.second = items[0] ; - } - return 0 ; -} - -template -int restore_trick_pair_skey_sdata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - char ** keys ; - char ** items ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (char **)keys_ref->address ; - items = (char **)items_ref->address ; - - in_pair.first = keys[0] ; - in_pair.second = items[0] ; - } - return 0 ; -} - -template -int restore_trick_pair_skey_stldata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - char ** keys ; - unsigned int * items ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (char **)keys_ref->address ; - items = (unsigned int *)items_ref->address ; - - typename STL::second_type mt ; - mt.stl_id = items[0] ; - mt.restart( object_name ) ; - - in_pair.first = keys[0] ; - in_pair.second = mt ; - } - return 0 ; -} - -template -int restore_trick_pair_stlkey_ndata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - unsigned int * keys ; - typename STL::second_type * items ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (unsigned int *)keys_ref->address ; - items = (typename STL::second_type *)items_ref->address ; - - typename STL::first_type kt ; - kt.stl_id = keys[0] ; - kt.restart( object_name ) ; - - in_pair.first = kt ; - in_pair.second = items[0] ; - } - return 0 ; -} - -template -int restore_trick_pair_stlkey_sdata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - unsigned int * keys ; - char ** items ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (unsigned int *)keys_ref->address ; - items = (char **)items_ref->address ; - - typename STL::first_type kt ; - kt.stl_id = keys[0] ; - kt.restart( object_name ) ; - - in_pair.first = kt ; - in_pair.second = items[0] ; - } - return 0 ; -} - -template -int restore_trick_pair_stlkey_stldata(STL & in_pair , std::string object_name , unsigned int id ) { - - char var_declare[128] ; - - REF2 * keys_ref , * items_ref ; - unsigned int * keys ; - unsigned int * items ; - - sprintf(var_declare, "%s_%06d_keys" , object_name.c_str(), id ) ; - keys_ref = ref_attributes(var_declare) ; - sprintf(var_declare, "%s_%06d_data" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( keys_ref != NULL && items_ref != NULL ) { - keys = (unsigned int *)keys_ref->address ; - items = (unsigned int *)items_ref->address ; - - typename STL::first_type kt ; - kt.stl_id = keys[0] ; - kt.restart( object_name ) ; - typename STL::second_type mt ; - mt.stl_id = items[0] ; - mt.restart( object_name ) ; - - in_pair.first = kt ; - in_pair.second = mt ; - } - return 0 ; -} - -#endif diff --git a/include/trick/checkpoint_trick_sequence_stl.hh b/include/trick/checkpoint_trick_sequence_stl.hh deleted file mode 100644 index ba13092f..00000000 --- a/include/trick/checkpoint_trick_sequence_stl.hh +++ /dev/null @@ -1,199 +0,0 @@ - -/* - PURPOSE: (Helpers to checkpoint STLs) -*/ - -#ifndef CHECKPOINT_TRICK_SEQUENCE_STL_HH -#define CHECKPOINT_TRICK_SEQUENCE_STL_HH - -#include -#include -#include -#include - -#ifdef __GNUC__ #include #endif - -#include "trick/STLInterface.hh" -#include "trick/memorymanager_c_intf.h" -#include "trick/message_proto.h" - -/* - These template routines perform the checkpoint and restore work for sequence STL types. - The sequence STL types include vectors, lists, deques, sets, and multisets. - There are 3 checkpoint and restore versions depending on the contained type. - */ - -template -int checkpoint_trick_sequence_stl(STL & in_stl , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - int status ; - - typename STL::value_type * items = NULL ; - typename STL::iterator it ; - typename STL::iterator end ; - - cont_size = in_stl.size() ; - - if ( cont_size > 0 ) { - - sprintf(var_declare, "%s %s_%06d[%d]" , - abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), id, cont_size) ; - items = (typename STL::value_type *)TMM_declare_var_s(var_declare) ; - //message_publish(1, "CHECKPOINT_SEQUENCE_STL with %s\n", var_declare) ; - - /* copy the contents of the stl */ - for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { - items[ii] = *it ; - } - } - - return 0 ; -} - -template -int checkpoint_trick_sequence_stl_string(STL & in_stl , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - const char ** items ; - typename STL::iterator it ; - typename STL::iterator end ; - - cont_size = in_stl.size() ; - - if ( cont_size > 0 ) { - - sprintf(var_declare, "char * %s_%06d[%d]" , object_name.c_str(), id , cont_size) ; - items = (const char **)TMM_declare_var_s(var_declare) ; - //message_publish(1, "CHECKPOINT_SEQUENCE_STL_STRING with %s\n", var_declare) ; - - /* copy the contents of the vector */ - for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { - items[ii] = it->c_str() ; - } - } - - return 0 ; -} - -template -int checkpoint_trick_sequence_stl_STLInterface(STL & in_stl , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - unsigned int * items = NULL ; - typename STL::iterator it ; - typename STL::iterator end ; - typename STL::value_type vt ; - - cont_size = in_stl.size() ; - - if ( cont_size > 0 ) { - sprintf(var_declare, "unsigned int %s_%06d[%d]" , object_name.c_str(), id, cont_size) ; - items = (unsigned int *)TMM_declare_var_s(var_declare) ; - //message_publish(1, "CHECKPOINT_SEQUENCE_STL with %s\n", var_declare) ; - - /* copy the contents of the stl */ - for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) { - items[ii] = (*it).stl_id ; - } - } - - return 0 ; -} - -template -int restore_trick_sequence_stl(STL & in_stl , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - REF2 * items_ref ; - typename STL::value_type * items ; - - //message_publish(1, "RESTORE_SEQUENCE_STL %s_%s\n", object_name.c_str() , var_name.c_str()) ; - in_stl.clear() ; - - sprintf(var_declare, "%s_%06d" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( items_ref != NULL ) { - items = (typename STL::value_type *)items_ref->address ; - cont_size = get_size((char *)items) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_stl.insert( in_stl.end(), items[ii] ) ; - } - } - - return 0 ; -} - -template -int restore_trick_sequence_stl_string(STL & in_stl , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - REF2 * items_ref ; - char ** items ; - - //message_publish(1, "in specialized vector template restore\n") ; - in_stl.clear() ; - - sprintf(var_declare, "%s_%06d" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( items_ref != NULL ) { - items = (char **)items_ref->address ; - cont_size = get_size((char *)items) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - in_stl.insert( in_stl.end(), items[ii] ) ; - } - } - - return 0 ; -} - -template -int restore_trick_sequence_stl_STLInterface(STL & in_stl , std::string object_name , unsigned int id ) { - - unsigned int ii ; - unsigned int cont_size ; - char var_declare[128] ; - - REF2 * items_ref ; - unsigned int * items ; - - //message_publish(1, "RESTORE_SEQUENCE_STL %s_%s\n", object_name.c_str() , var_name.c_str()) ; - in_stl.clear() ; - - sprintf(var_declare, "%s_%06d" , object_name.c_str(), id ) ; - items_ref = ref_attributes(var_declare) ; - - if ( items_ref != NULL ) { - items = (unsigned int *)items_ref->address ; - cont_size = get_size((char *)items) ; - - for ( ii = 0 ; ii < cont_size ; ii++ ) { - typename STL::value_type vt ; - vt.stl_id = items[ii] ; - vt.restart( object_name ) ; - in_stl.insert( in_stl.end(), vt ) ; - } - } - - return 0 ; -} - -#endif diff --git a/include/trick/trick_deque.hh b/include/trick/trick_deque.hh deleted file mode 100644 index b2a90661..00000000 --- a/include/trick/trick_deque.hh +++ /dev/null @@ -1,131 +0,0 @@ - -#ifndef TRICK_DEQUE_HH -#define TRICK_DEQUE_HH - -#include -#include -#ifndef SWIG -#include -#endif -#include "trick/checkpoint_trick_sequence_stl.hh" - -namespace Trick { - -// Empty template. This version is not used, it allows us to specialize below. -template , class dummy = void > -class deque {} ; - -// Template use for everything except strings and other STL types. -template -class deque<_Tp, _Alloc, - typename std::enable_if< !std::is_same<_Tp,std::string>::value && - !std::is_base_of::value - >::type > : public std::deque<_Tp,_Alloc> , public STLInterface { - public: - // default constructor - deque() {} ; - - // fill constructor - explicit deque(size_t __n, const _Tp & __value = _Tp(), - const _Alloc & __a = _Alloc()) : std::deque<_Tp,_Alloc>(__n, __value, __a) {} - - // iterator range constructor - template - deque(_InputIterator __first, _InputIterator __last, - const _Alloc& __a = _Alloc()) : std::deque<_Tp,_Alloc>(__first, __last, __a) {} - - // copy constructor - deque(const deque & __x) : std::deque<_Tp,_Alloc>(__x) {} - - // assignment operator - deque& operator=(const deque & __x) { - std::deque<_Tp,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized deque for other Trick STL types. -template -class deque<_Tp, _Alloc, typename std::enable_if::value>::type > : public std::deque<_Tp,_Alloc> , public STLInterface { - public: - // default constructor - deque() {} ; - - // fill constructor - explicit deque(size_t __n, const _Tp & __value = _Tp(), - const _Alloc & __a = _Alloc()) : std::deque<_Tp,_Alloc>(__n, __value, __a) {} - - // iterator range constructor - template - deque(_InputIterator __first, _InputIterator __last, - const _Alloc& __a = _Alloc()) : std::deque<_Tp,_Alloc>(__first, __last, __a) {} - - // copy constructor - deque(const deque & __x) : std::deque<_Tp,_Alloc>(__x) {} - - // assignment operator - deque& operator=(const deque & __x) { - std::deque<_Tp,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_STLInterface( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_STLInterface( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized deque for strings -template -class deque<_Tp, _Alloc, typename std::enable_if::value>::type > : public std::deque<_Tp,_Alloc> , public STLInterface { - public: - // default constructor - deque() {} ; - - // fill constructor - explicit deque(size_t __n, const _Tp & __value = _Tp(), - const _Alloc & __a = _Alloc()) : std::deque<_Tp,_Alloc>(__n, __value, __a) {} - - // iterator range constructor - template - deque(_InputIterator __first, _InputIterator __last, - const _Alloc& __a = _Alloc()) : std::deque<_Tp,_Alloc>(__first, __last, __a) {} - - // copy constructor - deque(const deque & __x) : std::deque<_Tp,_Alloc>(__x) {} - - // assignment operator - deque& operator=(const deque & __x) { - std::deque<_Tp,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_string( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_string( *this , obj_name , stl_id ) ; - } -} ; - -} ; - -#endif diff --git a/include/trick/trick_list.hh b/include/trick/trick_list.hh deleted file mode 100644 index b5e33c4c..00000000 --- a/include/trick/trick_list.hh +++ /dev/null @@ -1,131 +0,0 @@ - -#ifndef TRICK_LIST_HH -#define TRICK_LIST_HH - -#include -#include -#ifndef SWIG -#include -#endif -#include "trick/checkpoint_trick_sequence_stl.hh" - -namespace Trick { - -// Empty template. This version is not used, it allows us to specialize below. -template , class dummy = void > -class list {} ; - -// Template use for everything except strings and other STL types. -template -class list<_Tp, _Alloc, - typename std::enable_if< !std::is_same<_Tp,std::string>::value && - !std::is_base_of::value - >::type > : public std::list<_Tp,_Alloc> , public STLInterface { - public: - // default constructor - list() {} ; - - // fill constructor - explicit list(size_t __n, const _Tp & __value = _Tp(), - const _Alloc & __a = _Alloc()) : std::list<_Tp,_Alloc>(__n, __value, __a) {} - - // iterator range constructor - template - list(_InputIterator __first, _InputIterator __last, - const _Alloc& __a = _Alloc()) : std::list<_Tp,_Alloc>(__first, __last, __a) {} - - // copy constructor - list(const list & __x) : std::list<_Tp,_Alloc>(__x) {} - - // assignment operator - list& operator=(const list & __x) { - std::list<_Tp,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized list for other Trick STL types. -template -class list<_Tp, _Alloc, typename std::enable_if::value>::type > : public std::list<_Tp,_Alloc> , public STLInterface { - public: - // default constructor - list() {} ; - - // fill constructor - explicit list(size_t __n, const _Tp & __value = _Tp(), - const _Alloc & __a = _Alloc()) : std::list<_Tp,_Alloc>(__n, __value, __a) {} - - // iterator range constructor - template - list(_InputIterator __first, _InputIterator __last, - const _Alloc& __a = _Alloc()) : std::list<_Tp,_Alloc>(__first, __last, __a) {} - - // copy constructor - list(const list & __x) : std::list<_Tp,_Alloc>(__x) {} - - // assignment operator - list& operator=(const list & __x) { - std::list<_Tp,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_STLInterface( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_STLInterface( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized list for strings -template -class list<_Tp, _Alloc, typename std::enable_if::value>::type > : public std::list<_Tp,_Alloc> , public STLInterface { - public: - // default constructor - list() {} ; - - // fill constructor - explicit list(size_t __n, const _Tp & __value = _Tp(), - const _Alloc & __a = _Alloc()) : std::list<_Tp,_Alloc>(__n, __value, __a) {} - - // iterator range constructor - template - list(_InputIterator __first, _InputIterator __last, - const _Alloc& __a = _Alloc()) : std::list<_Tp,_Alloc>(__first, __last, __a) {} - - // copy constructor - list(const list & __x) : std::list<_Tp,_Alloc>(__x) {} - - // assignment operator - list& operator=(const list & __x) { - std::list<_Tp,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_string( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_string( *this , obj_name , stl_id ) ; - } -} ; - -} ; - -#endif diff --git a/include/trick/trick_map.hh b/include/trick/trick_map.hh deleted file mode 100644 index 2c5c1586..00000000 --- a/include/trick/trick_map.hh +++ /dev/null @@ -1,851 +0,0 @@ - -#ifndef TRICK_MAP_HH -#define TRICK_MAP_HH - -#include -#include -#ifndef SWIG -#include -#endif -#include "trick/checkpoint_trick_map_stl.hh" -#include "trick/STLUtilities.hh" - -namespace Trick { - -// Empty template. This version is not used, it allows us to specialize below. -template , - typename _Alloc = std::allocator<_Tp> , class dummy = void > -class map {} ; - -// Template used when both key and data are not strings or other STLs -template -class map<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< !std::is_same<_Key,std::string>::value && - !std::is_base_of::value && - !std::is_same<_Tp,std::string>::value && - !std::is_base_of::value - >::type > : public std::map<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - map() {} ; - - // iterator range constructor - template - map(_InputIterator __first, _InputIterator __last) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - map(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - map(const map & __x) : std::map<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - map& operator=(const map & __x) { - std::map<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_nkey_ndata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_nkey_ndata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized map normal key, string data. -template -class map<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< !std::is_same<_Key,std::string>::value && - !std::is_base_of::value && - std::is_same<_Tp,std::string>::value - >::type > : public std::map<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - map() {} ; - - // iterator range constructor - template - map(_InputIterator __first, _InputIterator __last) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - map(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - map(const map & __x) : std::map<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - map& operator=(const map & __x) { - std::map<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_nkey_sdata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_nkey_sdata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized map normal key, STL data. -template -class map<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< !std::is_same<_Key,std::string>::value && - !std::is_base_of::value && - std::is_base_of::value - >::type > : public std::map<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - map() {} ; - - // iterator range constructor - template - map(_InputIterator __first, _InputIterator __last) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - map(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - map(const map & __x) : std::map<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - map& operator=(const map & __x) { - std::map<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_nkey_stldata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_nkey_stldata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized map string key, normal data. -template -class map<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< std::is_same<_Key,std::string>::value && - !std::is_same<_Tp,std::string>::value && - !std::is_base_of::value - >::type > : public std::map<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - map() {} ; - - // iterator range constructor - template - map(_InputIterator __first, _InputIterator __last) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - map(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - map(const map & __x) : std::map<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - map& operator=(const map & __x) { - std::map<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_skey_ndata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_skey_ndata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized map string key, string data. -template -class map<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< std::is_same<_Key,std::string>::value && - std::is_same<_Tp,std::string>::value - >::type > : public std::map<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - map() {} ; - - // iterator range constructor - template - map(_InputIterator __first, _InputIterator __last) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - map(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - map(const map & __x) : std::map<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - map& operator=(const map & __x) { - std::map<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_skey_sdata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_skey_sdata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized map string key, STL data. -template -class map<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< std::is_same<_Key,std::string>::value && - std::is_base_of::value - >::type > : public std::map<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - map() {} ; - - // iterator range constructor - template - map(_InputIterator __first, _InputIterator __last) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - map(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - map(const map & __x) : std::map<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - map& operator=(const map & __x) { - std::map<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_skey_stldata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_skey_stldata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized map STL key, normal data. -template -class map<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< std::is_base_of::value && - !std::is_same<_Tp,std::string>::value && - !std::is_base_of::value - >::type > : public std::map<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - map() {} ; - - // iterator range constructor - template - map(_InputIterator __first, _InputIterator __last) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - map(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - map(const map & __x) : std::map<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - map& operator=(const map & __x) { - std::map<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_stlkey_ndata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_stlkey_ndata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized map STL key, string data. -template -class map<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< std::is_base_of::value && - std::is_same<_Tp,std::string>::value - >::type > : public std::map<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - map() {} ; - - // iterator range constructor - template - map(_InputIterator __first, _InputIterator __last) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - map(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - map(const map & __x) : std::map<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - map& operator=(const map & __x) { - std::map<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_stlkey_sdata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_stlkey_sdata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized map STL key, STL data. (Really? Who in their right mind would do this?) -template -class map<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< std::is_base_of::value && - std::is_base_of::value - >::type > : public std::map<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - map() {} ; - - // iterator range constructor - template - map(_InputIterator __first, _InputIterator __last) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - map(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::map<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - map(const map & __x) : std::map<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - map& operator=(const map & __x) { - std::map<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_stlkey_stldata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_stlkey_stldata( *this , obj_name , stl_id ) ; - } -} ; - -/* MULTIMAP */ - -// Empty template. This version is not used, it allows us to specialize below. -template , - typename _Alloc = std::allocator<_Tp> , class dummy = void > -class multimap {} ; - -// Template used when both key and data are not strings or other STLs -template -class multimap<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< !std::is_same<_Key,std::string>::value && - !std::is_base_of::value && - !std::is_same<_Tp,std::string>::value && - !std::is_base_of::value - >::type > : public std::multimap<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - multimap() {} ; - - // iterator range constructor - template - multimap(_InputIterator __first, _InputIterator __last) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - multimap(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - multimap(const multimap & __x) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - multimap& operator=(const multimap & __x) { - std::multimap<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_nkey_ndata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_nkey_ndata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized multimap normal key, string data. -template -class multimap<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< !std::is_same<_Key,std::string>::value && - !std::is_base_of::value && - std::is_same<_Tp,std::string>::value - >::type > : public std::multimap<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - multimap() {} ; - - // iterator range constructor - template - multimap(_InputIterator __first, _InputIterator __last) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - multimap(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - multimap(const multimap & __x) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - multimap& operator=(const multimap & __x) { - std::multimap<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_nkey_sdata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_nkey_sdata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized multimap normal key, STL data. -template -class multimap<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< !std::is_same<_Key,std::string>::value && - !std::is_base_of::value && - std::is_base_of::value - >::type > : public std::multimap<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - multimap() {} ; - - // iterator range constructor - template - multimap(_InputIterator __first, _InputIterator __last) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - multimap(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - multimap(const multimap & __x) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - multimap& operator=(const multimap & __x) { - std::multimap<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_nkey_stldata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_nkey_stldata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized multimap string key, normal data. -template -class multimap<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< std::is_same<_Key,std::string>::value && - !std::is_same<_Tp,std::string>::value && - !std::is_base_of::value - >::type > : public std::multimap<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - multimap() {} ; - - // iterator range constructor - template - multimap(_InputIterator __first, _InputIterator __last) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - multimap(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - multimap(const multimap & __x) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - multimap& operator=(const multimap & __x) { - std::multimap<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_skey_ndata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_skey_ndata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized multimap string key, string data. -template -class multimap<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< std::is_same<_Key,std::string>::value && - std::is_same<_Tp,std::string>::value - >::type > : public std::multimap<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - multimap() {} ; - - // iterator range constructor - template - multimap(_InputIterator __first, _InputIterator __last) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - multimap(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - multimap(const multimap & __x) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - multimap& operator=(const multimap & __x) { - std::multimap<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_skey_sdata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_skey_sdata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized multimap string key, STL data. -template -class multimap<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< std::is_same<_Key,std::string>::value && - std::is_base_of::value - >::type > : public std::multimap<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - multimap() {} ; - - // iterator range constructor - template - multimap(_InputIterator __first, _InputIterator __last) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - multimap(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - multimap(const multimap & __x) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - multimap& operator=(const multimap & __x) { - std::multimap<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_skey_stldata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_skey_stldata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized multimap STL key, normal data. -template -class multimap<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< std::is_base_of::value && - !std::is_same<_Tp,std::string>::value && - !std::is_base_of::value - >::type > : public std::multimap<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - multimap() {} ; - - // iterator range constructor - template - multimap(_InputIterator __first, _InputIterator __last) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - multimap(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - multimap(const multimap & __x) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - multimap& operator=(const multimap & __x) { - std::multimap<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_stlkey_ndata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_stlkey_ndata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized multimap STL key, string data. -template -class multimap<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< std::is_base_of::value && - std::is_same<_Tp,std::string>::value - >::type > : public std::multimap<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - multimap() {} ; - - // iterator range constructor - template - multimap(_InputIterator __first, _InputIterator __last) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - multimap(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - multimap(const multimap & __x) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - multimap& operator=(const multimap & __x) { - std::multimap<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_stlkey_sdata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_stlkey_sdata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized multimap STL key, STL data. (Really? Who in their right mind would do this?) -template -class multimap<_Key, _Tp, _Compare, _Alloc, - typename std::enable_if< std::is_base_of::value && - std::is_base_of::value - >::type > : public std::multimap<_Key,_Tp,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - multimap() {} ; - - // iterator range constructor - template - multimap(_InputIterator __first, _InputIterator __last) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - multimap(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - multimap(const multimap & __x) : std::multimap<_Key,_Tp,_Compare,_Alloc>(__x) {} - - // assignment operator - multimap& operator=(const multimap & __x) { - std::multimap<_Key,_Tp,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_map_stlkey_stldata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_map_stlkey_stldata( *this , obj_name , stl_id ) ; - } -} ; - -} ; - -#endif diff --git a/include/trick/trick_pair.hh b/include/trick/trick_pair.hh deleted file mode 100644 index 49393d82..00000000 --- a/include/trick/trick_pair.hh +++ /dev/null @@ -1,382 +0,0 @@ - -#ifndef TRICK_PAIR_HH -#define TRICK_PAIR_HH - -#include -#include -#ifndef SWIG -#include -#endif -#include "trick/checkpoint_trick_pair_stl.hh" -#include "trick/STLUtilities.hh" - - -namespace Trick { - -// Empty template. This version is not used, it allows us to specialize below. -template -class pair {} ; - -// Template used when both key and data are not strings or other STLs -template -class pair<_T1, _T2, - typename std::enable_if< !std::is_same<_T1,std::string>::value && - !std::is_base_of::value && - !std::is_same<_T2,std::string>::value && - !std::is_base_of::value - >::type > : public std::pair<_T1,_T2> , public STLInterface { - public: - // default constructor - pair() {} - - // incoming data constructor - pair(const _T1& __a, const _T2& __b) : std::pair<_T1,_T2>(__a,__b) {} - - // templated copy constructor - template - pair(const pair<_U1, _U2>& __p) : std::pair<_T1,_T2>(__p) {} - - // assignment operator - pair& operator=(const pair & __x) { - std::pair<_T1,_T2>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_pair_nkey_ndata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_pair_nkey_ndata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized pair normal key, string data. -template -class pair<_T1, _T2, - typename std::enable_if< !std::is_same<_T1,std::string>::value && - !std::is_base_of::value && - std::is_same<_T2,std::string>::value - >::type > : public std::pair<_T1,_T2> , public STLInterface { - public: - // default constructor - pair() {} ; - - // incoming data constructor - pair(const _T1& __a, const _T2& __b) : std::pair<_T1,_T2>(__a,__b) {} - - // templated copy constructor - template - pair(const pair<_U1, _U2>& __p) : std::pair<_T1,_T2>(__p) {} - - // assignment operator - pair& operator=(const pair & __x) { - std::pair<_T1,_T2>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_pair_nkey_sdata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_pair_nkey_sdata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized pair normal key, STL data. -template -class pair<_T1, _T2, - typename std::enable_if< !std::is_same<_T1,std::string>::value && - !std::is_base_of::value && - std::is_base_of::value - >::type > : public std::pair<_T1,_T2> , public STLInterface { - public: - // default constructor - pair() {} ; - - // incoming data constructor - pair(const _T1& __a, const _T2& __b) : std::pair<_T1,_T2>(__a,__b) {} - - // templated copy constructor - template - pair(const pair<_U1, _U2>& __p) : std::pair<_T1,_T2>(__p) {} - - // assignment operator - pair& operator=(const pair & __x) { - std::pair<_T1,_T2>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_pair_nkey_stldata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_pair_nkey_stldata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized pair string key, normal data. -template -class pair<_T1, _T2, - typename std::enable_if< std::is_same<_T1,std::string>::value && - !std::is_same<_T2,std::string>::value && - !std::is_base_of::value - >::type > : public std::pair<_T1,_T2> , public STLInterface { - public: - // default constructor - pair() {} ; - - // incoming data constructor - pair(const _T1& __a, const _T2& __b) : std::pair<_T1,_T2>(__a,__b) {} - - // templated copy constructor - template - pair(const pair<_U1, _U2>& __p) : std::pair<_T1,_T2>(__p) {} - - // assignment operator - pair& operator=(const pair & __x) { - std::pair<_T1,_T2>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_pair_skey_ndata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_pair_skey_ndata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized pair string key, string data. -template -class pair<_T1, _T2, - typename std::enable_if< std::is_same<_T1,std::string>::value && - std::is_same<_T2,std::string>::value - >::type > : public std::pair<_T1,_T2> , public STLInterface { - public: - // default constructor - pair() {} ; - - // incoming data constructor - pair(const _T1& __a, const _T2& __b) : std::pair<_T1,_T2>(__a,__b) {} - - // templated copy constructor - template - pair(const pair<_U1, _U2>& __p) : std::pair<_T1,_T2>(__p) {} - - // assignment operator - pair& operator=(const pair & __x) { - std::pair<_T1,_T2>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_pair_skey_sdata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_pair_skey_sdata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized pair string key, STL data. -template -class pair<_T1, _T2, - typename std::enable_if< std::is_same<_T1,std::string>::value && - std::is_base_of::value - >::type > : public std::pair<_T1,_T2> , public STLInterface { - public: - // default constructor - pair() {} ; - - // incoming data constructor - pair(const _T1& __a, const _T2& __b) : std::pair<_T1,_T2>(__a,__b) {} - - // templated copy constructor - template - pair(const pair<_U1, _U2>& __p) : std::pair<_T1,_T2>(__p) {} - - // assignment operator - pair& operator=(const pair & __x) { - std::pair<_T1,_T2>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_pair_skey_stldata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_pair_skey_stldata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized pair STL key, normal data. -template -class pair<_T1, _T2, - typename std::enable_if< std::is_base_of::value && - !std::is_same<_T2,std::string>::value && - !std::is_base_of::value - >::type > : public std::pair<_T1,_T2> , public STLInterface { - public: - // default constructor - pair() {} ; - - // incoming data constructor - pair(const _T1& __a, const _T2& __b) : std::pair<_T1,_T2>(__a,__b) {} - - // templated copy constructor - template - pair(const pair<_U1, _U2>& __p) : std::pair<_T1,_T2>(__p) {} - - // assignment operator - pair& operator=(const pair & __x) { - std::pair<_T1,_T2>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_pair_stlkey_ndata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_pair_stlkey_ndata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized pair STL key, string data. -template -class pair<_T1, _T2, - typename std::enable_if< std::is_base_of::value && - std::is_same<_T2,std::string>::value - >::type > : public std::pair<_T1,_T2> , public STLInterface { - public: - // default constructor - pair() {} ; - - // incoming data constructor - pair(const _T1& __a, const _T2& __b) : std::pair<_T1,_T2>(__a,__b) {} - - // templated copy constructor - template - pair(const pair<_U1, _U2>& __p) : std::pair<_T1,_T2>(__p) {} - - // assignment operator - pair& operator=(const pair & __x) { - std::pair<_T1,_T2>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_pair_stlkey_sdata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_pair_stlkey_sdata( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized pair STL key, STL data. -template -class pair<_T1, _T2, - typename std::enable_if< std::is_base_of::value && - std::is_base_of::value - >::type > : public std::pair<_T1,_T2> , public STLInterface { - public: - // default constructor - pair() {} ; - - // incoming data constructor - pair(const _T1& __a, const _T2& __b) : std::pair<_T1,_T2>(__a,__b) {} - - // templated copy constructor - template - pair(const pair<_U1, _U2>& __p) : std::pair<_T1,_T2>(__p) {} - - // assignment operator - pair& operator=(const pair & __x) { - std::pair<_T1,_T2>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_pair_stlkey_stldata( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::checkpoint - virtual void post_checkpoint( std::string obj_name ) { - delete_trick_map_stl( obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_pair_stlkey_stldata( *this , obj_name , stl_id ) ; - } -} ; - -template -inline pair<_T1, _T2> make_pair(_T1 __x, _T2 __y) { return pair<_T1, _T2>(__x, __y); } - -} ; - -#endif diff --git a/include/trick/trick_queue.hh b/include/trick/trick_queue.hh deleted file mode 100644 index 2ec05981..00000000 --- a/include/trick/trick_queue.hh +++ /dev/null @@ -1,160 +0,0 @@ - -#ifndef TRICK_QUEUE_HH -#define TRICK_QUEUE_HH - -#include -#include -#ifndef SWIG -#include -#endif -#include "trick/checkpoint_trick_sequence_stl.hh" - -/* - This algorithm depends on the queue container type is called "c" and is - a protected variable. There are no guarantees this works with anything but - the current gcc versions we are using. -*/ -namespace Trick { - -// Empty template. This version is not used, it allows us to specialize below. -template , class dummy = void > -class queue {} ; - -// Template use for everything except strings and other STL types. -template -class queue<_Tp, _Sequence, - typename std::enable_if< !std::is_same<_Tp,std::string>::value && - !std::is_base_of::value - >::type > : public std::queue<_Tp, _Sequence> , public STLInterface { - public: - // default constructor - explicit queue(const _Sequence& __c = _Sequence()) : std::queue<_Tp, _Sequence>(__c) { } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl( std::queue<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl( std::queue<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } -} ; - -// Specialized queue for strings -template -class queue<_Tp, _Sequence, typename std::enable_if::value>::type > - : public std::queue<_Tp, _Sequence> , public STLInterface { - public: - // default constructor - explicit queue(const _Sequence& __c = _Sequence()) : std::queue<_Tp, _Sequence>(__c) { } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_string( std::queue<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_string( std::queue<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } -} ; - -// Specialized queue for other Trick STL types. -template -class queue<_Tp, _Sequence, typename std::enable_if::value>::type > - : public std::queue<_Tp, _Sequence> , public STLInterface { - public: - // default constructor - explicit queue(const _Sequence& __s = _Sequence()) : std::queue<_Tp, _Sequence>(__s) { } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_STLInterface( std::queue<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_STLInterface( std::queue<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } -} ; - -/* PRIORITY QUEUE */ - -// Empty template. This version is not used, it allows us to specialize below. -template , - typename _Compare = std::less , class dummy = void > -class priority_queue {} ; - -// Template use for everything except strings and other STL types. -template -class priority_queue<_Tp, _Sequence, _Compare, - typename std::enable_if< !std::is_same<_Tp,std::string>::value && - !std::is_base_of::value - >::type > : public std::priority_queue<_Tp, _Sequence, _Compare> , public STLInterface { - public: - // default constructor - explicit priority_queue(const _Compare& __x = _Compare(), const _Sequence& __s = _Sequence()) - : std::priority_queue<_Tp, _Sequence, _Compare>(__x, __s) { } - - // iterator constructor - template - priority_queue(_InputIterator __first, _InputIterator __last, - const _Compare& __x = _Compare(), - const _Sequence& __s = _Sequence()) - : std::priority_queue<_Tp, _Sequence, _Compare>(__first, __last, __x, __s) { } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl( std::priority_queue<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl( std::priority_queue<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } -} ; - -// Specialized priority_queue for strings -template -class priority_queue<_Tp, _Sequence, _Compare, typename std::enable_if::value>::type > - : public std::priority_queue<_Tp, _Sequence, _Compare> , public STLInterface { - public: - // default constructor - explicit priority_queue(const _Compare& __x = _Compare(), const _Sequence& __s = _Sequence()) - : std::priority_queue<_Tp, _Sequence, _Compare>(__x, __s) { } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_string( std::priority_queue<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_string( std::priority_queue<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } -} ; - -// Specialized priority_queue for other Trick STL types. -template -class priority_queue<_Tp, _Sequence, _Compare, typename std::enable_if::value>::type > - : public std::priority_queue<_Tp, _Sequence, _Compare> , public STLInterface { - public: - // default constructor - explicit priority_queue(const _Compare& __x = _Compare(), const _Sequence& __s = _Sequence()) - : std::priority_queue<_Tp, _Sequence, _Compare>(__x, __s) { } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_STLInterface( std::priority_queue<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_STLInterface( std::priority_queue<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } -} ; - -} ; - -#endif diff --git a/include/trick/trick_set.hh b/include/trick/trick_set.hh deleted file mode 100644 index 0e86c07e..00000000 --- a/include/trick/trick_set.hh +++ /dev/null @@ -1,256 +0,0 @@ - -#ifndef TRICK_SET_HH -#define TRICK_SET_HH - -#include -#include -#ifndef SWIG -#include -#endif -#include "trick/checkpoint_trick_sequence_stl.hh" - -namespace Trick { - -// Empty template. This version is not used, it allows us to specialize below. -template , typename _Alloc = std::allocator<_Key>, class dummy = void > -class set {} ; - -// Template use for everything except strings and other STL types. -template -class set<_Key, _Compare, _Alloc, - typename std::enable_if< !std::is_same<_Key,std::string>::value && - !std::is_base_of::value - >::type > : public std::set<_Key,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - set() {} ; - - // iterator range constructor - template - set(_InputIterator __first, _InputIterator __last) : std::set<_Key,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - set(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::set<_Key,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - set(const set & __x) : std::set<_Key,_Compare,_Alloc>(__x) {} - - // assignment operator - set& operator=(const set & __x) { - std::set<_Key,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized set for other Trick STL types. -template -class set<_Key, _Compare, _Alloc, typename std::enable_if::value>::type > - : public std::set<_Key,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - set() {} ; - - // iterator range constructor - template - set(_InputIterator __first, _InputIterator __last) : std::set<_Key,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - set(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::set<_Key,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - set(const set & __x) : std::set<_Key,_Compare,_Alloc>(__x) {} - - // assignment operator - set& operator=(const set & __x) { - std::set<_Key,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_STLInterface( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_STLInterface( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized set for strings -template -class set<_Key, _Compare, _Alloc, typename std::enable_if::value>::type > - : public std::set<_Key,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - set() {} ; - - // iterator range constructor - template - set(_InputIterator __first, _InputIterator __last) : std::set<_Key,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - set(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::set<_Key,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - set(const set & __x) : std::set<_Key,_Compare,_Alloc>(__x) {} - - // assignment operator - set& operator=(const set & __x) { - std::set<_Key,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_string( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_string( *this , obj_name , stl_id ) ; - } -} ; - -// Empty template. This version is not used, it allows us to specialize below. -template , typename _Alloc = std::allocator<_Key>, class dummy = void > -class multiset {} ; - -// Template use for everything except strings and other STL types. -template -class multiset<_Key, _Compare, _Alloc, - typename std::enable_if< !std::is_same<_Key,std::string>::value && - !std::is_base_of::value - >::type > : public std::multiset<_Key,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - multiset() {} ; - - // iterator range constructor - template - multiset(_InputIterator __first, _InputIterator __last) : std::multiset<_Key,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - multiset(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::multiset<_Key,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - multiset(const multiset & __x) : std::multiset<_Key,_Compare,_Alloc>(__x) {} - - // assignment operator - multiset& operator=(const multiset & __x) { - std::multiset<_Key,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized multiset for other Trick STL types. -template -class multiset<_Key, _Compare, _Alloc, typename std::enable_if::value>::type > - : public std::multiset<_Key,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - multiset() {} ; - - // iterator range constructor - template - multiset(_InputIterator __first, _InputIterator __last) : std::multiset<_Key,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - multiset(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::multiset<_Key,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - multiset(const multiset & __x) : std::multiset<_Key,_Compare,_Alloc>(__x) {} - - // assignment operator - multiset& operator=(const multiset & __x) { - std::multiset<_Key,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_STLInterface( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_STLInterface( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized multiset for strings -template -class multiset<_Key, _Compare, _Alloc, typename std::enable_if::value>::type > - : public std::multiset<_Key,_Compare,_Alloc> , public STLInterface { - public: - // default constructor - multiset() {} ; - - // iterator range constructor - template - multiset(_InputIterator __first, _InputIterator __last) : std::multiset<_Key,_Compare,_Alloc>(__first, __last) {} - - // iterator range constructor with compare function - template - multiset(_InputIterator __first, _InputIterator __last, - const _Compare& __comp, - const _Alloc& __a = _Alloc()) : std::multiset<_Key,_Compare,_Alloc>(__first, __last,__comp,__a) {} - - // copy constructor - multiset(const multiset & __x) : std::multiset<_Key,_Compare,_Alloc>(__x) {} - - // assignment operator - multiset& operator=(const multiset & __x) { - std::multiset<_Key,_Compare,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_string( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_string( *this , obj_name , stl_id ) ; - } -} ; - -} ; - -#endif diff --git a/include/trick/trick_stack.hh b/include/trick/trick_stack.hh deleted file mode 100644 index a5c844c2..00000000 --- a/include/trick/trick_stack.hh +++ /dev/null @@ -1,83 +0,0 @@ - -#ifndef TRICK_STACK_HH -#define TRICK_STACK_HH - -#include -#include -#ifndef SWIG -#include -#endif -#include "trick/checkpoint_trick_sequence_stl.hh" - -/* - This algorithm depends on the stack container type is called "c" and is - a protected variable. There are no guarantees this works with anything but - the current gcc versions we are using. -*/ -namespace Trick { - -// Empty template. This version is not used, it allows us to specialize below. -template , class dummy = void > -class stack {} ; - -// Template use for everything except strings and other STL types. -template -class stack<_Tp, _Sequence, typename std::enable_if< !std::is_same<_Tp,std::string>::value && - !std::is_base_of::value - >::type > : public std::stack<_Tp, _Sequence> , public STLInterface { - public: - // default constructor - explicit stack(const _Sequence& __c = _Sequence()) : std::stack<_Tp, _Sequence>(__c) { } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl( std::stack<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl( std::stack<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } -} ; - -// Specialized stack for strings -template -class stack<_Tp, _Sequence, typename std::enable_if::value>::type > - : public std::stack<_Tp, _Sequence> , public STLInterface { - public: - // default constructor - explicit stack(const _Sequence& __c = _Sequence()) : std::stack<_Tp, _Sequence>(__c) { } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_string( std::stack<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_string( std::stack<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } -} ; - -// Specialized stack for other Trick STL types. -template -class stack<_Tp, _Sequence, typename std::enable_if::value>::type > - : public std::stack<_Tp, _Sequence> , public STLInterface { - public: - // default constructor - explicit stack(const _Sequence& __c = _Sequence()) : std::stack<_Tp, _Sequence>(__c) { } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_STLInterface( std::stack<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_STLInterface( std::stack<_Tp, _Sequence>::c , obj_name , stl_id ) ; - } -} ; - -} ; - -#endif diff --git a/include/trick/trick_vector.hh b/include/trick/trick_vector.hh deleted file mode 100644 index 9d1d886d..00000000 --- a/include/trick/trick_vector.hh +++ /dev/null @@ -1,133 +0,0 @@ - -#ifndef TRICK_VECTOR_HH -#define TRICK_VECTOR_HH - -#include -#include -#ifndef SWIG -#include -#endif -#include "trick/checkpoint_trick_sequence_stl.hh" - -namespace Trick { - -// Empty template. This version is not used, it allows us to specialize below. -template , class dummy = void > -class vector {} ; - -// Template use for everything except strings and other STL types. -template -class vector<_Tp, _Alloc, - typename std::enable_if< !std::is_same<_Tp,std::string>::value && - !std::is_base_of::value - >::type > : public std::vector<_Tp,_Alloc> , public STLInterface { - public: - // default constructor - vector() {} ; - - // fill constructor - explicit vector(size_t __n, const _Tp & __value = _Tp(), - const _Alloc & __a = _Alloc()) : std::vector<_Tp,_Alloc>(__n, __value, __a) {} - - // iterator range constructor - template - vector(_InputIterator __first, _InputIterator __last, - const _Alloc& __a = _Alloc()) : std::vector<_Tp,_Alloc>(__first, __last, __a) {} - - // copy constructor - vector(const vector & __x) : std::vector<_Tp,_Alloc>(__x) {} - - // assignment operator - vector& operator=(const vector & __x) { - std::vector<_Tp,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized vector for other Trick STL types. -template -class vector<_Tp, _Alloc, typename std::enable_if::value>::type > - : public std::vector<_Tp,_Alloc> , public STLInterface { - public: - // default constructor - vector() {} ; - - // fill constructor - explicit vector(size_t __n, const _Tp & __value = _Tp(), - const _Alloc & __a = _Alloc()) : std::vector<_Tp,_Alloc>(__n, __value, __a) {} - - // iterator range constructor - template - vector(_InputIterator __first, _InputIterator __last, - const _Alloc& __a = _Alloc()) : std::vector<_Tp,_Alloc>(__first, __last, __a) {} - - // copy constructor - vector(const vector & __x) : std::vector<_Tp,_Alloc>(__x) {} - - // assignment operator - vector& operator=(const vector & __x) { - std::vector<_Tp,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_STLInterface( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_STLInterface( *this , obj_name , stl_id ) ; - } -} ; - -// Specialized vector for strings -template -class vector<_Tp, _Alloc, typename std::enable_if::value>::type > - : public std::vector<_Tp,_Alloc> , public STLInterface { - public: - // default constructor - vector() {} ; - - // fill constructor - explicit vector(size_t __n, const _Tp & __value = _Tp(), - const _Alloc & __a = _Alloc()) : std::vector<_Tp,_Alloc>(__n, __value, __a) {} - - // iterator range constructor - template - vector(_InputIterator __first, _InputIterator __last, - const _Alloc& __a = _Alloc()) : std::vector<_Tp,_Alloc>(__first, __last, __a) {} - - // copy constructor - vector(const vector & __x) : std::vector<_Tp,_Alloc>(__x) {} - - // assignment operator - vector& operator=(const vector & __x) { - std::vector<_Tp,_Alloc>::operator = (__x) ; - return *this ; - } - - // inherited STLInterface::checkpoint - virtual void checkpoint( std::string obj_name ) { - checkpoint_trick_sequence_stl_string( *this , obj_name , stl_id ) ; - } - - // inherited STLInterface::restart - virtual void restart( std::string obj_name ) { - restore_trick_sequence_stl_string( *this , obj_name , stl_id ) ; - } -} ; - -} ; - -#endif diff --git a/share/trick/sim_objects/default_trick_sys.sm b/share/trick/sim_objects/default_trick_sys.sm index 17bf71bd..b08ce079 100644 --- a/share/trick/sim_objects/default_trick_sys.sm +++ b/share/trick/sim_objects/default_trick_sys.sm @@ -224,11 +224,6 @@ class CheckPointRestartSimObject : public Trick::SimObject { {TRK} P0 ("freeze") cpr.load_checkpoint_job() ; {TRK} P0 ("end_of_frame") cpr.load_checkpoint_job() ; - - {TRK} P0 ("checkpoint") cpr.pre_checkpoint() ; - {TRK} P0 ("post_checkpoint") cpr.post_checkpoint() ; - {TRK} P0 ("restart") cpr.restart() ; - } } CheckPointRestartSimObject trick_cpr ; diff --git a/test/SIM_stls/RUN_test/input.py b/test/SIM_stls/RUN_test/input.py index d49bbf77..458f7730 100644 --- a/test/SIM_stls/RUN_test/input.py +++ b/test/SIM_stls/RUN_test/input.py @@ -3,9 +3,9 @@ def main(): #trick.echo_jobs_on() - trick.sim_control_panel_set_enabled(True) - trick.real_time_enable() - trick.itimer_enable() + #trick.sim_control_panel_set_enabled(True) + #trick.real_time_enable() + #trick.itimer_enable() trick.checkpoint_pre_init(True) #trick.checkpoint_post_init(True) diff --git a/test/SIM_stls2/RUN_test/input.py b/test/SIM_stls2/RUN_test/input.py deleted file mode 100644 index 121ebb3f..00000000 --- a/test/SIM_stls2/RUN_test/input.py +++ /dev/null @@ -1,24 +0,0 @@ - -def main(): - - #trick.echo_jobs_on() - simControlPanel = trick.SimControlPanel() - simControlPanel.thisown = 0 - trick.add_external_application(simControlPanel) - - trick.real_time_enable() - #trick.itimer_enable() - - trick.checkpoint_post_init(True) - trick.checkpoint_end(True) - - trick.freeze(2.0) - - the_object.stlc2.name = "Daisy" - - trick.exec_set_freeze_frame(0.10) - trick.stop(5.0) - -if __name__ == "__main__": - main() - diff --git a/test/SIM_stls2/RUN_test/unit_test.py b/test/SIM_stls2/RUN_test/unit_test.py deleted file mode 100644 index 27d15f96..00000000 --- a/test/SIM_stls2/RUN_test/unit_test.py +++ /dev/null @@ -1,15 +0,0 @@ - -def main(): - - trick.checkpoint_post_init(True) - trick.checkpoint_end(True) - - the_object.stlc2.name = "Daisy" - - # Data recording HDF5 test - trick.exec_set_freeze_frame(0.10) - trick.stop(5.0) - -if __name__ == "__main__": - main() - diff --git a/test/SIM_stls2/S_define b/test/SIM_stls2/S_define deleted file mode 100644 index 38dfe170..00000000 --- a/test/SIM_stls2/S_define +++ /dev/null @@ -1,37 +0,0 @@ -#include "sim_objects/default_trick_sys.sm" - -##include "stl_checkpoint/STLCheckpoint.hh" - -/* This object tests having 2 of the same type of object containing STLs in the same sim_object. - The checkpoints use the name of the objects to give the STLs unique and identifiable names - in the checkpoint. This is done by invoking CHECKPOINT_STL for each variable (see stl_checkpoints.sm) */ - -class theSimObject : public Trick::SimObject { - - public: - STLCheckpoint stlc ; - STLCheckpoint stlc2 ; - - /** Constructor to add the jobs */ - theSimObject() : stlc(std::string("Petunia")) , stlc2() { - - (1.0, "scheduled") stlc.speak() ; - - #include "stl_checkpoints.sm" - } - -} ; - -// Multiple simobjects -theSimObject the_object ; -theSimObject the_object2 ; - -// Connect objects -void create_connections() { - - // Set the default termination time - trick_sys.sched.set_terminate_time(10.0) ; - trick_sys.sched.set_freeze_frame(0.10) ; - -} - diff --git a/test/SIM_stls2/S_overrides.mk b/test/SIM_stls2/S_overrides.mk deleted file mode 100644 index 27536a3b..00000000 --- a/test/SIM_stls2/S_overrides.mk +++ /dev/null @@ -1,4 +0,0 @@ - -TRICK_CFLAGS += -I./models -TRICK_CXXFLAGS += -I./models - diff --git a/test/SIM_stls2/models/stl_checkpoint/STLCheckpoint.cpp b/test/SIM_stls2/models/stl_checkpoint/STLCheckpoint.cpp deleted file mode 100644 index c8472d15..00000000 --- a/test/SIM_stls2/models/stl_checkpoint/STLCheckpoint.cpp +++ /dev/null @@ -1,281 +0,0 @@ - -#include "sim_services/Message/include/message_proto.h" -#include "STLCheckpoint.hh" - -/* These 2 constructors add different data to an STLCheckpoint. */ - -STLCheckpoint::STLCheckpoint() { - - my_double_map[11.1] = 111.1 ; - my_double_map[22.2] = 222.2 ; - my_double_map[33.3] = 333.3 ; - - my_string_key_map[std::string("one")] = 1 ; - my_string_key_map[std::string("two")] = 2 ; - my_string_key_map[std::string("three")] = 3 ; - - my_string_data_map[4] = std::string("vier") ; - my_string_data_map[5] = std::string("fumf") ; - my_string_data_map[6] = std::string("sechs") ; - - my_string_map[std::string("mother")] = std::string("Marge") ; - my_string_map[std::string("father")] = std::string("Homer") ; - my_string_map[std::string("son")] = std::string("Bart") ; - - my_int_multimap.insert(std::pair(11,111)) ; - my_int_multimap.insert(std::pair(22,222)) ; - my_int_multimap.insert(std::pair(33,333)) ; - my_int_multimap.insert(std::pair(11,111)) ; - my_int_multimap.insert(std::pair(22,222)) ; - my_int_multimap.insert(std::pair(33,333)) ; - - my_string_key_multimap.insert(std::pair("one", 1)) ; - my_string_key_multimap.insert(std::pair("two", 2)) ; - my_string_key_multimap.insert(std::pair("three", 3)) ; - my_string_key_multimap.insert(std::pair("one", 1)) ; - my_string_key_multimap.insert(std::pair("two", 2)) ; - my_string_key_multimap.insert(std::pair("three", 3)) ; - - my_string_data_multimap.insert(std::pair(4, "vier")) ; - my_string_data_multimap.insert(std::pair(5, "fumf")) ; - my_string_data_multimap.insert(std::pair(6, "sechs")) ; - my_string_data_multimap.insert(std::pair(4, "four")) ; - my_string_data_multimap.insert(std::pair(5, "five")) ; - my_string_data_multimap.insert(std::pair(6, "six")) ; - - my_string_multimap.insert(std::pair("mother","Marge")) ; - my_string_multimap.insert(std::pair("father","Homer")) ; - my_string_multimap.insert(std::pair("mother","Lois")) ; - my_string_multimap.insert(std::pair("father","Meg")) ; - - my_double_vector.push_back(1.0) ; - my_double_vector.push_back(2.0) ; - my_double_vector.push_back(3.0) ; - - my_string_vector.push_back("I") ; - my_string_vector.push_back("was") ; - my_string_vector.push_back("here") ; - - my_short_list.push_back(300) ; - my_short_list.push_back(301) ; - my_short_list.push_back(302) ; - - my_string_list.push_back("I") ; - my_string_list.push_back("was") ; - my_string_list.push_back("there") ; - - my_float_deque.push_back(12.3) ; - my_float_deque.push_back(45.6) ; - my_float_deque.push_back(78.9) ; - - my_string_deque.push_back("meow") ; - my_string_deque.push_back("bark") ; - my_string_deque.push_back("quack") ; - - my_int_set.insert(8) ; - my_int_set.insert(4) ; - my_int_set.insert(2) ; - my_int_set.insert(1) ; - - my_string_set.insert("e") ; - my_string_set.insert("a") ; - my_string_set.insert("d") ; - - my_long_multiset.insert(8) ; - my_long_multiset.insert(4) ; - my_long_multiset.insert(4) ; - my_long_multiset.insert(2) ; - my_long_multiset.insert(1) ; - - my_string_multiset.insert("e") ; - my_string_multiset.insert("a") ; - my_string_multiset.insert("d") ; - my_string_multiset.insert("e") ; - my_string_multiset.insert("a") ; - my_string_multiset.insert("d") ; - - my_uint_stack.push(10) ; - my_uint_stack.push(20) ; - my_uint_stack.push(30) ; - my_uint_stack.push(40) ; - - my_string_stack.push("abc I") ; - my_string_stack.push("abc want the one") ; - my_string_stack.push("abc with the bigger") ; - my_string_stack.push("abc Gee Bees") ; - - my_int_queue.push(10) ; - my_int_queue.push(20) ; - my_int_queue.push(30) ; - my_int_queue.push(40) ; - - my_string_queue.push("abc I") ; - my_string_queue.push("abc want") ; - my_string_queue.push("abc an") ; - my_string_queue.push("abc iPhone 4") ; - - my_int_priority_queue.push(30) ; - my_int_priority_queue.push(20) ; - my_int_priority_queue.push(40) ; - my_int_priority_queue.push(10) ; - - my_string_priority_queue.push("abc I") ; - my_string_priority_queue.push("abc want") ; - my_string_priority_queue.push("abc an") ; - my_string_priority_queue.push("abc iPhone 4") ; - - my_int_pair.first = 1 ; - my_int_pair.second = 2 ; - - my_string_first_pair.first = "abc string first" ; - my_string_first_pair.second = 2 ; - - my_string_second_pair.first = 2 ; - my_string_second_pair.second = "abc string second" ; - - my_string_pair.first = "abc pair first string" ; - my_string_pair.second = "abc pair second string" ; - return ; -} - -STLCheckpoint::STLCheckpoint(std::string in_name) { - - name = in_name ; - - my_double_map[44.4] = 444.4 ; - my_double_map[55.5] = 555.5 ; - my_double_map[66.6] = 666.6 ; - - my_string_key_map[std::string("four")] = 4 ; - my_string_key_map[std::string("five")] = 5 ; - my_string_key_map[std::string("six")] = 6 ; - - my_string_data_map[7] = std::string("seiben") ; - my_string_data_map[8] = std::string("acht") ; - my_string_data_map[9] = std::string("neun") ; - - my_string_map[std::string("sister")] = std::string("Lisa") ; - my_string_map[std::string("dog")] = std::string("Santa's Little Helper") ; - - my_int_multimap.insert(std::pair(44,444)) ; - my_int_multimap.insert(std::pair(55,555)) ; - my_int_multimap.insert(std::pair(66,666)) ; - my_int_multimap.insert(std::pair(44,444)) ; - my_int_multimap.insert(std::pair(55,555)) ; - my_int_multimap.insert(std::pair(66,666)) ; - - my_string_key_multimap.insert(std::pair("four", 4)) ; - my_string_key_multimap.insert(std::pair("five", 5)) ; - my_string_key_multimap.insert(std::pair("six", 6)) ; - my_string_key_multimap.insert(std::pair("four", 44)) ; - my_string_key_multimap.insert(std::pair("five", 55)) ; - my_string_key_multimap.insert(std::pair("six", 66)) ; - - my_string_data_multimap.insert(std::pair(7, "seiben")) ; - my_string_data_multimap.insert(std::pair(8, "acht")) ; - my_string_data_multimap.insert(std::pair(9, "neun")) ; - my_string_data_multimap.insert(std::pair(7, "seven")) ; - my_string_data_multimap.insert(std::pair(8, "eight")) ; - my_string_data_multimap.insert(std::pair(9, "nine")) ; - - my_string_multimap.insert(std::pair("sister","Lisa")) ; - my_string_multimap.insert(std::pair("dog","Santa's Little Helper")) ; - my_string_multimap.insert(std::pair("sister","Meg")) ; - my_string_multimap.insert(std::pair("dog","Brian")) ; - - my_double_vector.push_back(4.0) ; - my_double_vector.push_back(5.0) ; - my_double_vector.push_back(6.0) ; - - my_string_vector.push_back("It") ; - my_string_vector.push_back("has") ; - my_string_vector.push_back("the") ; - my_string_vector.push_back("Wi-Fies") ; - - my_short_list.push_back(400) ; - my_short_list.push_back(401) ; - my_short_list.push_back(402) ; - - my_string_list.push_back("I") ; - my_string_list.push_back("don't") ; - my_string_list.push_back("care") ; - - my_float_deque.push_back(98.7) ; - my_float_deque.push_back(65.4) ; - my_float_deque.push_back(32.1) ; - - my_string_deque.push_back("Welcome") ; - my_string_deque.push_back("to") ; - my_string_deque.push_back("PhoneMart") ; - - my_int_set.insert(8000) ; - my_int_set.insert(4000) ; - my_int_set.insert(2000) ; - my_int_set.insert(1000) ; - - my_string_set.insert("efg") ; - my_string_set.insert("abc") ; - my_string_set.insert("def") ; - - my_long_multiset.insert(8000) ; - my_long_multiset.insert(4000) ; - my_long_multiset.insert(4000) ; - my_long_multiset.insert(2000) ; - my_long_multiset.insert(1000) ; - - my_string_multiset.insert("efg") ; - my_string_multiset.insert("abc") ; - my_string_multiset.insert("def") ; - my_string_multiset.insert("efg") ; - my_string_multiset.insert("abc") ; - my_string_multiset.insert("def") ; - - my_uint_stack.push(1) ; - my_uint_stack.push(2) ; - my_uint_stack.push(3) ; - my_uint_stack.push(4) ; - - my_string_stack.push("I") ; - my_string_stack.push("want the one") ; - my_string_stack.push("with the bigger") ; - my_string_stack.push("Gee Bees") ; - - my_int_queue.push(1) ; - my_int_queue.push(2) ; - my_int_queue.push(3) ; - my_int_queue.push(4) ; - - my_string_queue.push("I") ; - my_string_queue.push("want") ; - my_string_queue.push("an") ; - my_string_queue.push("iPhone 4") ; - - my_int_priority_queue.push(3) ; - my_int_priority_queue.push(2) ; - my_int_priority_queue.push(4) ; - my_int_priority_queue.push(1) ; - - my_string_priority_queue.push("I") ; - my_string_priority_queue.push("want") ; - my_string_priority_queue.push("an") ; - my_string_priority_queue.push("iPhone 4") ; - - my_int_pair.first = 10 ; - my_int_pair.second = 20 ; - - my_string_first_pair.first = "string first" ; - my_string_first_pair.second = 25 ; - - my_string_second_pair.first = 25 ; - my_string_second_pair.second = "string second" ; - - my_string_pair.first = "pair first string" ; - my_string_pair.second = "pair second string" ; - return ; -} - -int STLCheckpoint::speak() { - message_publish(1,"Quack!\n") ; - return 0 ; -} - diff --git a/test/SIM_stls2/models/stl_checkpoint/STLCheckpoint.hh b/test/SIM_stls2/models/stl_checkpoint/STLCheckpoint.hh deleted file mode 100644 index 8a4b4031..00000000 --- a/test/SIM_stls2/models/stl_checkpoint/STLCheckpoint.hh +++ /dev/null @@ -1,93 +0,0 @@ -/* - PURPOSE: (Illustrate how to checkpoint STLs) - LIBRARY_DEPENDENCIES: ( - (STLCheckpoint.o) - ) -*/ - -#ifndef STLCHECKPOINT_HH -#define STLCHECKPOINT_HH - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* This shows the most difficult case in checkpointing STLs where all - STLs are private. There are no accessor routines to get individual - items out of the STLs. (In fact getting to all items in some of the - STLs forces changes in the contents, such as stacks and queues.) Anyways - in this case we need to specify a friend that carries out the checkpoint. - There are 2 methods one can use to call the Trick stl checkpoint routines: - 1) Provide a companion class that calls the Trick routines for each STL - (STLCompanion in this example). - -- OR -- - 2) Invoke Trick's CHECKPOINT_STL macro in the sim object class for each STL - (theSimObject in this example). - Whichever method is chosen, make that class a friend of the class with STLs - (STLCheckpoint in this example). - Public STLs can be checkpointed in the same way (but no need to specify friend). -*/ -class STLCheckpoint { - - friend class STLCompanion ; // method 1 - friend class theSimObject ; // method 2 - - public: - - STLCheckpoint() ; - STLCheckpoint(std::string in_name) ; - int speak() ; - - std::string name ; - - private: - - std::map< double , double > my_double_map ; - std::map< std::string , int > my_string_key_map ; - std::map< int , std::string > my_string_data_map ; - std::map< std::string , std::string > my_string_map ; - - std::multimap< int , int > my_int_multimap ; - std::multimap< std::string , int > my_string_key_multimap ; - std::multimap< int , std::string > my_string_data_multimap ; - std::multimap< std::string , std::string > my_string_multimap ; - - std::vector< double > my_double_vector ; - std::vector< std::string > my_string_vector ; - - std::list< short > my_short_list ; - std::list< std::string > my_string_list ; - - std::deque< float > my_float_deque ; - std::deque< std::string > my_string_deque ; - - std::set< int > my_int_set ; - std::set< std::string > my_string_set ; - - std::multiset< long > my_long_multiset ; - std::multiset< std::string > my_string_multiset ; - - std::stack< unsigned int > my_uint_stack ; - std::stack< std::string > my_string_stack ; - - std::queue< int > my_int_queue ; - std::queue< std::string > my_string_queue ; - - std::priority_queue< int > my_int_priority_queue ; - std::priority_queue< std::string > my_string_priority_queue ; - - std::pair< int , int > my_int_pair ; - std::pair< std::string , int > my_string_first_pair ; - std::pair< int , std::string > my_string_second_pair ; - std::pair< std::string , std::string > my_string_pair ; - -} ; - -#endif - diff --git a/test/SIM_stls2/stl_checkpoints.sm b/test/SIM_stls2/stl_checkpoints.sm deleted file mode 100644 index 83484f87..00000000 --- a/test/SIM_stls2/stl_checkpoints.sm +++ /dev/null @@ -1,57 +0,0 @@ -CHECKPOINT_STL(stlc.my_double_map) ; -CHECKPOINT_STL(stlc.my_string_key_map) ; -CHECKPOINT_STL(stlc.my_string_data_map) ; -CHECKPOINT_STL(stlc.my_string_map) ; -CHECKPOINT_STL(stlc.my_int_multimap) ; -CHECKPOINT_STL(stlc.my_string_key_multimap) ; -CHECKPOINT_STL(stlc.my_string_data_multimap) ; -CHECKPOINT_STL(stlc.my_string_multimap) ; -CHECKPOINT_STL(stlc.my_double_vector) ; -CHECKPOINT_STL(stlc.my_string_vector) ; -CHECKPOINT_STL(stlc.my_short_list) ; -CHECKPOINT_STL(stlc.my_string_list) ; -CHECKPOINT_STL(stlc.my_float_deque) ; -CHECKPOINT_STL(stlc.my_string_deque) ; -CHECKPOINT_STL(stlc.my_int_set) ; -CHECKPOINT_STL(stlc.my_string_set) ; -CHECKPOINT_STL(stlc.my_long_multiset) ; -CHECKPOINT_STL(stlc.my_string_multiset) ; -CHECKPOINT_STL(stlc.my_uint_stack) ; -CHECKPOINT_STL(stlc.my_string_stack) ; -CHECKPOINT_STL(stlc.my_int_queue) ; -CHECKPOINT_STL(stlc.my_string_queue) ; -CHECKPOINT_STL(stlc.my_int_priority_queue) ; -CHECKPOINT_STL(stlc.my_string_priority_queue) ; -CHECKPOINT_STL(stlc.my_int_pair) ; -CHECKPOINT_STL(stlc.my_string_first_pair) ; -CHECKPOINT_STL(stlc.my_string_second_pair) ; -CHECKPOINT_STL(stlc.my_string_pair) ; - -CHECKPOINT_STL(stlc2.my_double_map) ; -CHECKPOINT_STL(stlc2.my_string_key_map) ; -CHECKPOINT_STL(stlc2.my_string_data_map) ; -CHECKPOINT_STL(stlc2.my_string_map) ; -CHECKPOINT_STL(stlc2.my_int_multimap) ; -CHECKPOINT_STL(stlc2.my_string_key_multimap) ; -CHECKPOINT_STL(stlc2.my_string_data_multimap) ; -CHECKPOINT_STL(stlc2.my_string_multimap) ; -CHECKPOINT_STL(stlc2.my_double_vector) ; -CHECKPOINT_STL(stlc2.my_string_vector) ; -CHECKPOINT_STL(stlc2.my_short_list) ; -CHECKPOINT_STL(stlc2.my_string_list) ; -CHECKPOINT_STL(stlc2.my_float_deque) ; -CHECKPOINT_STL(stlc2.my_string_deque) ; -CHECKPOINT_STL(stlc2.my_int_set) ; -CHECKPOINT_STL(stlc2.my_string_set) ; -CHECKPOINT_STL(stlc2.my_long_multiset) ; -CHECKPOINT_STL(stlc2.my_string_multiset) ; -CHECKPOINT_STL(stlc2.my_uint_stack) ; -CHECKPOINT_STL(stlc2.my_string_stack) ; -CHECKPOINT_STL(stlc2.my_int_queue) ; -CHECKPOINT_STL(stlc2.my_string_queue) ; -CHECKPOINT_STL(stlc2.my_int_priority_queue) ; -CHECKPOINT_STL(stlc2.my_string_priority_queue) ; -CHECKPOINT_STL(stlc2.my_int_pair) ; -CHECKPOINT_STL(stlc2.my_string_first_pair) ; -CHECKPOINT_STL(stlc2.my_string_second_pair) ; -CHECKPOINT_STL(stlc2.my_string_pair) ; diff --git a/test/SIM_stls3/RUN_test/input.py b/test/SIM_stls3/RUN_test/input.py deleted file mode 100644 index 18c9b1a1..00000000 --- a/test/SIM_stls3/RUN_test/input.py +++ /dev/null @@ -1,8 +0,0 @@ - -def main(): - trick.checkpoint_pre_init(True) - trick.stop(1.0) - -if __name__ == "__main__": - main() - diff --git a/test/SIM_stls3/RUN_test/realtime.py b/test/SIM_stls3/RUN_test/realtime.py deleted file mode 100644 index f7d87131..00000000 --- a/test/SIM_stls3/RUN_test/realtime.py +++ /dev/null @@ -1,9 +0,0 @@ - -def main(): - trick.real_time_enable() - trick.exec_set_software_frame(0.1) - trick.sim_control_panel_set_enabled(True) - -if __name__ == "__main__": - main() - diff --git a/test/SIM_stls3/S_define b/test/SIM_stls3/S_define deleted file mode 100644 index 3ebebab5..00000000 --- a/test/SIM_stls3/S_define +++ /dev/null @@ -1,23 +0,0 @@ -/* - This sim demonstrates the use of Trick STLs. Trick includes - checkpointable versions of all the STL constructs. -*/ - -#include "sim_objects/default_trick_sys.sm" - -##include "TrickSTL/include/TrickSTLCheckpoint.hh" - -class theSimObject : public Trick::SimObject { - - public: - TrickSTLCheckpoint tstlc ; - - theSimObject() { - (1.0, "scheduled") tstlc.speak() ; - (1.0, "freeze_scheduled") tstlc.speak() ; - } - -} ; - -theSimObject the_object ; - diff --git a/test/SIM_stls3/S_overrides.mk b/test/SIM_stls3/S_overrides.mk deleted file mode 100644 index 1d1b5689..00000000 --- a/test/SIM_stls3/S_overrides.mk +++ /dev/null @@ -1,4 +0,0 @@ - -TRICK_CFLAGS += -I./models -TRICK_CXXFLAGS += -I./models -std=c++11 - diff --git a/test/SIM_stls3/models/TrickSTL/include/TrickSTLCheckpoint.hh b/test/SIM_stls3/models/TrickSTL/include/TrickSTLCheckpoint.hh deleted file mode 100644 index 2bff2fb6..00000000 --- a/test/SIM_stls3/models/TrickSTL/include/TrickSTLCheckpoint.hh +++ /dev/null @@ -1,167 +0,0 @@ -/* - PURPOSE: (Illustrate how to checkpoint STLs) - LIBRARY_DEPENDENCIES: ( - (TrickSTLCheckpoint.o) - ) -*/ - -#ifndef TRICKSTLCHECKPOINT_HH_ -#define TRICKSTLCHECKPOINT_HH_ - -#include -#include "sim_services/STL/include/trick_vector.hh" -#include "sim_services/STL/include/trick_list.hh" -#include "sim_services/STL/include/trick_deque.hh" -#include "sim_services/STL/include/trick_set.hh" -#include "sim_services/STL/include/trick_map.hh" -#include "sim_services/STL/include/trick_stack.hh" -#include "sim_services/STL/include/trick_queue.hh" -#include "sim_services/STL/include/trick_pair.hh" - -class ClassOfInts { - public: - int i1 ; - int i2 ; - int i3 ; - bool operator < ( const ClassOfInts & c ) const { - return i1 > c.i1 ; - } -} ; - -class TrickSTLCheckpoint { - - public: - - TrickSTLCheckpoint() ; - int speak() ; - - std::string name ; - - /* VECTOR */ - Trick::vector< double > vector_double ; - Trick::vector< double , std::allocator > vector_double_alloc ; - Trick::vector< std::string > vector_string ; - - Trick::vector< double > vector_range ; - Trick::vector< double > vector_fill ; - Trick::vector< double > vector_copy ; - - Trick::vector< ClassOfInts > vector_class ; - Trick::vector< ClassOfInts * > vector_class_ptr ; - - Trick::vector< Trick::vector< double > > vector_vector_double ; - - /* LIST */ - Trick::list< double > list_double ; - Trick::list< double , std::allocator > list_double_alloc ; - Trick::list< std::string > list_string ; - - Trick::list< double > list_range ; - Trick::list< double > list_fill ; - Trick::list< double > list_copy ; - - Trick::list< ClassOfInts > list_class ; - Trick::list< ClassOfInts * > list_class_ptr ; - - Trick::list< Trick::list< double > > list_list_double ; - - /* DEQUE */ - Trick::deque< double > deque_double ; - Trick::deque< double , std::allocator > deque_double_alloc ; - Trick::deque< std::string > deque_string ; - - Trick::deque< double > deque_range ; - Trick::deque< double > deque_fill ; - Trick::deque< double > deque_copy ; - - Trick::deque< ClassOfInts > deque_class ; - Trick::deque< ClassOfInts * > deque_class_ptr ; - - Trick::deque< Trick::deque< double > > deque_deque_double ; - - /* SET */ - Trick::set< double > set_double ; - Trick::set< double , std::less< double > > set_double_compare ; - Trick::set< double , std::less< double > , std::allocator > set_double_compare_alloc ; - Trick::set< std::string > set_string ; - - Trick::set< double > set_range ; - Trick::set< double > set_fill ; - Trick::set< double > set_copy ; - - Trick::set< ClassOfInts > set_class ; - Trick::set< ClassOfInts * > set_class_ptr ; - - Trick::set< Trick::set< double > > set_set_double ; - - /* MULTISET */ - Trick::multiset< double > multiset_double ; - Trick::multiset< double , std::less< double > > multiset_double_compare ; - Trick::multiset< double , std::less< double > , std::allocator > multiset_double_compare_alloc ; - Trick::multiset< std::string > multiset_string ; - - Trick::multiset< double > multiset_range ; - Trick::multiset< double > multiset_fill ; - Trick::multiset< double > multiset_copy ; - - Trick::multiset< ClassOfInts > multiset_class ; - Trick::multiset< ClassOfInts * > multiset_class_ptr ; - - Trick::multiset< Trick::multiset< double > > multiset_multiset_double ; - - /* MAP */ - Trick::map< double , double > map_double_double ; - Trick::map< int , std::string > map_int_string ; - Trick::map< int , Trick::vector< double > > map_int_vector_double ; - - Trick::map< std::string , int > map_string_int ; - Trick::map< std::string , std::string > map_string_string ; - Trick::map< std::string , Trick::vector< double > > map_string_vector_double ; - - Trick::map< Trick::list< int > , double > map_list_int_double ; - Trick::map< Trick::list< int > , std::string > map_list_int_string ; - Trick::map< Trick::list< int > , Trick::vector< double > > map_list_int_vector_double ; - - /* MULTIMAP */ - Trick::multimap< double , double > multimap_double_double ; - Trick::multimap< int , std::string > multimap_int_string ; - Trick::multimap< int , Trick::vector< double > > multimap_int_vector_double ; - - Trick::multimap< std::string , int > multimap_string_int ; - Trick::multimap< std::string , std::string > multimap_string_string ; - Trick::multimap< std::string , Trick::vector< double > > multimap_string_vector_double ; - - Trick::multimap< Trick::list< int > , double > multimap_list_int_double ; - Trick::multimap< Trick::list< int > , std::string > multimap_list_int_string ; - Trick::multimap< Trick::list< int > , Trick::vector< double > > multimap_list_int_vector_double ; - - /* STACK */ - Trick::stack< unsigned int > stack_uint ; - Trick::stack< std::string > stack_string ; - Trick::stack< Trick::vector< double > > stack_vector_double ; - - /* QUEUE */ - Trick::queue< unsigned int > queue_uint ; - Trick::queue< std::string > queue_string ; - Trick::queue< Trick::vector< double > > queue_vector_double ; - - /* PRIORITY QUEUE */ - Trick::priority_queue< unsigned int > priority_queue_uint ; - Trick::priority_queue< std::string > priority_queue_string ; - Trick::priority_queue< Trick::vector< double > > priority_queue_vector_double ; - - /* PAIRS */ - Trick::pair< int , int > pair_int_int ; - Trick::pair< int , int > pair_fill_int_int ; - Trick::pair< int , std::string > pair_int_string ; - Trick::pair< int , Trick::list< int > > pair_int_list_int ; - Trick::pair< std::string , int > pair_string_int ; - Trick::pair< std::string , std::string > pair_string_string ; - Trick::pair< std::string , Trick::list< int > > pair_string_list_int ; - Trick::pair< Trick::list< int > , int > pair_list_int_int ; - Trick::pair< Trick::list< int > , std::string > pair_list_int_string ; - Trick::pair< Trick::list< int > , Trick::list< int > > pair_list_int_list_int ; -} ; - -#endif - diff --git a/test/SIM_stls3/models/TrickSTL/src/TrickSTLCheckpoint.cpp b/test/SIM_stls3/models/TrickSTL/src/TrickSTLCheckpoint.cpp deleted file mode 100644 index 13654318..00000000 --- a/test/SIM_stls3/models/TrickSTL/src/TrickSTLCheckpoint.cpp +++ /dev/null @@ -1,504 +0,0 @@ - -#include "TrickSTLCheckpoint.hh" -#include "sim_services/Message/include/message_proto.h" -#include "sim_services/MemoryManager/include/memorymanager_c_intf.h" - -double matrix[3][3] = {{101,102,103},{104,105,106},{107,108,109}} ; - -TrickSTLCheckpoint::TrickSTLCheckpoint() - : vector_range(matrix[2], matrix[2] + 3) , - vector_fill( 5 , 200 ) , - vector_copy( vector_range ) , - list_range(matrix[2], matrix[2] + 3) , - list_fill( 5 , 200 ) , - list_copy( list_range ) , - deque_range(matrix[2], matrix[2] + 3) , - deque_fill( 5 , 200 ) , - deque_copy( deque_range ) , - pair_fill_int_int( 92 , 93 ) -{ - ClassOfInts coi ; - ClassOfInts * coi_ptr ; - - /* VECTOR */ - vector_double.push_back(1.0) ; - vector_double.push_back(2.0) ; - vector_double.push_back(3.0) ; - - vector_double_alloc.push_back(4.0) ; - vector_double_alloc.push_back(5.0) ; - vector_double_alloc.push_back(6.0) ; - - vector_string.push_back("I") ; - vector_string.push_back("was") ; - vector_string.push_back("here") ; - - coi.i1 = 1 ; - coi.i2 = 2 ; - coi.i3 = 3 ; - vector_class.push_back(coi) ; - coi.i1 = 4 ; - coi.i2 = 5 ; - coi.i3 = 6 ; - vector_class.push_back(coi) ; - - coi_ptr = (ClassOfInts *)TMM_declare_var_1d("ClassOfInts" , 1) ; - coi_ptr->i1 = 11 ; - coi_ptr->i2 = 12 ; - coi_ptr->i3 = 13 ; - vector_class_ptr.push_back(coi_ptr) ; - coi_ptr = (ClassOfInts *)TMM_declare_var_1d("ClassOfInts" , 1) ; - coi_ptr->i1 = 14 ; - coi_ptr->i2 = 15 ; - coi_ptr->i3 = 16 ; - vector_class_ptr.push_back(coi_ptr) ; - - Trick::vector< double > vector_d3( 3 , 300 ) ; - Trick::vector< double > vector_d4( 4 , 400 ) ; - Trick::vector< double > vector_d5( 5 , 500 ) ; - - vector_vector_double.push_back(vector_d3) ; - vector_vector_double.push_back(vector_d4) ; - vector_vector_double.push_back(vector_d5) ; - - /* LIST */ - list_double.push_back(1.0) ; - list_double.push_back(2.0) ; - list_double.push_back(3.0) ; - - list_double_alloc.push_back(4.0) ; - list_double_alloc.push_back(5.0) ; - list_double_alloc.push_back(6.0) ; - - list_string.push_back("I") ; - list_string.push_back("was") ; - list_string.push_back("here") ; - - coi.i1 = 1 ; - coi.i2 = 2 ; - coi.i3 = 3 ; - list_class.push_back(coi) ; - coi.i1 = 4 ; - coi.i2 = 5 ; - coi.i3 = 6 ; - list_class.push_back(coi) ; - - coi_ptr = (ClassOfInts *)TMM_declare_var_1d("ClassOfInts" , 1) ; - coi_ptr->i1 = 11 ; - coi_ptr->i2 = 12 ; - coi_ptr->i3 = 13 ; - list_class_ptr.push_back(coi_ptr) ; - coi_ptr = (ClassOfInts *)TMM_declare_var_1d("ClassOfInts" , 1) ; - coi_ptr->i1 = 14 ; - coi_ptr->i2 = 15 ; - coi_ptr->i3 = 16 ; - list_class_ptr.push_back(coi_ptr) ; - - Trick::list< double > list_d3( 3 , 300 ) ; - Trick::list< double > list_d4( 4 , 400 ) ; - Trick::list< double > list_d5( 5 , 500 ) ; - list_list_double.push_back(list_d3) ; - list_list_double.push_back(list_d4) ; - list_list_double.push_back(list_d5) ; - - /* DEQUE */ - deque_double.push_back(1.0) ; - deque_double.push_back(2.0) ; - deque_double.push_back(3.0) ; - - deque_double_alloc.push_back(4.0) ; - deque_double_alloc.push_back(5.0) ; - deque_double_alloc.push_back(6.0) ; - - deque_string.push_back("I") ; - deque_string.push_back("was") ; - deque_string.push_back("here") ; - - coi.i1 = 1 ; - coi.i2 = 2 ; - coi.i3 = 3 ; - deque_class.push_back(coi) ; - coi.i1 = 4 ; - coi.i2 = 5 ; - coi.i3 = 6 ; - deque_class.push_back(coi) ; - - coi_ptr = (ClassOfInts *)TMM_declare_var_1d("ClassOfInts" , 1) ; - coi_ptr->i1 = 11 ; - coi_ptr->i2 = 12 ; - coi_ptr->i3 = 13 ; - deque_class_ptr.push_back(coi_ptr) ; - coi_ptr = (ClassOfInts *)TMM_declare_var_1d("ClassOfInts" , 1) ; - coi_ptr->i1 = 14 ; - coi_ptr->i2 = 15 ; - coi_ptr->i3 = 16 ; - deque_class_ptr.push_back(coi_ptr) ; - - Trick::deque< double > deque_d3( 3 , 300 ) ; - Trick::deque< double > deque_d4( 4 , 400 ) ; - Trick::deque< double > deque_d5( 5 , 500 ) ; - deque_deque_double.push_back(deque_d3) ; - deque_deque_double.push_back(deque_d4) ; - deque_deque_double.push_back(deque_d5) ; - - /* SET */ - set_double.insert(1.0) ; - set_double.insert(2.0) ; - set_double.insert(3.0) ; - - set_double_compare_alloc.insert(4.0) ; - set_double_compare_alloc.insert(5.0) ; - set_double_compare_alloc.insert(6.0) ; - - set_string.insert("I") ; - set_string.insert("was") ; - set_string.insert("here") ; - - coi.i1 = 1 ; - coi.i2 = 2 ; - coi.i3 = 3 ; - set_class.insert(coi) ; - coi.i1 = 4 ; - coi.i2 = 5 ; - coi.i3 = 6 ; - set_class.insert(coi) ; - - coi_ptr = (ClassOfInts *)TMM_declare_var_1d("ClassOfInts" , 1) ; - coi_ptr->i1 = 11 ; - coi_ptr->i2 = 12 ; - coi_ptr->i3 = 13 ; - set_class_ptr.insert(coi_ptr) ; - coi_ptr = (ClassOfInts *)TMM_declare_var_1d("ClassOfInts" , 1) ; - coi_ptr->i1 = 14 ; - coi_ptr->i2 = 15 ; - coi_ptr->i3 = 16 ; - set_class_ptr.insert(coi_ptr) ; - - Trick::set< double > set_d3( matrix[0], matrix[0] + 3 ) ; - Trick::set< double > set_d4( matrix[1], matrix[1] + 3 ) ; - Trick::set< double > set_d5( matrix[2], matrix[2] + 3 ) ; - set_set_double.insert(set_d3) ; - set_set_double.insert(set_d4) ; - set_set_double.insert(set_d5) ; - - /* MULTISET */ - multiset_double.insert(1.0) ; - multiset_double.insert(2.0) ; - multiset_double.insert(3.0) ; - - multiset_double_compare_alloc.insert(4.0) ; - multiset_double_compare_alloc.insert(5.0) ; - multiset_double_compare_alloc.insert(6.0) ; - - multiset_string.insert("I") ; - multiset_string.insert("was") ; - multiset_string.insert("here") ; - - coi.i1 = 1 ; - coi.i2 = 2 ; - coi.i3 = 3 ; - multiset_class.insert(coi) ; - coi.i1 = 4 ; - coi.i2 = 5 ; - coi.i3 = 6 ; - multiset_class.insert(coi) ; - // Add an extra copy for multi-set. - multiset_class.insert(coi) ; - - coi_ptr = (ClassOfInts *)TMM_declare_var_1d("ClassOfInts" , 1) ; - coi_ptr->i1 = 11 ; - coi_ptr->i2 = 12 ; - coi_ptr->i3 = 13 ; - multiset_class_ptr.insert(coi_ptr) ; - coi_ptr = (ClassOfInts *)TMM_declare_var_1d("ClassOfInts" , 1) ; - coi_ptr->i1 = 14 ; - coi_ptr->i2 = 15 ; - coi_ptr->i3 = 16 ; - multiset_class_ptr.insert(coi_ptr) ; - - Trick::multiset< double > multiset_d3( matrix[0], matrix[0] + 3 ) ; - Trick::multiset< double > multiset_d4( matrix[1], matrix[1] + 3 ) ; - Trick::multiset< double > multiset_d5( matrix[2], matrix[2] + 3 ) ; - multiset_multiset_double.insert(multiset_d3) ; - multiset_multiset_double.insert(multiset_d4) ; - multiset_multiset_double.insert(multiset_d5) ; - - /* MAP */ - map_double_double[11.1] = 111.1 ; - map_double_double[22.2] = 222.2 ; - map_double_double[33.3] = 333.3 ; - - map_string_int[std::string("one")] = 1 ; - map_string_int[std::string("two")] = 2 ; - map_string_int[std::string("three")] = 3 ; - - map_int_string[4] = std::string("vier") ; - map_int_string[5] = std::string("fumf") ; - map_int_string[6] = std::string("sechs") ; - - map_string_string[std::string("mother")] = std::string("Marge") ; - map_string_string[std::string("father")] = std::string("Homer") ; - map_string_string[std::string("son")] = std::string("Bart") ; - - map_int_vector_double[80] = vector_d3 ; - map_int_vector_double[81] = vector_d4 ; - map_int_vector_double[82] = vector_d5 ; - - map_string_vector_double[std::string("cat")] = vector_d3 ; - map_string_vector_double[std::string("dog")] = vector_d4 ; - map_string_vector_double[std::string("duck")] = vector_d5 ; - - Trick::list< int > list_int_i1(3 , 111) ; - Trick::list< int > list_int_i2(3 , 222) ; - - map_list_int_double[list_int_i1] = 11.1 ; - map_list_int_double[list_int_i2] = 22.2 ; - // this line should overwrite the previous - map_list_int_double[list_int_i2] = 33.3 ; - - map_list_int_string[list_int_i1] = std::string("banana") ; - map_list_int_string[list_int_i2] = std::string("apple") ; - - map_list_int_vector_double[list_int_i1] = vector_d3 ; - map_list_int_vector_double[list_int_i2] = vector_d4 ; - - /* MULTIMAP */ - multimap_double_double.insert(std::pair(11.1,111.1)) ; - multimap_double_double.insert(std::pair(22.2,222.2)) ; - multimap_double_double.insert(std::pair(33.2,333.3)) ; - - multimap_string_int.insert(std::pair(std::string("one"),1)) ; - multimap_string_int.insert(std::pair(std::string("two"),2)) ; - multimap_string_int.insert(std::pair(std::string("three"),3)) ; - - multimap_int_string.insert(std::pair(4 , std::string("vier"))) ; - multimap_int_string.insert(std::pair(5 , std::string("fumf"))) ; - multimap_int_string.insert(std::pair(6 , std::string("sechs"))) ; - - multimap_string_string.insert(std::pair(std::string("mother") , std::string("Marge"))) ; - multimap_string_string.insert(std::pair(std::string("father") , std::string("Homer"))) ; - multimap_string_string.insert(std::pair(std::string("son") , std::string("Bart"))) ; - - multimap_int_vector_double.insert(std::pair >(80, vector_d3)) ; - multimap_int_vector_double.insert(std::pair >(81, vector_d4)) ; - multimap_int_vector_double.insert(std::pair >(82, vector_d5)) ; - - multimap_string_vector_double.insert(std::pair >(std::string("cat"), vector_d3)) ; - multimap_string_vector_double.insert(std::pair >(std::string("dog"), vector_d4)) ; - multimap_string_vector_double.insert(std::pair >(std::string("duck"), vector_d5)) ; - - multimap_list_int_double.insert(std::pair< Trick::list, double >(list_int_i1, 11.1)) ; - multimap_list_int_double.insert(std::pair< Trick::list, double >(list_int_i2, 22.2)) ; - // this line should not overwrite the previous - multimap_list_int_double.insert(std::pair< Trick::list, double >(list_int_i2, 33.3)) ; - - multimap_list_int_string.insert(std::pair< Trick::list, std::string >(list_int_i1, std::string("banana"))) ; - multimap_list_int_string.insert(std::pair< Trick::list, std::string >(list_int_i2, std::string("apple"))) ; - - multimap_list_int_vector_double.insert(std::pair< Trick::list, Trick::vector >(list_int_i1, vector_d3)) ; - multimap_list_int_vector_double.insert(std::pair< Trick::list, Trick::vector >(list_int_i2, vector_d4)) ; - - stack_uint.push(60) ; - stack_uint.push(61) ; - stack_uint.push(62) ; - stack_uint.push(63) ; - - stack_string.push("abc I") ; - stack_string.push("abc want the one") ; - stack_string.push("abc with the bigger") ; - stack_string.push("abc Gee Bees") ; - - stack_vector_double.push(vector_d3) ; - stack_vector_double.push(vector_d4) ; - stack_vector_double.push(vector_d5) ; - - queue_uint.push(70) ; - queue_uint.push(71) ; - queue_uint.push(72) ; - queue_uint.push(73) ; - - queue_string.push("efg I") ; - queue_string.push("efg want the one") ; - queue_string.push("efg with the bigger") ; - queue_string.push("efg Gee Bees") ; - - queue_vector_double.push(vector_d3) ; - queue_vector_double.push(vector_d4) ; - queue_vector_double.push(vector_d5) ; - - priority_queue_uint.push(81) ; - priority_queue_uint.push(80) ; - priority_queue_uint.push(83) ; - priority_queue_uint.push(82) ; - - priority_queue_string.push("efg I") ; - priority_queue_string.push("efg want the one") ; - priority_queue_string.push("efg with the bigger") ; - priority_queue_string.push("efg Gee Bees") ; - - priority_queue_vector_double.push(vector_d3) ; - priority_queue_vector_double.push(vector_d4) ; - priority_queue_vector_double.push(vector_d5) ; - - pair_int_int = Trick::make_pair( 90 , 91 ) ; - pair_int_string = Trick::make_pair( 94 , "earth" ) ; - pair_int_list_int = Trick::make_pair( 95 , list_int_i1 ) ; - pair_string_int = Trick::make_pair( "mars" , 2 ) ; - pair_string_string = Trick::make_pair( "blue" , "moon" ) ; - pair_string_list_int = Trick::make_pair( "tissue" , list_int_i2 ) ; - - pair_list_int_int = Trick::make_pair( list_int_i1 , 96 ) ; - pair_list_int_string = Trick::make_pair( list_int_i1 , "bag" ) ; - pair_list_int_list_int = Trick::make_pair( list_int_i1 , list_int_i2 ) ; -} - -template< typename T> -void print_sequence(T & container) { - typename T::iterator lit ; - for ( lit = container.begin() ; lit != container.end() ; lit++ ) { - std::cout << (*lit) << " " ; - } - std::cout << std::endl ; -} - -template< typename T> -void print_class_of_ints(T & container) { - typename T::iterator lit ; - unsigned int ii ; - for ( ii = 0 , lit = container.begin() ; lit != container.end() ; ii++ , lit++ ) { - std::cout << "ii = " << ii << ": " << (*lit).i1 << " " << (*lit).i2 ; - std::cout << " " << (*lit).i3 << std::endl ; - } -} - -template< typename T> -void print_2d_container(T & container) { - typename T::iterator lldit ; - for ( lldit = container.begin() ; lldit != container.end() ; lldit++ ) { - std::cout << "size = " << (*lldit).size() << std::endl ; - typename T::value_type::iterator ldit ; - for ( ldit = (*lldit).begin() ; ldit != (*lldit).end() ; ldit++ ) { - std::cout << (*ldit) << " " ; - } - std::cout << std::endl ; - } -} - -template< typename T> -void print_map(T & container) { - typename T::iterator lit ; - unsigned int ii ; - for ( ii = 0 , lit = container.begin() ; lit != container.end() ; ii++ , lit++ ) { - std::cout << "ii = " << ii << ": " << (*lit).first << " " << (*lit).second << std::endl ; - } -} - -template< typename T> -void print_map_keys(T & container) { - typename T::iterator lit ; - unsigned int ii ; - for ( ii = 0 , lit = container.begin() ; lit != container.end() ; ii++ , lit++ ) { - std::cout << "ii = " << ii << ": " << (*lit).first << std::endl ; - } -} - -template< typename T> -void print_map_data(T & container) { - typename T::iterator lit ; - unsigned int ii ; - for ( ii = 0 , lit = container.begin() ; lit != container.end() ; ii++ , lit++ ) { - std::cout << "ii = " << ii << ": " << (*lit).second << std::endl ; - } -} - -int TrickSTLCheckpoint::speak() { - - std::cout << "VECTOR" << std::endl ; - print_class_of_ints< Trick::vector< ClassOfInts > >( vector_class ) ; - print_2d_container< Trick::vector< Trick::vector< double > > >( vector_vector_double ) ; - std::cout << std::endl ; - - std::cout << "LIST" << std::endl ; - print_class_of_ints< Trick::list< ClassOfInts > >( list_class ) ; - print_2d_container< Trick::list< Trick::list< double > > >( list_list_double ) ; - std::cout << std::endl ; - - std::cout << "DEQUE" << std::endl ; - print_class_of_ints< Trick::deque< ClassOfInts > >( deque_class ) ; - print_2d_container< Trick::deque< Trick::deque< double > > >( deque_deque_double ) ; - std::cout << std::endl ; - - std::cout << "SET" << std::endl ; - print_class_of_ints< Trick::set< ClassOfInts > >( set_class ) ; - print_2d_container< Trick::set< Trick::set< double > > >( set_set_double ) ; - std::cout << std::endl ; - - std::cout << "MULTISET" << std::endl ; - print_class_of_ints< Trick::multiset< ClassOfInts > >( multiset_class ) ; - print_2d_container< Trick::multiset< Trick::multiset< double > > >( multiset_multiset_double ) ; - std::cout << std::endl ; - - std::cout << "MAP" << std::endl ; - print_map< Trick::map< double,double > >( map_double_double ) ; - print_map< Trick::map< std::string,int > >( map_string_int ) ; - print_map< Trick::map< int,std::string > >( map_int_string ) ; - print_map< Trick::map< std::string,std::string > >( map_string_string ) ; - print_map_keys< Trick::map< int , Trick::vector< double > > >( map_int_vector_double ) ; - print_map_keys< Trick::map< std::string , Trick::vector< double > > >( map_string_vector_double ) ; - print_map_data< Trick::map< Trick::list< int > , double > >( map_list_int_double ) ; - print_map_data< Trick::map< Trick::list< int > , std::string > >( map_list_int_string ) ; - std::cout << std::endl ; - - std::cout << "MULTIMAP" << std::endl ; - print_map< Trick::multimap< double,double > >( multimap_double_double ) ; - print_map< Trick::multimap< std::string,int > >( multimap_string_int ) ; - print_map< Trick::multimap< int,std::string > >( multimap_int_string ) ; - print_map< Trick::multimap< std::string,std::string > >( multimap_string_string ) ; - print_map_keys< Trick::multimap< int , Trick::vector< double > > >( multimap_int_vector_double ) ; - print_map_keys< Trick::multimap< std::string , Trick::vector< double > > >( multimap_string_vector_double ) ; - print_map_data< Trick::multimap< Trick::list< int > , double > >( multimap_list_int_double ) ; - print_map_data< Trick::multimap< Trick::list< int > , std::string > >( multimap_list_int_string ) ; - std::cout << std::endl ; - - std::cout << "STACK" << std::endl ; - std::cout << "top " << stack_uint.top() << std::endl ; - std::cout << "top " << stack_string.top() << std::endl ; - print_sequence< Trick::vector< double > >( stack_vector_double.top() ) ; - std::cout << std::endl ; - - std::cout << "QUEUE" << std::endl ; - std::cout << "front " << queue_uint.front() << std::endl ; - std::cout << "front " << queue_string.front() << std::endl ; - print_sequence< Trick::vector< double > >( queue_vector_double.front() ) ; - std::cout << std::endl ; - - std::cout << "PRIORITY QUEUE" << std::endl ; - std::cout << "top " << priority_queue_uint.top() << std::endl ; - std::cout << "top " << priority_queue_string.top() << std::endl ; - //print_sequence< Trick::vector< double > >( priority_queue_vector_double.top() ) ; - std::cout << std::endl ; - - std::cout << "PAIR" << std::endl ; - std::cout << "pair_int_int " << pair_int_int.first << " " << pair_int_int.second << std::endl ; - std::cout << "pair_fill_int_int " << pair_fill_int_int.first << " " << pair_fill_int_int.second << std::endl ; - std::cout << "pair_int_string " << pair_int_string.first << " " << pair_int_string.second << std::endl ; - std::cout << "pair_int_list_int " << pair_int_list_int.first << std::endl ; - print_sequence< Trick::list< int > >(pair_int_list_int.second) ; - std::cout << "pair_string_int " << pair_string_int.first << " " << pair_string_int.second << std::endl ; - std::cout << "pair_string_string " << pair_string_string.first << " " << pair_string_string.second << std::endl ; - std::cout << "pair_string_list_int " << pair_string_list_int.first << std::endl ; - print_sequence< Trick::list< int > >(pair_string_list_int.second) ; - std::cout << "pair_list_int_int " << std::endl ; - print_sequence< Trick::list< int > >(pair_list_int_int.first) ; - std::cout << pair_list_int_int.second << std::endl ; - std::cout << "pair_list_int_string " << std::endl ; - print_sequence< Trick::list< int > >(pair_list_int_string.first) ; - std::cout << pair_list_int_string.second << std::endl ; - std::cout << "pair_list_int_list_int " << std::endl ; - print_sequence< Trick::list< int > >(pair_list_int_list_int.first) ; - print_sequence< Trick::list< int > >(pair_list_int_list_int.second) ; - std::cout << std::endl ; - - return 0 ; -} - diff --git a/test/makefile b/test/makefile index 9fbbbae1..329b1aa0 100644 --- a/test/makefile +++ b/test/makefile @@ -7,7 +7,6 @@ COMPILE_DIRS = \ SIM_events \ SIM_rti \ SIM_stls \ - SIM_stls2 \ SIM_test_dp \ SIM_test_dr \ SIM_test_io \ @@ -30,7 +29,6 @@ SIMS_NEEDING_TEST = \ # SIM_test_varserv ( not sure what it is testing ) # SIM_dynamic_sim_object ( not running, class won't instantiate ) # SIM_segments ( not a test, but a demo ) -# SIM_stls3 ( not compiling on most platforms ) # This test is temporarily sitting out until fixed. # SIM_test_varserv diff --git a/trick_source/sim_services/CheckPointRestart/CheckPointRestart.cpp b/trick_source/sim_services/CheckPointRestart/CheckPointRestart.cpp index 9784bc95..e2d9abf6 100644 --- a/trick_source/sim_services/CheckPointRestart/CheckPointRestart.cpp +++ b/trick_source/sim_services/CheckPointRestart/CheckPointRestart.cpp @@ -23,7 +23,6 @@ #include "trick/message_proto.h" #include "trick/message_type.h" #include "trick/TrickConstant.hh" -#include "trick/checkpoint_stl.hh" Trick::CheckPointRestart * the_cpr ; @@ -397,24 +396,6 @@ int Trick::CheckPointRestart::safestore_checkpoint() { return(0) ; } -// These are jobs called from the S_define file. I called this one pre_checkpoint to avoid name overloading -int Trick::CheckPointRestart::pre_checkpoint() { - checkpoint_stl(checkpoint_times , std::string("trick_mm") , std::string("checkpoint_times")) ; - return 0 ; -} - -int Trick::CheckPointRestart::post_checkpoint() { - if ( ! checkpoint_times.empty() ) { - delete_stl(checkpoint_times , std::string("trick_mm") , std::string("checkpoint_times")) ; - } - return 0 ; -} - -int Trick::CheckPointRestart::restart() { - restore_stl(checkpoint_times , std::string("trick_mm") , std::string("checkpoint_times")) ; - return 0 ; -} - void Trick::CheckPointRestart::load_checkpoint(std::string file_name) { load_checkpoint_file_name = file_name ; } diff --git a/trick_source/sim_services/CheckPointRestart/Makefile b/trick_source/sim_services/CheckPointRestart/Makefile index 2d680508..7261c8c1 100644 --- a/trick_source/sim_services/CheckPointRestart/Makefile +++ b/trick_source/sim_services/CheckPointRestart/Makefile @@ -7,5 +7,3 @@ ifneq ($(DMTCP),) TRICK_CXXFLAGS += -D_DMTCP -I$(DMTCP)/dmtcpaware endif -TRICK_CXXFLAGS += -std=c++11 - diff --git a/trick_source/sim_services/CheckPointRestart/Makefile_deps b/trick_source/sim_services/CheckPointRestart/Makefile_deps index 5128017f..7d60ca41 100644 --- a/trick_source/sim_services/CheckPointRestart/Makefile_deps +++ b/trick_source/sim_services/CheckPointRestart/Makefile_deps @@ -16,46 +16,8 @@ object_${TRICK_HOST_CPU}/CheckPointRestart_c_intf.o: CheckPointRestart_c_intf.cp ${TRICK_HOME}/include/trick/io_alloc.h \ ${TRICK_HOME}/include/trick/message_proto.h \ ${TRICK_HOME}/include/trick/message_type.h -object_${TRICK_HOST_CPU}/checkpoint_queue.o: checkpoint_queue.cpp \ - ${TRICK_HOME}/include/trick/checkpoint_queue.hh \ - ${TRICK_HOME}/include/trick/checkpoint_sequence_stl.hh \ - ${TRICK_HOME}/include/trick/memorymanager_c_intf.h \ - ${TRICK_HOME}/include/trick/parameter_types.h \ - ${TRICK_HOME}/include/trick/attributes.h \ - ${TRICK_HOME}/include/trick/reference.h \ - ${TRICK_HOME}/include/trick/value.h \ - ${TRICK_HOME}/include/trick/dllist.h \ - ${TRICK_HOME}/include/trick/var.h \ - ${TRICK_HOME}/include/trick/io_alloc.h \ - ${TRICK_HOME}/include/trick/message_proto.h \ - ${TRICK_HOME}/include/trick/message_type.h -object_${TRICK_HOST_CPU}/checkpoint_map.o: checkpoint_map.cpp \ - ${TRICK_HOME}/include/trick/checkpoint_map.hh \ - ${TRICK_HOME}/include/trick/memorymanager_c_intf.h \ - ${TRICK_HOME}/include/trick/parameter_types.h \ - ${TRICK_HOME}/include/trick/attributes.h \ - ${TRICK_HOME}/include/trick/reference.h \ - ${TRICK_HOME}/include/trick/value.h \ - ${TRICK_HOME}/include/trick/dllist.h \ - ${TRICK_HOME}/include/trick/var.h \ - ${TRICK_HOME}/include/trick/io_alloc.h \ - ${TRICK_HOME}/include/trick/message_proto.h \ - ${TRICK_HOME}/include/trick/message_type.h object_${TRICK_HOST_CPU}/next_attr_name.o: next_attr_name.cpp \ ${TRICK_HOME}/include/trick/CheckPointRestart_c_intf.hh -object_${TRICK_HOST_CPU}/checkpoint_stack.o: checkpoint_stack.cpp \ - ${TRICK_HOME}/include/trick/checkpoint_stack.hh \ - ${TRICK_HOME}/include/trick/checkpoint_sequence_stl.hh \ - ${TRICK_HOME}/include/trick/memorymanager_c_intf.h \ - ${TRICK_HOME}/include/trick/parameter_types.h \ - ${TRICK_HOME}/include/trick/attributes.h \ - ${TRICK_HOME}/include/trick/reference.h \ - ${TRICK_HOME}/include/trick/value.h \ - ${TRICK_HOME}/include/trick/dllist.h \ - ${TRICK_HOME}/include/trick/var.h \ - ${TRICK_HOME}/include/trick/io_alloc.h \ - ${TRICK_HOME}/include/trick/message_proto.h \ - ${TRICK_HOME}/include/trick/message_type.h object_${TRICK_HOST_CPU}/CheckPointRestart.o: CheckPointRestart.cpp \ ${TRICK_HOME}/include/trick/DMTCP.hh \ ${TRICK_HOME}/include/trick/dmtcp_checkpoint_c_intf.hh \ @@ -77,47 +39,22 @@ object_${TRICK_HOST_CPU}/CheckPointRestart.o: CheckPointRestart.cpp \ ${TRICK_HOME}/include/trick/CheckPointAgent.hh \ ${TRICK_HOME}/include/trick/UCFn.hh \ ${TRICK_HOME}/include/trick/Executive.hh \ - ${TRICK_HOME}/include/trick/Scheduler.hh \ - ${TRICK_HOME}/include/trick/ScheduledJobQueue.hh \ - ${TRICK_HOME}/include/trick/SimObject.hh \ ${TRICK_HOME}/include/trick/Threads.hh \ ${TRICK_HOME}/include/trick/ThreadBase.hh \ + ${TRICK_HOME}/include/trick/ThreadTrigger.hh \ ${TRICK_HOME}/include/trick/sim_mode.h \ ${TRICK_HOME}/include/trick/exec_proto.hh \ ${TRICK_HOME}/include/trick/exec_proto.h \ - ${TRICK_HOME}/include/trick/sim_mode.h \ ${TRICK_HOME}/include/trick/command_line_protos.h \ ${TRICK_HOME}/include/trick/message_proto.h \ ${TRICK_HOME}/include/trick/message_type.h \ ${TRICK_HOME}/include/trick/TrickConstant.hh \ ${TRICK_HOME}/include/trick/checkpoint_stl.hh \ ${TRICK_HOME}/include/trick/checkpoint_sequence_stl.hh \ + ${TRICK_HOME}/include/trick/checkpoint_is_stl_container.hh \ + ${TRICK_HOME}/include/trick/checkpoint_fwd_declare.hh \ ${TRICK_HOME}/include/trick/memorymanager_c_intf.h \ ${TRICK_HOME}/include/trick/checkpoint_map.hh \ ${TRICK_HOME}/include/trick/checkpoint_stack.hh \ ${TRICK_HOME}/include/trick/checkpoint_queue.hh \ ${TRICK_HOME}/include/trick/checkpoint_pair.hh -object_${TRICK_HOST_CPU}/checkpoint_pair.o: checkpoint_pair.cpp \ - ${TRICK_HOME}/include/trick/checkpoint_pair.hh \ - ${TRICK_HOME}/include/trick/memorymanager_c_intf.h \ - ${TRICK_HOME}/include/trick/parameter_types.h \ - ${TRICK_HOME}/include/trick/attributes.h \ - ${TRICK_HOME}/include/trick/reference.h \ - ${TRICK_HOME}/include/trick/value.h \ - ${TRICK_HOME}/include/trick/dllist.h \ - ${TRICK_HOME}/include/trick/var.h \ - ${TRICK_HOME}/include/trick/io_alloc.h \ - ${TRICK_HOME}/include/trick/message_proto.h \ - ${TRICK_HOME}/include/trick/message_type.h -object_${TRICK_HOST_CPU}/checkpoint_sequence_stl.o: checkpoint_sequence_stl.cpp \ - ${TRICK_HOME}/include/trick/checkpoint_sequence_stl.hh \ - ${TRICK_HOME}/include/trick/memorymanager_c_intf.h \ - ${TRICK_HOME}/include/trick/parameter_types.h \ - ${TRICK_HOME}/include/trick/attributes.h \ - ${TRICK_HOME}/include/trick/reference.h \ - ${TRICK_HOME}/include/trick/value.h \ - ${TRICK_HOME}/include/trick/dllist.h \ - ${TRICK_HOME}/include/trick/var.h \ - ${TRICK_HOME}/include/trick/io_alloc.h \ - ${TRICK_HOME}/include/trick/message_proto.h \ - ${TRICK_HOME}/include/trick/message_type.h diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_map.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_map.cpp deleted file mode 100644 index a7206ea4..00000000 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_map.cpp +++ /dev/null @@ -1,23 +0,0 @@ - -#include -#include - -#include "trick/checkpoint_map.hh" - -#if 0 -int checkpoint_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl_strings( in_map , object_name , var_name ) ; -} - -int checkpoint_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return checkpoint_map_stl_strings( in_map , object_name , var_name ) ; -} - -int restore_stl(std::map & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_strings( in_map , object_name , var_name ) ; -} - -int restore_stl(std::multimap & in_map , std::string object_name , std::string var_name ) { - return restore_map_stl_strings( in_map , object_name , var_name ) ; -} -#endif diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp deleted file mode 100644 index 208ae9be..00000000 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_pair.cpp +++ /dev/null @@ -1,7 +0,0 @@ - -#include -#include - -#include "trick/checkpoint_pair.hh" - - diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp deleted file mode 100644 index 8cc281ea..00000000 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_queue.cpp +++ /dev/null @@ -1,4 +0,0 @@ - -#include "trick/checkpoint_queue.hh" - - diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_sequence_stl.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_sequence_stl.cpp deleted file mode 100644 index d169b858..00000000 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_sequence_stl.cpp +++ /dev/null @@ -1,3 +0,0 @@ - -#include "trick/checkpoint_sequence_stl.hh" - diff --git a/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp b/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp deleted file mode 100644 index 757e6e37..00000000 --- a/trick_source/sim_services/CheckPointRestart/checkpoint_stack.cpp +++ /dev/null @@ -1,3 +0,0 @@ - -#include "trick/checkpoint_stack.hh" - From c1eb4e6fc52b53c3be389d1c10c1d7fa073ceef3 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Thu, 31 Mar 2016 15:48:19 -0500 Subject: [PATCH 8/9] Add direct STL checkpointing The typenames on the Mac need to be converted for strings. The templates are genererating the long form of the string type name. I wrote a function to catch test the template parameter types and return std::string. refs #206 --- include/trick/checkpoint_map.hh | 13 +++++++++---- include/trick/checkpoint_pair.hh | 13 +++++++++---- include/trick/checkpoint_queue.hh | 7 +++++-- include/trick/checkpoint_sequence_stl.hh | 5 +++-- include/trick/checkpoint_stack.hh | 4 +++- include/trick/checkpoint_stl_protos.hh | 7 +++++++ .../CheckPointRestart/stl_type_name_convert.cpp | 11 +++++++++++ 7 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 include/trick/checkpoint_stl_protos.hh create mode 100644 trick_source/sim_services/CheckPointRestart/stl_type_name_convert.cpp diff --git a/include/trick/checkpoint_map.hh b/include/trick/checkpoint_map.hh index 661e66b2..cd58c6c8 100644 --- a/include/trick/checkpoint_map.hh +++ b/include/trick/checkpoint_map.hh @@ -19,6 +19,7 @@ #endif #include "checkpoint_is_stl_container.hh" +#include "checkpoint_stl_protos.hh" #include "checkpoint_fwd_declare.hh" #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" @@ -50,7 +51,8 @@ int checkpoint_map_ik_id(STL & in_map , std::string object_name , std::string va std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - var_declare << abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_keys[" << cont_size << "]" ; keys = (typename STL::key_type *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; @@ -58,7 +60,8 @@ int checkpoint_map_ik_id(STL & in_map , std::string object_name , std::string va var_declare.str("") ; var_declare.clear() ; - var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_data[" << cont_size << "]" ; items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_data").c_str()) ; @@ -104,7 +107,8 @@ int checkpoint_map_ik_sd(STL & in_map , std::string object_name , std::string va std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - var_declare << abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_keys[" << cont_size << "]" ; keys = (typename STL::key_type *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_keys").c_str()) ; @@ -174,7 +178,8 @@ int checkpoint_map_sk_id(STL & in_map , std::string object_name , std::string va var_declare.str("") ; var_declare.clear() ; - var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_data[" << cont_size << "]" ; items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_data").c_str()) ; diff --git a/include/trick/checkpoint_pair.hh b/include/trick/checkpoint_pair.hh index f4580bee..7591846e 100644 --- a/include/trick/checkpoint_pair.hh +++ b/include/trick/checkpoint_pair.hh @@ -18,6 +18,7 @@ #endif #include "checkpoint_is_stl_container.hh" +#include "checkpoint_stl_protos.hh" #include "checkpoint_fwd_declare.hh" #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" @@ -33,7 +34,8 @@ int checkpoint_stl(std::pair & in_pair , std::string object_name SECOND * second = nullptr ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - var_declare << abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_first[1]" ; first = (FIRST *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; @@ -41,7 +43,8 @@ int checkpoint_stl(std::pair & in_pair , std::string object_name var_declare.str("") ; var_declare.clear() ; - var_declare << abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status ) << " " + type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_second[1]" ; second = (SECOND *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; @@ -62,7 +65,8 @@ int checkpoint_stl(std::pair & in_pair , std::string object_name std::string * second = nullptr ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); - var_declare << abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*first).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_first[1]" ; first = (FIRST *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_first").c_str()) ; @@ -99,7 +103,8 @@ int checkpoint_stl(std::pair & in_pair , std::string object_name var_declare.str("") ; var_declare.clear() ; - var_declare << abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*second).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "_second[1]" ; second = (SECOND *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name + "_second").c_str()) ; diff --git a/include/trick/checkpoint_queue.hh b/include/trick/checkpoint_queue.hh index c784424d..f46af853 100644 --- a/include/trick/checkpoint_queue.hh +++ b/include/trick/checkpoint_queue.hh @@ -17,6 +17,7 @@ #endif #include "checkpoint_is_stl_container.hh" +#include "checkpoint_stl_protos.hh" #include "checkpoint_fwd_declare.hh" #include "checkpoint_sequence_stl.hh" #include "trick/memorymanager_c_intf.h" @@ -42,7 +43,8 @@ int checkpoint_stl(std::queue & in_stl , std::string object std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status )) ; + var_declare << type_string << " " << 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()) ; @@ -110,7 +112,8 @@ int checkpoint_stl(std::priority_queue & in_stl std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status )) ; + var_declare << type_string << " " << 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()) ; diff --git a/include/trick/checkpoint_sequence_stl.hh b/include/trick/checkpoint_sequence_stl.hh index cbdf9b50..aed918bc 100644 --- a/include/trick/checkpoint_sequence_stl.hh +++ b/include/trick/checkpoint_sequence_stl.hh @@ -20,6 +20,7 @@ #endif #include "checkpoint_is_stl_container.hh" +#include "checkpoint_stl_protos.hh" #include "checkpoint_fwd_declare.hh" #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" @@ -44,8 +45,8 @@ int checkpoint_sequence_i(STL & in_stl , std::string object_name , std::string v std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - - var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status )) ; + var_declare << type_string << " " << object_name << "_" << var_name << "[" << cont_size << "]" ; items = (typename STL::value_type *)TMM_declare_var_s(var_declare.str().c_str()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ; diff --git a/include/trick/checkpoint_stack.hh b/include/trick/checkpoint_stack.hh index 116930fc..4dca87e5 100644 --- a/include/trick/checkpoint_stack.hh +++ b/include/trick/checkpoint_stack.hh @@ -17,6 +17,7 @@ #endif #include "trick/checkpoint_sequence_stl.hh" +#include "checkpoint_stl_protos.hh" #include "trick/memorymanager_c_intf.h" #include "trick/message_proto.h" @@ -39,7 +40,8 @@ int checkpoint_stl(std::stack & in_stl , std::string object std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); if ( cont_size > 0 ) { - var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " " + std::string type_string = stl_type_name_convert(abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status )) ; + var_declare << type_string << " " << 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()) ; diff --git a/include/trick/checkpoint_stl_protos.hh b/include/trick/checkpoint_stl_protos.hh new file mode 100644 index 00000000..b72c29fa --- /dev/null +++ b/include/trick/checkpoint_stl_protos.hh @@ -0,0 +1,7 @@ + +#include + +// prototype of functions used in checkpoint_stl templates + +std::string stl_type_name_convert(std::string in_type) ; + diff --git a/trick_source/sim_services/CheckPointRestart/stl_type_name_convert.cpp b/trick_source/sim_services/CheckPointRestart/stl_type_name_convert.cpp new file mode 100644 index 00000000..2299d411 --- /dev/null +++ b/trick_source/sim_services/CheckPointRestart/stl_type_name_convert.cpp @@ -0,0 +1,11 @@ + +#include + +std::string stl_type_name_convert(std::string in_type) { + std::string type_string(in_type) ; + std::string basic_string("std::__1::basic_string") ; + if ( !type_string.compare(0, basic_string.length(), basic_string)) { + type_string = "std::string" ; + } + return type_string ; +} From ba6a00315ea559050f5cce51a2981e860dfc2d92 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Thu, 31 Mar 2016 17:30:00 -0500 Subject: [PATCH 9/9] Add direct STL checkpointing Fixing the unit tests that broke because of my changes. Memory Manager tests need to be compiled with c++11, and the STL unit test was using a variable that did not exist anymore. [Issue: x] --- test/SIM_stls/RUN_test/unit_test.py | 2 - .../MemoryManager/test/MM_alloc_deps.cc | 40 +++++++++---------- .../sim_services/MemoryManager/test/Makefile | 2 +- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/test/SIM_stls/RUN_test/unit_test.py b/test/SIM_stls/RUN_test/unit_test.py index 27d15f96..6f11ebd5 100644 --- a/test/SIM_stls/RUN_test/unit_test.py +++ b/test/SIM_stls/RUN_test/unit_test.py @@ -4,8 +4,6 @@ def main(): trick.checkpoint_post_init(True) trick.checkpoint_end(True) - the_object.stlc2.name = "Daisy" - # Data recording HDF5 test trick.exec_set_freeze_frame(0.10) trick.stop(5.0) diff --git a/trick_source/sim_services/MemoryManager/test/MM_alloc_deps.cc b/trick_source/sim_services/MemoryManager/test/MM_alloc_deps.cc index 8d0764a1..30554f52 100644 --- a/trick_source/sim_services/MemoryManager/test/MM_alloc_deps.cc +++ b/trick_source/sim_services/MemoryManager/test/MM_alloc_deps.cc @@ -42,14 +42,14 @@ bool dependencies_contain(std::vector& dependencies, const char* na // ================================================================================ TEST_F(MM_alloc_deps, dbl_singleton) { - std::vector dependencies; + std::vector & dependencies = memmgr->dependencies ; //memmgr->set_debug_level(1); double *dbl_p = (double*)memmgr->declare_var("double dbl_singleton"); *dbl_p = 3.1415; - memmgr->get_alloc_deps_in_allocation(dependencies, "dbl_singleton"); + memmgr->get_alloc_deps_in_allocation("dbl_singleton"); // There should be 1 dependency. EXPECT_EQ( dependencies.size(), 1); @@ -59,7 +59,7 @@ TEST_F(MM_alloc_deps, dbl_singleton) { // ================================================================================ TEST_F(MM_alloc_deps, dbl_pointer) { - std::vector dependencies; + std::vector & dependencies = memmgr->dependencies ; //memmgr->set_debug_level(1); @@ -68,7 +68,7 @@ TEST_F(MM_alloc_deps, dbl_pointer) { *dbl_pp = dbl_p; - memmgr->get_alloc_deps_in_allocation(dependencies, "dbl_pointer"); + memmgr->get_alloc_deps_in_allocation("dbl_pointer"); // There should be 1 dependency. EXPECT_EQ( dependencies.size(), 2); @@ -78,7 +78,7 @@ TEST_F(MM_alloc_deps, dbl_pointer) { // ================================================================================ TEST_F(MM_alloc_deps, dbl_array) { - std::vector dependencies; + std::vector & dependencies = memmgr->dependencies ; //memmgr->set_debug_level(1); @@ -88,7 +88,7 @@ TEST_F(MM_alloc_deps, dbl_array) { dbl_p[1] = 2.2; dbl_p[2] = 3.3; - memmgr->get_alloc_deps_in_allocation(dependencies, "dbl_array"); + memmgr->get_alloc_deps_in_allocation("dbl_array"); // There should be 1 dependency. EXPECT_EQ( dependencies.size(), 1); @@ -97,7 +97,7 @@ TEST_F(MM_alloc_deps, dbl_array) { // ================================================================================ TEST_F(MM_alloc_deps, dbl_array_pointers) { - std::vector dependencies; + std::vector & dependencies = memmgr->dependencies ; //memmgr->set_debug_level(2); @@ -111,7 +111,7 @@ TEST_F(MM_alloc_deps, dbl_array_pointers) { dbl_pa[1] = dbl_p2; dbl_pa[2] = dbl_p3; - memmgr->get_alloc_deps_in_allocation(dependencies, "dbl_array_ptrs"); + memmgr->get_alloc_deps_in_allocation("dbl_array_ptrs"); // There should be 4 dependencies. EXPECT_EQ( dependencies.size(), 4); @@ -123,7 +123,7 @@ TEST_F(MM_alloc_deps, dbl_array_pointers) { // ================================================================================ TEST_F(MM_alloc_deps, udt_singleton_no_deps) { - std::vector dependencies; + std::vector & dependencies = memmgr->dependencies ; //memmgr->set_debug_level(1); @@ -133,7 +133,7 @@ TEST_F(MM_alloc_deps, udt_singleton_no_deps) { udt_p->udt_p = NULL; udt_p->dbl_p = NULL; - memmgr->get_alloc_deps_in_allocation(dependencies, "udt_singleton"); + memmgr->get_alloc_deps_in_allocation("udt_singleton"); // There should be 1 dependency. EXPECT_EQ( dependencies.size(), 1); @@ -142,7 +142,7 @@ TEST_F(MM_alloc_deps, udt_singleton_no_deps) { // ================================================================================ TEST_F(MM_alloc_deps, udt_singleton_self_referential) { - std::vector dependencies; + std::vector & dependencies = memmgr->dependencies ; //memmgr->set_debug_level(1); @@ -152,7 +152,7 @@ TEST_F(MM_alloc_deps, udt_singleton_self_referential) { udt_p->udt_p = udt_p; udt_p->dbl_p = NULL; - memmgr->get_alloc_deps_in_allocation(dependencies, "udt_singleton"); + memmgr->get_alloc_deps_in_allocation("udt_singleton"); // There should be 1 dependency. EXPECT_EQ( dependencies.size(), 1); @@ -161,7 +161,7 @@ TEST_F(MM_alloc_deps, udt_singleton_self_referential) { // ================================================================================ TEST_F(MM_alloc_deps, udt_singleton_deps) { - std::vector dependencies; + std::vector & dependencies = memmgr->dependencies ; //memmgr->set_debug_level(1); @@ -173,7 +173,7 @@ TEST_F(MM_alloc_deps, udt_singleton_deps) { udt1_p->udt_p = udt2_p; udt1_p->dbl_p = dbl1_p; - memmgr->get_alloc_deps_in_allocation(dependencies, "udt1"); + memmgr->get_alloc_deps_in_allocation("udt1"); // There should be 3 dependencies. EXPECT_EQ( dependencies.size(), 3); @@ -184,7 +184,7 @@ TEST_F(MM_alloc_deps, udt_singleton_deps) { // ================================================================================ TEST_F(MM_alloc_deps, udt_pointer) { - std::vector dependencies; + std::vector & dependencies = memmgr->dependencies ; //memmgr->set_debug_level(1); @@ -196,7 +196,7 @@ TEST_F(MM_alloc_deps, udt_pointer) { *udt1_p = a1; - memmgr->get_alloc_deps_in_allocation(dependencies, "udt_p"); + memmgr->get_alloc_deps_in_allocation("udt_p"); // There should be 2 dependencies. EXPECT_EQ( dependencies.size(), 2); @@ -207,7 +207,7 @@ TEST_F(MM_alloc_deps, udt_pointer) { // ================================================================================ TEST_F(MM_alloc_deps, udt_array_no_deps) { - std::vector dependencies; + std::vector & dependencies = memmgr->dependencies ; //memmgr->set_debug_level(1); @@ -225,7 +225,7 @@ TEST_F(MM_alloc_deps, udt_array_no_deps) { udt_p[2].udt_p = NULL; udt_p[2].dbl_p = NULL; - memmgr->get_alloc_deps_in_allocation(dependencies, "udt_array"); + memmgr->get_alloc_deps_in_allocation("udt_array"); // There should be 1 dependency. EXPECT_EQ( dependencies.size(), 1); @@ -234,7 +234,7 @@ TEST_F(MM_alloc_deps, udt_array_no_deps) { // ================================================================================ TEST_F(MM_alloc_deps, udt_array_deps) { - std::vector dependencies; + std::vector & dependencies = memmgr->dependencies ; //memmgr->set_debug_level(1); @@ -259,7 +259,7 @@ TEST_F(MM_alloc_deps, udt_array_deps) { udt_p[2].udt_p = udt3_p; udt_p[2].dbl_p = dbl3_p; - memmgr->get_alloc_deps_in_allocation(dependencies, "udt_array"); + memmgr->get_alloc_deps_in_allocation("udt_array"); // There should be 1 dependency. EXPECT_EQ( dependencies.size(), 7); diff --git a/trick_source/sim_services/MemoryManager/test/Makefile b/trick_source/sim_services/MemoryManager/test/Makefile index 6537a7fc..94f37216 100644 --- a/trick_source/sim_services/MemoryManager/test/Makefile +++ b/trick_source/sim_services/MemoryManager/test/Makefile @@ -11,7 +11,7 @@ include ${TRICK_HOME}/share/trick/makefiles/Makefile.common #TRICK_LDFLAGS += ${COVERAGE_FLAGS} # Flags passed to the preprocessor. -TRICK_CPPFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra ${COVERAGE_FLAGS} +TRICK_CPPFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra ${COVERAGE_FLAGS} -std=c++11 TRICK_LIBS = -L${TRICK_LIB_DIR} -ltrick_mm -ltrick_units -ltrick -ltrick_mm -ltrick_units -ltrick