1 #ifndef AMO_TOOLS_SUITE_CHILLERS_H 2 #define AMO_TOOLS_SUITE_CHILLERS_H 14 #include "chillers/CoolingTower.h" 22 double GetDouble(std::string
const &key, Local<Object> obj)
24 v8::Isolate *isolate = v8::Isolate::GetCurrent();
25 v8::Local<v8::Context> context = isolate->GetCurrentContext();
26 Local<String> getName = Nan::New<String>(key).ToLocalChecked();
27 Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
28 if (rObj->IsUndefined())
30 ThrowTypeError(std::string(
"GetDouble method in calculator.h: " + key +
" not present in object").c_str());
32 return Nan::To<double>(rObj).FromJust();
35 std::vector<double> GetVector(std::string
const &key, Local<Object> obj)
37 v8::Isolate *isolate = v8::Isolate::GetCurrent();
38 v8::Local<v8::Context> context = isolate->GetCurrentContext();
39 Local<String> getName = Nan::New<String>(key).ToLocalChecked();
40 Local<Value> arrayTmp = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
41 if (arrayTmp->IsUndefined())
43 ThrowTypeError(std::string(
"GetVector method in calculator.h: " + key +
" not present in object").c_str());
45 Local<Array> jsArray = v8::Local<v8::Array>::Cast(arrayTmp);
46 std::vector<double> array;
47 for (
unsigned int i = 0; i < jsArray->Length(); i++)
49 v8::Local<v8::Value> jsElement = jsArray->Get(context, i).ToLocalChecked();
50 double val = Nan::To<double>(jsElement).FromJust();
57 T GetEnumVal(std::string
const &key, Local<Object> obj)
59 v8::Isolate *isolate = v8::Isolate::GetCurrent();
60 v8::Local<v8::Context> context = isolate->GetCurrentContext();
61 Local<String> getName = Nan::New<String>(key).ToLocalChecked();
62 Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
63 if (rObj->IsUndefined())
65 ThrowTypeError(std::string(
"GetEnumVal method in calculator.h: Enum value " + key +
" not present in object").c_str());
67 return static_cast<T
>(Nan::To<double>(rObj).FromJust());
70 bool GetBool(std::string
const &key, Local<Object> obj)
72 v8::Isolate *isolate = v8::Isolate::GetCurrent();
73 v8::Local<v8::Context> context = isolate->GetCurrentContext();
74 Local<String> getName = Nan::New<String>(key).ToLocalChecked();
75 Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
76 if (rObj->IsUndefined())
78 ThrowTypeError(std::string(
"GetBool method in calculator.h: Boolean value " + key +
" not present in object").c_str());
80 return Nan::To<bool>(rObj).FromJust();
83 std::string GetStr(std::string
const &key, Local<Object> obj)
85 v8::Isolate *isolate = v8::Isolate::GetCurrent();
86 v8::Local<v8::Context> context = isolate->GetCurrentContext();
87 Local<String> getName = Nan::New<String>(key).ToLocalChecked();
88 Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
89 if (rObj->IsUndefined())
91 ThrowTypeError(std::string(
"GetStr method in calculator.h: String " + key +
" not present in object").c_str());
93 v8::String::Utf8Value s(isolate, rObj);
94 return std::string(*s);
98 bool isDefined(Local<Object> obj, std::string
const &key)
100 v8::Isolate *isolate = v8::Isolate::GetCurrent();
101 v8::Local<v8::Context> context = isolate->GetCurrentContext();
102 Local<String> getName = Nan::New<String>(key).ToLocalChecked();
103 Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
104 return !rObj->IsUndefined();
108 inline void SetR(
const std::string &key,
double val)
110 Nan::Set(r, Nan::New<String>(key).ToLocalChecked(), Nan::New<Number>(val));
115 v8::Isolate *isolate = v8::Isolate::GetCurrent();
116 v8::Local<v8::Context> context = isolate->GetCurrentContext();
117 Local<String> getName = Nan::New<String>(
"operatingConditionsData").ToLocalChecked();
118 Local<Object> coolingTowerOperatingConditionsDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
119 if (coolingTowerOperatingConditionsDataV8->IsUndefined())
121 ThrowTypeError(std::string(
"CoolingTowerMakeupWater: getCoolingTowerOperatingConditionsData method in chillers.h: operatingConditionsData not present in object").c_str());
123 double flowRate = GetDouble(
"flowRate", coolingTowerOperatingConditionsDataV8);
124 double coolingLoad = GetDouble(
"coolingLoad", coolingTowerOperatingConditionsDataV8);
125 int operationalHours =
static_cast<int>(GetDouble(
"operationalHours", coolingTowerOperatingConditionsDataV8));
126 double lossCorrectionFactor = GetDouble(
"lossCorrectionFactor", coolingTowerOperatingConditionsDataV8);
131 lossCorrectionFactor};
136 v8::Isolate *isolate = v8::Isolate::GetCurrent();
137 v8::Local<v8::Context> context = isolate->GetCurrentContext();
138 Local<String> getName;
139 if(hasDriftEliminators)
141 getName = Nan::New<String>(
"waterConservationModificationData").ToLocalChecked();
145 getName = Nan::New<String>(
"waterConservationBaselineData").ToLocalChecked();
147 Local<Object> coolingTowerWaterConservationDataV8 = Nan::To<Object>(obj->Get(context, getName).ToLocalChecked()).ToLocalChecked();
148 if (coolingTowerWaterConservationDataV8->IsUndefined())
150 ThrowTypeError(std::string(
"CoolingTowerMakeupWater: getCoolingTowerWaterConservationData method in chillers.h: neither waterConservationBaselineData nor waterConservationModificationData are present in object").c_str());
152 int cyclesOfConcentration =
static_cast<int>(GetDouble(
"cyclesOfConcentration", coolingTowerWaterConservationDataV8));
153 double driftLossFactor = GetDouble(
"driftLossFactor", coolingTowerWaterConservationDataV8);
155 cyclesOfConcentration,
159 NAN_METHOD(coolingTowerMakeupWater)
161 inp = Nan::To<Object>(info[0]).ToLocalChecked();
162 r = Nan::New<Object>();
165 v8::Isolate *isolate = v8::Isolate::GetCurrent();
166 v8::Local<v8::Context> context = isolate->GetCurrentContext();
167 Local<String> getName = Nan::New<String>(
"coolingTowerMakeupWaterCalculator").ToLocalChecked();
168 Local<Object> coolingTowerMakeupWaterCalculatorV8 = Nan::To<Object>(inp->Get(context, getName).ToLocalChecked()).ToLocalChecked();
176 SetR(
"wcBaseline", results.wcBaseline);
177 SetR(
"wcModification", results.wcModification);
178 SetR(
"waterSavings", results.waterSavings);
180 catch (std::runtime_error
const &e)
182 std::string
const what = e.what();
183 ThrowError(std::string(
"std::runtime_error thrown in coolingTowerMakeupWater - chillers.h: " + what).c_str());
185 info.GetReturnValue().Set(r);
188 #endif //AMO_TOOLS_SUITE_CHILLERS_H Contains the declarations of cooling tower classes including the getters and setters as well as the c...