Add direct STL checkpointing

Added the templates required for maps, multimaps, and pairs.

refs #206
This commit is contained in:
Alex Lin 2016-03-30 16:57:45 -05:00
parent f7c74d7872
commit 94febe62f2
12 changed files with 1142 additions and 853 deletions

View File

@ -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 <vector>
#include <list>
#include <deque>
#include <set>
#include <utility>
#include <string>
#include <type_traits>
#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 <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::vector<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::vector<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
// list
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::list<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::list<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
// deque
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::deque<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::deque<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
// set
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::set<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::set<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
// multiset
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::multiset<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::multiset<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
// map
template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
!is_stl_container<DATA>::value >::type* = nullptr >
int checkpoint_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
is_stl_container<DATA>::value >::type* = nullptr >
int checkpoint_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
!is_stl_container<DATA>::value >::type* = nullptr >
int checkpoint_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
is_stl_container<DATA>::value >::type* = nullptr >
int checkpoint_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
// multimap
template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
!is_stl_container<DATA>::value >::type* = nullptr >
int checkpoint_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
is_stl_container<DATA>::value >::type* = nullptr >
int checkpoint_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
!is_stl_container<DATA>::value >::type* = nullptr >
int checkpoint_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
is_stl_container<DATA>::value >::type* = nullptr >
int checkpoint_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
// pair
template <class FIRST, class SECOND, typename std::enable_if<!is_stl_container<FIRST>::value &&
!is_stl_container<SECOND>::value >::type* = nullptr >
int checkpoint_stl(std::pair<FIRST , SECOND> & in_pair , std::string object_name , std::string var_name ) ;
template <class FIRST, class SECOND, typename std::enable_if<!is_stl_container<FIRST>::value &&
is_stl_container<SECOND>::value >::type* = nullptr >
int checkpoint_stl(std::pair<FIRST , SECOND> & in_pair , std::string object_name , std::string var_name ) ;
template <class FIRST, class SECOND, typename std::enable_if< is_stl_container<FIRST>::value &&
!is_stl_container<SECOND>::value >::type* = nullptr >
int checkpoint_stl(std::pair<FIRST , SECOND> & in_pair , std::string object_name , std::string var_name ) ;
template <class FIRST, class SECOND, typename std::enable_if< is_stl_container<FIRST>::value &&
is_stl_container<SECOND>::value >::type* = nullptr >
int checkpoint_stl(std::pair<FIRST , SECOND> & in_pair , std::string object_name , std::string var_name ) ;
/* ===================================================================================================== */
// Restore routines
// vector
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::vector<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::vector<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
// list
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::list<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::list<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
// deque
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::deque<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::deque<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
// set
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::set<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::set<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
// multiset
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::multiset<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::multiset<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
// map
template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
!is_stl_container<DATA>::value >::type* = nullptr >
int restore_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
is_stl_container<DATA>::value >::type* = nullptr >
int restore_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
!is_stl_container<DATA>::value >::type* = nullptr >
int restore_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
is_stl_container<DATA>::value >::type* = nullptr >
int restore_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
// multimap
template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
!is_stl_container<DATA>::value >::type* = nullptr >
int restore_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
is_stl_container<DATA>::value >::type* = nullptr >
int restore_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
!is_stl_container<DATA>::value >::type* = nullptr >
int restore_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
is_stl_container<DATA>::value >::type* = nullptr >
int restore_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) ;
// pair
template <class FIRST, class SECOND, typename std::enable_if<!is_stl_container<FIRST>::value &&
!is_stl_container<SECOND>::value >::type* = nullptr >
int restore_stl(std::pair<FIRST , SECOND> & in_pair , std::string object_name , std::string var_name ) ;
template <class FIRST, class SECOND, typename std::enable_if<!is_stl_container<FIRST>::value &&
is_stl_container<SECOND>::value >::type* = nullptr >
int restore_stl(std::pair<FIRST , SECOND> & in_pair , std::string object_name , std::string var_name ) ;
template <class FIRST, class SECOND, typename std::enable_if< is_stl_container<FIRST>::value &&
!is_stl_container<SECOND>::value >::type* = nullptr >
int restore_stl(std::pair<FIRST , SECOND> & in_pair , std::string object_name , std::string var_name ) ;
template <class FIRST, class SECOND, typename std::enable_if< is_stl_container<FIRST>::value &&
is_stl_container<SECOND>::value >::type* = nullptr >
int restore_stl(std::pair<FIRST , SECOND> & in_pair , std::string object_name , std::string var_name ) ;
#endif

View File

