Skip to content

Commit 8cce3d5

Browse files
authored
Generalize serialize to support more containers in a generalized way, and store mapping name in a stack stored in the serializer (#1271)
1 parent 37d1c19 commit 8cce3d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+889
-1395
lines changed

src/sst/core/Makefile.am

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,18 @@ nobase_dist_sst_HEADERS = \
9898
serialization/serialize_impl_fwd.h \
9999
serialization/objectMap.h \
100100
serialization/objectMapDeferred.h \
101+
serialization/impl/serialize_adapter.h \
101102
serialization/impl/serialize_array.h \
102103
serialization/impl/serialize_atomic.h \
103104
serialization/impl/ser_buffer_accessor.h \
104-
serialization/impl/serialize_deque.h \
105-
serialization/impl/serialize_list.h \
106-
serialization/impl/serialize_map.h \
107-
serialization/impl/serialize_multiset.h \
105+
serialization/impl/serialize_insertable.h \
106+
serialization/impl/serialize_tuple.h \
107+
serialization/impl/serialize_utility.h \
108108
serialization/impl/mapper.h \
109109
serialization/impl/packer.h \
110-
serialization/impl/serialize_priority_queue.h \
111-
serialization/impl/serialize_set.h \
112110
serialization/impl/sizer.h \
113111
serialization/impl/serialize_string.h \
114112
serialization/impl/unpacker.h \
115-
serialization/impl/serialize_vector.h \
116113
serialization/serializer.h \
117114
serialization/serializer_fwd.h \
118115
serialization/statics.h \

src/sst/core/baseComponent.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ SerializeBaseComponentHelper::unpack_basecomponent(serializable_base*& s, serial
10621062
}
10631063

10641064
void
1065-
SerializeBaseComponentHelper::map_basecomponent(serializable_base*& s, serializer& ser, const char* name)
1065+
SerializeBaseComponentHelper::map_basecomponent(serializable_base*& s, serializer& ser, const std::string& name)
10661066
{
10671067
if ( nullptr == s ) return;
10681068

src/sst/core/baseComponent.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ class SerializeBaseComponentHelper
11451145

11461146
static void unpack_basecomponent(serializable_base*& s, serializer& ser);
11471147

1148-
static void map_basecomponent(serializable_base*& s, serializer& ser, const char* name);
1148+
static void map_basecomponent(serializable_base*& s, serializer& ser, const std::string& name);
11491149
};
11501150

11511151
} // namespace pvt
@@ -1170,17 +1170,11 @@ class serialize_impl<T*, std::enable_if_t<std::is_base_of_v<SST::BaseComponent,
11701170
pvt::SerializeBaseComponentHelper::unpack_basecomponent(sp, ser);
11711171
break;
11721172
case serializer::MAP:
1173-
// Add your code here
1173+
pvt::SerializeBaseComponentHelper::map_basecomponent(sp, ser, ser.getMapName());
11741174
break;
11751175
}
11761176
s = static_cast<T*>(sp);
11771177
}
1178-
1179-
void operator()(T*& s, serializer& ser, const char* name)
1180-
{
1181-
serializable_base* sp = static_cast<serializable_base*>(s);
1182-
pvt::SerializeBaseComponentHelper::map_basecomponent(sp, ser, name);
1183-
}
11841178
};
11851179

11861180
} // namespace Core::Serialization

src/sst/core/from_string.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,36 @@ from_string(const std::string& input)
9292
return T(input);
9393
}
9494

95+
template <class T>
96+
std::enable_if_t<std::is_enum_v<T>, T>
97+
from_string(const std::string& input)
98+
{
99+
return static_cast<T>(from_string<std::underlying_type_t<T>>(input));
100+
}
101+
102+
template <class T>
103+
std::enable_if_t<!std::is_enum_v<T>, std::string>
104+
to_string(const T& input)
105+
{
106+
if constexpr ( std::is_fundamental_v<T> )
107+
return std::to_string(input);
108+
else
109+
return typeid(T).name(); // For now, return a string if the type isn't fundamental or handled elsewhere
110+
}
111+
112+
template <class T>
113+
std::enable_if_t<std::is_enum_v<T>, std::string>
114+
to_string(const T& input)
115+
{
116+
return std::to_string(static_cast<std::underlying_type_t<T>>(input));
117+
}
118+
119+
inline std::string
120+
to_string(std::string s)
121+
{
122+
return s;
123+
}
124+
95125
} // end namespace SST::Core
96126

97127
#endif // SST_CORE_FROM_STRING_H

