Пример #1
0
 void ParserKeyword::initSizeKeyword(const Json::JsonObject& sizeObject) {
     if (sizeObject.is_object()) {
         std::string sizeKeyword = sizeObject.get_string("keyword");
         std::string sizeItem = sizeObject.get_string("item");
         initSizeKeyword(sizeKeyword, sizeItem);
     } else {
         m_keywordSizeType = ParserKeywordSizeEnumFromString( sizeObject.as_string() );
     }
 }
Пример #2
0
    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 );
    }
Пример #3
0
    ParserItem::ParserItem(const Json::JsonObject& jsonConfig) {
        if (jsonConfig.has_item("name"))
            m_name = jsonConfig.get_string("name");
        else
            throw std::invalid_argument("Json config object missing \"name\": ... item");

        if (jsonConfig.has_item("size_type")) {
            const std::string sizeTypeString = jsonConfig.get_string("size_type");
            m_sizeType = ParserItemSizeEnumFromString( sizeTypeString );
        } else
          m_sizeType = SINGLE;
        
        m_defaultSet = false;
    }
Пример #4
0
    ParserKeyword::ParserKeyword(const Json::JsonObject& jsonConfig) {

      if (jsonConfig.has_item("name")) {
            ParserKeywordSizeEnum sizeType = UNKNOWN;
            commonInit(jsonConfig.get_string("name"), sizeType);
        } else
            throw std::invalid_argument("Json object is missing the 'name' property");

        if (jsonConfig.has_item("deck_names") || jsonConfig.has_item("deck_name_regex") )
            // if either the deck names or the regular expression for deck names are
            // explicitly specified, we do not implicitly add the contents of the 'name'
            // item to the deck names...
            clearDeckNames();

        initSize(jsonConfig);
        initDeckNames(jsonConfig);
        initSectionNames(jsonConfig);
        initMatchRegex(jsonConfig);

        if (jsonConfig.has_item("items") && jsonConfig.has_item("records"))
            throw std::invalid_argument("Fatal error in " + getName() + " configuration. Can NOT have both records: and items:");

        if (jsonConfig.has_item("items")) {
            const Json::JsonObject itemsConfig = jsonConfig.get_item("items");
            addItems(itemsConfig);
        }

        if (jsonConfig.has_item("records")) {
            const Json::JsonObject recordsConfig = jsonConfig.get_item("records");
            if (recordsConfig.is_array()) {
                size_t num_records = recordsConfig.size();
                for (size_t i = 0; i < num_records; i++) {
                    const Json::JsonObject itemsConfig = recordsConfig.get_array_item(i);
                    addItems(itemsConfig);
                }
            } else
                throw std::invalid_argument("The records item must point to an array item");
        }

        if (jsonConfig.has_item("data"))
            initData(jsonConfig);

        if (jsonConfig.has_item("description")) {
            m_Description = jsonConfig.get_string("description");
        }

    }
Пример #5
0
 ParserStringItem::ParserStringItem(const Json::JsonObject& jsonConfig) : ParserItem(jsonConfig) {
     if (jsonConfig.has_item("default")) 
         setDefault( jsonConfig.get_string("default") );
     else
         m_default = defaultString();
 }