Cloudy
Spectral Synthesis Code for Astrophysics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
physconst.h
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2023 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #ifndef PHYSCONST_H_
5 #define PHYSCONST_H_
6 
7 void prt_phys_constants(FILE* io);
8 
9 class t_physconst : public Singleton<t_physconst>
10 {
11  friend class Singleton<t_physconst>;
12 
13  map<string,double> p_constant;
14 protected:
15  t_physconst();
16 public:
17  void add_constant(const string& s, double v)
18  {
19  p_constant[s] = v;
20  }
21  void prt_constants(FILE* io) const
22  {
23  map<string,double>::const_iterator p;
24  for( p = p_constant.begin(); p != p_constant.end(); ++p )
25  fprintf( io, "%-20s %.15g\n", (*p).first.c_str(), (*p).second );
26  }
27  double get_constant(const string& s) const
28  {
29  map<string,double>::const_iterator p = p_constant.find(s);
30  if( p == p_constant.end() )
31  return 0.;
32  else
33  return (*p).second;
34  }
35 };
36 
37 #ifdef HAVE_CONSTEXPR
38 #define NEW_CONSTANT(NAME, VALUE) constexpr double NAME = (VALUE)
39 #else
40 #define NEW_CONSTANT(NAME, VALUE) const double NAME = (VALUE)
41 #endif
42 #include "physconst_template.h"
43 #undef NEW_CONSTANT
44 
45 #endif /* PHYSCONST_H_ */
Definition: physconst.h:9
Definition: cddefines.h:213
map< string, double > p_constant
Definition: physconst.h:13
void prt_phys_constants(FILE *io)
Definition: physconst.cpp:76
t_physconst()
Definition: physconst.cpp:22
void prt_constants(FILE *io) const
Definition: physconst.h:21
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1325
void add_constant(const string &s, double v)
Definition: physconst.h:17
double get_constant(const string &s) const
Definition: physconst.h:27