walberla::selectable::SelectableObject< T, A, S > Class Template Referenceabstract

Detailed Description

template<typename T, typename A, typename S>
class walberla::selectable::SelectableObject< T, A, S >

Abstract base class for storing and selecting objects of type T which are attached with selection attributes of type A.

The sole purpose of this class is to store selectable objects of type T, meaning objects which are attached with additional selection attributes of type A, in order to later retrieve only those objects which match certain requested attributes. For the retrieval (see functions "get") a selection object of type S is used (type S may or may not be equal to type A).

Requirements for type A:

  • objects of type A must be comparable with operator "!="
  • A must implement operator "<<" for output via a std::ostream object

Additionally, it must be possible to store objects of both types T and A in a std::vector.

Objects can be added by calling the function "add" (for every object that is added an identifier string can be provided) and be retrieved by calling "get". For additional information refer to the documentation of these functions.

Every class that derives from SelectableObject must implement the function

void select( std::vector< size_t >& index, const S& selector ) const

After returning from the call to this function, the vector "index" must contain the index of every object in "attributes_" that matches with the provided selector "selector" (for an actual implementation of SelectableObject see "SetSelectableObject.h").

#include <SelectableObject.h>

Classes

class  const_iterator
 
class  iterator
 

Iterators

class const_iterator
 
class iterator
 
std::vector< T > object_
 
std::vector< std::string > identifier_
 
std::vector< A > attributes_
 
virtual ~SelectableObject ()=default
 
void add (const T &object, const A &attributes, const std::string &identifier=std::string())
 This function is used to add an object together with its selection attributes stored in "attributes". More...
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
size_t getNumberOfMatching (const S &selector) const
 Returns the number of objects matching the specified "selector". More...
 
size_t get (T &object, const S &selector) const
 This function can be used to retrieve the one object whose attributes match with "selector". More...
 
void get (std::vector< T > &object, const S &selector) const
 This function can be used to retrieve all objects whose attributes match with the selector "selector". More...
 
size_t get (T &object, std::string &identifier, const S &selector) const
 This function can be used to retrieve the one object whose attributes match with "selector". More...
 
void get (std::vector< T > &object, std::vector< std::string > &identifier, const S &selector) const
 This function can be used to retrieve all objects whose attributes match with the selector "selector". More...
 
T * getUnique (const S &selector)
 Non-const version of getUnique(). More...
 
const T * getUnique (const S &selector) const
 This function can be used to retrieve a pointer (!) to the object whose attributes match with "selector". More...
 
T * getUnique (const S &selector, std::string &identifierOut)
 Non-const version of getUnique(const S&, std::string& ). More...
 
const T * getUnique (const S &selector, std::string &identifierOut) const
 This function is similar to getUnique(const S &selector) but takes an additional output parameter identifier, which is set to the string identifier of the selected object, if a non-zero pointer is returned, otherwise the identifier string is not changed. More...
 
void toStream (std::ostream &os) const
 
std::string toString () const
 
size_t size () const
 
bool empty () const
 
virtual void select (std::vector< size_t > &index, const S &selector) const =0
 Every class that derives from SelectableObject must implement this function. More...
 

Constructor & Destructor Documentation

◆ ~SelectableObject()

template<typename T , typename A , typename S >
virtual walberla::selectable::SelectableObject< T, A, S >::~SelectableObject ( )
virtualdefault

Member Function Documentation

◆ add()

template<typename T , typename A , typename S >
void walberla::selectable::SelectableObject< T, A, S >::add ( const T &  object,
const A &  attributes,
const std::string &  identifier = std::string() 
)

This function is used to add an object together with its selection attributes stored in "attributes".

Optionally, an identifier string can be provided which is used during output (see "toStream" and "toString"). In debug mode, this function triggers an assertion and fails if another object with the same selection attributes already exists.

◆ begin() [1/2]

template<typename T , typename A , typename S >
iterator walberla::selectable::SelectableObject< T, A, S >::begin ( )
inline

◆ begin() [2/2]

template<typename T , typename A , typename S >
const_iterator walberla::selectable::SelectableObject< T, A, S >::begin ( ) const
inline

◆ empty()

template<typename T , typename A , typename S >
bool walberla::selectable::SelectableObject< T, A, S >::empty ( ) const
inline

◆ end() [1/2]

template<typename T , typename A , typename S >
iterator walberla::selectable::SelectableObject< T, A, S >::end ( )
inline

◆ end() [2/2]

template<typename T , typename A , typename S >
const_iterator walberla::selectable::SelectableObject< T, A, S >::end ( ) const
inline

◆ get() [1/4]

template<typename T , typename A , typename S >
void walberla::selectable::SelectableObject< T, A, S >::get ( std::vector< T > &  object,
const S &  selector 
) const

This function can be used to retrieve all objects whose attributes match with the selector "selector".

