85 class ExprBase :
public std::enable_shared_from_this<ExprBase>
104 virtual std::shared_ptr<ExprBase>
copy()
const = 0;
116 virtual void replace_arg(
const ExprID& old_arg_id,
const std::shared_ptr<ExprBase>& new_expr) = 0;
163 template<
typename... X>
178 :
_x(std::make_tuple((x)...))
213 [old_arg_id,new_expr](
auto &&... x)
230 template<
typename X_>
231 static std::shared_ptr<X_>
__copy(
const std::shared_ptr<X_>& x)
233 return std::dynamic_pointer_cast<X_>(x->copy());
248 static void __replace_arg(std::shared_ptr<D>& x,
const ExprID& old_arg_id,
const std::shared_ptr<ExprBase>& new_expr)
250 if(x->unique_id() == old_arg_id)
252 assert(std::dynamic_pointer_cast<VarBase>(x) &&
"this subexpr should be some variable");
253 x = std::dynamic_pointer_cast<D>(new_expr);
256 x->replace_arg(old_arg_id, new_expr);
259 std::tuple<std::shared_ptr<X>...>
_x;
Abstract base class for representing an expression.
Definition codac2_ExprBase.h:86
const ExprID & unique_id() const
Returns the unique identifier of the expression.
virtual ~ExprBase()=default
Virtual destructor.
const ExprID _unique_id
unique identifier for this expression
Definition codac2_ExprBase.h:146
virtual void replace_arg(const ExprID &old_arg_id, const std::shared_ptr< ExprBase > &new_expr)=0
Replaces a variable by a new expression.
virtual std::shared_ptr< ExprBase > copy() const =0
Creates a copy of the current expression.
ExprBase()
Default constructor.
bool operator==(const ExprBase &e) const
Equality operator for comparing two expressions.
A class representing a unique identifier for expressions.
Definition codac2_ExprBase.h:34
ExprID()
Default constructor.
bool operator<(const ExprID &i) const
Comparison operator.
Index id() const
Retrieves the unique identifier of the expression.
static std::atomic< Index > _id_counter
thread-safe counter used to generate unique IDs
Definition codac2_ExprBase.h:74
const Index _id
unique identifier, cannot be modified after initialization
Definition codac2_ExprBase.h:73
bool operator==(const ExprID &i) const
Equality operator.
OperationExprBase(const OperationExprBase< X... > &e)
Copy constructor.
Definition codac2_ExprBase.h:191
void replace_arg(const ExprID &old_arg_id, const std::shared_ptr< ExprBase > &new_expr)
Replaces a variable by a new expression.
Definition codac2_ExprBase.h:210
OperationExprBase(std::shared_ptr< X >... x)
Constructs an OperationExprBase with operand expressions.
Definition codac2_ExprBase.h:177
static void __replace_arg(std::shared_ptr< D > &x, const ExprID &old_arg_id, const std::shared_ptr< ExprBase > &new_expr)
Helper function to replace a variable by a new expression.
Definition codac2_ExprBase.h:248
std::tuple< std::shared_ptr< X >... > _x
tuple storing the operand expressions
Definition codac2_ExprBase.h:259
static std::shared_ptr< X_ > __copy(const std::shared_ptr< X_ > &x)
Helper function to copy a single operand expression.
Definition codac2_ExprBase.h:231
Abstract base class for representing variables in analytic or set functions.
Definition codac2_VarBase.h:24
Definition codac2_OctaSym.h:21