NuriaProject Framework  0.1
The NuriaProject Framework
Public Types | Public Member Functions | List of all members
Nuria::LazyCondition Class Reference

LazyCondition offers lazily evaluated conditions for C++. More...

#include <lazyevaluation.hpp>

Public Types

enum  Type {
  Empty = 0, Single, Equal, NonEqual,
  Greater, GreaterEqual, Less, LessEqual,
  LogicAnd, LogicOr
}
 

Public Member Functions

 LazyCondition ()
 
 LazyCondition (const Field &field)
 
 LazyCondition (const QVariant &single)
 
 LazyCondition (const LazyCondition &other)
 
 LazyCondition (const QVariant &left, Type type, const QVariant &right)
 
 ~LazyCondition ()
 
void compile (AbstractConditionEvaluator *evaluator=nullptr)
 
bool evaluate (const QVariantList &arguments) const
 
bool isValid () const
 
const QVariant & left () const
 
 operator QVariant () const
 
LazyCondition operator&& (const LazyCondition &other)
 
template<typename... Args>
bool operator() (const Args &...args)
 
LazyConditionoperator= (const LazyCondition &other)
 
LazyCondition operator|| (const LazyCondition &other)
 
const QVariant & right () const
 
Type type () const
 

Detailed Description

LazyCondition offers lazily evaluated conditions for C++.

Usage
LazyCondition tries to be as simple to use as possible, thus it mimics the behaviour to C++. This means that you can write conditions like you're used to from C++. Please be aware of possible problems when mixing lazy and strict evaluation by accident. Expressions that are written without telling the compiler about LazyCondition will be evaluated before it is passed to LazyCondition! For this reason, you need to use Nuria::val to start a lazy condition.

This class also acts as functor, meaning that you can later call it like a method. This also means that you can pass a instance to every function which expects a functor, like STL algorithms.

You can reference to arguments by index (Starting from 0) using Nuria::arg.

Example
The following example removes the first two elements from 'list' using std::remove_if and a lazy condition:
QList< int > list { 1, 2, 3, 4, 5 };
std::remove_if (list.begin (), list.end (), arg(0) < 3);
qDebug() << list;

Member Enumeration Documentation

Available types of conditions.

Enumerator
Single 

Invalid instance, evaluates to false.

Equal 

Evaluates to (left).

NonEqual 

Evaluates to (left == right).

Greater 

Evaluates to (left != right).

GreaterEqual 

Evaluates to (left > right).

Less 

Evaluates to (left >= right).

LessEqual 

Evaluates to (left < right).

LogicAnd 

Evaluates to (left <= right).

LogicOr 

Evaluates to (left && right).

Evaluates to (left || right).

Constructor & Destructor Documentation

Nuria::LazyCondition::LazyCondition ( )

Constructs a instance of type Empty.

Nuria::LazyCondition::~LazyCondition ( )

Destructor.

Nuria::LazyCondition::LazyCondition ( const Field field)

Constructs a instance of type Single.

Nuria::LazyCondition::LazyCondition ( const QVariant &  single)

Constructs a instance of type Single.

Nuria::LazyCondition::LazyCondition ( const LazyCondition other)

Copy constructor.

Nuria::LazyCondition::LazyCondition ( const QVariant &  left,
Type  type,
const QVariant &  right 
)

Constructor.

Member Function Documentation

void Nuria::LazyCondition::compile ( AbstractConditionEvaluator evaluator = nullptr)

Compiles the condition using evaluator. If no evaluator is given, the default implementation will be used. Ownership of evaluator will be transferred to this instance.

See also
AbstractConditionEvaluator ConditionEvaluator
Note
You only need to use this method explicitly if you want to use a custom evaluator.
bool Nuria::LazyCondition::evaluate ( const QVariantList &  arguments) const

Evaluates the condition with arguments as input. If not already done the condition will be first compiled.

See also
compile
bool Nuria::LazyCondition::isValid ( ) const

Returns true if the type of this condition is not Empty.

const QVariant& Nuria::LazyCondition::left ( ) const

Returns the left-hand side value of the condition.

Nuria::LazyCondition::operator QVariant ( ) const

Allow implicit conversion to QVariant.

LazyCondition Nuria::LazyCondition::operator&& ( const LazyCondition other)

Returns a LazyCondition with a logical and conjunction between this instance (on the left-hand side) and other (on the right-hand side).

template<typename... Args>
bool Nuria::LazyCondition::operator() ( const Args &...  args)
inline

Evaluates the condition.

LazyCondition& Nuria::LazyCondition::operator= ( const LazyCondition other)

Assignment operator.

LazyCondition Nuria::LazyCondition::operator|| ( const LazyCondition other)

Returns a LazyCondition with a logical or conjunction between this instance (on the left-hand side) and other (on the right-hand side).

const QVariant& Nuria::LazyCondition::right ( ) const

Returns the right-hand side value of the condition.

Type Nuria::LazyCondition::type ( ) const

Returns the type of this instance.

See also
Type

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