Exemple #1
0
    void ParserKeyword::initSize(const Json::JsonObject& jsonConfig) {
        // The number of record has been set explicitly with the size: keyword
        if (jsonConfig.has_item("size")) {
            Json::JsonObject sizeObject = jsonConfig.get_item("size");

            if (sizeObject.is_number()) {
                m_fixedSize = (size_t) sizeObject.as_int();
                m_keywordSizeType = FIXED;
            } else
                initSizeKeyword(sizeObject);

        } else {
            if (jsonConfig.has_item("num_tables")) {
                Json::JsonObject numTablesObject = jsonConfig.get_item("num_tables");

                if (!numTablesObject.is_object())
                    throw std::invalid_argument("The num_tables key must point to a {} object");

                initSizeKeyword(numTablesObject);
                m_isTableCollection = true;
            } else {
                if (jsonConfig.has_item("items") || jsonConfig.has_item("records"))
                    // The number of records is undetermined - the keyword will be '/' terminated.
                    m_keywordSizeType = SLASH_TERMINATED;
                else {
                    m_keywordSizeType = FIXED;
                    if (jsonConfig.has_item("data"))
                        m_fixedSize = 1;
                    else
                        m_fixedSize = 0;
                }
            }
        }
    }
Exemple #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 );
    }
Exemple #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;
    }
Exemple #4
0
 ParserIntItem::ParserIntItem(const Json::JsonObject& jsonConfig) : ParserItem(jsonConfig)
 {
     if (jsonConfig.has_item("default")) 
         setDefault( jsonConfig.get_int("default") );
     else
         m_default = defaultInt();
 }
 ParserDoubleItem::ParserDoubleItem(const Json::JsonObject& jsonConfig) :
         ParserItem(jsonConfig)
 {
     m_default = std::numeric_limits<double>::quiet_NaN();
     if (jsonConfig.has_item("default"))
         setDefault( jsonConfig.get_double("default") );
 }
 ParserFloatItem::ParserFloatItem(const Json::JsonObject& jsonConfig) :
         ParserItem(jsonConfig)
 {
     if (jsonConfig.has_item("default"))
         setDefault( jsonConfig.get_double("default"));
     else
         m_default = defaultFloat();
 }
Exemple #7
0
    void ParserKeyword::initMatchRegex(const Json::JsonObject& jsonObject) {
        if (!jsonObject.has_item("deck_name_regex"))
            return;

        const Json::JsonObject regexStringObject = jsonObject.get_item("deck_name_regex");
        if (!regexStringObject.is_string())
            throw std::invalid_argument("The 'deck_name_regex' JSON item of keyword "+m_name+" need to be a string");

        setMatchRegex(regexStringObject.as_string());
    }
Exemple #8
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");
        }

    }
Exemple #9
0
    void ParserKeyword::initSectionNames(const Json::JsonObject& jsonObject) {
        if (!jsonObject.has_item("sections"))
            throw std::invalid_argument("The 'sections' JSON item of keyword "+m_name+" needs to be defined");

        const Json::JsonObject namesObject = jsonObject.get_item("sections");

        if (!namesObject.is_array())
            throw std::invalid_argument("The 'sections' JSON item of keyword "+m_name+" needs to be a list");

        m_validSectionNames.clear();
        for (size_t nameIdx = 0; nameIdx < namesObject.size(); ++ nameIdx) {
            const Json::JsonObject nameObject = namesObject.get_array_item(nameIdx);

            if (!nameObject.is_string())
                throw std::invalid_argument("The sub-items of 'sections' of keyword "+m_name+" need to be strings");

            addValidSectionName(nameObject.as_string());
        }
    }
Exemple #10
0
    void ParserKeyword::initDeckNames(const Json::JsonObject& jsonObject) {
        if (!jsonObject.has_item("deck_names"))
            return;

        const Json::JsonObject namesObject = jsonObject.get_item("deck_names");
        if (!namesObject.is_array())
            throw std::invalid_argument("The 'deck_names' JSON item of keyword "+m_name+" needs to be a list");

        if (namesObject.size() > 0)
            m_deckNames.clear();

        for (size_t nameIdx = 0; nameIdx < namesObject.size(); ++ nameIdx) {
            const Json::JsonObject nameObject = namesObject.get_array_item(nameIdx);

            if (!nameObject.is_string())
                throw std::invalid_argument("The sub-items of 'deck_names' of keyword "+m_name+" need to be strings");

            addDeckName(nameObject.as_string());
        }
    }
 ParserDoubleItem::ParserDoubleItem(const Json::JsonObject& jsonConfig) :
         ParserItem(jsonConfig)
 {
     if (jsonConfig.has_item("default")) 
         setDefault( jsonConfig.get_double("default") );
 }
 ParserStringItem::ParserStringItem(const Json::JsonObject& jsonConfig) : ParserItem(jsonConfig) {
     if (jsonConfig.has_item("default")) 
         setDefault( jsonConfig.get_string("default") );
     else
         m_default = defaultString();
 }