pianod2
multisource multiuser scriptable networked music player
Public Types | Public Member Functions | Private Attributes | List of all members
MusicLibrary::ThingieContainer< TThing, TParent > Class Template Reference

Customized hash tables for music library. More...

#include <musiclibrary.h>

Inheritance diagram for MusicLibrary::ThingieContainer< TThing, TParent >:
Inheritance graph
[legend]
Collaboration diagram for MusicLibrary::ThingieContainer< TThing, TParent >:
Collaboration graph
[legend]

Public Types

using Allocator = std::function< TThing *(TParent *const, const std::string &, const std::string &)>
 

Public Member Functions

 ThingieContainer (const Allocator &alloc)
 Constructor: Construct a new ThingieContainer and assign it an allocator. More...
 
 ~ThingieContainer ()
 Destructor: Release all contents prior to destruction. More...
 
void clear ()
 Remove all items from the hash table. More...
 
void purge (bool pred(const TThing *))
 Remove items according to the predicate. More...
 
TThing * getById (const std::string &key) const
 Get a thing by its id. More...
 
TThing * getById (const Parsnip::Data &data, const char *field)
 Get a thing by its id, getting the ID from JSON data. More...
 
TThing * getByName (const std::string &name, TParent *parent) const
 Search the things looking for a name and parent match. More...
 
std::string getNewId (MusicThingie::Type item_type) const
 Construct unique, random ID for a new item. More...
 
TThing * addItem (const std::string &name, std::string id, TParent *parent)
 Construct a new item instance and add it to the hash by its ID. More...
 
TThing * addOrGetItem (const std::string &name, std::string id, TParent *parent)
 Retrieve an item by ID or by name. More...
 
TThing * addOrGetItem (const std::string &name, TParent *parent)
 
TThing * addOrGetItem (const Parsnip::Data &data, TParent *parent, const std::string &namefield, const std::string &idfield)
 Reconstitute an item from a persisted file. More...
 

Private Attributes

const Allocator allocate
 An allocator for making new items of derived types we could store. More...
 

Detailed Description

template<class TThing, class TParent>
class MusicLibrary::ThingieContainer< TThing, TParent >

Customized hash tables for music library.

These add persist/restore capabilities, and provide for items that are cross-linked with parent objects.

Member Typedef Documentation

◆ Allocator

template<class TThing , class TParent >
using MusicLibrary::ThingieContainer< TThing, TParent >::Allocator = std::function <TThing * (TParent *const, const std::string &, const std::string &)>

Constructor & Destructor Documentation

◆ ThingieContainer()

template<class TThing , class TParent >
MusicLibrary::ThingieContainer< TThing, TParent >::ThingieContainer ( const Allocator alloc)

Constructor: Construct a new ThingieContainer and assign it an allocator.

◆ ~ThingieContainer()

template<class TThing , class TParent >
MusicLibrary::ThingieContainer< TThing, TParent >::~ThingieContainer

Destructor: Release all contents prior to destruction.

Member Function Documentation

◆ addItem()

template<class TThing , class TParent >
TThing * MusicLibrary::ThingieContainer< TThing, TParent >::addItem ( const std::string &  name,
std::string  id,
TParent *  parent 
)

Construct a new item instance and add it to the hash by its ID.

Parameters
nameThe new item's name.
idThe item's ID, if known, or the empty string.
parentThe parent object to which the new item will be linked.
Here is the caller graph for this function:

◆ addOrGetItem() [1/3]

template<class TThing , class TParent >
TThing * MusicLibrary::ThingieContainer< TThing, TParent >::addOrGetItem ( const Parsnip::Data data,
TParent *  parent,
const std::string &  namefield,
const std::string &  idfield 
)

Reconstitute an item from a persisted file.

Parameters
dataThe JSON node with data to be restored.
parentThe parent to which the new record will be attached.
namefieldThe name of the name field within data.
idfieldThe name of the ID field within data.
Returns
A newly constructed item, attached to its parent.
Here is the call graph for this function:

◆ addOrGetItem() [2/3]

template<class TThing , class TParent >
TThing * MusicLibrary::ThingieContainer< TThing, TParent >::addOrGetItem ( const std::string &  name,
std::string  id,
TParent *  parent 
)

Retrieve an item by ID or by name.

  • If ID is given, that is used.
  • Otherwise, a "persistent ID" based on hashing the name is tried; if a match is found, use that.
  • Otherwise, try searching by name and parent. If found, use that.
  • Otherwise, create a new item with the name and a new ID assigned.
    Parameters
    nameThe name to search for.
    idThe ID to search for.
    parentThe parent item.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addOrGetItem() [3/3]

template<class TThing , class TParent >
TThing* MusicLibrary::ThingieContainer< TThing, TParent >::addOrGetItem ( const std::string &  name,
TParent *  parent 
)
inline
Here is the call graph for this function:

◆ clear()

template<class TThing , class TParent >
void MusicLibrary::ThingieContainer< TThing, TParent >::clear

Remove all items from the hash table.

Here is the caller graph for this function:

◆ getById() [1/2]

template<class TThing , class TParent >
TThing * MusicLibrary::ThingieContainer< TThing, TParent >::getById ( const Parsnip::Data data,
const char *  field 
)

Get a thing by its id, getting the ID from JSON data.

◆ getById() [2/2]

template<class TThing , class TParent >
TThing * MusicLibrary::ThingieContainer< TThing, TParent >::getById ( const std::string &  key) const

Get a thing by its id.

Here is the caller graph for this function:

◆ getByName()

template<class TThing , class TParent >
TThing * MusicLibrary::ThingieContainer< TThing, TParent >::getByName ( const std::string &  name,
TParent *  parent 
) const

Search the things looking for a name and parent match.

Here is the caller graph for this function:

◆ getNewId()

template<class TThing , class TParent >
std::string MusicLibrary::ThingieContainer< TThing, TParent >::getNewId ( MusicThingie::Type  item_type) const

Construct unique, random ID for a new item.

Parameters
item_typeThe type code for the item.
Returns
The unique ID string.

◆ purge()

template<class TThing , class TParent >
void MusicLibrary::ThingieContainer< TThing, TParent >::purge ( bool   predconst TThing *)

Remove items according to the predicate.

Parameters
predPredicate, which returns true to indicate removal.
Here is the caller graph for this function:

Member Data Documentation

◆ allocate

template<class TThing , class TParent >
const Allocator MusicLibrary::ThingieContainer< TThing, TParent >::allocate
private

An allocator for making new items of derived types we could store.


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