NeoFOAM
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
stencilDataBase.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2023 NeoFOAM authors
3#pragma once
4
5#include <unordered_map>
6#include <any>
7#include <string>
8
9namespace NeoFOAM
10{
11
20{
21public:
22
26 StencilDataBase() = default;
27
35 template<typename T>
36 void insert(const std::string& key, T value)
37 {
38 stencilDB_.emplace(key, value);
39 }
40
47 std::any& operator[](const std::string& key);
48
56 const std::any& operator[](const std::string& key) const;
57
66 template<typename T>
67 T& get(const std::string& key)
68 {
69 return std::any_cast<T&>(stencilDB_.at(key));
70 }
71
81 template<typename T>
82 const T& get(const std::string& key) const
83 {
84 return std::any_cast<const T&>(stencilDB_.at(key));
85 }
86
94 bool contains(const std::string& key) const;
95
96private:
97
101 std::unordered_map<std::string, std::any> stencilDB_;
102};
103
104} // namespace NeoFOAM
A class that represents a stencil database.
const T & get(const std::string &key) const
Retrieves a const reference to the value associated with the given key.
T & get(const std::string &key)
Retrieves a reference to the value associated with the given key.
std::any & operator[](const std::string &key)
Retrieves a reference to the value associated with the given key.
StencilDataBase()=default
Default constructor for StencilDataBase.
const std::any & operator[](const std::string &key) const
Retrieves a const reference to the value associated with the given key.
bool contains(const std::string &key) const
Checks if the stencil database contains a value associated with the given key.
void insert(const std::string &key, T value)
Inserts a value into the stencil database.