ParserIntItem::ParserIntItem(const Json::JsonObject& jsonConfig) : ParserItem(jsonConfig) { if (jsonConfig.has_item("default")) setDefault( jsonConfig.get_int("default") ); else m_default = defaultInt(); }
void ParserKeyword::initData(const Json::JsonObject& jsonConfig) { this->m_fixedSize = 1U; this->m_keywordSizeType = FIXED; const Json::JsonObject dataConfig = jsonConfig.get_item("data"); if (!dataConfig.has_item("value_type") ) throw std::invalid_argument("The 'value_type' JSON item of keyword "+getName()+" is missing"); ParserValueTypeEnum valueType = ParserValueTypeEnumFromString(dataConfig.get_string("value_type")); const std::string itemName("data"); bool hasDefault = dataConfig.has_item("default"); ParserRecord record; ParserItem item( itemName, ParserItem::item_size::ALL ); switch (valueType) { case INT: { item.setType( int() ); if(hasDefault) { int defaultValue = dataConfig.get_int("default"); item.setDefault(defaultValue); } record.addDataItem( item ); } break; case STRING: { item.setType( std::string() ); if (hasDefault) { std::string defaultValue = dataConfig.get_string("default"); item.setDefault(defaultValue); } record.addItem( item ); } break; case DOUBLE: { item.setType( double() ); if (hasDefault) { double defaultValue = dataConfig.get_double("default"); item.setDefault(defaultValue); } set_dimensions( item, dataConfig, this->getName() ); record.addDataItem( item ); } break; default: throw std::invalid_argument("While initializing keyword "+getName()+": Values of type "+dataConfig.get_string("value_type")+" are not implemented."); } this->addDataRecord( record ); }