20 #ifndef JDFTX_CORE_ENERGYCOMPONENTS_H 21 #define JDFTX_CORE_ENERGYCOMPONENTS_H 40 double&
operator[](
const char* key) {
return std::map<string,double>::operator[](
string(key)); }
42 double&
operator[](
const string& key) {
return std::map<string,double>::operator[](key); }
46 double operator[](
const char* key)
const {
auto iter = find(
string(key));
return iter==end() ? 0. : iter->second; }
48 double operator[](
const string& key)
const {
auto iter = find(key);
return iter==end() ? 0. : iter->second; }
53 (*this)[
"default"] =
value;
58 { (*this)[
"default"] +=
value;
63 operator double()
const 65 for(const_iterator i=begin(); i!=end(); i++)
75 void print(FILE* fp,
bool nonzeroOnly,
const char* format=
"\t%s = %le\n")
const 77 std::map<string,double> reducedComponents;
78 for(
auto entry: *
this)
79 if((not nonzeroOnly) or (entry.second != 0))
80 reducedComponents[entry.first.substr(0, entry.first.find_last_not_of(
"0123456789-")+1)] += entry.second;
81 for(
auto entry: reducedComponents)
82 fprintf(fp, format, entry.first.c_str(), entry.second);
86 #endif //JDFTX_CORE_ENERGYCOMPONENTS_H double & operator[](const char *key)
Access by C-style string (need this to prevent ambiguous overload)
Definition: EnergyComponents.h:40
STL strings and streams with case insensitive comparison.
double operator[](const string &key) const
Expose base-class function hidden by the C-style string version above.
Definition: EnergyComponents.h:48
void print(FILE *fp, bool nonzeroOnly, const char *format="\t%s = %le\n") const
Definition: EnergyComponents.h:75
__hostanddev__ double value(const double *coeff, double x)
Compute value of quintic spline. Warning: x is not range-checked.
double & operator[](const string &key)
Expose base-class function hidden by the C-style string version above.
Definition: EnergyComponents.h:42
void operator=(const double &value)
Set to a simple scalar.
Definition: EnergyComponents.h:51
double operator[](const char *key) const
Access by C-style string (need this to prevent ambiguous overload)
Definition: EnergyComponents.h:46
void operator+=(const double &value)
Accumulate a simple scalar.
Definition: EnergyComponents.h:57
Definition: EnergyComponents.h:36