pianod2
multisource multiuser scriptable networked music player
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
Filter Class Reference

Track data filter. More...

#include <filter.h>

Inheritance diagram for Filter:
Inheritance graph
[legend]
Collaboration diagram for Filter:
Collaboration graph
[legend]

Classes

class  DisallowedOperator
 Error for filter expressions trying to use a relational operation incorrectly. More...
 
class  InvalidValue
 Error for filter expression containing an invalid value. More...
 
class  Operation
 Nodes for the filter parse tree. More...
 
class  ParseError
 Error for generic filter syntax/parse errors. More...
 

Public Types

enum class  Field {
  Invalid = 0 , Id , Artist , Album ,
  Type , Genre , Playlist , Title ,
  Search , Name , Year , Duration ,
  Lastplay , Track , Rating , Played ,
  Heard , Rated , UserRating , False ,
  Compilation , Count
}
 Fields on which comparisons can be done by the filter. More...
 
enum class  Action {
  Noop , And , Or , LessThan ,
  LessEqual , Equal , NotEqual , GreaterThan ,
  GreaterEqual , Match
}
 Filter operations; each node in the parse tree has one action indicating how to proceed. More...
 
using DuplicationFlags = EnumeratedArray< Field, bool >
 
using FilterRating = float
 

Public Member Functions

 Filter (void)
 
 Filter (const Filter &)=default
 
 Filter (Filter &&from_filter)=default
 
 Filter (const std::string &expression)
 Create a new filter from an expression. More...
 
 Filter (const MusicThingie *thing, const MusicThingie::Type type=MusicThingie::Type(0), const DuplicationFlags &manner=DuplicationFlags(true))
 Create a new filter. More...
 
Filteroperator= (const std::string &expression)
 Assign a new expression to a filter. More...
 
Filteroperator= (const Filter &filter)=default
 
Filteroperator= (Filter &&from_filter)=default
 
virtual ~Filter ()
 Destroy a filter. More...
 
template<typename MusicThing >
bool matches (const MusicThing *thing) const
 Check if a filter matches a song, album, artist or playlist. More...
 
bool canPersist (void) const
 
std::string toString () const
 Get a filter's expression. More...
 
template<>
bool matches (const MusicThingie *thing) const
 Specialization for matching to determine the type of thing being tested by the filter expression at run-time. More...
 
template<>
bool matches (const MusicThingie *thing) const
 

Static Public Attributes

static const unsigned FieldCount = static_cast <unsigned> (Field::Count)
 
static const Filter All
 Selects all tracks. More...
 
static const Filter None
 Selects nothing. More...
 

Protected Types

using Op = std::unique_ptr< Operation >
 Container for Operation, to ensure instances are cleaned up. More...
 

Protected Member Functions

const char * skipWhitespace (const char **const command)
 
std::string gatherString (const char **const command, const char *error_reason)
 Gather a string, either quoted or not, processing quote characters. More...
 
Op parseParenthesis (const char **const command)
 Handle (parenthesis in an expression). More...
 
Op parseComparison (const char **const command)
 Handle comparison or other base operator in expression. More...
 
Op parseSearch (const char **const command)
 Handle bare search term in expression. More...
 
Op parseNegation (const char **const command)
 Handle negation operator, then choose parenthesis or a comparison. More...
 
Op parseOr (const char **const command)
 Handle binary OR, either as | or ||. More...
 
Op parseAnd (const char **const command)
 Handle binary AND, either as & or &&. More...
 

Protected Attributes

std::shared_ptr< Operationparsetree
 
bool persistable = true
 Not true if user referenced or other problematic expressions. More...
 

Friends

class Constraints
 
class Query::Details
 
class Query::List
 

Detailed Description

Track data filter.

Created from a logical statement describing match criteria, the track filter can then be used to test if a track/song, album, artist or playlist matches the criteria.

Member Typedef Documentation

◆ DuplicationFlags

◆ FilterRating

using Filter::FilterRating = float

◆ Op

using Filter::Op = std::unique_ptr<Operation>
protected

Container for Operation, to ensure instances are cleaned up.

Member Enumeration Documentation

◆ Action

enum Filter::Action
strong

Filter operations; each node in the parse tree has one action indicating how to proceed.

Enumerator
Noop 
And 
Or 
LessThan 
LessEqual 
Equal 
NotEqual 
GreaterThan 
GreaterEqual 
Match 

◆ Field

enum Filter::Field
strong

Fields on which comparisons can be done by the filter.

Enumerator
Invalid 
Id 
Artist 
Album 
Type 
Genre 
Playlist 
Title 

Song name.

Search 
Name 
Year 
Duration 
Lastplay 
Track 

Track number.

Rating 
Played 
Heard 
Rated 
UserRating 
False 
Compilation 
Count 

Constructor & Destructor Documentation

◆ Filter() [1/5]

Filter::Filter ( void  )
inline

◆ Filter() [2/5]

