コード例 #1
0
ファイル: ParserIntItem.cpp プロジェクト: AtleH/opm-parser
 ParserIntItem::ParserIntItem(const Json::JsonObject& jsonConfig) : ParserItem(jsonConfig)
 {
     if (jsonConfig.has_item("default")) 
         setDefault( jsonConfig.get_int("default") );
     else
         m_default = defaultInt();
 }
コード例 #2
0
 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") );
 }
コード例 #3
0
ファイル: ParserFloatItem.cpp プロジェクト: karbor/opm-parser
 ParserFloatItem::ParserFloatItem(const Json::JsonObject& jsonConfig) :
         ParserItem(jsonConfig)
 {
     if (jsonConfig.has_item("default"))
         setDefault( jsonConfig.get_double("default"));
     else
         m_default = defaultFloat();
 }
コード例 #4
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() );
     }
 }
コード例 #5
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());
    }
コード例 #6
0
ファイル: Parser.cpp プロジェクト: PETECLAM/opm-parser
    void Parser::loadKeywords(const Json::JsonObject& jsonKeywords) {
        if (jsonKeywords.is_array()) {
            for (size_t index = 0; index < jsonKeywords.size(); index++) {
                Json::JsonObject jsonKeyword = jsonKeywords.get_array_item(index);
                ParserKeywordConstPtr parserKeyword(new ParserKeyword(jsonKeyword));

                addKeyword(parserKeyword);
            }
        } else
            throw std::invalid_argument("Input JSON object is not an array");
    }
コード例 #7
0
Json::JsonArray*  CUnitedQuery::toJson()
{
	Json::JsonArray* jRet((Json::JsonArray*)(Json::JsonFactory::createArray()));
	Json::JsonObject* jConnection = NULL;
	std::auto_ptr<Json::JsonArray> jQueryArr;

	int iStart = 0;

	if (m_iPack > 0)
	{
		Json::JsonObject& jGroup = jRet->add(Json::JsonFactory::createObject()).asObject(0);
		Json::JsonArray& jgArr = jGroup.add(L"group", Json::JsonFactory::createArray()).asArray(L"group");

		Json::JsonObject& jqParam = jgArr.add(Json::JsonFactory::createObject()).asObject(0);
		jqParam.add(L"col", Json::JsonFactory::createInt(m_iColIndex));
		jqParam.add(L"param", Json::JsonFactory::createString((Json::json_char*)(LPCTSTR)m_strParam));



		for (int i = 0; i < m_iPack; ++i)
		{
			jConnection = Json::JsonFactory::createObject();
			jConnection->add(L"and", Json::JsonFactory::createBool(m_vecQuerys[i]->bIsAnd));
			jgArr.add(jConnection);

			jQueryArr.reset(m_vecQuerys[i]->pAdvanceQuery->toJson());
			for (int j = jQueryArr->size() - 1; j >= 0; --j)
			{
				jgArr.add(jQueryArr->erase(0));
			}
		}
		iStart = m_iPack;
	}
	else
	{
		Json::JsonObject& jqParam = jRet->add(Json::JsonFactory::createObject()).asObject(0);
		jqParam.add(L"col", Json::JsonFactory::createInt(m_iColIndex));
		jqParam.add(L"param", Json::JsonFactory::createString((Json::json_char*)(LPCTSTR)m_strParam));
	}
	for (int i = iStart, len = m_vecQuerys.size(); i < len; ++i)
	{
		jConnection = Json::JsonFactory::createObject();
		jConnection->add(L"and", Json::JsonFactory::createBool(m_vecQuerys[i]->bIsAnd));
		jRet->add(jConnection);

		jQueryArr.reset(m_vecQuerys[i]->pAdvanceQuery->toJson());
		for (int j = jQueryArr->size() - 1; j >= 0; --j)
		{
			jRet->add(jQueryArr->erase(0));
		}
	}

	return jRet;
}
コード例 #8
0
    void ParserKeyword::addItems(const Json::JsonObject& itemsConfig) {
        if( !itemsConfig.is_array() )
            throw std::invalid_argument("The 'items' JSON item missing must be an array in keyword "+getName()+".");

        size_t num_items = itemsConfig.size();
        ParserRecord record;

        for (size_t i = 0; i < num_items; i++) {
            const Json::JsonObject& itemConfig = itemsConfig.get_array_item(i);
            record.addItem( ParserItem( itemConfig ) );
        }

        this->addRecord( record );
    }
コード例 #9
0
ファイル: ParserItem.cpp プロジェクト: PETECLAM/opm-parser
    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;
    }
コード例 #10
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 );
    }
コード例 #11
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());
        }
    }
コード例 #12
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());
        }
    }
コード例 #13
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");
        }

    }
コード例 #14
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;
                }
            }
        }
    }
コード例 #15
0
 ParserDoubleItem::ParserDoubleItem(const Json::JsonObject& jsonConfig) :
         ParserItem(jsonConfig)
 {
     if (jsonConfig.has_item("default")) 
         setDefault( jsonConfig.get_double("default") );
 }
コード例 #16
0
 ParserStringItem::ParserStringItem(const Json::JsonObject& jsonConfig) : ParserItem(jsonConfig) {
     if (jsonConfig.has_item("default")) 
         setDefault( jsonConfig.get_string("default") );
     else
         m_default = defaultString();
 }