ScaleOut C++ Native Client API  5.1
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
sosscli::Filter Class Reference

An object that holds a filtering expression which is used by NamedCache::query to determine which objects in the NamedCache to return. More...

#include <filter.h>

Public Member Functions

 Filter ()
 Default constructor. More...
 
virtual ~Filter ()
 Destructor.
 
Filter operator&& (Filter const &other)
 Creates a new Filter object where the underlying expression is the logical AND of this Filter's expression and the other Filter's expression. More...
 
Filter operator|| (Filter const &other)
 Creates a new Filter object where the underlying expression is the logical OR of this Filter's expression and the other Filter's expression. More...
 
Filter operator! ()
 Creates a new Filter object where the underlying expression is the logical complement of this expression. More...
 
bool is_empty () const
 If true, this Filter is an "empty" filter, created with the default constructor. More...
 
std::string str () const
 Returns a canonicalized string representation of the filter expression. More...
 
virtual void accept (QueryExpression::Visitor &v) const
 Implements the Visitor pattern by accepting a QueryExpression::Visitor object and causing the visitor to examine each of the nodes in the underlying expression tree. More...
 
boost::shared_ptr
< QueryExpression const > 
query_expression () const
 Returns a shared pointer to the underlying QueryExpression that this Filter object represents. More...
 

Friends

class ReferenceComparand
 
class ValueComparand
 

Detailed Description

An object that holds a filtering expression which is used by NamedCache::query to determine which objects in the NamedCache to return.

With the exception of the trivial "empty" Filter, Filters are only meaningful in conjunction with a TypedNamedCache subclass, such as NamedProtobufCache, that supports serialization of metadata whenever objects are written to the ScaleOut StateServer and query expression translation into a format understood by the StateServer.

Filter objects are intended to be created via operator overload factory methods by creating an initial Filter from ComparisonExpressions and StringContains expressions. Those filters may then be logically combined with other Filter clauses. For example:

auto filter1 = ReferenceComparand("amount_due") >= 50

will create a Filter, filter1, that compares the "amount_due" field of objects persisted in the StateServer with the value 50. Only objects with an amount_due greater than or equal to 50 will be returned. The filter

auto filter2 = ReferenceComparand("amount_due") >= 50
&& ReferenceComparand("days_outstanding") > 30

finds objects in StateServer where the amount_due field is greater than or equal to 50 and the days_outstanding field is greater than 30. This filter could have equivalently been written:

auto filter2 = filter1 && ReferenceComparand("days_outstanding") > 30

These examples assume that the amount_due field and the days_outstanding fields have been attributed with the SossIndex annotation using the mechanism appropriate for the serializer in use by your TypedNamedCache subclass.

Constructor & Destructor Documentation

sosscli::Filter::Filter ( )

Default constructor.

Creates an empty Filter object.

If passed an empty Filter object, the base NamedCache::query class will return SossKey key objects for all objects in the NamedCache. If the NamedCache has been subclassed by a query-providing layer such as NamedProtobufCache, then an empty filter will cause key objects to be returned for all objects of the given type (provided they have a compatible index metadata layout).

More interesting Filter objects can be created via the operator overloads defined on ReferenceOperand and ValueOperand.

Member Function Documentation

virtual void sosscli::Filter::accept ( QueryExpression::Visitor v) const
virtual

Implements the Visitor pattern by accepting a QueryExpression::Visitor object and causing the visitor to examine each of the nodes in the underlying expression tree.

Parameters
vThe visitor implementation to accept.
bool sosscli::Filter::is_empty ( ) const

If true, this Filter is an "empty" filter, created with the default constructor.

Returns
true if this Filter was created with the default constructor. Otherwise, false.
Filter sosscli::Filter::operator! ( )

Creates a new Filter object where the underlying expression is the logical complement of this expression.

Returns
a new Filter instance representing the logical complement of the original this Filter value.
Filter sosscli::Filter::operator&& ( Filter const &  other)

Creates a new Filter object where the underlying expression is the logical AND of this Filter's expression and the other Filter's expression.

Parameters
otherThe filter to combine with
Returns
a new Filter instance representing the logical AND of the original two Filter values.
Filter sosscli::Filter::operator|| ( Filter const &  other)

Creates a new Filter object where the underlying expression is the logical OR of this Filter's expression and the other Filter's expression.

Parameters
otherThe filter to combine with
Returns
a new Filter instance representing the logical OR of the original two Filter values.
boost::shared_ptr<QueryExpression const> sosscli::Filter::query_expression ( ) const

Returns a shared pointer to the underlying QueryExpression that this Filter object represents.

Returns
a boost::shared_ptr to the QueryExpression that this Filter represents.
std::string sosscli::Filter::str ( ) const

Returns a canonicalized string representation of the filter expression.

Returns
a canonicalized string representation of this filter.

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