hummingbird
Solving the self-adjoint angular flux transport equation using spectral elements on Cartesian geometry
Loading...
Searching...
No Matches
bank_base.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2// Copyright (c) 2026, Liam Pohlmann
3
4#ifndef HUMMINGBIRD_BANKS_BANK_BASE_H_
5#define HUMMINGBIRD_BANKS_BANK_BASE_H_
6
7#include <nlohmann/json.hpp>
8#include <string>
9#include <unordered_map>
10
11using nlohmann::json;
12
13namespace hummingbird {
14/**
15 * @brief Base class for banks that store objects of type T by integer ID and
16 * look them up by the name given in the JSON input file
17 *
18 * @tparam T Stored object type
19 */
20template <typename T>
21class BankBase {
22 public:
23 /**
24 * @brief Get the object by its ID
25 *
26 * @param id ID
27 * @return const T&
28 */
29 const T& GetByID(const int id) const { return id_object_map_.at(id); }
30
31 /**
32 * @brief Get the object by its name in the JSON input file
33 *
34 * @param name Object name
35 * @return const T&
36 */
37 const T& GetByName(const std::string& name) const {
38 return GetByID(name_id_map_.at(name));
39 }
40
41 /**
42 * @brief Get the ID of an object by its name in the JSON input file
43 *
44 * @param name Object name
45 * @return int
46 */
47 int GetIDByName(const std::string& name) const {
48 return name_id_map_.at(name);
49 }
50
51 protected:
52 /// @brief ID to object map
53 std::unordered_map<int, T> id_object_map_;
54
55 /// @brief name to object ID map
56 std::unordered_map<std::string, int> name_id_map_;
57
58 /**
59 * @brief Build the bank
60 *
61 * @param json_input JSON input
62 */
63 virtual void Build(const json& json_input) = 0;
64};
65} // namespace hummingbird
66
67#endif // HUMMINGBIRD_BANKS_BANK_BASE_H_
Base class for banks that store objects of type T by integer ID and look them up by the name given in...
Definition bank_base.h:21
const T & GetByID(const int id) const
Get the object by its ID.
Definition bank_base.h:29
virtual void Build(const json &json_input)=0
Build the bank.
const T & GetByName(const std::string &name) const
Get the object by its name in the JSON input file.
Definition bank_base.h:37
std::unordered_map< std::string, int > name_id_map_
name to object ID map
Definition bank_base.h:56
std::unordered_map< int, T > id_object_map_
ID to object map.
Definition bank_base.h:53
int GetIDByName(const std::string &name) const
Get the ID of an object by its name in the JSON input file.
Definition bank_base.h:47