SST 15.0
Structural Simulation Toolkit
sizer.h
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_SIZER_H
13#define SST_CORE_SERIALIZATION_IMPL_SIZER_H
14
15#ifndef SST_INCLUDING_SERIALIZER_H
16#warning \
17 "The header file sst/core/serialization/impl/sizer.h should not be directly included as it is not part of the stable public API. The file is included in sst/core/serialization/serializer.h"
18#endif
19
20#include "sst/core/warnmacros.h"
21
22#include <cstddef>
23
24namespace SST::Core::Serialization::pvt {
25
26class ser_sizer
27{
28public:
29 ser_sizer() :
30 size_(0)
31 {}
32
33 template <class T>
34 void size(T& UNUSED(t))
35 {
36 size_ += sizeof(T);
37 }
38
39 void size_string(std::string& str);
40
41 void add(size_t s) { size_ += s; }
42
43 size_t size() const { return size_; }
44
45 void reset() { size_ = 0; }
46
47protected:
48 size_t size_;
49};
50
51} // namespace SST::Core::Serialization::pvt
52
53#endif // SST_CORE_SERIALIZATION_IMPL_SIZER_H