src/sst/core/impl/interactive/simpleDebug.cc

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ SimpleDebugger::cmd_pwd(std::vector<std::string>& UNUSED(tokens))
7171
void
7272
SimpleDebugger::cmd_ls(std::vector<std::string>& UNUSED(tokens))
7373
{
74-
std::vector<std::pair<std::string, SST::Core::Serialization::ObjectMap*>> vars = obj_->getVariables();
74+
auto& vars = obj_->getVariables();
7575
for ( auto& x : vars ) {
7676
if ( x.second->isFundamental() ) {
7777
printf("%s = %s (%s)\n", x.first.c_str(), x.second->get().c_str(), x.second->getType().c_str());
@@ -293,16 +293,8 @@ SimpleDebugger::cmd_watch(std::vector<std::string>& tokens)
293293
return;
294294
}
295295

296-
Core::Serialization::ObjectMap* map = nullptr;
297-
298296
// Look for variable
299-
std::vector<std::pair<std::string, SST::Core::Serialization::ObjectMap*>> vars = obj_->getVariables();
300-
for ( auto& x : vars ) {
301-
if ( x.first == var ) {
302-
// Found the variable
303-
map = x.second;
304-
}
305-
}
297+
Core::Serialization::ObjectMap* map = obj_->findVariable(var);
306298

307299
// Check for errors
308300

src/sst/core/link.cc

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
namespace SST {
3434

3535
void
36-
SST::Core::Serialization::serialize_impl<Link*>::operator()(Link*& s, SST::Core::Serialization::serializer& ser)
36+
SST::Core::Serialization::serialize_impl<Link*>::operator()(Link*& s, serializer& ser)
3737
{
3838
// Need to treat Links and SelfLinks differently
3939
bool self_link;
@@ -559,18 +559,11 @@ SST::Core::Serialization::serialize_impl<Link*>::operator()(Link*& s, SST::Core:
559559
}
560560
break;
561561
case serializer::MAP:
562-
// This version of the function is not called in mapping mode.
562+
// TODO: Implement Link mapping mode
563563
break;
564564
}
565565
}
566566

567-
void
568-
SST::Core::Serialization::serialize_impl<Link*>::operator()(
569-
Link*& UNUSED(s), SST::Core::Serialization::serializer& UNUSED(ser), const char* UNUSED(name))
570-
{
571-
// TODO: Implement Link mapping mode
572-
}
573-
574567
/**
575568
* Null Event. Used when nullptr is passed into any of the send
576569
* functions. On delivery, it will delete itself and return nullptr.

src/sst/core/link.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class SST::Core::Serialization::serialize_impl<Link*>
4343
friend class serialize;
4444
// Function implemented in link.cc
4545
void operator()(Link*& s, SST::Core::Serialization::serializer& ser);
46-
void operator()(Link*& s, SST::Core::Serialization::serializer& ser, const char* name);
4746
};
4847

4948

src/sst/core/serialization/impl/CMakeLists.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@ set(SSTSerializationImplHeaders
1818
mapper.h
1919
packer.h
2020
ser_buffer_accessor.h
21+
serialize_adapter.h
2122
serialize_array.h
2223
serialize_atomic.h
23-
serialize_deque.h
24-
serialize_list.h
25-
serialize_map.h
26-
serialize_multiset.h
27-
serialize_priority_queue.h
28-
serialize_set.h
24+
serialize_insertable.h
2925
serialize_string.h
30-
serialize_vector.h
26+
serialize_tuple.h
27+
serialize_utility.h
3128
sizer.h
3229
unpacker.h)
3330

src/sst/core/serialization/impl/packer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "sst/core/serialization/impl/ser_buffer_accessor.h"
2121

22+
#include <cstddef>
2223
#include <string>
2324

2425
namespace SST::Core::Serialization::pvt {
@@ -40,7 +41,7 @@ class ser_packer : public ser_buffer_accessor
4041
* @param buf Must be non-null
4142
* @param size Must be non-zero
4243
*/
43-
void pack_buffer(void* buf, int size);
44+
void pack_buffer(void* buf, size_t size);
4445

4546
void pack_string(std::string& str);
4647
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2009-2025 NTESS. Under the terms
2+
// of Contract DE-NA0003525 with NTESS, the U.S.
3+
// Government retains certain rights in this software.
4+
//
5+
// Copyright (c) 2009-2025, NTESS
6+
// All rights reserved.
7+
//
8+
// This file is part of the SST software package. For license
9+
// information, see the LICENSE file in the top level directory of the
10+
// distribution.
11+
12+
#ifndef SST_CORE_SERIALIZATION_IMPL_SERIALIZE_ADAPTER_H
13+
#define SST_CORE_SERIALIZATION_IMPL_SERIALIZE_ADAPTER_H
14+
15+
#ifndef SST_INCLUDING_SERIALIZE_H
16+
#warning \
17+
"The header file sst/core/serialization/impl/serialize_adapter.h should not be directly included as it is not part of the stable public API. The file is included in sst/core/serialization/serialize.h"
18+
#endif
19+
20+
#include "sst/core/serialization/impl/serialize_utility.h"
21+
#include "sst/core/serialization/serializer.h"
22+
23+
#include <queue>
24+
#include <stack>
25+
26+
namespace SST::Core::Serialization {
27+
28+
// Serialize adapter classes std::stack, std::queue, std::priority_queue
29+
template <template <typename...> class T, typename... Ts>
30+
class serialize_impl<
31+
T<Ts...>, std::enable_if_t<
32+
is_same_template_v<T, std::stack> || is_same_template_v<T, std::queue> ||
33+
is_same_template_v<T, std::priority_queue>>>
34+
{
35+
struct S : T<Ts...>
36+
{
37+
using T<Ts...>::c; // access protected container
38+
};
39+
40+
public:
41+
void operator()(T<Ts...>& v, serializer& ser)
42+
{
43+
ser& static_cast<S&>(v).c; // serialize the underlying container
44+
}
45+
};
46+
47+
} // namespace SST::Core::Serialization
48+
49+
#endif // SST_CORE_SERIALIZATION_IMPL_SERIALIZE_ADAPTER_H

0 commit comments

Comments
 (0)