Filter::Filter ( const Filter )
default

◆ Filter() [3/5]

Filter::Filter ( Filter &&  from_filter)
default

◆ Filter() [4/5]

Filter::Filter ( const std::string &  expr)

Create a new filter from an expression.

Parameters
exprThe expression for the filter.
Exceptions
CommandErrorindicating nature of syntax or semantic errors. bad_alloc may also be thrown.
Here is the call graph for this function:

◆ Filter() [5/5]

Filter::Filter ( const MusicThingie thing,
const MusicThingie::Type  type = MusicThingie::Type (0),
const DuplicationFlags manner = DuplicationFlags (true) 
)

Create a new filter.

Parameters
thingCriteria for the new filter.
typeThe type of filter to create. Songs can create song, album, or artist filters; albums can create album or artist filters.
mannerFlags indicating what criteria to include in the filter.
Here is the call graph for this function:

◆ ~Filter()

Filter::~Filter ( )
virtual

Destroy a filter.

Member Function Documentation

◆ canPersist()

bool Filter::canPersist ( void  ) const
inline
Here is the caller graph for this function:

◆ gatherString()

std::string Filter::gatherString ( const char **const  command,
const char *  error_reason 
)
protected

Gather a string, either quoted or not, processing quote characters.

Parameters
commandThe point in the command being parsed at which to gather.
error_reasonA message to include in a ParseError should there be no string to gather.
Returns
String found, with quoted characters adapted.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ matches() [1/3]

template<typename MusicThing >
bool Filter::matches ( const MusicThing *  thing) const
inline

Check if a filter matches a song, album, artist or playlist.

Parameters
thingThe item to compare.
Returns
True if it matches, false otherwise.
Here is the caller graph for this function:

◆ matches() [2/3]

template<>
bool Filter::matches ( const MusicThingie thing) const

Specialization for matching to determine the type of thing being tested by the filter expression at run-time.

Parameters
thingA thing to compare.
Returns
true if the thing matches, false if not.
Here is the call graph for this function:

◆ matches() [3/3]

template<>
bool Filter::matches ( const MusicThingie thing) const

◆ operator=() [1/3]

Filter& Filter::operator= ( const Filter filter)
default

◆ operator=() [2/3]

Filter & Filter::operator= ( const std::string &  expr)

Assign a new expression to a filter.

Parameters
exprThe new expression.

◆ operator=() [3/3]

Filter& Filter::operator= ( Filter &&  from_filter)
default

◆ parseAnd()

Filter::Op Filter::parseAnd ( const char **const  command)
protected

Handle binary AND, either as & or &&.

Parameters
commandThe point in the command being parsed. On return, updated to reflect expression portions consumed.
Returns
parse tree representing expression parsed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseComparison()

Filter::Op Filter::parseComparison ( const char **const  command)
protected

Handle comparison or other base operator in expression.

Parameters
commandThe point in the command being parsed. On return, updated to reflect expression portions consumed.
Returns
Operation representing comparison or operator parsed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseNegation()

Filter::Op Filter::parseNegation ( const char **const  command)
protected

Handle negation operator, then choose parenthesis or a comparison.

Parameters
commandThe point in the command being parsed. On return, updated to reflect expression portions consumed.
Returns
parse tree representing expression parsed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseOr()

Filter::Op Filter::parseOr ( const char **const  command)
protected

Handle binary OR, either as | or ||.

Parameters
commandThe point in the command being parsed. On return, updated to reflect expression portions consumed.
Returns
parse tree representing expression parsed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseParenthesis()

Filter::Op Filter::parseParenthesis ( const char **const  command)
protected

Handle (parenthesis in an expression).

Parameters
commandThe point in the command being parsed. On return, updated to reflect expression portions consumed.
Returns
Operation tree representing expression parsed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseSearch()

Filter::Op Filter::parseSearch ( const char **const  command)
protected

Handle bare search term in expression.

This is identified by a quote (either ' or ") where we expect a comparison term in the expression.

Parameters
commandThe point in the command being parsed. On return, updated to reflect expression portions consumed.
Returns
Operation representing search term.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ skipWhitespace()

const char* Filter::skipWhitespace ( const char **const  command)
inlineprotected
Here is the caller graph for this function:

◆ toString()

std::string Filter::toString ( ) const

Get a filter's expression.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ Constraints

friend class Constraints
friend

◆ Query::Details

friend class Query::Details
friend

◆ Query::List

friend class Query::List
friend

Member Data Documentation

◆ All

const Filter Filter::All
static

Selects all tracks.

◆ FieldCount

const unsigned Filter::FieldCount = static_cast <unsigned> (Field::Count)
static

◆ None

const Filter Filter::None
static

Selects nothing.

◆ parsetree

std::shared_ptr<Operation> Filter::parsetree
protected

◆ persistable

bool Filter::persistable = true
protected

Not true if user referenced or other problematic expressions.


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