NeoFOAM
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
NeoFOAM::CollectionMixin< DocumentType > Class Template Reference

A mixin class for collection of documents in a database to simplify the implementation of common operations. More...

#include <collection.hpp>

Public Member Functions

 CollectionMixin (NeoFOAM::Database &db, std::string name)
 Constructs a CollectionMixin with the given database and collection name.
 
 CollectionMixin (const CollectionMixin &)=delete
 
CollectionMixinoperator= (const CollectionMixin &)=delete
 
 CollectionMixin (CollectionMixin &&)=default
 
CollectionMixinoperator= (CollectionMixin &&)=delete
 
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.
 
std::size_t size () const
 Gets the number of documents in the collection.
 
const NeoFOAM::Databasedb () const
 Gets a const reference to the database.
 
NeoFOAM::Databasedb ()
 Gets a reference to the database.
 
const std::string & name () const
 Gets the name of the collection.
 
std::string type () const
 Gets the type name of the documents in the collection.
 
std::vector< std::string > sortedKeys () const
 Gets the sorted keys of the documents in the collection.
 

Protected Attributes

std::unordered_map< std::string, DocumentType > docs_
 The map of document IDs to documents.
 
NeoFOAM::Databasedb_
 The reference to the database.
 
std::string name_
 The name of the collection.
 

Detailed Description

template<typename DocumentType>
class NeoFOAM::CollectionMixin< DocumentType >

A mixin class for collection of documents in a database to simplify the implementation of common operations.

Template Parameters
DocumentTypeThe type of documents stored in the collection.

Definition at line 214 of file collection.hpp.

Constructor & Destructor Documentation

◆ CollectionMixin() [1/3]

template<typename DocumentType >
NeoFOAM::CollectionMixin< DocumentType >::CollectionMixin ( NeoFOAM::Database db,
std::string  name 
)
inline

Constructs a CollectionMixin with the given database and collection name.

Parameters
dbThe database reference.
nameThe name of the collection.

Definition at line 225 of file collection.hpp.

◆ CollectionMixin() [2/3]

template<typename DocumentType >
NeoFOAM::CollectionMixin< DocumentType >::CollectionMixin ( const CollectionMixin< DocumentType > &  )
delete

@biref A CollectionMixin is not copyable, only moveable.

◆ CollectionMixin() [3/3]

template<typename DocumentType >
NeoFOAM::CollectionMixin< DocumentType >::CollectionMixin ( CollectionMixin< DocumentType > &&  )
default

@biref A CollectionMixin is moveable, but not copyable.

Member Function Documentation

◆ db() [1/2]

template<typename DocumentType >
NeoFOAM::Database & NeoFOAM::CollectionMixin< DocumentType >::db ( )
inline

Gets a reference to the database.

Returns
NeoFOAM::Database& A reference to the database.

Definition at line 301 of file collection.hpp.

◆ db() [2/2]

template<typename DocumentType >
const NeoFOAM::Database & NeoFOAM::CollectionMixin< DocumentType >::db ( ) const
inline

Gets a const reference to the database.

Returns
const NeoFOAM::Database& A const reference to the database.

Definition at line 294 of file collection.hpp.

◆ doc() [1/2]

template<typename DocumentType >
Document & NeoFOAM::CollectionMixin< DocumentType >::doc ( const std::string &  id)
inline

Retrieves a document by its ID.

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

Definition at line 253 of file collection.hpp.

◆ doc() [2/2]

template<typename DocumentType >
const Document & NeoFOAM::CollectionMixin< DocumentType >::doc ( const std::string &  id) const
inline

Retrieves a document by its ID (const version).

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

Definition at line 261 of file collection.hpp.

◆ find()

template<typename DocumentType >
std::vector< std::string > NeoFOAM::CollectionMixin< DocumentType >::find ( const std::function< bool(const Document &)> &  predicate) const
inline

Finds documents that match a given predicate.

Parameters
predicateA function that takes a const reference to a Document and returns a bool.
Returns
std::vector<std::string> A vector of document IDs that match the predicate.

Definition at line 269 of file collection.hpp.

◆ name()

template<typename DocumentType >
const std::string & NeoFOAM::CollectionMixin< DocumentType >::name ( ) const
inline

Gets the name of the collection.

Returns
const std::string& A const reference to the collection name.

Definition at line 308 of file collection.hpp.

◆ operator=() [1/2]

template<typename DocumentType >
CollectionMixin & NeoFOAM::CollectionMixin< DocumentType >::operator= ( CollectionMixin< DocumentType > &&  )
delete

@biref A CollectionMixin is not move-assign-able.

◆ operator=() [2/2]

template<typename DocumentType >
CollectionMixin & NeoFOAM::CollectionMixin< DocumentType >::operator= ( const CollectionMixin< DocumentType > &  )
delete

@biref A CollectionMixin is not copyable, only moveable.

◆ size()

template<typename DocumentType >
std::size_t NeoFOAM::CollectionMixin< DocumentType >::size ( ) const
inline

Gets the number of documents in the collection.

Returns
std::size_t The number of documents.

Definition at line 287 of file collection.hpp.

◆ sortedKeys()

template<typename DocumentType >
std::vector< std::string > NeoFOAM::CollectionMixin< DocumentType >::sortedKeys ( ) const
inline

Gets the sorted keys of the documents in the collection.

Returns
std::vector<std::string> A vector of sorted document keys.

Definition at line 322 of file collection.hpp.

◆ type()

template<typename DocumentType >
std::string NeoFOAM::CollectionMixin< DocumentType >::type ( ) const
inline

Gets the type name of the documents in the collection.

Returns
std::string The type name of the documents.

Definition at line 315 of file collection.hpp.

Member Data Documentation

◆ db_

template<typename DocumentType >
NeoFOAM::Database& NeoFOAM::CollectionMixin< DocumentType >::db_
protected

The reference to the database.

Definition at line 336 of file collection.hpp.

◆ docs_

template<typename DocumentType >
std::unordered_map<std::string, DocumentType> NeoFOAM::CollectionMixin< DocumentType >::docs_
protected

The map of document IDs to documents.

Definition at line 335 of file collection.hpp.

◆ name_

template<typename DocumentType >
std::string NeoFOAM::CollectionMixin< DocumentType >::name_
protected

The name of the collection.

Definition at line 337 of file collection.hpp.


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