11#pragma once
22
3- #include " cura-formulae-engine/eval.h"
4-
5- #include < zeus/expected.hpp>
6-
73#include < functional>
84#include < string>
95#include < unordered_set>
6+ #include < zeus/expected.hpp>
7+
8+ #include " cura-formulae-engine/eval.h"
109
1110namespace CuraFormulaeEngine ::eval
1211{
@@ -36,10 +35,13 @@ class EnvironmentMap : public Environment
3635{
3736private:
3837 std::unordered_map<std::string, eval::Value> environment_ = {};
39- public:
4038
39+ public:
4140 EnvironmentMap () = default ;
42- explicit EnvironmentMap (const std::unordered_map<std::string, eval::Value>& map) : environment_(map) {}
41+ explicit EnvironmentMap (const std::unordered_map<std::string, eval::Value>& map)
42+ : environment_(map)
43+ {
44+ }
4345 ~EnvironmentMap () override = default ;
4446
4547 [[nodiscard]] std::optional<eval::Value> get (const std::string& key) const noexcept override ;
@@ -52,31 +54,58 @@ class EnvironmentMap : public Environment
5254
5355 void set (const std::string& key, const eval::Value& value) noexcept ;
5456
55- [[nodiscard]] EnvironmentMap clone () const noexcept ;
57+ void add ( const std::unordered_map<std::string, eval::Value> values) ;
5658
59+ [[nodiscard]] EnvironmentMap clone () const noexcept ;
5760};
5861
59- class LocalEnvironment : public Environment
62+ class ChainableEnvironment : public Environment
6063{
64+ private:
65+ const Environment* shadow_environment_{ nullptr };
66+
6167public:
68+ explicit ChainableEnvironment (const Environment* shadow_environment = nullptr )
69+ : shadow_environment_(shadow_environment)
70+ {
71+ }
72+ ~ChainableEnvironment () override = default ;
6273
63- LocalEnvironment () = default ;
64- explicit LocalEnvironment (const Environment* shadow_environment_)
65- : shadow_environment_(shadow_environment_)
74+ [[nodiscard]] std::optional<eval::Value> get (const std::string& key) const noexcept override final ;
75+
76+ [[nodiscard]] bool has (const std::string& key) const noexcept override final ;
77+
78+ [[nodiscard]] std::unordered_map<std::string, eval::Value> getAll () const noexcept override final ;
79+
80+ protected:
81+ [[nodiscard]] virtual std::optional<eval::Value> getImpl (const std::string& key) const noexcept = 0;
82+
83+ [[nodiscard]] virtual bool hasImpl (const std::string& key) const noexcept = 0;
84+
85+ [[nodiscard]] virtual std::unordered_map<std::string, eval::Value> getAllImpl () const noexcept = 0;
86+ };
87+
88+ class LocalEnvironment : public ChainableEnvironment
89+ {
90+ private:
91+ EnvironmentMap local_environment_;
92+
93+ public:
94+ explicit LocalEnvironment (const Environment* shadow_environment = nullptr )
95+ : ChainableEnvironment(shadow_environment)
6696 {
6797 }
6898 ~LocalEnvironment () override = default ;
6999
70- EnvironmentMap local_environment_ = {};
71- const Environment* shadow_environment_;
72-
73- [[nodiscard]] std::optional<eval::Value> get (const std::string& key) const noexcept override ;
100+ [[nodiscard]] std::optional<eval::Value> getImpl (const std::string& key) const noexcept override ;
74101
75- [[nodiscard]] bool has (const std::string& key) const noexcept override ;
102+ [[nodiscard]] bool hasImpl (const std::string& key) const noexcept override ;
76103
77- [[nodiscard]] std::unordered_map<std::string, eval::Value> getAll () const noexcept override ;
104+ [[nodiscard]] std::unordered_map<std::string, eval::Value> getAllImpl () const noexcept override ;
78105
79106 void set (const std::string& key, const eval::Value& value);
107+
108+ void add (const std::unordered_map<std::string, eval::Value> values);
80109};
81110
82111} // namespace CuraFormulaeEngine::env
@@ -123,7 +152,8 @@ struct Expr
123152 [[nodiscard]] virtual bool deepEq (const Expr& other) const = 0;
124153
125154 /* *
126- * @brief Traverses the expression tree and applies the visitor function to each node.
155+ * @brief Traverses the expression tree and applies the visitor function to
156+ * each node.
127157 *
128158 * @param visitor The visitor function to apply to each node.
129159 */
0 commit comments