@ -9,6 +9,8 @@
#include <list> #include <list>
#include <deque> #include <deque>
#include <set> #include <set>
#include <map>
#include <utility>
template <typename T> template <typename T>
struct is_stl_container { struct is_stl_container {
@ -40,5 +42,20 @@ struct is_stl_container<std::multiset<T,Compare,Alloc> > {
static const bool value = true; static const bool value = true;
}; };
template <typename _Key, typename _Tp , typename _Compare, typename _Alloc>
struct is_stl_container<std::map<_Key,_Tp ,_Compare,_Alloc> > {
static const bool value = true;
};
template <typename _Key, typename _Tp , typename _Compare, typename _Alloc>
struct is_stl_container<std::multimap<_Key,_Tp ,_Compare,_Alloc> > {
static const bool value = true;
};
template <typename _T1,typename _T2>
struct is_stl_container<std::pair<_T1,_T2> > {
static const bool value = true;
};
#endif #endif

View File

@ -11,15 +11,19 @@
#include <map> #include <map>
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#include <sstream>
#include <typeinfo> #include <typeinfo>
#include <type_traits>
#ifdef __GNUC__ #ifdef __GNUC__
#include <cxxabi.h> #include <cxxabi.h>
#endif #endif
#include "checkpoint_is_stl_container.hh"
#include "checkpoint_fwd_declare.hh"
#include "trick/memorymanager_c_intf.h" #include "trick/memorymanager_c_intf.h"
#include "trick/message_proto.h" #include "trick/message_proto.h"
#ifndef TRICK_ICG /* =================================================================================================*/
/* For all of the checkpoint_map_stl variations. Declare 2 memory manager arrays to hold /* 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 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" the STL requires a unique name to be saved correctly. The incoming "object_name" and "var_name"
gives that unique name. gives that unique name.
*/ */
// intrinsic key, intrinsic data
template <class STL> template <class STL>
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 ii ;
unsigned int cont_size ; unsigned int cont_size ;
char var_declare[128] ; std::ostringstream var_declare ;
typename STL::iterator iter ; typename STL::iterator iter ;
int status ; int status ;
@ -44,15 +50,17 @@ 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<int,int>(&std::ispunct), '_'); std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
if ( cont_size > 0 ) { if ( cont_size > 0 ) {
sprintf(var_declare, "%s %s_%s_keys[%d]" , var_declare << abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ) << " "
abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; << object_name << "_" << var_name << "_keys[" << cont_size << "]" ;
keys = (typename STL::key_type *)TMM_declare_var_s(var_declare) ; 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()) ; 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]" , var_declare.str("") ;
abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; var_declare.clear() ;
items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare) ; 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()) ; 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) ;
@ -65,146 +73,202 @@ int checkpoint_map_stl(STL & in_map , std::string object_name , std::string var_
return 0 ; return 0 ;
} }
template <class MAP_KEY, class MAP_ITEM> template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
int checkpoint_stl(std::map<MAP_KEY , MAP_ITEM> & in_map , std::string object_name , std::string var_name ) { !is_stl_container<DATA>::value >::type* >
return checkpoint_map_stl( in_map , object_name , var_name ) ; int checkpoint_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return checkpoint_map_stl_ik_id( in_map , object_name , var_name ) ;
} }
template <class MAP_KEY, class MAP_ITEM> template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
int checkpoint_stl(std::multimap<MAP_KEY , MAP_ITEM> & in_map , std::string object_name , std::string var_name ) { !is_stl_container<DATA>::value >::type*>
return checkpoint_map_stl( in_map , object_name , var_name ) ; int checkpoint_stl(std::multimap<KEY , DATA> & 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 <class STL> template <class STL>
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 ii ;
unsigned int cont_size ; unsigned int cont_size ;
char var_declare[128] ; std::ostringstream var_declare ;
typename STL::iterator iter ; typename STL::iterator iter ;
int status ; 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<int,int>(&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 <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
is_stl_container<DATA>::value >::type* >
int checkpoint_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return checkpoint_map_stl_ik_sd( in_map , object_name , var_name ) ;
}
template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
is_stl_container<DATA>::value >::type*>
int checkpoint_stl(std::multimap<KEY , DATA> & 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 <class STL>
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 ; typename STL::mapped_type * items = nullptr ;
cont_size = in_map.size() ; cont_size = in_map.size() ;
std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_'); std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
if ( cont_size > 0 ) { if ( cont_size > 0 ) {
sprintf(var_declare, "char * %s_%s_keys[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; var_declare << "std::string "
keys = (char **)TMM_declare_var_s(var_declare) ; << 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()) ; 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]" , var_declare.str("") ;
abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str() , cont_size) ; var_declare.clear() ;
items = (typename STL::mapped_type *)TMM_declare_var_s(var_declare) ; 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()) ; 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 */ /* copy the contents of the map the 2 arrays */
for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { 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<typename STL::key_type &>(iter->first) ,
object_name + "_" + var_name + "_keys", index_string.str() ) ;
items[ii] = iter->second ; items[ii] = iter->second ;
} }
} }
return 0 ; return 0 ;
} }
template <class MAP_ITEM> template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
int checkpoint_stl(std::map<std::string , MAP_ITEM> & in_map , std::string object_name , std::string var_name ) { !is_stl_container<DATA>::value >::type* >
return checkpoint_map_stl_key_string( in_map , object_name , var_name ) ; int checkpoint_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return checkpoint_map_stl_sk_id( in_map , object_name , var_name ) ;
} }
template <class MAP_ITEM> template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
int checkpoint_stl(std::multimap<std::string , MAP_ITEM> & in_map , std::string object_name , std::string var_name ) { !is_stl_container<DATA>::value >::type*>
return checkpoint_map_stl_key_string( in_map , object_name , var_name ) ; int checkpoint_stl(std::multimap<KEY , DATA> & 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 <class STL> template <class STL>
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 ii ;
unsigned int cont_size ; unsigned int cont_size ;
char var_declare[128] ; std::ostringstream var_declare ;
typename STL::iterator iter ; typename STL::iterator iter ;
int status ; int status ;
typename STL::key_type * keys = nullptr ; std::string * keys = nullptr ;
char ** items ; std::string * items = nullptr ;
cont_size = in_map.size() ; cont_size = in_map.size() ;
std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_'); std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
if ( cont_size > 0 ) { if ( cont_size > 0 ) {
sprintf(var_declare, "%s %s_%s_keys[%d]" , var_declare << "std::string "
abi::__cxa_demangle(typeid(*keys).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str() , cont_size) ; << object_name << "_" << var_name << "_keys[" << cont_size << "]" ;
keys = (typename STL::key_type *)TMM_declare_var_s(var_declare) ; 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()) ; 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) ; var_declare.str("") ;
items = (char **)TMM_declare_var_s(var_declare) ; 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()) ; 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 */ /* copy the contents of the map the 2 arrays */
for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) { for ( iter = in_map.begin() , ii = 0 ; iter != in_map.end() ; iter++ , ii++ ) {
keys[ii] = iter->first ; std::ostringstream sub_elements ;
items[ii] = (char *)((iter->second).c_str()) ; sub_elements << object_name << "_" << var_name << "_keys_" << ii ;
keys[ii] = sub_elements.str() ;
std::ostringstream index_string ;
index_string << ii ;
checkpoint_stl( const_cast<typename STL::key_type &>(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 ; return 0 ;
} }
template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
template <class MAP_KEYS> is_stl_container<DATA>::value >::type* >
int checkpoint_stl(std::map<MAP_KEYS, std::string> & in_map , std::string object_name , std::string var_name ) { int checkpoint_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return checkpoint_map_stl_data_string( in_map , object_name , var_name ) ; return checkpoint_map_stl_sk_sd( in_map , object_name , var_name ) ;
} }
template <class MAP_KEYS> template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
int checkpoint_stl(std::multimap<MAP_KEYS, std::string> & in_map , std::string object_name , std::string var_name ) { is_stl_container<DATA>::value >::type*>
return checkpoint_map_stl_data_string( in_map , object_name , var_name ) ; int checkpoint_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return checkpoint_map_stl_sk_sd( in_map , object_name , var_name ) ;
} }
/* =================================================================================================*/
template <class STL>
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<int,int>(&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<std::string , std::string> & in_map , std::string object_name , std::string var_name ) ;
int checkpoint_stl(std::multimap<std::string , std::string> & in_map , std::string object_name , std::string var_name ) ;
template <class STL> template <class STL>
int delete_map_stl(STL & in_map __attribute__ ((unused)), std::string object_name , std::string var_name ) { int delete_map_stl(STL & in_map __attribute__ ((unused)), std::string object_name , std::string var_name ) {
@ -219,16 +283,18 @@ int delete_map_stl(STL & in_map __attribute__ ((unused)), std::string object_nam
return 0 ; return 0 ;
} }
template <class MAP_KEY, class MAP_ITEM> template <class KEY, class DATA>
int delete_stl(std::map<MAP_KEY , MAP_ITEM> & in_map , std::string object_name , std::string var_name ) { int delete_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return delete_map_stl(in_map , object_name , var_name) ; return delete_map_stl(in_map , object_name , var_name) ;
} }
template <class MAP_KEY, class MAP_ITEM> template <class KEY, class DATA>
int delete_stl(std::multimap<MAP_KEY , MAP_ITEM> & in_map , std::string object_name , std::string var_name ) { int delete_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return delete_map_stl(in_map , object_name , var_name) ; return delete_map_stl(in_map , object_name , var_name) ;
} }
/* =================================================================================================*/
/* For all restore_map_stl varieties. /* 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 From the address of the resulting ref_attributes, we can figure out the number
@ -236,7 +302,7 @@ int delete_stl(std::multimap<MAP_KEY , MAP_ITEM> & in_map , std::string object_n
the map from the 2 arrays. the map from the 2 arrays.
*/ */
template <class STL> template <class STL>
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 ii ;
unsigned int cont_size ; 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<int,int>(&std::ispunct), '_'); std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; keys_ref = ref_attributes((char *)(object_name + "_" + var_name + "_keys").c_str()) ;
items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; items_ref = ref_attributes((char *)(object_name + "_" + var_name + "_data").c_str()) ;
if ( keys_ref != NULL && items_ref != NULL ) { if ( keys_ref != NULL && items_ref != NULL ) {
in_map.clear() ; in_map.clear() ;
@ -267,139 +333,164 @@ int restore_map_stl(STL & in_map , std::string object_name , std::string var_nam
return 0 ; return 0 ;
} }
template <class MAP_KEY, class MAP_ITEM> template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
int restore_stl(std::map<MAP_KEY , MAP_ITEM> & in_map , std::string object_name , std::string var_name ) { !is_stl_container<DATA>::value >::type* >
return restore_map_stl(in_map , object_name , var_name) ; int restore_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return 0 ; return restore_map_stl_ik_id(in_map , object_name , var_name) ;
} }
template <class MAP_KEY, class MAP_ITEM> template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
int restore_stl(std::multimap<MAP_KEY , MAP_ITEM> & in_map , std::string object_name , std::string var_name ) { !is_stl_container<DATA>::value >::type* >
return restore_map_stl(in_map , object_name , var_name) ; int restore_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return restore_map_stl_ik_id(in_map , object_name , var_name) ;
} }
template <class STL> template <class STL>
int restore_map_stl_key_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 ;
char ** keys ;
typename STL::mapped_type * items ;
std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&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 , typename STL::mapped_type>(std::string(keys[ii]), items[ii])) ;
}
delete_stl( in_map , object_name , var_name ) ;
}
return 0 ;
}
template <class MAP_ITEM>
int restore_stl(std::map<std::string , MAP_ITEM> & in_map , std::string object_name , std::string var_name ) {
return restore_map_stl_key_string(in_map , object_name , var_name) ;
}
template <class MAP_ITEM>
int restore_stl(std::multimap<std::string , MAP_ITEM> & in_map , std::string object_name , std::string var_name ) {
return restore_map_stl_key_string(in_map , object_name , var_name) ;
}
template <class STL>
int restore_map_stl_data_string(STL & in_map , std::string object_name , std::string var_name ) {
unsigned int ii ; unsigned int ii ;
unsigned int cont_size ; unsigned int cont_size ;
REF2 * keys_ref , * items_ref ; REF2 * keys_ref , * items_ref ;
typename STL::key_type * keys ; 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<int,int>(&std::ispunct), '_'); std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; keys_ref = ref_attributes((char *)(object_name + "_" + var_name + "_keys").c_str()) ;
items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; items_ref = ref_attributes((char *)(object_name + "_" + var_name + "_data").c_str()) ;
if ( keys_ref != NULL && items_ref != NULL ) { if ( keys_ref != NULL && items_ref != NULL ) {
in_map.clear() ; in_map.clear() ;
keys = (typename STL::key_type *)keys_ref->address ; 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) ; cont_size = get_size((char *)keys) ;
for ( ii = 0 ; ii < cont_size ; ii++ ) { for ( ii = 0 ; ii < cont_size ; ii++ ) {
in_map.insert( std::pair<typename STL::key_type, std::string>(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<typename STL::key_type , typename STL::mapped_type>(keys[ii], mt)) ;
}
delete_stl( in_map , object_name , var_name ) ; delete_stl( in_map , object_name , var_name ) ;
} }
return 0 ; return 0 ;
} }
template <class MAP_KEY> template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
int restore_stl(std::map<MAP_KEY , std::string> & in_map , std::string object_name , std::string var_name ) { is_stl_container<DATA>::value >::type* >
return restore_map_stl_data_string(in_map , object_name , var_name) ; int restore_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return restore_map_stl_ik_sd(in_map , object_name , var_name) ;
} }
template <class MAP_KEY> template <class KEY, class DATA, typename std::enable_if<!is_stl_container<KEY>::value &&
int restore_stl(std::multimap<MAP_KEY , std::string> & in_map , std::string object_name , std::string var_name ) { is_stl_container<DATA>::value >::type* >
return restore_map_stl_data_string(in_map , object_name , var_name) ; int restore_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return restore_map_stl_ik_sd(in_map , object_name , var_name) ;
} }
template <class STL> template <class STL>
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 ii ;
unsigned int cont_size ; unsigned int cont_size ;
REF2 * keys_ref , * items_ref ; REF2 * keys_ref , * items_ref ;
char ** keys ; std::string * keys ;
char ** items ; 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<int,int>(&std::ispunct), '_'); std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
keys_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_keys")).c_str()) ; keys_ref = ref_attributes((char *)(object_name + "_" + var_name + "_keys").c_str()) ;
items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_data")).c_str()) ; items_ref = ref_attributes((char *)(object_name + "_" + var_name + "_data").c_str()) ;
if ( keys_ref != NULL && items_ref != NULL ) { if ( keys_ref != NULL && items_ref != NULL ) {
in_map.clear() ; in_map.clear() ;
keys = (char **)keys_ref->address ; keys = (std::string *)keys_ref->address ;
items = (char **)items_ref->address ; items = (typename STL::mapped_type *)items_ref->address ;
cont_size = get_size((char *)keys) ; cont_size = get_size((char *)keys) ;
for ( ii = 0 ; ii < cont_size ; ii++ ) { for ( ii = 0 ; ii < cont_size ; ii++ ) {
in_map.insert( std::pair<std::string, std::string>(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<typename STL::key_type , typename STL::mapped_type>(kt, items[ii])) ;
}
delete_stl( in_map , object_name , var_name ) ; delete_stl( in_map , object_name , var_name ) ;
} }
return 0 ; return 0 ;
} }
int restore_stl(std::map<std::string, std::string> & in_map , std::string object_name , std::string var_name ) ; template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
int restore_stl(std::multimap<std::string, std::string> & in_map , std::string object_name , std::string var_name ) ; !is_stl_container<DATA>::value >::type* >
int restore_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
#endif return restore_map_stl_sk_id(in_map , object_name , var_name) ;
}
template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
!is_stl_container<DATA>::value >::type* >
int restore_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return restore_map_stl_sk_id(in_map , object_name , var_name) ;
}
template <class STL>
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<int,int>(&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<typename STL::key_type , typename STL::mapped_type>(kt, mt)) ;
}
delete_stl( in_map , object_name , var_name ) ;
}
return 0 ;
}
template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
is_stl_container<DATA>::value >::type* >
int restore_stl(std::map<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return restore_map_stl_sk_sd(in_map , object_name , var_name) ;
}
template <class KEY, class DATA, typename std::enable_if< is_stl_container<KEY>::value &&
is_stl_container<DATA>::value >::type* >
int restore_stl(std::multimap<KEY , DATA> & in_map , std::string object_name , std::string var_name ) {
return restore_map_stl_sk_sd(in_map , object_name , var_name) ;
}
#endif #endif

View File

@ -7,124 +7,192 @@
#define CHECKPOINT_PAIR_HH #define CHECKPOINT_PAIR_HH
#include <utility> #include <utility>
#include <sstream>
#include <algorithm> #include <algorithm>
#include <typeinfo> #include <typeinfo>
#include <functional> #include <functional>
#include <string>
#include <type_traits>
#ifdef __GNUC__ #ifdef __GNUC__
#include <cxxabi.h> #include <cxxabi.h>
#endif #endif
#include "checkpoint_is_stl_container.hh"
#include "checkpoint_fwd_declare.hh"
#include "trick/memorymanager_c_intf.h" #include "trick/memorymanager_c_intf.h"
#include "trick/message_proto.h" #include "trick/message_proto.h"
#ifndef TRICK_ICG // intrinsic first , intrinsic second
template <class FIRST_TYPE, class SECOND_TYPE> template <class FIRST, class SECOND>
int delete_stl(std::pair<FIRST_TYPE, SECOND_TYPE> & in_stl __attribute__ ((unused)) , std::string object_name , std::string var_name ) { int checkpoint_pair_if_is(std::pair<FIRST, SECOND> & 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<int,int>(&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 <class FIRST, class SECOND, typename std::enable_if<!is_stl_container<FIRST>::value &&
!is_stl_container<SECOND>::value >::type* >
int checkpoint_stl(std::pair<FIRST , SECOND> & 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 <class FIRST, class SECOND>
int checkpoint_pair_if_ss(std::pair<FIRST, SECOND> & 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<int,int>(&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 <class FIRST, class SECOND, typename std::enable_if<!is_stl_container<FIRST>::value &&
is_stl_container<SECOND>::value >::type* >
int checkpoint_stl(std::pair<FIRST , SECOND> & 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 <class FIRST, class SECOND>
int checkpoint_pair_sf_is(std::pair<FIRST, SECOND> & 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<int,int>(&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 <class FIRST, class SECOND, typename std::enable_if< is_stl_container<FIRST>::value &&
!is_stl_container<SECOND>::value >::type* >
int checkpoint_stl(std::pair<FIRST , SECOND> & 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 <class FIRST, class SECOND>
int checkpoint_pair_sf_ss(std::pair<FIRST, SECOND> & 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<int,int>(&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 <class FIRST, class SECOND, typename std::enable_if< is_stl_container<FIRST>::value &&
is_stl_container<SECOND>::value >::type* >
int checkpoint_stl(std::pair<FIRST , SECOND> & in_pair , std::string object_name , std::string var_name ) {
return checkpoint_pair_sf_ss( in_pair, object_name, var_name ) ;
}
/* =================================================================================================*/
template <class FIRST, class SECOND>
int delete_stl(std::pair<FIRST, SECOND> & in_stl __attribute__ ((unused)) , std::string object_name , std::string var_name ) {
std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_'); std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
REF2 * items_ref ; 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 ) { 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 + "_" + var_name + "_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 + "_second").c_str() ) ;
free(items_ref) ; free(items_ref) ;
} }
return 0 ; return 0 ;
} }
template <class FIRST_TYPE, class SECOND_TYPE> /* =================================================================================================*/
int checkpoint_stl(std::pair<FIRST_TYPE, SECOND_TYPE> & 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<int,int>(&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 <class FIRST_TYPE>
int checkpoint_stl(std::pair<FIRST_TYPE, std::string> & 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<int,int>(&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 <class SECOND_TYPE>
int checkpoint_stl(std::pair<std::string, SECOND_TYPE> & 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<int,int>(&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 <class FIRST_TYPE, class SECOND_TYPE>
int restore_stl(std::pair<FIRST_TYPE, SECOND_TYPE> & in_stl , std::string object_name , std::string var_name ) {
// intrinsic first, intrinsic second
template <class FIRST, class SECOND>
int restore_pair_if_is(std::pair<FIRST, SECOND> & in_stl , std::string object_name , std::string var_name ) {
REF2 * first_ref ; REF2 * first_ref ;
REF2 * second_ref ; REF2 * second_ref ;
FIRST_TYPE * first ; FIRST * first ;
SECOND_TYPE * second ; SECOND * second ;
std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_'); std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
//message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; //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()) ; first_ref = ref_attributes((char *)(object_name + "_" + var_name + "_first").c_str()) ;
second_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_second")).c_str()) ; second_ref = ref_attributes((char *)(object_name + "_" + var_name + "_second").c_str()) ;
if ( first_ref != NULL && second_ref != NULL ) { if ( first_ref != NULL && second_ref != NULL ) {
first = (FIRST_TYPE *)first_ref->address ; first = (FIRST *)first_ref->address ;
second = (SECOND_TYPE *)second_ref->address ; second = (SECOND *)second_ref->address ;
in_stl.first = first[0] ; in_stl.first = first[0] ;
in_stl.second = second[0] ; in_stl.second = second[0] ;
@ -135,27 +203,34 @@ int restore_stl(std::pair<FIRST_TYPE, SECOND_TYPE> & in_stl , std::string object
return 0 ; return 0 ;
} }
template <class FIRST_TYPE> template <class FIRST, class SECOND, typename std::enable_if<!is_stl_container<FIRST>::value &&
int restore_stl(std::pair<FIRST_TYPE, std::string > & in_stl , std::string object_name , std::string var_name ) { !is_stl_container<SECOND>::value >::type* >
int restore_stl(std::pair<FIRST , SECOND> & 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 <class FIRST, class SECOND>
int restore_pair_if_ss(std::pair<FIRST, SECOND> & in_stl , std::string object_name , std::string var_name ) {
REF2 * first_ref ; REF2 * first_ref ;
REF2 * second_ref ; REF2 * second_ref ;
FIRST_TYPE * first ; FIRST * first ;
char ** second ; std::string * second ;
std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
//message_publish(1, "RESTORE_STL_queue %s_%s\n", object_name.c_str() , var_name.c_str()) ; //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()) ; first_ref = ref_attributes((char *)(object_name + "_" + var_name + "_first").c_str()) ;
second_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_second")).c_str()) ; second_ref = ref_attributes((char *)(object_name + "_" + var_name + "_second").c_str()) ;
if ( first_ref != NULL && second_ref != NULL ) { if ( first_ref != NULL && second_ref != NULL ) {
first = (FIRST_TYPE *)first_ref->address ; first = (FIRST *)first_ref->address ;
second = (char **)second_ref->address ; second = (std::string *)second_ref->address ;
in_stl.first = first[0] ; 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 ) ; delete_stl( in_stl , object_name , var_name ) ;
} }
@ -163,25 +238,33 @@ int restore_stl(std::pair<FIRST_TYPE, std::string > & in_stl , std::string objec
return 0 ; return 0 ;
} }
template <class SECOND_TYPE> template <class FIRST, class SECOND, typename std::enable_if<!is_stl_container<FIRST>::value &&
int restore_stl(std::pair<std::string, SECOND_TYPE> & in_stl , std::string object_name , std::string var_name ) { is_stl_container<SECOND>::value >::type* >
int restore_stl(std::pair<FIRST , SECOND> & 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 <class FIRST, class SECOND>
int restore_pair_sf_is(std::pair<FIRST, SECOND> & in_stl , std::string object_name , std::string var_name ) {
REF2 * first_ref ; REF2 * first_ref ;
REF2 * second_ref ; REF2 * second_ref ;
char ** first ; std::string * first ;
SECOND_TYPE * second ; SECOND * 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<int,int>(&std::ispunct), '_');
first_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_first")).c_str()) ; std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
second_ref = ref_attributes((char *)(object_name + std::string("_") + var_name + std::string("_second")).c_str()) ; //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 ) { if ( first_ref != NULL && second_ref != NULL ) {
first = (char **)first_ref->address ; first = (std::string *)first_ref->address ;
second = (SECOND_TYPE *)second_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] ; in_stl.second = second[0] ;
delete_stl( in_stl , object_name , var_name ) ; delete_stl( in_stl , object_name , var_name ) ;
@ -190,10 +273,45 @@ int restore_stl(std::pair<std::string, SECOND_TYPE> & in_stl , std::string objec
return 0 ; return 0 ;
} }
// Specialized routines for strings. template <class FIRST, class SECOND, typename std::enable_if< is_stl_container<FIRST>::value &&
int checkpoint_stl(std::pair<std::string, std::string> & in_stl , std::string object_name , std::string var_name ) ; !is_stl_container<SECOND>::value >::type* >
int restore_stl(std::pair<std::string, std::string> & in_stl , std::string object_name , std::string var_name ) ; int restore_stl(std::pair<FIRST , SECOND> & in_pair , std::string object_name , std::string var_name ) {
return restore_pair_sf_is( in_pair, object_name, var_name ) ;
#endif }
// STL first, STL second
template <class FIRST, class SECOND>
int restore_pair_sf_ss(std::pair<FIRST, SECOND> & 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<int,int>(&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 <class FIRST, class SECOND, typename std::enable_if< is_stl_container<FIRST>::value &&
is_stl_container<SECOND>::value >::type* >
int restore_stl(std::pair<FIRST , SECOND> & in_pair , std::string object_name , std::string var_name ) {
return restore_pair_sf_ss( in_pair, object_name, var_name ) ;
}
#endif #endif

View File

@ -13,77 +13,41 @@
#include <set> #include <set>
#include <algorithm> #include <algorithm>
#include <typeinfo> #include <typeinfo>
#include <sstream>
#include <stack> #include <type_traits>
#include <queue>
#include <utility>
#ifdef __GNUC__ #ifdef __GNUC__
#include <cxxabi.h> #include <cxxabi.h>
#endif #endif
#include <type_traits> #include "checkpoint_is_stl_container.hh"
#include "checkpoint_fwd_declare.hh"
#include "trick/memorymanager_c_intf.h" #include "trick/memorymanager_c_intf.h"
#include "trick/message_proto.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 <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::vector<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::vector<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::list<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::list<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::deque<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::deque<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::set<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::set<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::multiset<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int checkpoint_stl(std::multiset<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
// End forward declarations.
template <class STL> template <class STL>
int checkpoint_sequence_stl_intrinsic(STL & in_stl , std::string object_name , std::string var_name ) { int checkpoint_sequence_stl_intrinsic(STL & in_stl , std::string object_name , std::string var_name ) {
unsigned int ii ; unsigned int ii ;
unsigned int cont_size ; unsigned int cont_size ;
char var_declare[128] ; std::ostringstream var_declare ;
int status ; int status ;
typename STL::value_type * items = NULL ; typename STL::value_type * items = NULL ;
typename STL::iterator it ; typename STL::iterator it ;
typename STL::iterator end ; typename STL::iterator end ;
message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; //message_publish(1, "%s\n", __PRETTY_FUNCTION__) ;
cont_size = in_stl.size() ; cont_size = in_stl.size() ;
std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_'); std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
if ( cont_size > 0 ) { if ( cont_size > 0 ) {
sprintf(var_declare, "%s %s_%s[%d]" , var_declare << abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ) << " "
abi::__cxa_demangle(typeid(*items).name(), 0, 0, &status ), object_name.c_str(), var_name.c_str(), cont_size) ; << object_name << "_" << var_name << "[" << cont_size << "]" ;
items = (typename STL::value_type *)TMM_declare_var_s(var_declare) ; 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()) ; TMM_add_checkpoint_alloc_dependency(std::string(object_name + "_" + var_name).c_str()) ;
//message_publish(1, "CHECKPOINT_SEQUENCE_STL with %s\n", var_declare) ; //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 ; return 0 ;
} }
template <class STL>
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<int,int>(&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 <class STL> template <class STL>
int checkpoint_sequence_stl_stl(STL & in_stl , std::string object_name , std::string var_name ) { int checkpoint_sequence_stl_stl(STL & in_stl , std::string object_name , std::string var_name ) {
unsigned int ii ; unsigned int ii ;
unsigned int cont_size ; 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 it ;
typename STL::iterator end ; 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() ; cont_size = in_stl.size() ;
std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_'); std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; //message_publish(1, "%s\n", __PRETTY_FUNCTION__) ;
if ( cont_size > 0 ) { if ( cont_size > 0 ) {
sprintf(var_declare, "char * %s_%s[%d]" , object_name.c_str(), var_name.c_str() , cont_size) ; var_declare << "std::string " << object_name << "_" << var_name << "[" << cont_size << "]" ;
items = (const char **)TMM_declare_var_s(var_declare) ; 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()) ; 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 */ /* 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++ ) { for ( ii = 0 , it = in_stl.begin() , end = in_stl.end() ; it != end ; it++ , ii++ ) {
char sub_elements[128] ; std::ostringstream sub_elements ;
sprintf(sub_elements, "%s_%s_%d", object_name.c_str(), var_name.c_str() , ii) ; sub_elements << object_name << "_" << var_name << "_" << ii ;
items[ii] = TMM_strdup(sub_elements) ; items[ii] = sub_elements.str() ;
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] ; std::ostringstream index_string ;
sprintf(index_string, "%d", ii) ; index_string << ii ;
message_publish(1, "recursive call to checkpoint_stl %s\n", __PRETTY_FUNCTION__) ; //message_publish(1, "recursive call to checkpoint_stl %s\n", __PRETTY_FUNCTION__) ;
checkpoint_stl( (*it) , object_name + "_" + var_name , std::string(index_string) ) ; checkpoint_stl( (*it) , object_name + "_" + var_name , index_string.str() ) ;
} }
} }
return 0 ; return 0 ;
@ -185,9 +115,6 @@ int checkpoint_stl(std::vector<ITEM_TYPE> & in_stl , std::string object_name , s
return checkpoint_sequence_stl_intrinsic( in_stl , object_name , 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<std::string> & in_vector , std::string object_name , std::string var_name ) ;
// ----------- // -----------
// std::list // std::list
@ -202,9 +129,6 @@ int checkpoint_stl(std::list<ITEM_TYPE> & in_stl , std::string object_name , std
return checkpoint_sequence_stl_intrinsic( in_stl , object_name , 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<std::string> & in_list , std::string object_name , std::string var_name ) ;
// ----------- // -----------
// std::deque // std::deque
@ -219,9 +143,6 @@ int checkpoint_stl(std::deque<ITEM_TYPE> & in_stl , std::string object_name , st
return checkpoint_sequence_stl_intrinsic( in_stl , object_name , 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<std::string> & in_vector , std::string object_name , std::string var_name ) ;
// ----------- // -----------
// std::set // std::set
@ -236,9 +157,6 @@ int checkpoint_stl(std::set<ITEM_TYPE> & in_stl , std::string object_name , std:
return checkpoint_sequence_stl_intrinsic( in_stl , object_name , 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<std::string> & in_vector , std::string object_name , std::string var_name ) ;
// ----------- // -----------
// std::multiset // std::multiset
@ -253,9 +171,6 @@ int checkpoint_stl(std::multiset<ITEM_TYPE> & in_stl , std::string object_name ,
return checkpoint_sequence_stl_intrinsic( in_stl , object_name , 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<std::string> & in_vector , std::string object_name , std::string var_name ) ;
/* =================================================================================================*/ /* =================================================================================================*/
template <class STL> template <class STL>
@ -298,38 +213,6 @@ int delete_stl(std::multiset<ITEM_TYPE> & in_stl , std::string object_name , std
/* =================================================================================================*/ /* =================================================================================================*/
// Forward declare all of the specialized templates that can be used in checkpoint_sequence_stl_stl
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::vector<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::vector<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::list<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::list<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::deque<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::deque<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::set<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::set<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::multiset<ITEM_TYPE> & in_stl , std::string object_name , std::string var_name ) ;
template <typename ITEM_TYPE, typename std::enable_if<!is_stl_container<ITEM_TYPE>::value>::type* = nullptr >
int restore_stl(std::multiset<ITEM_TYPE> & 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 /* 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 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 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()) ; //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()) ; items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ;
if ( items_ref != NULL ) { if ( items_ref != NULL ) {
@ -364,35 +246,6 @@ int restore_sequence_stl_intrinsic(STL & in_stl , std::string object_name , std:
return 0 ; return 0 ;
} }
template <class STL>
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<int,int>(&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 <class STL> template <class STL>
int restore_sequence_stl_stl(STL & in_stl , std::string object_name , std::string var_name ) { 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 ; unsigned int cont_size ;
REF2 * items_ref ; REF2 * items_ref ;
char ** items ; std::string * items ;
std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_'); std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun<int,int>(&std::ispunct), '_');
//message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; //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 ) { if ( items_ref != NULL ) {
in_stl.clear() ; in_stl.clear() ;
items = (char **)items_ref->address ; items = (std::string *)items_ref->address ;
cont_size = get_size((char *)items) ; cont_size = get_size((char *)items) ;
for ( ii = 0 ; ii < cont_size ; ii++ ) { for ( ii = 0 ; ii < cont_size ; ii++ ) {
typename STL::value_type vt ; typename STL::value_type vt ;
char index_string[16] ; std::ostringstream index_string ;
sprintf(index_string, "%d", ii) ; index_string << ii ;
restore_stl(vt, object_name + "_" + var_name , std::string(index_string)) ; restore_stl(vt, object_name + "_" + var_name , index_string.str()) ;
in_stl.insert( in_stl.end(), vt ) ; in_stl.insert( in_stl.end(), vt ) ;
} }
delete_stl( in_stl , object_name , var_name ) ; delete_stl( in_stl , object_name , var_name ) ;
@ -440,9 +293,6 @@ int restore_stl(std::vector<ITEM_TYPE> & in_stl , std::string object_name , std:
return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ;
} }
// Specialized routines for strings.
int restore_stl(std::vector<std::string> & in_vector , std::string object_name , std::string var_name ) ;
// ----------- // -----------
// std::list // std::list
@ -458,8 +308,6 @@ int restore_stl(std::list<ITEM_TYPE> & in_stl , std::string object_name , std::s
return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ;
} }
int restore_stl(std::list<std::string> & in_list , std::string object_name , std::string var_name ) ;
// ----------- // -----------
// std::deque // std::deque
@ -475,8 +323,6 @@ int restore_stl(std::deque<ITEM_TYPE> & in_stl , std::string object_name , std::
return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ;
} }
int restore_stl(std::deque<std::string> & in_deque , std::string object_name , std::string var_name ) ;
// ----------- // -----------
// std::set // std::set
@ -492,8 +338,6 @@ int restore_stl(std::set<ITEM_TYPE> & in_stl , std::string object_name , std::st
return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ;
} }
int restore_stl(std::set<std::string> & in_set , std::string object_name , std::string var_name ) ;
// ----------- // -----------
// std::multiset // std::multiset
@ -509,7 +353,4 @@ int restore_stl(std::multiset<ITEM_TYPE> & in_stl , std::string object_name , st
return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ; return restore_sequence_stl_intrinsic( in_stl , object_name , var_name ) ;
} }
// Specialized routines for strings.
int restore_stl(std::multiset<std::string> & in_multiset , std::string object_name , std::string var_name ) ;
#endif #endif

View File

@ -3,9 +3,9 @@ def main():
#trick.echo_jobs_on() #trick.echo_jobs_on()
#trick.sim_control_panel_set_enabled(True) trick.sim_control_panel_set_enabled(True)
#trick.real_time_enable() trick.real_time_enable()
#trick.itimer_enable() trick.itimer_enable()
trick.checkpoint_pre_init(True) trick.checkpoint_pre_init(True)
#trick.checkpoint_post_init(True) #trick.checkpoint_post_init(True)

View File

@ -6,363 +6,413 @@
STLCheckpoint::STLCheckpoint() { STLCheckpoint::STLCheckpoint() {
my_double_map[11.1] = 111.1 ; double_map[11.1] = 111.1 ;
my_double_map[22.2] = 222.2 ; double_map[22.2] = 222.2 ;
my_double_map[33.3] = 333.3 ; double_map[33.3] = 333.3 ;
my_string_key_map[std::string("one")] = 1 ; string_key_map[std::string("one")] = 1 ;
my_string_key_map[std::string("two")] = 2 ; string_key_map[std::string("two")] = 2 ; string_key_map[std::string("three")] = 3 ;
my_string_key_map[std::string("three")] = 3 ;
my_string_data_map[4] = std::string("vier") ; string_data_map[4] = std::string("vier") ;
my_string_data_map[5] = std::string("fumf") ; string_data_map[5] = std::string("fumf") ;
my_string_data_map[6] = std::string("sechs") ; string_data_map[6] = std::string("sechs") ;
my_string_map[std::string("mother")] = std::string("Marge") ; string_map[std::string("mother")] = std::string("Marge") ;
my_string_map[std::string("father")] = std::string("Homer") ; string_map[std::string("father")] = std::string("Homer") ;
my_string_map[std::string("son")] = std::string("Bart") ; string_map[std::string("son")] = std::string("Bart") ;
my_int_multimap.insert(std::pair<int, int>(11,111)) ; int_multimap.insert(std::pair<int, int>(11,111)) ;
my_int_multimap.insert(std::pair<int, int>(22,222)) ; int_multimap.insert(std::pair<int, int>(22,222)) ;
my_int_multimap.insert(std::pair<int, int>(33,333)) ; int_multimap.insert(std::pair<int, int>(33,333)) ;
my_int_multimap.insert(std::pair<int, int>(11,111)) ; int_multimap.insert(std::pair<int, int>(11,111)) ;
my_int_multimap.insert(std::pair<int, int>(22,222)) ; int_multimap.insert(std::pair<int, int>(22,222)) ;
my_int_multimap.insert(std::pair<int, int>(33,333)) ; int_multimap.insert(std::pair<int, int>(33,333)) ;
my_string_key_multimap.insert(std::pair<std::string, int>("one", 1)) ; string_key_multimap.insert(std::pair<std::string, int>("one", 1)) ;
my_string_key_multimap.insert(std::pair<std::string, int>("two", 2)) ; string_key_multimap.insert(std::pair<std::string, int>("two", 2)) ;
my_string_key_multimap.insert(std::pair<std::string, int>("three", 3)) ; string_key_multimap.insert(std::pair<std::string, int>("three", 3)) ;
my_string_key_multimap.insert(std::pair<std::string, int>("one", 1)) ; string_key_multimap.insert(std::pair<std::string, int>("one", 1)) ;
my_string_key_multimap.insert(std::pair<std::string, int>("two", 2)) ; string_key_multimap.insert(std::pair<std::string, int>("two", 2)) ;
my_string_key_multimap.insert(std::pair<std::string, int>("three", 3)) ; string_key_multimap.insert(std::pair<std::string, int>("three", 3)) ;
my_string_data_multimap.insert(std::pair<int, std::string>(4, "vier")) ; string_data_multimap.insert(std::pair<int, std::string>(4, "vier")) ;
my_string_data_multimap.insert(std::pair<int, std::string>(5, "fumf")) ; string_data_multimap.insert(std::pair<int, std::string>(5, "fumf")) ;
my_string_data_multimap.insert(std::pair<int, std::string>(6, "sechs")) ; string_data_multimap.insert(std::pair<int, std::string>(6, "sechs")) ;
my_string_data_multimap.insert(std::pair<int, std::string>(4, "four")) ; string_data_multimap.insert(std::pair<int, std::string>(4, "four")) ;
my_string_data_multimap.insert(std::pair<int, std::string>(5, "five")) ; string_data_multimap.insert(std::pair<int, std::string>(5, "five")) ;
my_string_data_multimap.insert(std::pair<int, std::string>(6, "six")) ; string_data_multimap.insert(std::pair<int, std::string>(6, "six")) ;
my_string_multimap.insert(std::pair<std::string, std::string>("mother","Marge")) ; string_multimap.insert(std::pair<std::string, std::string>("mother","Marge")) ;
my_string_multimap.insert(std::pair<std::string, std::string>("father","Homer")) ; string_multimap.insert(std::pair<std::string, std::string>("father","Homer")) ;
my_string_multimap.insert(std::pair<std::string, std::string>("mother","Lois")) ; string_multimap.insert(std::pair<std::string, std::string>("mother","Lois")) ;
my_string_multimap.insert(std::pair<std::string, std::string>("father","Meg")) ; string_multimap.insert(std::pair<std::string, std::string>("father","Meg")) ;
my_double_vector.push_back(1.0) ; double_vector.push_back(1.0) ;
my_double_vector.push_back(2.0) ; double_vector.push_back(2.0) ;
my_double_vector.push_back(3.0) ; double_vector.push_back(3.0) ;
my_string_vector.push_back("I") ; string_vector.push_back("I") ;
my_string_vector.push_back("was") ; string_vector.push_back("was") ;
my_string_vector.push_back("here") ; string_vector.push_back("here") ;
my_short_list.push_back(300) ; short_list.push_back(300) ;
my_short_list.push_back(301) ; short_list.push_back(301) ;
my_short_list.push_back(302) ; short_list.push_back(302) ;
my_string_list.push_back("I") ; string_list.push_back("I") ;
my_string_list.push_back("was") ; string_list.push_back("was") ;
my_string_list.push_back("there") ; string_list.push_back("there") ;
my_float_deque.push_back(12.3) ; float_deque.push_back(12.3) ;
my_float_deque.push_back(45.6) ; float_deque.push_back(45.6) ;
my_float_deque.push_back(78.9) ; float_deque.push_back(78.9) ;
my_string_deque.push_back("meow") ; string_deque.push_back("meow") ;
my_string_deque.push_back("bark") ; string_deque.push_back("bark") ;
my_string_deque.push_back("quack") ; string_deque.push_back("quack") ;
my_int_set.insert(8) ; int_set.insert(8) ;
my_int_set.insert(4) ; int_set.insert(4) ;
my_int_set.insert(2) ; int_set.insert(2) ;
my_int_set.insert(1) ; int_set.insert(1) ;
my_string_set.insert("e") ; string_set.insert("e") ;
my_string_set.insert("a") ; string_set.insert("a") ;
my_string_set.insert("d") ; string_set.insert("d") ;
my_long_multiset.insert(8) ; long_multiset.insert(8) ;
my_long_multiset.insert(4) ; long_multiset.insert(4) ;
my_long_multiset.insert(4) ; long_multiset.insert(4) ;
my_long_multiset.insert(2) ; long_multiset.insert(2) ;
my_long_multiset.insert(1) ; long_multiset.insert(1) ;
my_string_multiset.insert("e") ; string_multiset.insert("e") ;
my_string_multiset.insert("a") ; string_multiset.insert("a") ;
my_string_multiset.insert("d") ; string_multiset.insert("d") ;
my_string_multiset.insert("e") ; string_multiset.insert("e") ;
my_string_multiset.insert("a") ; string_multiset.insert("a") ;
my_string_multiset.insert("d") ; string_multiset.insert("d") ;
my_uint_stack.push(10) ; uint_stack.push(10) ;
my_uint_stack.push(20) ; uint_stack.push(20) ;
my_uint_stack.push(30) ; uint_stack.push(30) ;
my_uint_stack.push(40) ; uint_stack.push(40) ;
my_string_stack.push("abc I") ; string_stack.push("abc I") ;
my_string_stack.push("abc want the one") ; string_stack.push("abc want the one") ;
my_string_stack.push("abc with the bigger") ; string_stack.push("abc with the bigger") ;
my_string_stack.push("abc Gee Bees") ; string_stack.push("abc Gee Bees") ;
my_int_queue.push(10) ; int_queue.push(10) ;
my_int_queue.push(20) ; int_queue.push(20) ;
my_int_queue.push(30) ; int_queue.push(30) ;
my_int_queue.push(40) ; int_queue.push(40) ;
my_string_queue.push("abc I") ; string_queue.push("abc I") ;
my_string_queue.push("abc want") ; string_queue.push("abc want") ;
my_string_queue.push("abc an") ; string_queue.push("abc an") ;
my_string_queue.push("abc iPhone 4") ; string_queue.push("abc iPhone 4") ;
my_int_priority_queue.push(30) ; int_priority_queue.push(30) ;
my_int_priority_queue.push(20) ; int_priority_queue.push(20) ;
my_int_priority_queue.push(40) ; int_priority_queue.push(40) ;
my_int_priority_queue.push(10) ; int_priority_queue.push(10) ;
my_string_priority_queue.push("abc I") ; string_priority_queue.push("abc I") ;
my_string_priority_queue.push("abc want") ; string_priority_queue.push("abc want") ;
my_string_priority_queue.push("abc an") ; string_priority_queue.push("abc an") ;
my_string_priority_queue.push("abc iPhone 4") ; string_priority_queue.push("abc iPhone 4") ;
my_int_pair.first = 1 ; int_pair.first = 1 ;
my_int_pair.second = 2 ; int_pair.second = 2 ;
my_string_first_pair.first = "abc string first" ; string_first_pair.first = "abc string first" ;
my_string_first_pair.second = 2 ; string_first_pair.second = 2 ;
my_string_second_pair.first = 2 ; string_second_pair.first = 2 ;
my_string_second_pair.second = "abc string second" ; string_second_pair.second = "abc string second" ;
my_string_pair.first = "abc pair first string" ; string_pair.first = "abc pair first string" ;
my_string_pair.second = "abc pair second string" ; string_pair.second = "abc pair second string" ;
return ; return ;
} }
STLCheckpoint::STLCheckpoint(std::string in_name) : STLCheckpoint::STLCheckpoint(std::string in_name) :
my_vector_vector_double(4, std::vector<double>(3)) , vector_vector_double(4, std::vector<double>(3)) ,
my_vector_vector_vector_double(5, std::vector<std::vector<double> >(4, std::vector<double>(3))) vector_vector_vector_double(5, std::vector<std::vector<double> >(4, std::vector<double>(3)))
{ {
name = in_name ; name = in_name ;
my_double_map[44.4] = 444.4 ; double_map[44.4] = 444.4 ;
my_double_map[55.5] = 555.5 ; double_map[55.5] = 555.5 ;
my_double_map[66.6] = 666.6 ; double_map[66.6] = 666.6 ;
my_string_key_map[std::string("four")] = 4 ; string_key_map[std::string("four")] = 4 ;
my_string_key_map[std::string("five")] = 5 ; string_key_map[std::string("five")] = 5 ;
my_string_key_map[std::string("six")] = 6 ; string_key_map[std::string("six")] = 6 ;
my_string_data_map[7] = std::string("seiben") ; string_data_map[7] = std::string("seiben") ;
my_string_data_map[8] = std::string("acht") ; string_data_map[8] = std::string("acht") ;
my_string_data_map[9] = std::string("neun") ; string_data_map[9] = std::string("neun") ;
my_string_map[std::string("sister")] = std::string("Lisa") ; std::vector< int > v ;
my_string_map[std::string("dog")] = std::string("Santa's Little Helper") ; 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<int, int>(44,444)) ; std::pair< int , int > p ;
my_int_multimap.insert(std::pair<int, int>(55,555)) ; p.first = 24 ;
my_int_multimap.insert(std::pair<int, int>(66,666)) ; p.second = 30 ;
my_int_multimap.insert(std::pair<int, int>(44,444)) ; gcd[p] = 6 ;
my_int_multimap.insert(std::pair<int, int>(55,555)) ;
my_int_multimap.insert(std::pair<int, int>(66,666)) ;
my_string_key_multimap.insert(std::pair<std::string, int>("four", 4)) ; p.first = 50 ;
my_string_key_multimap.insert(std::pair<std::string, int>("five", 5)) ; p.second = 60 ;
my_string_key_multimap.insert(std::pair<std::string, int>("six", 6)) ; std::pair< int , int > q ;
my_string_key_multimap.insert(std::pair<std::string, int>("four", 44)) ; q.first = 70 ;
my_string_key_multimap.insert(std::pair<std::string, int>("five", 55)) ; q.second = 80 ;
my_string_key_multimap.insert(std::pair<std::string, int>("six", 66)) ; map_pair_pair[p] = q ;
my_string_data_multimap.insert(std::pair<int, std::string>(7, "seiben")) ; p.first = 3 ;
my_string_data_multimap.insert(std::pair<int, std::string>(8, "acht")) ; p.second = 5 ;
my_string_data_multimap.insert(std::pair<int, std::string>(9, "neun")) ; v.clear() ;
my_string_data_multimap.insert(std::pair<int, std::string>(7, "seven")) ; v.push_back(15) ;
my_string_data_multimap.insert(std::pair<int, std::string>(8, "eight")) ; v.push_back(30) ;
my_string_data_multimap.insert(std::pair<int, std::string>(9, "nine")) ; 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<std::string, std::string>("sister","Lisa")) ; string_map[std::string("sister")] = std::string("Lisa") ;
my_string_multimap.insert(std::pair<std::string, std::string>("dog","Santa's Little Helper")) ; string_map[std::string("dog")] = std::string("Santa's Little Helper") ;
my_string_multimap.insert(std::pair<std::string, std::string>("sister","Meg")) ;
my_string_multimap.insert(std::pair<std::string, std::string>("dog","Brian")) ;
my_double_vector.push_back(4.0) ; int_multimap.insert(std::pair<int, int>(44,444)) ;
my_double_vector.push_back(5.0) ; int_multimap.insert(std::pair<int, int>(55,555)) ;
my_double_vector.push_back(6.0) ; int_multimap.insert(std::pair<int, int>(66,666)) ;
int_multimap.insert(std::pair<int, int>(44,444)) ;
int_multimap.insert(std::pair<int, int>(55,555)) ;
int_multimap.insert(std::pair<int, int>(66,666)) ;
my_string_vector.push_back("It") ; string_key_multimap.insert(std::pair<std::string, int>("four", 4)) ;
my_string_vector.push_back("has") ; string_key_multimap.insert(std::pair<std::string, int>("five", 5)) ;
my_string_vector.push_back("the") ; string_key_multimap.insert(std::pair<std::string, int>("six", 6)) ;
my_string_vector.push_back("Wi-Fies") ; string_key_multimap.insert(std::pair<std::string, int>("four", 44)) ;
string_key_multimap.insert(std::pair<std::string, int>("five", 55)) ;
string_key_multimap.insert(std::pair<std::string, int>("six", 66)) ;
my_short_list.push_back(400) ; string_data_multimap.insert(std::pair<int, std::string>(7, "seiben")) ;
my_short_list.push_back(401) ; string_data_multimap.insert(std::pair<int, std::string>(8, "acht")) ;
my_short_list.push_back(402) ; string_data_multimap.insert(std::pair<int, std::string>(9, "neun")) ;
string_data_multimap.insert(std::pair<int, std::string>(7, "seven")) ;
string_data_multimap.insert(std::pair<int, std::string>(8, "eight")) ;
string_data_multimap.insert(std::pair<int, std::string>(9, "nine")) ;
my_string_list.push_back("I") ; string_multimap.insert(std::pair<std::string, std::string>("sister","Lisa")) ;
my_string_list.push_back("don't") ; string_multimap.insert(std::pair<std::string, std::string>("dog","Santa's Little Helper")) ;
my_string_list.push_back("care") ; string_multimap.insert(std::pair<std::string, std::string>("sister","Meg")) ;
string_multimap.insert(std::pair<std::string, std::string>("dog","Brian")) ;
my_float_deque.push_back(98.7) ; double_vector.push_back(4.0) ;
my_float_deque.push_back(65.4) ; double_vector.push_back(5.0) ;
my_float_deque.push_back(32.1) ; double_vector.push_back(6.0) ;
my_string_deque.push_back("Welcome") ; string_vector.push_back("It") ;
my_string_deque.push_back("to") ; string_vector.push_back("has") ;
my_string_deque.push_back("PhoneMart") ; string_vector.push_back("the") ;
string_vector.push_back("Wi-Fies") ;
my_int_set.insert(8000) ; short_list.push_back(400) ;
my_int_set.insert(4000) ; short_list.push_back(401) ;
my_int_set.insert(2000) ; short_list.push_back(402) ;
my_int_set.insert(1000) ;
my_string_set.insert("efg") ; string_list.push_back("I") ;
my_string_set.insert("abc") ; string_list.push_back("don't") ;
my_string_set.insert("def") ; string_list.push_back("care") ;
my_long_multiset.insert(8000) ; float_deque.push_back(98.7) ;
my_long_multiset.insert(4000) ; float_deque.push_back(65.4) ;
my_long_multiset.insert(4000) ; float_deque.push_back(32.1) ;
my_long_multiset.insert(2000) ;
my_long_multiset.insert(1000) ;
my_string_multiset.insert("efg") ; string_deque.push_back("Welcome") ;
my_string_multiset.insert("abc") ; string_deque.push_back("to") ;
my_string_multiset.insert("def") ; string_deque.push_back("PhoneMart") ;
my_string_multiset.insert("efg") ;
my_string_multiset.insert("abc") ;
my_string_multiset.insert("def") ;
my_uint_stack.push(1) ; int_set.insert(8000) ;
my_uint_stack.push(2) ; int_set.insert(4000) ;
my_uint_stack.push(3) ; int_set.insert(2000) ;
my_uint_stack.push(4) ; int_set.insert(1000) ;
my_string_stack.push("I") ; string_set.insert("efg") ;
my_string_stack.push("want the one") ; string_set.insert("abc") ;
my_string_stack.push("with the bigger") ; string_set.insert("def") ;
my_string_stack.push("Gee Bees") ;
my_int_queue.push(1) ; long_multiset.insert(8000) ;
my_int_queue.push(2) ; long_multiset.insert(4000) ;
my_int_queue.push(3) ; long_multiset.insert(4000) ;
my_int_queue.push(4) ; long_multiset.insert(2000) ;
long_multiset.insert(1000) ;
my_string_queue.push("I") ; string_multiset.insert("efg") ;
my_string_queue.push("want") ; string_multiset.insert("abc") ;
my_string_queue.push("an") ; string_multiset.insert("def") ;
my_string_queue.push("iPhone 4") ; string_multiset.insert("efg") ;
string_multiset.insert("abc") ;
string_multiset.insert("def") ;
my_int_priority_queue.push(3) ; uint_stack.push(1) ;
my_int_priority_queue.push(2) ; uint_stack.push(2) ;
my_int_priority_queue.push(4) ; uint_stack.push(3) ;
my_int_priority_queue.push(1) ; uint_stack.push(4) ;
my_string_priority_queue.push("I") ; string_stack.push("I") ;
my_string_priority_queue.push("want") ; string_stack.push("want the one") ;
my_string_priority_queue.push("an") ; string_stack.push("with the bigger") ;
my_string_priority_queue.push("iPhone 4") ; string_stack.push("Gee Bees") ;
my_int_pair.first = 10 ; int_queue.push(1) ;
my_int_pair.second = 20 ; int_queue.push(2) ;
int_queue.push(3) ;
int_queue.push(4) ;
my_string_first_pair.first = "string first" ; string_queue.push("I") ;
my_string_first_pair.second = 25 ; string_queue.push("want") ;
string_queue.push("an") ;
string_queue.push("iPhone 4") ;
my_string_second_pair.first = 25 ; int_priority_queue.push(3) ;
my_string_second_pair.second = "string second" ; int_priority_queue.push(2) ;
int_priority_queue.push(4) ;
int_priority_queue.push(1) ;
my_string_pair.first = "pair first string" ; string_priority_queue.push("I") ;
my_string_pair.second = "pair second string" ; string_priority_queue.push("want") ;
string_priority_queue.push("an") ;
string_priority_queue.push("iPhone 4") ;
my_vector_vector_double[0][0] = 100 ; int_pair.first = 10 ;
my_vector_vector_double[0][1] = 101 ; int_pair.second = 20 ;
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 ; string_first_pair.first = "string first" ;
my_vector_vector_vector_double[0][0][1] = 1 ; string_first_pair.second = 25 ;
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 ; string_second_pair.first = 25 ;
my_vector_vector_vector_double[1][0][1] = 1001 ; string_second_pair.second = "string second" ;
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 ; string_pair.first = "pair first string" ;
my_vector_vector_vector_double[2][0][1] = 2001 ; string_pair.second = "pair second string" ;
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 ; int_pair_int_int.first = 200 ;
my_vector_vector_vector_double[3][0][1] = 3001 ; p.first = 10 ;
my_vector_vector_vector_double[3][0][2] = 3002 ; p.second = 20 ;
my_vector_vector_vector_double[3][1][0] = 3003 ; int_pair_int_int.second = p ;
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 ; p.first = 15 ;
my_vector_vector_vector_double[4][0][1] = 4001 ; p.second = 12 ;
my_vector_vector_vector_double[4][0][2] = 4002 ; pair_int_int_int.first = p ;
my_vector_vector_vector_double[4][1][0] = 4003 ; pair_int_int_int.second = 180 ;
my_vector_vector_vector_double[4][1][1] = 4004 ;
my_vector_vector_vector_double[4][1][2] = 4005 ; pair_pair_pair.first.first = 51 ;
my_vector_vector_vector_double[4][2][0] = 4006 ; pair_pair_pair.first.second = 52 ;
my_vector_vector_vector_double[4][2][1] = 4007 ; pair_pair_pair.second.first = 53 ;
my_vector_vector_vector_double[4][2][2] = 4008 ; pair_pair_pair.second.second = 54 ;
my_vector_vector_vector_double[4][3][0] = 4009 ;
my_vector_vector_vector_double[4][3][1] = 4010 ; vector_vector_double[0][0] = 100 ;
my_vector_vector_vector_double[4][3][2] = 4011 ; 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 ; return ;
} }
int STLCheckpoint::speak() { 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,"double_vector: %f %f %f\n", double_vector[0], double_vector[1], double_vector[2]) ;
message_publish(1,"my_vector_vector_double[1]: %f %f %f\n", //message_publish(1,"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]) ; // vector_vector_double[1][0], vector_vector_double[1][1], vector_vector_double[1][2]) ;
message_publish(1,"my_vector_vector_vector_double[4][2]: %f %f %f\n", //message_publish(1,"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]) ; // 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<int, int >(24,30)]) ;
//message_publish(1,"common_multiples = %d\n", common_multiples[std::pair<int, int >(3,5)][1]) ;
//message_publish(1,"common_multiples = %d\n", common_multiples[std::pair<int, int >(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 ; return 0 ;
} }

View File

@ -28,48 +28,58 @@ class STLCheckpoint {
std::string name ; std::string name ;
std::map< double , double > my_double_map ; std::map< double , double > double_map ;
std::map< std::string , int > my_string_key_map ; std::map< std::string , int > string_key_map ;
std::map< int , std::string > my_string_data_map ; std::map< int , std::string > string_data_map ;
std::map< std::string , std::string > my_string_map ; std::map< std::string , std::string > string_map ;
std::multimap< int , int > my_int_multimap ; std::map< int , std::vector< int > > map_int_vector_int ;
std::multimap< std::string , int > my_string_key_multimap ; std::map< std::pair< int , int > , int > gcd ;
std::multimap< int , std::string > my_string_data_multimap ; std::map< std::pair< int , int > , std::pair< int , int > > map_pair_pair ;
std::multimap< std::string , std::string > my_string_multimap ; std::map< std::pair< int , int > , std::vector< int > > common_multiples ;
std::vector< double > my_double_vector ; std::multimap< int , int > int_multimap ;
std::vector< std::string > my_string_vector ; 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::vector< double > double_vector ;
std::list< std::string > my_string_list ; std::vector< std::string > string_vector ;
std::deque< float > my_float_deque ; std::list< short > short_list ;
std::deque< std::string > my_string_deque ; std::list< std::string > string_list ;
std::set< int > my_int_set ; std::deque< float > float_deque ;
std::set< std::string > my_string_set ; std::deque< std::string > string_deque ;
std::multiset< long > my_long_multiset ; std::set< int > int_set ;
std::multiset< std::string > my_string_multiset ; std::set< std::string > string_set ;
std::stack< unsigned int > my_uint_stack ; std::multiset< long > long_multiset ;
std::stack< std::string > my_string_stack ; std::multiset< std::string > string_multiset ;
std::queue< int > my_int_queue ; std::stack< unsigned int > uint_stack ;
std::queue< std::string > my_string_queue ; std::stack< std::string > string_stack ;
std::priority_queue< int > my_int_priority_queue ; std::queue< int > int_queue ;
std::priority_queue< std::string > my_string_priority_queue ; std::queue< std::string > string_queue ;
std::pair< int , int > my_int_pair ; std::priority_queue< int > int_priority_queue ;
std::pair< std::string , int > my_string_first_pair ; std::priority_queue< std::string > string_priority_queue ;
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::pair< int , int > int_pair ;
std::vector< std::vector< std::vector< double > > > my_vector_vector_vector_double ; std::pair< std::string , int > string_first_pair ;
//std::vector< std::list< double > > my_vector_list_double ; 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 #endif

View File

@ -300,7 +300,7 @@ static std::map<std::string, bool> init_stl_classes() {
my_map.insert(std::pair<std::string, bool>("std::map", 1)) ; my_map.insert(std::pair<std::string, bool>("std::map", 1)) ;
my_map.insert(std::pair<std::string, bool>("std::multiset", 1)) ; my_map.insert(std::pair<std::string, bool>("std::multiset", 1)) ;
my_map.insert(std::pair<std::string, bool>("std::multimap", 1)) ; my_map.insert(std::pair<std::string, bool>("std::multimap", 1)) ;
my_map.insert(std::pair<std::string, bool>("std::pair", 1)) ; my_map.insert(std::pair<std::string, bool>("std::pair", 0)) ;
my_map.insert(std::pair<std::string, bool>("std::priority_queue", 0)) ; my_map.insert(std::pair<std::string, bool>("std::priority_queue", 0)) ;
my_map.insert(std::pair<std::string, bool>("std::queue", 0)) ; my_map.insert(std::pair<std::string, bool>("std::queue", 0)) ;
my_map.insert(std::pair<std::string, bool>("std::set", 1)) ; my_map.insert(std::pair<std::string, bool>("std::set", 1)) ;
@ -311,7 +311,7 @@ static std::map<std::string, bool> init_stl_classes() {
my_map.insert(std::pair<std::string, bool>("std::__1::map", 1)) ; my_map.insert(std::pair<std::string, bool>("std::__1::map", 1)) ;
my_map.insert(std::pair<std::string, bool>("std::__1::multiset", 1)) ; my_map.insert(std::pair<std::string, bool>("std::__1::multiset", 1)) ;
my_map.insert(std::pair<std::string, bool>("std::__1::multimap", 1)) ; my_map.insert(std::pair<std::string, bool>("std::__1::multimap", 1)) ;
my_map.insert(std::pair<std::string, bool>("std::__1::pair", 1)) ; my_map.insert(std::pair<std::string, bool>("std::__1::pair", 0)) ;
my_map.insert(std::pair<std::string, bool>("std::__1::priority_queue", 0)) ; my_map.insert(std::pair<std::string, bool>("std::__1::priority_queue", 0)) ;
my_map.insert(std::pair<std::string, bool>("std::__1::queue", 0)) ; my_map.insert(std::pair<std::string, bool>("std::__1::queue", 0)) ;
my_map.insert(std::pair<std::string, bool>("std::__1::set", 1)) ; my_map.insert(std::pair<std::string, bool>("std::__1::set", 1)) ;
@ -343,6 +343,9 @@ bool FieldVisitor::VisitRecordType(clang::RecordType *rt) {
while ((pos = tst_string.find("class ")) != std::string::npos ) { while ((pos = tst_string.find("class ")) != std::string::npos ) {
tst_string.erase(pos , 6) ; 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 // clang changes bool to _Bool. We need to change it back
if ((pos = tst_string.find("<_Bool")) != std::string::npos ) { if ((pos = tst_string.find("<_Bool")) != std::string::npos ) {
tst_string.replace(pos , 6, "<bool") ; tst_string.replace(pos , 6, "<bool") ;

View File

@ -4,6 +4,7 @@
#include "trick/checkpoint_map.hh" #include "trick/checkpoint_map.hh"
#if 0
int checkpoint_stl(std::map<std::string , std::string> & in_map , std::string object_name , std::string var_name ) { int checkpoint_stl(std::map<std::string , std::string> & in_map , std::string object_name , std::string var_name ) {
return checkpoint_map_stl_strings( in_map , object_name , var_name ) ; return checkpoint_map_stl_strings( in_map , object_name , var_name ) ;
} }
@ -19,4 +20,4 @@ int restore_stl(std::map<std::string , std::string> & in_map , std::string objec
int restore_stl(std::multimap<std::string , std::string> & in_map , std::string object_name , std::string var_name ) { int restore_stl(std::multimap<std::string , std::string> & in_map , std::string object_name , std::string var_name ) {
return restore_map_stl_strings( in_map , object_name , var_name ) ; return restore_map_stl_strings( in_map , object_name , var_name ) ;
} }
#endif

View File

@ -4,50 +4,4 @@
#include "trick/checkpoint_pair.hh" #include "trick/checkpoint_pair.hh"
int checkpoint_stl(std::pair<std::string, std::string> & 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<int,int>(&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<std::string, std::string> & 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<int,int>(&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 ;
}

View File

@ -1,6 +1,7 @@
#include "trick/checkpoint_sequence_stl.hh" #include "trick/checkpoint_sequence_stl.hh"
/*
int checkpoint_stl(std::vector<std::string> & in_stl , std::string object_name , std::string var_name ) { int checkpoint_stl(std::vector<std::string> & in_stl , std::string object_name , std::string var_name ) {
return checkpoint_sequence_stl_string( in_stl , object_name , var_name ) ; return checkpoint_sequence_stl_string( in_stl , object_name , var_name ) ;
} }
@ -40,4 +41,4 @@ int restore_stl(std::set<std::string> & in_stl , std::string object_name , std::
int restore_stl(std::multiset<std::string> & in_stl , std::string object_name , std::string var_name ) { int restore_stl(std::multiset<std::string> & in_stl , std::string object_name , std::string var_name ) {
return restore_sequence_stl_string( in_stl , object_name , var_name ) ; return restore_sequence_stl_string( in_stl , object_name , var_name ) ;
} }
*/