NeoFOAM
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
NeoFOAM::Collection Class Reference

A type-erased interface collection types. More...

#include <collection.hpp>

Public Member Functions

template<typename CollectionType >
 Collection (CollectionType collection)
 Constructs a Collection from a specific collection type.
 
 Collection (const Collection &other)=delete
 A Collection is not copyable, only moveable.
 
Collectionoperator= (const Collection &other)=delete
 A Collection is not copyable, only moveable.
 
 Collection (Collection &&other)=default
 A Collection is moveable, but not copyable.
 
Collectionoperator= (Collection &&other)=default
 A Collection is moveable, but not copyable.
 
Documentdoc (const std::string &id)
 Retrieves a document by its ID.
 
const Documentdoc (const std::string &id) const
 Retrieves a document by its ID (const version).
 
std::vector< std::string > find (const std::function< bool(const Document &)> &predicate) const
 Finds documents that match a given predicate.
 
size_t size () const
 Returns the number of documents in the collection.
 
std::string type () const
 Returns the type of the collection.
 
std::string name () const
 Returns the name of the collection.
 
Databasedb ()
 Returns a reference to the database containing the collection.
 
const Databasedb () const
 Returns a const reference to the database containing the collection.
 
template<typename CollectionType >
CollectionType & as ()
 Casts the collection to a specific collection type.
 
template<typename CollectionType >
const CollectionType & as () const
 Casts the collection to a specific collection type (const version).
 

Detailed Description

A type-erased interface collection types.

The Collection class provides a type-erased interface for different collection types. It allows operations such as retrieving documents, finding documents based on predicates, and accessing collection metadata.

Definition at line 28 of file collection.hpp.

Constructor & Destructor Documentation

◆ Collection() [1/3]

template<typename CollectionType >
NeoFOAM::Collection::Collection ( CollectionType  collection)
inline

Constructs a Collection from a specific collection type.

Template Parameters
CollectionTypeThe type of the collection to be wrapped.
Parameters
collectionThe collection instance to be wrapped.

Definition at line 39 of file collection.hpp.

◆ Collection() [2/3]

NeoFOAM::Collection::Collection ( const Collection other)
delete

A Collection is not copyable, only moveable.

◆ Collection() [3/3]

NeoFOAM::Collection::Collection ( Collection &&  other)
default

A Collection is moveable, but not copyable.

Member Function Documentation

◆ as() [1/2]

template<typename CollectionType >
CollectionType & NeoFOAM::Collection::as ( )
inline

Casts the collection to a specific collection type.

Template Parameters
CollectionTypeThe type to cast to.
Returns
CollectionType& A reference to the casted collection.
Exceptions
std::bad_castif the cast fails.

Definition at line 131 of file collection.hpp.

◆ as() [2/2]

template<typename CollectionType >
const CollectionType & NeoFOAM::Collection::as ( ) const
inline

Casts the collection to a specific collection type (const version).

Template Parameters
CollectionTypeThe type to cast to.
Returns
const CollectionType& A const reference to the casted collection.
Exceptions
std::bad_castif the cast fails.

Definition at line 150 of file collection.hpp.

◆ db() [1/2]

Database & NeoFOAM::Collection::db ( )

Returns a reference to the database containing the collection.

Returns
Database& A reference to the database.

◆ db() [2/2]

const Database & NeoFOAM::Collection::db ( ) const

Returns a const reference to the database containing the collection.

Returns
const Database& A const reference to the database.

◆ doc() [1/2]

Document & NeoFOAM::Collection::doc ( const std::string &  id)

Retrieves a document by its ID.

Parameters
idThe ID of the document to retrieve.
Returns
Document& A reference to the document.

◆ doc() [2/2]

const Document & NeoFOAM::Collection::doc ( const std::string &  id) const

Retrieves a document by its ID (const version).

Parameters
idThe ID of the document to retrieve.
Returns
const Document& A const reference to the document.

◆ find()

std::vector< std::string > NeoFOAM::Collection::find ( const std::function< bool(const Document &)> &  predicate) const

Finds documents that match a given predicate.

Parameters
predicateA function that takes a Document and returns true if it matches the criteria.
Returns
std::vector<std::string> A vector of document IDs that match the predicate.

◆ name()

std::string NeoFOAM::Collection::name ( ) const

Returns the name of the collection.

Returns
std::string The name of the collection.

◆ operator=() [1/2]

Collection & NeoFOAM::Collection::operator= ( Collection &&  other)
default

A Collection is moveable, but not copyable.

◆ operator=() [2/2]

Collection & NeoFOAM::Collection::operator= ( const Collection other)
delete

A Collection is not copyable, only moveable.

◆ size()

size_t NeoFOAM::Collection::size ( ) const

Returns the number of documents in the collection.

Returns
size_t The number of documents.

◆ type()

std::string NeoFOAM::Collection::type ( ) const

Returns the type of the collection.

Returns
std::string The type of the collection.

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