SERiF 0.0.1a
3+1D Stellar Structure and Evolution
Loading...
Searching...
No Matches
const.h
Go to the documentation of this file.
1/* ***********************************************************************
2//
3// Copyright (C) 2025 -- The 4D-STAR Collaboration
4// File Author: Emily Boudreaux
5// Last Modified: March 17, 2025
6//
7// 4DSSE is free software; you can use it and/or modify
8// it under the terms and restrictions the GNU General Library Public
9// License version 3 (GPLv3) as published by the Free Software Foundation.
10//
11// 4DSSE is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14// See the GNU Library General Public License for more details.
15//
16// You should have received a copy of the GNU Library General Public License
17// along with this software; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19//
20// *********************************************************************** */
21#pragma once
22#include <string>
23#include <iostream>
24#include <set>
25#include <map>
26
27namespace serif::constant {
31struct Constant {
32 const std::string name;
33 const double value;
34 const double uncertainty;
35 const std::string unit;
36 const std::string reference;
37
46 Constant(const std::string& name, const double value, const double uncertainty, const std::string& unit, const std::string& reference)
48
52 friend std::ostream& operator<<(std::ostream& os, const Constant& c) {
53 os << "<" << c.name << ": ";
54 os << c.value << "±" << c.uncertainty << " ";
55 os << c.unit << " (" << c.reference << ")>\n";
56 return os;
57 }
58};
59
63class Constants {
64private:
65 bool loaded_ = false;
66 const int col_widths_[6] = {25, 52, 20, 20, 17, 45}; // From the python script used to generate the constants file
67 std::map<std::string, Constant> constants_;
68
72 Constants();
73
78 bool load();
79
84 bool initialize();
85
91 std::string trim(const std::string& str);
92
93public:
94
100 static Constants instance;
101 return instance;
102 }
103
108 bool isLoaded() const { return loaded_; }
109
115 Constant get(const std::string& key) const;
116
123 Constant operator[](const std::string& key) const;
124
130 bool has(const std::string& key) const;
131
136 std::set<std::string> keys() const;
137
138};
139
140} // namespace serif::const
141
Constant operator[](const std::string &key) const
Overloaded subscript operator to access constants by key.
Definition const.cpp:51
std::map< std::string, Constant > constants_
Map to store constants by name.
Definition const.h:67
bool has(const std::string &key) const
Check if a constant exists by key.
Definition const.cpp:55
std::set< std::string > keys() const
Get a list of all constant keys.
Definition const.cpp:59
bool loaded_
Flag to indicate if constants are loaded.
Definition const.h:65
bool initialize()
Initialize constants.
Definition const.cpp:38
static Constants & getInstance()
get instance of constants singleton
Definition const.h:99
bool load()
Load constants from the embedded header file.
Definition const.cpp:74
bool isLoaded() const
Check if constants are loaded.
Definition const.h:108
const int col_widths_[6]
Definition const.h:66
Constants()
Default constructor. Private to avoid direct instantiation.
Definition const.cpp:34
Constant get(const std::string &key) const
Get a constant by key.
Definition const.cpp:42
std::string trim(const std::string &str)
Trim leading and trailing whitespace from a string.
Definition const.cpp:67
Structure to hold a constant's details.
Definition const.h:31
Constant(const std::string &name, const double value, const double uncertainty, const std::string &unit, const std::string &reference)
Parameterized constructor.
Definition const.h:46
const std::string unit
Unit of the constant.
Definition const.h:35
friend std::ostream & operator<<(std::ostream &os, const Constant &c)
overload the << operator for pretty printing
Definition const.h:52
const double uncertainty
Uncertainty in the constant's value.
Definition const.h:34
const std::string name
Name of the constant.
Definition const.h:32
const std::string reference
Reference for the constant's value.
Definition const.h:36
const double value
Value of the constant.
Definition const.h:33