The objects are returned using the provided vector "objects" (this function may return none, exactly one, ore multiple objects depending on "selector" and the actual implementation of the function "select").

◆ get() [2/4]

template<typename T , typename A , typename S >
void walberla::selectable::SelectableObject< T, A, S >::get ( std::vector< T > &  object,
std::vector< std::string > &  identifier,
const S &  selector 
) const

This function can be used to retrieve all objects whose attributes match with the selector "selector".

The objects are returned using the provided vector "objects" (this function may return none, exactly one, ore multiple objects depending on "selector" and the actual implementation of the function "select"). Additionally, for every object that is found, its corresponding identifier is also returned via "identifier".

◆ get() [3/4]

template<typename T , typename A , typename S >
size_t walberla::selectable::SelectableObject< T, A, S >::get ( T &  object,
const S &  selector 
) const

This function can be used to retrieve the one object whose attributes match with "selector".

Depending on "selector" and the actual implementation of the function "select", no object, one object, or multiple objects may be found. If only one object is found, it is returned via the parameter "object". If multiple objects are found, the first object whose attributes match is returned via "object". In any case, the number of objects that match with "selector" is returned by this function - and only if the return value is equal to '1' exactly one object was found and stored in "object".

◆ get() [4/4]

template<typename T , typename A , typename S >
size_t walberla::selectable::SelectableObject< T, A, S >::get ( T &  object,
std::string &  identifier,
const S &  selector 
) const

This function can be used to retrieve the one object whose attributes match with "selector".

Depending on "selector" and the actual implementation of the function "select", no object, one object, or multiple objects may be found. If only one object is found, it is returned via the parameter "object". If multiple objects are found, the first object whose attributes match is returned via "object". In any case, the number of objects that match with "selector" is returned by this function - and only if the return value is equal to '1' exactly one object was found and stored in "object". Additionally, the corresponding identifier is also returned via the parameter "identifier".

◆ getNumberOfMatching()

template<typename T , typename A , typename S >
size_t walberla::selectable::SelectableObject< T, A, S >::getNumberOfMatching ( const S &  selector) const

Returns the number of objects matching the specified "selector".

◆ getUnique() [1/4]

template<typename T , typename A , typename S >
T * walberla::selectable::SelectableObject< T, A, S >::getUnique ( const S &  selector)

Non-const version of getUnique().

◆ getUnique() [2/4]

template<typename T , typename A , typename S >
const T * walberla::selectable::SelectableObject< T, A, S >::getUnique ( const S &  selector) const

This function can be used to retrieve a pointer (!) to the object whose attributes match with "selector".

Depending on "selector" and the actual implementation of the function "select", no object, one object, or multiple objects may be found. If no objects or multiple objects are found, NULL is returned. Attention: The pointer may get invalidated by subsequent calls to the member function "add".

◆ getUnique() [3/4]

template<typename T , typename A , typename S >
T * walberla::selectable::SelectableObject< T, A, S >::getUnique ( const S &  selector,
std::string &  identifierOut 
)

Non-const version of getUnique(const S&, std::string& ).

◆ getUnique() [4/4]

template<typename T , typename A , typename S >
const T * walberla::selectable::SelectableObject< T, A, S >::getUnique ( const S &  selector,
std::string &  identifierOut 
) const

This function is similar to getUnique(const S &selector) but takes an additional output parameter identifier, which is set to the string identifier of the selected object, if a non-zero pointer is returned, otherwise the identifier string is not changed.

◆ select()

◆ size()

template<typename T , typename A , typename S >
size_t walberla::selectable::SelectableObject< T, A, S >::size ( ) const
inline

◆ toStream()

template<typename T , typename A , typename S >
void walberla::selectable::SelectableObject< T, A, S >::toStream ( std::ostream &  os) const

◆ toString()

template<typename T , typename A , typename S >
std::string walberla::selectable::SelectableObject< T, A, S >::toString
inline

Friends And Related Function Documentation

◆ const_iterator

template<typename T , typename A , typename S >
friend class const_iterator
friend

◆ iterator

template<typename T , typename A , typename S >
friend class iterator
friend

Member Data Documentation

◆ attributes_

template<typename T , typename A , typename S >
std::vector< A > walberla::selectable::SelectableObject< T, A, S >::attributes_
protected

◆ identifier_

template<typename T , typename A , typename S >
std::vector< std::string > walberla::selectable::SelectableObject< T, A, S >::identifier_
private

◆ object_

template<typename T , typename A , typename S >
std::vector< T > walberla::selectable::SelectableObject< T, A, S >::object_
private

The documentation for this class was generated from the following file:
@ S
South.
Definition: Directions.h:47
virtual void select(std::vector< size_t > &index, const S &selector) const =0
Every class that derives from SelectableObject must implement this function.