CoolProp  6.6.0
An open-source fluid property and humid air property database
CachedElement.h
Go to the documentation of this file.
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 
35  private:
36  bool is_cached;
37  CoolPropDbl value;
38 
39  public:
42  this->clear();
43  };
44 
46  void _do_cache(double value) {
47  this->value = value;
48  this->is_cached = true;
49  }
50 
52  void operator=(const double& value) {
53  _do_cache(value);
54  };
55 
57  operator bool() {
58  return is_cached;
59  };
60 
62  operator double() {
63  if (is_cached) {
64  return static_cast<double>(value);
65  } else {
66  throw std::exception();
67  }
68  }
69 #ifndef COOLPROPDBL_MAPS_TO_DOUBLE
70  operator CoolPropDbl() {
71  if (is_cached) {
72  return value;
73  } else {
74  throw std::exception();
75  }
76  }
77 #endif
79  void clear() {
80  is_cached = false;
81  this->value = _HUGE;
82  };
84  return this->value;
85  }
86 };
87 
88 } /* namespace CoolProp */
89 #endif /* CACHEDELEMENT_H_ */