예제 #1
0
    void Parser::parseFile(DeckPtr deck, const boost::filesystem::path& file, const boost::filesystem::path& rootPath, bool parseStrict) const {
        bool verbose = false;
        std::ifstream inputstream;
        size_t lineNR = 0;
        inputstream.open(file.string().c_str());

        if (inputstream) {
            RawKeywordPtr rawKeyword;
            
            while (tryParseKeyword(deck, file.string() , lineNR , inputstream, rawKeyword, parseStrict)) {
                if (rawKeyword->getKeywordName() == Opm::RawConsts::include) {
                    RawRecordConstPtr firstRecord = rawKeyword->getRecord(0);
                    std::string includeFileString = firstRecord->getItem(0);
                    boost::filesystem::path includeFile(includeFileString);

                    if (includeFile.is_relative())
                        includeFile = rootPath / includeFile;

                    if (verbose)
                        std::cout << rawKeyword->getKeywordName() << "  " << includeFile << std::endl;

                    parseFile(deck, includeFile, rootPath , parseStrict);
                } else {
                    if (verbose)
                        std::cout << rawKeyword->getKeywordName() << std::endl;

                    if (hasKeyword(rawKeyword->getKeywordName())) {
                        ParserKeywordConstPtr parserKeyword = m_parserKeywords.at(rawKeyword->getKeywordName());
                        ParserKeywordActionEnum action = parserKeyword->getAction();
                        if (action == INTERNALIZE) {
                            DeckKeywordConstPtr deckKeyword = parserKeyword->parse(rawKeyword);
                            deck->addKeyword(deckKeyword);
                        } else if (action == IGNORE_WARNING) 
                            deck->addWarning( "The keyword " + rawKeyword->getKeywordName() + " is ignored - this might potentially affect the results" , file.string() , rawKeyword->getLineNR());
                    } else {
                        DeckKeywordConstPtr deckKeyword(new DeckKeyword(rawKeyword->getKeywordName(), false));
                        deck->addKeyword(deckKeyword);
                        deck->addWarning( "The keyword " + rawKeyword->getKeywordName() + " is not recognized" , file.string() , lineNR);
                    }
                }
                rawKeyword.reset();
            }

            inputstream.close();
        } else
            throw std::invalid_argument("Failed to open file: " + file.string());
    }
예제 #2
0
static std::shared_ptr< Deck > deckWithGRUPTREE() {
    DeckPtr deck = createDeck();
    DeckKeyword gruptreeKeyword("GRUPTREE");

    DeckRecord recordChildOfField;
    auto itemChild1 = DeckItem::make< std::string >( "CHILD_GROUP" );
    itemChild1.push_back(std::string("BARNET"));
    auto itemParent1 = DeckItem::make< std::string >( "PARENT_GROUP" );
    itemParent1.push_back(std::string("FAREN"));

    recordChildOfField.addItem( std::move( itemChild1 ) );
    recordChildOfField.addItem( std::move( itemParent1 ) );
    gruptreeKeyword.addRecord( std::move( recordChildOfField ) );
    deck->addKeyword( std::move( gruptreeKeyword ) );

    return deck;
}