NeoN
A framework for CFD software
Loading...
Searching...
No Matches
NeoN::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 (NeoN::Database &db, std::string name)
 Constructs a CollectionMixin with the given database and collection name.
 CollectionMixin (const CollectionMixin &)=delete
CollectionMixin & operator= (const CollectionMixin &)=delete
 CollectionMixin (CollectionMixin &&)=default
CollectionMixin & operator= (CollectionMixin &&)=delete
Document & doc (const std::string &id)
 Retrieves a document by its ID.
const Document & doc (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.
sizeType size () const
 Gets the number of documents in the collection.
const NeoN::Database & db () const
 Gets a const reference to the database.
NeoN::Database & db ()
 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.
NeoN::Database & db_
 The reference to the database.
std::string name_
 The name of the collection.

Detailed Description

template<typename DocumentType>
class NeoN::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 217 of file collection.hpp.

Constructor & Destructor Documentation

◆ CollectionMixin() [1/3]

template<typename DocumentType>
NeoN::CollectionMixin< DocumentType >::CollectionMixin ( NeoN::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 228 of file collection.hpp.

◆ CollectionMixin() [2/3]

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

@biref A CollectionMixin is not copyable, only moveable.

◆ CollectionMixin() [3/3]

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

@biref A CollectionMixin is moveable, but not copyable.

Member Function Documentation

◆ db() [1/2]

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

Gets a reference to the database.

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

Definition at line 304 of file collection.hpp.

◆ db() [2/2]

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

Gets a const reference to the database.

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

Definition at line 297 of file collection.hpp.

◆ doc() [1/2]

template<typename DocumentType>
Document & NeoN::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 256 of file collection.hpp.

◆ doc() [2/2]

template<typename DocumentType>
const Document & NeoN::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 264 of file collection.hpp.

◆ find()

template<typename DocumentType>
std::vector< std::string > NeoN::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 272 of file collection.hpp.

◆ name()

template<typename DocumentType>
const std::string & NeoN::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 311 of file collection.hpp.

◆ operator=() [1/2]

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

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

◆ operator=() [2/2]

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

@biref A CollectionMixin is not copyable, only moveable.

◆ size()

template<typename DocumentType>
sizeType NeoN::CollectionMixin< DocumentType >::size ( ) const
inline

Gets the number of documents in the collection.

Returns
sizeType The number of documents.

Definition at line 290 of file collection.hpp.

◆ sortedKeys()

template<typename DocumentType>
std::vector< std::string > NeoN::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 325 of file collection.hpp.

◆ type()

template<typename DocumentType>
std::string NeoN::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 318 of file collection.hpp.

Member Data Documentation

◆ db_

template<typename DocumentType>
NeoN::Database& NeoN::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> NeoN::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 NeoN::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: