47 template<
class FieldType>
49 const FieldType&
field,
56 {{
"name",
field.name},
93 std::string
id()
const;
108 template<
class FieldType>
111 return doc_.
get<FieldType&>(
"field");
120 template<
class FieldType>
123 return doc_.
get<
const FieldType&>(
"field");
298 template<
class FieldType>
302 field,
"attempting to retrieve FieldCollection from unregistered field"
304 return instance(field.db(), field.fieldCollectionName);
313 template<
class FieldType>
317 field,
"attempting to retrieve FieldCollection from unregistered field"
332 template<
class FieldType>
338 throw std::runtime_error(
"Document is not valid");
343 FieldType& field = fd.
field<FieldType>();
345 field.fieldCollectionName =
name();
364template<
typename FieldType>
371 std::int64_t
timeIndex = std::numeric_limits<std::int64_t>::max();
381 field.internalField(),
382 field.boundaryConditions(),
388 if (
field.registered())
392 if (
timeIndex == std::numeric_limits<std::int64_t>::max())
400 if (
subCycleIndex == std::numeric_limits<std::int64_t>::max())
A mixin class for collection of documents in a database to simplify the implementation of common oper...
const std::string & name() const
Gets the name of the collection.
Document & doc(const std::string &id)
Retrieves a document by its ID.
const NeoFOAM::Database & db() const
Gets a const reference to the database.
A type-erased interface collection types.
CollectionType & as()
Casts the collection to a specific collection type.
Collection & at(const std::string &name)
Retrieves a collection by its name.
T & get(const std::string &key)
Retrieves the value associated with the given key, casting it to the specified type.
A class representing a document in a database.
Creates a FieldDocument from an existing field.
std::int64_t subCycleIndex
std::int64_t iterationIndex
FieldDocument operator()(Database &db)
A class representing a collection of field documents in a database.
bool contains(const std::string &id) const
Checks if the collection contains a field with the given ID.
FieldType & registerField(CreateFunction createFunc)
Registers a field in the collection.
static const FieldCollection & instance(const NeoFOAM::Database &db, std::string name)
Retrieves the instance of the FieldCollection with the given name (const version).
FieldCollection & operator=(FieldCollection &&)=delete
A FieldCollection is not move-assign-able, but move-construct-able.
static FieldCollection & instance(NeoFOAM::Database &db, std::string name)
Retrieves the instance of the FieldCollection with the given name.
static const FieldCollection & instance(const FieldType &field)
Retrieves the instance of the FieldCollection from a const registered FieldType.
static FieldCollection & instance(FieldType &field)
Retrieves the instance of the FieldCollection from a const registered FieldType.
const FieldDocument & fieldDoc(const std::string &id) const
Retrieves a field document by its ID (const version).
std::string insert(const FieldDocument &fd)
Inserts a field document into the collection.
FieldDocument & fieldDoc(const std::string &id)
Retrieves a field document by its ID.
FieldCollection(FieldCollection &&)=default
A FieldCollection is move constructable, but not copyable.
FieldCollection & operator=(const FieldCollection &)=delete
A FieldCollection is not copyable, but moveable.
FieldCollection(const FieldCollection &)=delete
A FieldCollection is not copyable, but moveable.
FieldCollection(NeoFOAM::Database &db, std::string name)
Constructs a FieldCollection with the given database and name.
A class representing a field document in a database.
FieldType & field()
Retrieves the field from the document.
FieldDocument(const FieldType &field, std::int64_t timeIndex, std::int64_t iterationIndex, std::int64_t subCycleIndex)
Constructs a FieldDocument with the given field and metadata.
const FieldType & field() const
Retrieves the field from the document (const version).
FieldDocument(const Document &doc)
Constructs a FieldDocument with the given Document.
std::string name() const
Retrieves the name of the field.
Document & doc()
Retrieves the underlying Document.
std::int64_t timeIndex() const
Retrieves the time index of the field.
std::string id() const
Retrieves the unique identifier of the field collection.
std::int64_t & timeIndex()
Retrieves the time index of the field.
const Document & doc() const
Retrieves the underlying Document (const version).
static std::string typeName()
Retrieves the type name of the field.
std::int64_t subCycleIndex() const
Retrieves the sub-cycle index of the field.
std::int64_t & iterationIndex()
Retrieves the iteration index of the field.
std::int64_t & subCycleIndex()
Retrieves the sub-cycle index of the field.
std::int64_t iterationIndex() const
Retrieves the iteration index of the field.
std::string & name()
Retrieves the time index of the field.
bool validateFieldDoc(const Document &doc)
Validates a FieldDocument.
std::function< FieldDocument(NeoFOAM::Database &db)> CreateFunction
A function type for creating a FieldDocument.
void validateRegistration(const Type &obj, const std::string errorMessage)
Validates that a field is registered in the database.