NeoN
A framework for CFD software
Loading...
Searching...
No Matches
database.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 - 2025 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <unordered_map>
8#include <string>
9#include <memory>
10
12
13namespace NeoN
14{
15
16
18{
19public:
20
28 Collection& insert(const std::string& key, Collection&& col);
29
36 bool contains(const std::string& name) const;
37
46 bool remove(const std::string& name);
47
58 Collection& at(const std::string& name);
59
70 const Collection& at(const std::string& name) const;
71
82 template<typename CollectionType = Collection>
83 CollectionType& at(const std::string& name)
84 {
85 Collection& collection = at(name);
86 return collection.as<CollectionType>();
87 }
88
89
97 std::size_t size() const;
98
99
100private:
101
108 std::unordered_map<std::string, Collection> collections_;
109};
110
111
120template<typename Type>
121void validateRegistration(const Type& field, const std::string& errorMessage)
122{
123 if (!field.registered())
124 {
125 throw std::runtime_error {errorMessage};
126 }
127}
128
129} // namespace NeoN
A type-erased interface collection types.
CollectionType & as()
Casts the collection to a specific collection type.
bool contains(const std::string &name) const
Checks if the database contains an collection with the specified name.
Collection & at(const std::string &name)
Retrieves a collection by its name.
const Collection & at(const std::string &name) const
Retrieves a collection by its name (const version).
CollectionType & at(const std::string &name)
Retrieves a collection by its name and casts it to the specified type.
Definition database.hpp:83
Collection & insert(const std::string &key, Collection &&col)
Inserts a collection into the database with the specified key.
std::size_t size() const
Returns the size of the database.
bool remove(const std::string &name)
Removes a collection from the database.
Definition array.hpp:20
void validateRegistration(const Type &field, const std::string &errorMessage)
Validates that a field is registered in the database.
Definition database.hpp:121
const std::string & name(const NeoN::Document &doc)
Retrieves the name of a Document.