diff --git a/include/trick/checkpoint_fwd_declare.hh b/include/trick/checkpoint_fwd_declare.hh index 3dbce509..61ff274f 100644 --- a/include/trick/checkpoint_fwd_declare.hh +++ b/include/trick/checkpoint_fwd_declare.hh @@ -5,6 +5,7 @@ #ifndef CHECKPOINT_FWD_DECLARE #define CHECKPOINT_FWD_DECLARE +#include #include #include #include @@ -23,6 +24,15 @@ // Checkpoint routines +// array +template ::value>::type* = nullptr > +int checkpoint_stl(std::array & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int checkpoint_stl(std::array & in_stl , std::string object_name , std::string var_name ) ; + // vector template ::value>::type* = nullptr > @@ -164,6 +174,15 @@ int checkpoint_stl(std::stack & in_stl , std::string objec // Restore routines +// array +template ::value>::type* = nullptr > +int restore_stl(std::array & in_stl , std::string object_name , std::string var_name ) ; + +template ::value>::type* = nullptr > +int restore_stl(std::array & in_stl , std::string object_name , std::string var_name ) ; + // vector template ::value>::type* = nullptr > diff --git a/include/trick/checkpoint_is_stl_container.hh b/include/trick/checkpoint_is_stl_container.hh index 71b8d13a..ee993357 100644 --- a/include/trick/checkpoint_is_stl_container.hh +++ b/include/trick/checkpoint_is_stl_container.hh @@ -5,6 +5,7 @@ #ifndef CHECKPOINT_IS_STL_CONTAINER #define CHECKPOINT_IS_STL_CONTAINER +#include #include #include #include @@ -19,6 +20,11 @@ struct is_stl_container { static const bool value = false; }; +template +struct is_stl_container > { + static const bool value = true; +}; + template struct is_stl_container > { static const bool value = true; diff --git a/include/trick/checkpoint_sequence_stl.hh b/include/trick/checkpoint_sequence_stl.hh index f5bd106b..e135dd5e 100644 --- a/include/trick/checkpoint_sequence_stl.hh +++ b/include/trick/checkpoint_sequence_stl.hh @@ -7,6 +7,7 @@ #define CHECKPOINT_SEQUENCE_STL_HH #include +#include #include #include #include @@ -101,6 +102,23 @@ int checkpoint_sequence_s(STL & in_stl , std::string object_name , std::string v return 0 ; } +// ----------- +// std::array + +// This template is only enabled if the items in the array are an STL +template ::value>::type* > +int checkpoint_stl(std::array & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_s( in_stl , object_name , var_name ) ; +} + +// This template is only enabled if the items in the array are NOT an STL, except for std::string +template ::value>::type* > +int checkpoint_stl(std::array & in_stl , std::string object_name , std::string var_name ) { + return checkpoint_sequence_i( in_stl , object_name , var_name ) ; +} + // ----------- // std::vector @@ -196,6 +214,11 @@ int delete_sequence_alloc(STL & in_stl __attribute__ ((unused)), std::string obj return 0 ; } +template +int delete_stl(std::array & in_stl , std::string object_name , std::string var_name ) { + return delete_sequence_alloc( in_stl , object_name , var_name ) ; +} + template int delete_stl(std::vector & in_stl , std::string object_name , std::string var_name ) { return delete_sequence_alloc( in_stl , object_name , var_name ) ; @@ -289,6 +312,69 @@ int restore_sequence_s(STL & in_stl , std::string object_name , std::string var_ return 0 ; } +// ----------- +// std::array + +// This template is only enabled if the items in the array are an STL +template ::value>::type* > +int restore_stl(std::array & in_stl , std::string object_name , std::string var_name ) { + unsigned int ii ; + unsigned int cont_size ; + + REF2 * items_ref ; + std::string * items ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + //message_publish(1, "%s\n", __PRETTY_FUNCTION__) ; + + items_ref = ref_attributes((char *)(object_name + "_" + var_name).c_str()) ; + + if ( items_ref != NULL ) { + items = (std::string *)items_ref->address ; + cont_size = get_size((char *)items) ; + + for ( ii = 0 ; ii < cont_size ; ii++ ) { + typename std::array::value_type vt ; + std::ostringstream index_string ; + index_string << ii ; + restore_stl(vt, object_name + "_" + var_name , index_string.str()) ; + in_stl[ii] = vt ; + } + delete_stl( in_stl , object_name , var_name ) ; + } + + return 0 ; +} + +// This template is only enabled if the items in the array are NOT an STL, except for std::string +template ::value>::type* > +int restore_stl(std::array & in_stl , std::string object_name , std::string var_name ) { + unsigned int ii ; + unsigned int cont_size ; + + REF2 * items_ref ; + typename std::array::value_type * items ; + std::replace_if(object_name.begin(), object_name.end(), std::ptr_fun(&std::ispunct), '_'); + + //message_publish(1, "RESTORE_SEQUENCE_STL %s_%s\n", object_name.c_str() , var_name.c_str()) ; + + items_ref = ref_attributes((char *)(object_name + std::string("_") + var_name).c_str()) ; + + if ( items_ref != NULL ) { + items = (typename std::array::value_type *)items_ref->address ; + cont_size = get_size((char *)items) ; + + for ( ii = 0 ; ii < cont_size ; ii++ ) { + in_stl[ii] = items[ii] ; + } + delete_stl( in_stl , object_name , var_name ) ; + } + + return 0 ; +} + // ----------- // std::vector diff --git a/include/trick/checkpoint_stl.hh b/include/trick/checkpoint_stl.hh index b1fcd6d2..db63c2e0 100644 --- a/include/trick/checkpoint_stl.hh +++ b/include/trick/checkpoint_stl.hh @@ -6,7 +6,7 @@ #ifndef CHECKPOINT_STL_HH #define CHECKPOINT_STL_HH -// vector, list, deque, set , multiset +// array, vector, list, deque, set, multiset #include "trick/checkpoint_sequence_stl.hh" // map, multimap diff --git a/libexec/trick/convert_swig b/libexec/trick/convert_swig index 71aa7e2e..f0ca3bef 100755 --- a/libexec/trick/convert_swig +++ b/libexec/trick/convert_swig @@ -101,16 +101,18 @@ my $template_var_def = qr/(?:\:\:)?[_A-Za-z][:\w]*\s* # template name # This list is the list of all STL types to ignore. my %all_stl_names = qw(vector 1 list 1 deque 1 set 1 multiset 1 map 1 multimap 1 hash_set 1 hash_multiset 1 hash_map 1 hash_multimap 1 stack 1 queue 1 priority_queue 1 bitset 1 auto_ptr 1 + array 1 std::vector 1 std::list 1 std::deque 1 std::set 1 std::multiset 1 std::map 1 std::multimap 1 std::hash_set 1 std::hash_multiset 1 std::hash_map 1 std::hash_multimap 1 std::stack 1 std::queue 1 std::priority_queue 1 - std::bitset 1 std::auto_ptr 1 pair 1 std::pair 1 std::tr1::shared_ptr 1) ; + std::bitset 1 std::auto_ptr 1 pair 1 std::pair 1 std::tr1::shared_ptr 1 std::array 1) ; # This is a partial list of STL types to ignore. We do not ignore vector, map, list if we allow STLs my %stl_names = qw(deque 1 set 1 multiset 1 multimap 1 hash_set 1 hash_multiset 1 hash_map 1 hash_multimap 1 stack 1 queue 1 priority_queue 1 bitset 1 auto_ptr 1 + array 1 std::deque 1 std::set 1 std::multiset 1 std::multimap 1 std::hash_set 1 std::hash_multiset 1 std::hash_map 1 std::hash_multimap 1 std::stack 1 std::queue 1 std::priority_queue 1 - std::bitset 1 std::auto_ptr 1 pair 1 std::pair 1 std::tr1::shared_ptr 1) ; + std::bitset 1 std::auto_ptr 1 pair 1 std::pair 1 std::tr1::shared_ptr 1 std::array 1) ; Getopt::Long::Configure ("bundling"); GetOptions ( "stl|s" => sub { $stls = 1 } , diff --git a/share/trick/trick_ver.txt b/share/trick/trick_ver.txt index 27659c17..fb4998dd 100644 --- a/share/trick/trick_ver.txt +++ b/share/trick/trick_ver.txt @@ -1 +1 @@ -current_version = "17.1.dev" +current_version = "17.2.dev" diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp index 1223114b..d670ef79 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp @@ -301,6 +301,7 @@ bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl * static std::map init_stl_classes() { std::map my_map ; + my_map.insert(std::pair("std::array", 0)) ; my_map.insert(std::pair("std::deque", 1)) ; my_map.insert(std::pair("std::list", 1)) ; my_map.insert(std::pair("std::map", 1)) ; @@ -312,6 +313,7 @@ static std::map init_stl_classes() { my_map.insert(std::pair("std::set", 1)) ; my_map.insert(std::pair("std::stack", 0)) ; my_map.insert(std::pair("std::vector", 1)) ; + my_map.insert(std::pair("std::__1::array", 0)) ; my_map.insert(std::pair("std::__1::deque", 1)) ; my_map.insert(std::pair("std::__1::list", 1)) ; my_map.insert(std::pair("std::__1::map", 1)) ; @@ -323,6 +325,7 @@ static std::map init_stl_classes() { my_map.insert(std::pair("std::__1::set", 1)) ; my_map.insert(std::pair("std::__1::stack", 0)) ; my_map.insert(std::pair("std::__1::vector", 1)) ; + my_map.insert(std::pair("std::__cxx11::array", 0)) ; my_map.insert(std::pair("std::__cxx11::deque", 1)) ; my_map.insert(std::pair("std::__cxx11::list", 1)) ; my_map.insert(std::pair("std::__cxx11::map", 1)) ;