/* Copyright 2013 Statoil ASA. This file is part of the Open Porous Media project (OPM). OPM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OPM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OPM. If not, see . */ #include #include #include #include namespace Opm { KeywordContainer::KeywordContainer() { } bool KeywordContainer::hasKeyword(const std::string& keyword) const { return (m_keywordMap.find(keyword) != m_keywordMap.end()); } size_t KeywordContainer::size() const { return m_keywordList.size(); } void KeywordContainer::addKeyword(DeckKeywordConstPtr keyword) { m_keywordList.push_back(keyword); if (!hasKeyword(keyword->name())) { m_keywordMap[keyword->name()] = std::vector(); } { std::vector& keywordList = m_keywordMap[keyword->name()]; keywordList.push_back(keyword); } } const std::vector& KeywordContainer::getKeywordList(const std::string& keyword) const { if (hasKeyword(keyword)) { const std::vector& keywordList = m_keywordMap.find(keyword)->second; return keywordList; } else throw std::invalid_argument("Keyword: " + keyword + " is not found in the container"); } DeckKeywordConstPtr KeywordContainer::getKeyword(const std::string& keyword, size_t index) const { const std::vector& keywordList = getKeywordList( keyword ); if (index < keywordList.size()) return keywordList[index]; else throw std::out_of_range("Keyword index is out of range."); } DeckKeywordConstPtr KeywordContainer::getKeyword(const std::string& keyword) const { const std::vector& keywordList = getKeywordList( keyword ); return keywordList.back(); } DeckKeywordConstPtr KeywordContainer::getKeyword(size_t index) const { if (index < m_keywordList.size()) return m_keywordList[index]; else throw std::out_of_range("Keyword index is out of range."); } size_t KeywordContainer::numKeywords(const std::string& keyword) const{ if (hasKeyword(keyword)) { const std::vector& keywordList = getKeywordList( keyword ); return keywordList.size(); } else return 0; } }