CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::Constraint::ConstraintVariable Class Referencefinal

A variable as used in an expression. More...

#include <CeresEngine/Foundation/Constraint/ConstraintVariable.hpp>

Classes

class  Data
 

Public Member Functions

 ConstraintVariable (String name, Any &&context=Any())
 
 ConstraintVariable (const ConstraintVariable &)=default
 
ConstraintVariableoperator= (const ConstraintVariable &)=default
 
 ConstraintVariable (ConstraintVariable &&) noexcept=default
 
ConstraintVariableoperator= (ConstraintVariable &&) noexcept=default
 
 ~ConstraintVariable ()=default
 
const StringgetName () const
 
AnygetContext () const
 
void setContext (Any &&context)
 
double getValue () const
 
void setValue (const double value)
 
bool equals (const ConstraintVariable &other)
 
String toString () const
 Gets a string representation of the variable.
 

Private Attributes

RC< DatamData
 A pointer to the shared object of the variable.
 

Friends

std::ostream & operator<< (std::ostream &stream, const ConstraintVariable &variable)
 Writes the variable to the given stream.
 
bool operator< (const ConstraintVariable &lhs, const ConstraintVariable &rhs)
 

Detailed Description

A variable as used in an expression.

Variables don't use the normal C++ copy semantics: objects are actually counted references. The following example illustrates this:

Variable x("x"), y("y");
y = x;
// y is now 1
x.setValue(2);
// both x and y are now 2
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25

Also note that a variable is nullable. A variable that has been constructed without a type cannot be used in expressions.

Another caveat: x == y is not a boolean, but an LinearExpression that can be evaluated and used in constraints. There are two ways to compare two variables, depending on whether you want to test for equality or equivalence:

Variable x("x"), y(x), z("z");
x.is(y); // true: y was constructed from x
x.is(z); // false: x and z both have the value 2, but they are different variables
x.getValue() == y.getValue(); // true
x.getValue() == z.getValue(); // also true

Constructor & Destructor Documentation

◆ ConstraintVariable() [1/3]

CeresEngine::Constraint::ConstraintVariable::ConstraintVariable ( String  name,
Any &&  context = Any() 
)
inlineexplicit

◆ ConstraintVariable() [2/3]

CeresEngine::Constraint::ConstraintVariable::ConstraintVariable ( const ConstraintVariable )
default

◆ ConstraintVariable() [3/3]

CeresEngine::Constraint::ConstraintVariable::ConstraintVariable ( ConstraintVariable &&  )
defaultnoexcept

◆ ~ConstraintVariable()

CeresEngine::Constraint::ConstraintVariable::~ConstraintVariable ( )
default

Member Function Documentation

◆ equals()

bool CeresEngine::Constraint::ConstraintVariable::equals ( const ConstraintVariable other)
inline

◆ getContext()

Any & CeresEngine::Constraint::ConstraintVariable::getContext ( ) const
inline

◆ getName()

const String & CeresEngine::Constraint::ConstraintVariable::getName ( ) const
inline

◆ getValue()

double CeresEngine::Constraint::ConstraintVariable::getValue ( ) const
inline

◆ operator=() [1/2]

ConstraintVariable & CeresEngine::Constraint::ConstraintVariable::operator= ( const ConstraintVariable )
default

◆ operator=() [2/2]

ConstraintVariable & CeresEngine::Constraint::ConstraintVariable::operator= ( ConstraintVariable &&  )
defaultnoexcept

◆ setContext()

void CeresEngine::Constraint::ConstraintVariable::setContext ( Any &&  context)
inline

◆ setValue()

void CeresEngine::Constraint::ConstraintVariable::setValue ( const double  value)
inline

◆ toString()

String CeresEngine::Constraint::ConstraintVariable::toString ( ) const

Gets a string representation of the variable.

Friends And Related Symbol Documentation

◆ operator<

◆ operator<<

std::ostream & operator<< ( std::ostream &  stream,
const ConstraintVariable variable 
)
friend

Writes the variable to the given stream.

Member Data Documentation

◆ mData

RC<Data> CeresEngine::Constraint::ConstraintVariable::mData
private

A pointer to the shared object of the variable.


The documentation for this class was generated from the following file: