pianod2
multisource multiuser scriptable networked music player
Classes | Enumerations | Functions | Variables
Predicate Namespace Reference

Functions and types for parsing and interpreting predicates. More...

Classes

struct  Predicate
 

Enumerations

enum  MANNER {
  MANNER::NAME, MANNER::ID, MANNER::WHERE, MANNER::LIKE,
  MANNER::SOURCE
}
 Manners in which predicates may be specified. More...
 

Functions

void construct_predicate_parsers (PianodParser *parser)
 
static Predicate getFullPredicate (const PianodConnection &conn, const Parsnip::Data &predicate, Filter::Field field)
 Parse a command's predicate and return a matching filter. More...
 
std::unique_ptr< FiltergetPredicate (const PianodConnection &conn, const Parsnip::Data &predicate, Filter::Field field)
 Return just the filter portion of a predicate, for external use. More...
 
static ThingieList getPredicateIdItems (const Parsnip::Data &predicate)
 Specialization for getting things by ID. More...
 
static ThingieList getPartialSpecifiedThings (Predicate &pred, SearchRange search_what)
 Gather a list of assorted things specified by a predicate, which must be present. More...
 
ThingieList getSpecifiedThings (const PianodConnection &conn, const Parsnip::Data &predicate, SearchRange search_what)
 Gather a list of assorted things specified by a predicate. More...
 
MusicThingiegetSpecifiedThing (const PianodConnection &conn, const Parsnip::Data &predicate)
 Interpret a request for an unspecified type of thing and return it. More...
 
static PlaylistList getSpecifiedPlaylistsById (const Parsnip::Data &predicate)
 Get playlist items by id. More...
 
PlaylistList getSpecifiedPlaylists (const PianodConnection &conn, const Parsnip::Data &predicate)
 Interpret a list of playlists specified by a predicate. More...
 
PianodPlaylistgetSpecifiedPlaylist (const PianodConnection &conn, const Parsnip::Data &predicate)
 Gather a request for a single playlist and return it. More...
 
SongList getSpecifiedSongs (const PianodConnection &conn, const Parsnip::Data &predicate, SearchRange search_what)
 Interpret a list of songs specified by a predicate. More...
 
PianodSonggetSpecifiedSong (const PianodConnection &conn, const Parsnip::Data &predicate)
 Gather a request for a single song and return it. More...
 
bool havePredicate (const Parsnip::Data &options)
 Check for presence of a predicate. More...
 

Variables

const LookupTable< MANNERPredicateManners ({ { "name", MANNER::NAME }, { "id", MANNER::ID }, { "where", MANNER::WHERE }, { "like", MANNER::LIKE } })
 Lookup table for manner names to enumeration. More...
 
const LookupTable< Filter::FieldSearchFields ({ { "any", Filter::Field::Search }, { "artist", Filter::Field::Artist }, { "album", Filter::Field::Album }, { "song", Filter::Field::Title }, { "playlist", Filter::Field::Playlist }, { "genre", Filter::Field::Genre } })
 Lookup table for optional type to filter field. More...
 

Detailed Description

Functions and types for parsing and interpreting predicates.

Enumeration Type Documentation

◆ MANNER

enum Predicate::MANNER
strong

Manners in which predicates may be specified.

Enumerator
NAME 
ID 
WHERE 
LIKE 
SOURCE 

Function Documentation

◆ construct_predicate_parsers()

void Predicate::construct_predicate_parsers ( PianodParser parser)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFullPredicate()

static Predicate Predicate::getFullPredicate ( const PianodConnection conn,
const Parsnip::Data predicate,
Filter::Field  field 
)
static

Parse a command's predicate and return a matching filter.

Predicate forms are:

  • ID {id} ... (exact match on 1 or more IDs)
  • NAME {name} ... (exact match on 1 or more names)
  • [type] LIKE {text} ... (permuted on text) If type was not specified, each word matches any text field; otherwise, the words must match on the specified field.
  • WHERE {expression} ... (logical filter expression)
  • SOURCE TYPE {type} NAME {name} {manner} {expression} ... Executes one of the other manners of predicates against a specific source.

This function requires the command be defined with the following named fields:

  • manner - to match the predicate keyword
  • expression - the start of the predicate parameter
  • type (optional) - the optional type for LIKE. Tag names vary slightly for playlist predicates. (It is a syntax error if other predicates have this.)
    Parameters
    connThe connection for which the predicate is evaluated.
    predicateDetails from the parsed predicate.
    fieldThe field to use for name searches and the 'like' default.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPartialSpecifiedThings()

static ThingieList Predicate::getPartialSpecifiedThings ( Predicate pred,
SearchRange  search_what 
)
static

Gather a list of assorted things specified by a predicate, which must be present.

This differs from the standard call in that when querying the media manager, it does not consider a single source's inability to complete a query as a failure.

Parameters
predThe predicate, including source and filter.
search_whatSpecifies manner of search.
Returns
The things specified.
Exceptions
CommandErrorif no matching things are found.
Query::impossibleIf no sources could handle the query.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPredicate()

std::unique_ptr< Filter > Predicate::getPredicate ( const PianodConnection conn,
const Parsnip::Data predicate,
Filter::Field  field 
)

Return just the filter portion of a predicate, for external use.

See also
getFullPredicate.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPredicateIdItems()

static ThingieList Predicate::getPredicateIdItems ( const Parsnip::Data predicate)
static

Specialization for getting things by ID.

Parameters
predicateThe predicate options.
Exceptions
CommandErrorif the ID does not match any item.
Note
Specifying the same ID multiple items will produce duplicates in the returned list return.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSpecifiedPlaylist()

PianodPlaylist * Predicate::getSpecifiedPlaylist ( const PianodConnection conn,
const Parsnip::Data predicate 
)

Gather a request for a single playlist and return it.

Predicate must be present.

Returns
The requested playlist, or nullptr.
Exceptions
CommandErrorif no playlists or multiple playlists are found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSpecifiedPlaylists()

PlaylistList Predicate::getSpecifiedPlaylists ( const PianodConnection conn,
const Parsnip::Data predicate 
)

Interpret a list of playlists specified by a predicate.

Parameters
connThe connection for which the predicate is being interpreted.
predicateThe predicate options.
Returns
The playlists specified. If the predicate is missing, returns all playlists for the current source.
Exceptions
CommandErrorif no matching playlists are found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSpecifiedPlaylistsById()

static PlaylistList Predicate::getSpecifiedPlaylistsById ( const Parsnip::Data predicate)
static

Get playlist items by id.

Parameters
predicateThe predicate options.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSpecifiedSong()

PianodSong * Predicate::getSpecifiedSong ( const PianodConnection conn,
const Parsnip::Data predicate 
)

Gather a request for a single song and return it.

Predicate must be present.

Returns
The requested song, or nullptr.
Exceptions
CommandErrorif no songs or multiple songs are found.
Here is the call graph for this function:

◆ getSpecifiedSongs()

SongList Predicate::getSpecifiedSongs ( const PianodConnection conn,
const Parsnip::Data predicate,
SearchRange  search_what 
)

Interpret a list of songs specified by a predicate.

Parameters
connThe connection for which the predicate is being interpreted.
predicateThe predicate options.
search_whatSpecifies manner of search.
Returns
The songs specified or belonging to the artists, albums, or playlists specified.
Exceptions
CommandErrorif no matching songs are found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSpecifiedThing()

MusicThingie * Predicate::getSpecifiedThing ( const PianodConnection conn,
const Parsnip::Data predicate 
)

Interpret a request for an unspecified type of thing and return it.

Predicate must be present.

Returns
The requested thing.
Exceptions
CommandErrorif no things or multiple things are found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSpecifiedThings()

ThingieList Predicate::getSpecifiedThings ( const PianodConnection conn,
const Parsnip::Data predicate,
SearchRange  search_what 
)

Gather a list of assorted things specified by a predicate.

The predicate must be present.

Parameters
connThe connection for which the predicate is being interpreted.
predicateThe predicate options.
search_whatNature of items to search for (requestable, etc).
Returns
The things specified.
Exceptions
CommandErrorif no matching things are found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ havePredicate()

bool Predicate::havePredicate ( const Parsnip::Data options)
inline

Check for presence of a predicate.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ PredicateManners

const LookupTable<MANNER> Predicate::PredicateManners({ { "name", MANNER::NAME }, { "id", MANNER::ID }, { "where", MANNER::WHERE }, { "like", MANNER::LIKE } })

Lookup table for manner names to enumeration.

◆ SearchFields

const LookupTable<Filter::Field> Predicate::SearchFields({ { "any", Filter::Field::Search }, { "artist", Filter::Field::Artist }, { "album", Filter::Field::Album }, { "song", Filter::Field::Title }, { "playlist", Filter::Field::Playlist }, { "genre", Filter::Field::Genre } })

Lookup table for optional type to filter field.