libcopp  2.2.0
stack_context.cpp
Go to the documentation of this file.
1 // Copyright 2023 owent
2 
3 #include <libcopp/utils/config/libcopp_build_features.h>
4 
6 
7 // clang-format off
8 #include <libcopp/utils/config/stl_include_prefix.h> // NOLINT(build/include_order)
9 // clang-format on
10 #include <cstring>
11 // clang-format off
12 #include <libcopp/utils/config/stl_include_suffix.h> // NOLINT(build/include_order)
13 // clang-format on
14 
15 LIBCOPP_COPP_NAMESPACE_BEGIN
16 
17 LIBCOPP_COPP_API stack_context::stack_context() LIBCOPP_MACRO_NOEXCEPT : size(0),
18  sp(nullptr)
19 #ifdef LIBCOPP_MACRO_USE_SEGMENTED_STACKS
20  ,
21  segments_ctx()
22 #endif
23 #ifdef LIBCOPP_MACRO_USE_VALGRIND
24  ,
25  valgrind_stack_id(0)
26 #endif
27 {
28 }
29 
30 LIBCOPP_COPP_API stack_context::~stack_context() LIBCOPP_MACRO_NOEXCEPT {}
31 
32 LIBCOPP_COPP_API stack_context::stack_context(const stack_context &other) LIBCOPP_MACRO_NOEXCEPT { copy_from(other); }
33 
34 LIBCOPP_COPP_API stack_context &stack_context::operator=(const stack_context &other) LIBCOPP_MACRO_NOEXCEPT {
35  copy_from(other);
36  return *this;
37 }
38 
39 LIBCOPP_COPP_API stack_context::stack_context(stack_context &&other) LIBCOPP_MACRO_NOEXCEPT {
40  copy_from(other);
41  other.reset();
42 }
43 
44 LIBCOPP_COPP_API stack_context &stack_context::operator=(stack_context &&other) LIBCOPP_MACRO_NOEXCEPT {
45  copy_from(other);
46  other.reset();
47  return *this;
48 }
49 
50 LIBCOPP_COPP_API void stack_context::reset() LIBCOPP_MACRO_NOEXCEPT {
51  size = 0;
52  sp = nullptr;
53 #ifdef LIBCOPP_MACRO_USE_SEGMENTED_STACKS
54  memset(segments_ctx, 0, sizeof(segments_ctx));
55 #endif
56 #ifdef LIBCOPP_MACRO_USE_VALGRIND
57  valgrind_stack_id = 0;
58 #endif
59 }
60 
61 LIBCOPP_COPP_API void stack_context::copy_from(const stack_context &other) LIBCOPP_MACRO_NOEXCEPT {
62  size = other.size;
63  sp = other.sp;
64 #ifdef LIBCOPP_MACRO_USE_SEGMENTED_STACKS
65  memcpy(segments_ctx, other.segments_ctx, sizeof(segments_ctx));
66 #endif
67 #ifdef LIBCOPP_MACRO_USE_VALGRIND
68  valgrind_stack_id = other.valgrind_stack_id;
69 #endif
70 }
71 LIBCOPP_COPP_NAMESPACE_END
constexpr auto size(TCONTAINER &&container) -> decltype(container.size())
Definition: span.h:44
void reset() LIBCOPP_MACRO_NOEXCEPT
stack_context & operator=(const stack_context &other) LIBCOPP_MACRO_NOEXCEPT
~stack_context() LIBCOPP_MACRO_NOEXCEPT
void * sp
stack size
Definition: stack_context.h:20
stack_context() LIBCOPP_MACRO_NOEXCEPT
stack end pointer
void copy_from(const stack_context &other) LIBCOPP_MACRO_NOEXCEPT