22
33#pragma once
44
5- #include " global.h"
5+ #include < stack>
6+ #include < vector>
7+
8+ #include " string_pool.h"
69#include " spimpl.h"
710
811namespace libscratchcpp
@@ -13,6 +16,7 @@ class IEngine;
1316class Promise ;
1417class IStackTimer ;
1518class IRandomGenerator ;
19+ struct StringPtr ;
1620class ExecutionContextPrivate ;
1721
1822/* ! \brief The ExecutionContext represents the execution context of a target (can be a clone) with variables, lists, etc. */
@@ -21,7 +25,7 @@ class LIBSCRATCHCPP_EXPORT ExecutionContext
2125 public:
2226 ExecutionContext (Thread *thread);
2327 ExecutionContext (const ExecutionContext &) = delete ;
24- virtual ~ExecutionContext () { }
28+ virtual ~ExecutionContext ();
2529
2630 Thread *thread () const ;
2731 IEngine *engine () const ;
@@ -35,8 +39,35 @@ class LIBSCRATCHCPP_EXPORT ExecutionContext
3539 IRandomGenerator *rng () const ;
3640 void setRng (IRandomGenerator *newRng);
3741
42+ inline StringPtr **pushStringStack (size_t stringCount)
43+ {
44+ m_stringStack.push ({});
45+
46+ auto &strings = m_stringStack.top ();
47+
48+ for (size_t i = 0 ; i < stringCount; i++) {
49+ StringPtr *str = string_pool_new ();
50+ strings.push_back (str);
51+ }
52+
53+ return strings.data ();
54+ }
55+
56+ inline void popStringStack ()
57+ {
58+ assert (!m_stringStack.empty ());
59+ const auto &strings = m_stringStack.top ();
60+
61+ for (StringPtr *str : strings)
62+ string_pool_free (str);
63+
64+ m_stringStack.pop ();
65+ }
66+
3867 private:
3968 spimpl::unique_impl_ptr<ExecutionContextPrivate> impl;
69+
70+ std::stack<std::vector<StringPtr *>> m_stringStack;
4071};
4172
4273} // namespace libscratchcpp
0 commit comments