84 class ExprBase :
public std::enable_shared_from_this<ExprBase>
103 virtual std::shared_ptr<ExprBase>
copy()
const = 0;
115 virtual void replace_arg(
const ExprID& old_arg_id,
const std::shared_ptr<ExprBase>& new_expr) = 0;
162 template<
typename... X>
177 :
_x(std::make_tuple((x)...))
212 [old_arg_id,new_expr](
auto &&... x)
229 template<
typename X_>
230 static std::shared_ptr<X_>
__copy(
const std::shared_ptr<X_>& x)
232 return std::dynamic_pointer_cast<X_>(x->copy());
247 static void __replace_arg(std::shared_ptr<D>& x,
const ExprID& old_arg_id,
const std::shared_ptr<ExprBase>& new_expr)
249 if(x->unique_id() == old_arg_id)
251 assert(std::dynamic_pointer_cast<VarBase>(x) &&
"this subexpr should be some variable");
252 x = std::dynamic_pointer_cast<D>(new_expr);
255 x->replace_arg(old_arg_id, new_expr);
258 std::tuple<std::shared_ptr<X>...>
_x;
Abstract base class for representing an expression.
Definition codac2_ExprBase.h:85
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:145
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:33
ExprID()
Default constructor.
bool operator<(const ExprID &i) const
Comparison operator.
Index id() const
Retrieves the unique identifier of the expression.
static Index _id_counter
static counter used to generate unique IDs for each ExprID object
Definition codac2_ExprBase.h:73
const Index _id
unique identifier, cannot be modified after initialization
Definition codac2_ExprBase.h:72
bool operator==(const ExprID &i) const
Equality operator.
OperationExprBase(const OperationExprBase< X... > &e)
Copy constructor.
Definition codac2_ExprBase.h:190
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:209
OperationExprBase(std::shared_ptr< X >... x)
Constructs an OperationExprBase with operand expressions.
Definition codac2_ExprBase.h:176
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:247
std::tuple< std::shared_ptr< X >... > _x
tuple storing the operand expressions
Definition codac2_ExprBase.h:258
static std::shared_ptr< X_ > __copy(const std::shared_ptr< X_ > &x)
Helper function to copy a single operand expression.
Definition codac2_ExprBase.h:230
Abstract base class for representing variables in analytic or set functions.
Definition codac2_VarBase.h:24