CoolProp
CachedElement.h
1 /*
2  * CachedElement.h
3  *
4  * Created on: 21 Dec 2013
5  * Author: jowr
6  */
7 
8 #ifndef CACHEDELEMENT_H_
9 #define CACHEDELEMENT_H_
10 
11 #include "CoolPropTools.h"
12 #include "DataStructures.h"
13 
14 namespace CoolProp {
15 
33 
34 private:
35  bool is_cached;
36  CoolPropDbl value;
37 public:
40  this->clear();
41  };
42 
44  void _do_cache(double value)
45  {
46  this->value = value;
47  this->is_cached = true;
48  }
49 
51  void operator=(const double& value) {
52  _do_cache(value);
53  };
54 
56  operator bool() {return is_cached;};
57 
59  operator double() {
60  if (is_cached) {return static_cast<double>(value); }
61  else {
62  throw std::exception();
63  }
64  }
65 #ifndef COOLPROPDBL_MAPS_TO_DOUBLE
66  operator CoolPropDbl() {
67  if (is_cached) {return value; }
68  else {
69  throw std::exception();
70  }
71  }
72 #endif
73  void clear() {
75  is_cached = false;
76  this->value = _HUGE;
77  };
78  CoolPropDbl &pt(){
79  return this->value;
80  }
81 };
82 
83 } /* namespace CoolProp */
84 #endif /* CACHEDELEMENT_H_ */
void _do_cache(double value)
Function to carry out the caching.
Definition: CachedElement.h:44
void clear()
Clear the flag and the value.
Definition: CachedElement.h:74
CachedElement()
Default constructor.
Definition: CachedElement.h:39
This file contains flash routines in which the state is unknown, and a solver of some kind must be us...
Definition: AbstractState.h:19
void operator=(const double &value)
Assignment operator - sets the value and sets the flag.
Definition: CachedElement.h:51
Definition: CachedElement.h:32