MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / fixupEnumerationValue

Function fixupEnumerationValue

src/epjson/epJSONTranslator.cpp:190–250  ·  view source on GitHub ↗

epJSON (unlike IDF) is case sensitive, so this routine find the correct 'enum' choice casing * It applies to fieldType = 'ChoiceType' or 'RealType' (since RealType can also be `anyOf` with values like 'Autosize' 'Autocalculate')) * eg: if given value='autosize', will convert it to 'Autosize' so that EnergyPlus' InputParser does recognize it */

Source from the content-addressed store, hash-verified

188 * It applies to fieldType = 'ChoiceType' or 'RealType' (since RealType can also be `anyOf` with values like 'Autosize' 'Autocalculate'))
189 * eg: if given value='autosize', will convert it to 'Autosize' so that EnergyPlus' InputParser does recognize it */
190std::string fixupEnumerationValue(const Json::Value& schema, const std::string& value, const std::string& type_description,
191 const std::string& group_name, const std::string& field_name, const openstudio::IddFieldType fieldType) {
192
193 if (fieldType == openstudio::IddFieldType::ChoiceType) {
194 const auto& fieldProperty = getSchemaObjectFieldProperty(schema, type_description, group_name, field_name, "enum");
195 const auto lower = boost::to_lower_copy(value);
196
197 if (fieldProperty.isNull()) {
198 LOG_FREE(LogLevel::Error, "epJSONTranslator", "Unable to find enum value for " << value << " in " << group_name << "::" << field_name)
199 return value;
200 }
201
202 for (const auto& enumOption : fieldProperty) {
203 if (enumOption.isString()) {
204 const auto& enumStr = enumOption.asString();
205 if (boost::to_lower_copy(enumStr) == lower) {
206 return enumStr;
207 }
208 }
209 }
210
211 // value wasn't found, so return passed-in value
212 return value;
213 }
214
215 if (fieldType == openstudio::IddFieldType::RealType) {
216
217 const auto& fieldProperty = getSchemaObjectFieldProperty(schema, type_description, group_name, field_name, "anyOf");
218
219 if (fieldProperty.isArray()) {
220 const auto lower = boost::to_lower_copy(value);
221
222 for (const auto& possibleValues : fieldProperty) {
223 const auto& enumOptions = possibleValues["enum"];
224 if (enumOptions.isArray()) {
225 for (const auto& enumOption : enumOptions) {
226 if (enumOption.isString()) {
227 const auto& enumStr = enumOption.asString();
228 const auto lowerEnumStr = boost::to_lower_copy(enumStr);
229
230 if (lowerEnumStr == lower) {
231 return enumStr;
232 }
233
234 if (lowerEnumStr.find("auto") == 0 && lower.find("auto") == 0) {
235 // it's the "auto" option, return it
236 return enumStr;
237 }
238 }
239 }
240 }
241 }
242 }
243
244 // value wasn't found, so return passed-in value
245 return value;
246 }
247

Callers 1

toJSONFunction · 0.85

Calls 2

isNullMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected