Changed ParserItem from template based to a base-inheritance based system. Corresponds to and creates DeckItem objects
This commit is contained in:
parent
b36f000377
commit
2d6e6842d6
@ -1,6 +1,7 @@
|
||||
add_subdirectory( Logger )
|
||||
add_subdirectory(Parser/tests)
|
||||
add_subdirectory(RawDeck/tests)
|
||||
add_subdirectory(Deck/tests)
|
||||
|
||||
set( rawdeck_source
|
||||
RawDeck/RawDeck.cpp
|
||||
@ -8,13 +9,25 @@ RawDeck/RawKeyword.cpp
|
||||
RawDeck/RawRecord.cpp
|
||||
RawDeck/RawParserKWs.cpp )
|
||||
|
||||
set( deck_source
|
||||
Deck/DeckIntItem.cpp
|
||||
)
|
||||
|
||||
set( parser_source
|
||||
Parser/ParserRecordSize.cpp
|
||||
Parser/ParserKW.cpp
|
||||
Parser/Parser.cpp
|
||||
Parser/ParserItemSize.cpp )
|
||||
Parser/ParserItemSize.cpp
|
||||
Parser/ParserRecord.cpp
|
||||
Parser/ParserItem.cpp
|
||||
Parser/ParserIntItem.cpp
|
||||
Parser/ParserBoolItem.cpp
|
||||
Parser/ParserDoubleItem.cpp
|
||||
Parser/ParserStringItem.cpp
|
||||
)
|
||||
|
||||
add_library(Parser ${rawdeck_source} ${parser_source})
|
||||
|
||||
add_library(Parser ${rawdeck_source} ${parser_source} ${deck_source})
|
||||
|
||||
|
||||
|
||||
|
31
opm/parser/eclipse/Deck/DeckIntItem.cpp
Normal file
31
opm/parser/eclipse/Deck/DeckIntItem.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "DeckIntItem.hpp"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
namespace Opm {
|
||||
|
||||
int DeckIntItem::getInt(unsigned int index) const {
|
||||
if (index < m_data.size()) {
|
||||
return m_data[index];
|
||||
} else
|
||||
throw std::out_of_range("Out of range, index must be lower than " + boost::lexical_cast<std::string>(m_data.size()));
|
||||
}
|
||||
}
|
||||
|
40
opm/parser/eclipse/Deck/DeckIntItem.hpp
Normal file
40
opm/parser/eclipse/Deck/DeckIntItem.hpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DECKINTITEM_HPP
|
||||
#define DECKINTITEM_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class DeckIntItem : public DeckItem {
|
||||
public:
|
||||
int getInt(unsigned int index) const;
|
||||
private:
|
||||
std::vector<int> m_data;
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<DeckIntItem> DeckIntItemPtr;
|
||||
typedef boost::shared_ptr<const DeckIntItem> DeckIntItemConstPtr;
|
||||
}
|
||||
#endif /* DECKINTITEM_HPP */
|
||||
|
51
opm/parser/eclipse/Deck/DeckItem.hpp
Normal file
51
opm/parser/eclipse/Deck/DeckItem.hpp
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DECKITEM_HPP
|
||||
#define DECKITEM_HPP
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
class DeckItem {
|
||||
public:
|
||||
|
||||
virtual int getInt(unsigned int index) const {
|
||||
throw std::logic_error("This implementation of DeckItem does not support int");
|
||||
};
|
||||
|
||||
virtual double getDouble(unsigned int index) const {
|
||||
throw std::logic_error("This implementation of DeckItem does not support double");
|
||||
};
|
||||
|
||||
virtual bool getBool(unsigned int index) const {
|
||||
throw std::logic_error("This implementation of DeckItem does not support bool");
|
||||
}
|
||||
|
||||
virtual std::string getString(unsigned int index) const {
|
||||
throw std::logic_error("This implementation of DeckItem does not support string");
|
||||
}
|
||||
|
||||
virtual ~DeckItem() {}
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif /* DECKITEM_HPP */
|
||||
|
BIN
opm/parser/eclipse/Deck/tests/.DeckItemTests.cpp.swp
Normal file
BIN
opm/parser/eclipse/Deck/tests/.DeckItemTests.cpp.swp
Normal file
Binary file not shown.
7
opm/parser/eclipse/Deck/tests/CMakeLists.txt
Normal file
7
opm/parser/eclipse/Deck/tests/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
||||
add_executable(runDeckItemTests DeckItemTests.cpp)
|
||||
|
||||
target_link_libraries(runDeckItemTests Parser Logger ${Boost_LIBRARIES})
|
||||
|
||||
add_test(NAME runDeckItemTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runDeckItemTests )
|
||||
|
||||
set_property(SOURCE DeckItemTests.cpp PROPERTY COMPILE_FLAGS "-Wno-error")
|
37
opm/parser/eclipse/Deck/tests/DeckItemTests.cpp
Normal file
37
opm/parser/eclipse/Deck/tests/DeckItemTests.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#define BOOST_TEST_MODULE DeckItemTests
|
||||
|
||||
#include <stdexcept>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckIntItem.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize) {
|
||||
BOOST_REQUIRE_NO_THROW(DeckIntItem deckIntItem);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetIntAtIndex_NoData_ExceptionThrown) {
|
||||
const DeckIntItem deckIntItem;
|
||||
BOOST_CHECK_THROW(deckIntItem.getInt(0), std::out_of_range);
|
||||
}
|
||||
|
@ -17,15 +17,9 @@
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ParserBoolItem.hpp"
|
||||
|
||||
#define BOOST_TEST_MODULE ParserTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
namespace Opm {
|
||||
|
||||
#include "opm/parser/eclipse/Parser/ParserRecordItem.hpp"
|
||||
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize_int) {
|
||||
BOOST_REQUIRE_NO_THROW(ParserRecordItem<int> item);
|
||||
|
||||
}
|
36
opm/parser/eclipse/Parser/ParserBoolItem.hpp
Normal file
36
opm/parser/eclipse/Parser/ParserBoolItem.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PARSERBOOLITEM_HPP
|
||||
#define PARSERBOOLITEM_HPP
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
namespace Opm {
|
||||
|
||||
class ParserBoolItem : public ParserItem {
|
||||
public:
|
||||
ParserBoolItem(const std::string& itemName, ParserItemSizeConstPtr itemSize) : ParserItem(itemName, itemSize) {};
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* PARSERBOOLITEM_HPP */
|
||||
|
24
opm/parser/eclipse/Parser/ParserDoubleItem.cpp
Normal file
24
opm/parser/eclipse/Parser/ParserDoubleItem.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ParserIntItem.hpp"
|
||||
|
||||
namespace Opm {
|
||||
|
||||
}
|
35
opm/parser/eclipse/Parser/ParserDoubleItem.hpp
Normal file
35
opm/parser/eclipse/Parser/ParserDoubleItem.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PARSERDOUBLEITEM_HPP
|
||||
#define PARSERDOUBLEITEM_HPP
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
namespace Opm {
|
||||
|
||||
class ParserDoubleItem : public ParserItem {
|
||||
public:
|
||||
ParserDoubleItem(const std::string& itemName, ParserItemSizeConstPtr itemSize) : ParserItem(itemName, itemSize) {};
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* PARSERDOUBLEITEM_HPP */
|
||||
|
28
opm/parser/eclipse/Parser/ParserIntItem.cpp
Normal file
28
opm/parser/eclipse/Parser/ParserIntItem.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
|
||||
namespace Opm {
|
||||
DeckIntItemConstPtr ParserIntItem::scan(std::vector<std::string>& stringTokens) {
|
||||
DeckIntItemConstPtr deckItem(new DeckIntItem());
|
||||
return deckItem;
|
||||
}
|
||||
|
||||
}
|
40
opm/parser/eclipse/Parser/ParserIntItem.hpp
Normal file
40
opm/parser/eclipse/Parser/ParserIntItem.hpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PARSERINTITEM_HPP
|
||||
#define PARSERINTITEM_HPP
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckIntItem.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class ParserIntItem : public ParserItem {
|
||||
public:
|
||||
ParserIntItem(const std::string& itemName, ParserItemSizeConstPtr itemSize) : ParserItem(itemName, itemSize) {};
|
||||
DeckIntItemConstPtr scan(std::vector<std::string>& stringTokens);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* PARSERINTITEM_HPP */
|
||||
|
28
opm/parser/eclipse/Parser/ParserItem.cpp
Normal file
28
opm/parser/eclipse/Parser/ParserItem.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
ParserItem::ParserItem(const std::string& itemName, ParserItemSizeConstPtr itemSize) {
|
||||
m_name.assign(itemName);
|
||||
m_itemSize = itemSize;
|
||||
}
|
||||
}
|
@ -20,15 +20,15 @@
|
||||
#define PARSER_ITEM_H
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <vector>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserItemSize.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
template<class T>
|
||||
class ParserItem {
|
||||
private:
|
||||
std::string m_name;
|
||||
@ -36,49 +36,46 @@ namespace Opm {
|
||||
|
||||
public:
|
||||
|
||||
ParserItem<T>(const std::string& itemName, ParserItemSizeConstPtr itemSize) {
|
||||
m_name.assign(itemName);
|
||||
m_itemSize = itemSize;
|
||||
}
|
||||
ParserItem(const std::string& itemName, ParserItemSizeConstPtr itemSize);
|
||||
|
||||
bool scanItem(const std::string& itemString, T& value) {
|
||||
std::istringstream inputStream(itemString);
|
||||
T newValue;
|
||||
inputStream >> newValue;
|
||||
|
||||
if (inputStream.fail())
|
||||
return false;
|
||||
else {
|
||||
char c;
|
||||
inputStream >> c;
|
||||
if (inputStream.eof() || c == ' ') {
|
||||
value = newValue;
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
// bool scanItem(const std::string& itemString, T& value) {
|
||||
// std::istringstream inputStream(itemString);
|
||||
// T newValue;
|
||||
// inputStream >> newValue;
|
||||
//
|
||||
// if (inputStream.fail())
|
||||
// return false;
|
||||
// else {
|
||||
// char c;
|
||||
// inputStream >> c;
|
||||
// if (inputStream.eof() || c == ' ') {
|
||||
// value = newValue;
|
||||
// return true;
|
||||
// } else
|
||||
// return false;
|
||||
// }
|
||||
};
|
||||
|
||||
int scanItems(const std::string& itemString, size_t items, std::vector<T>& values) {
|
||||
std::istringstream inputStream(itemString);
|
||||
unsigned int itemsRead = 0;
|
||||
|
||||
while (inputStream.good() && itemsRead < items) {
|
||||
T value;
|
||||
inputStream >> value;
|
||||
values.push_back(value);
|
||||
itemsRead++;
|
||||
}
|
||||
|
||||
return itemsRead;
|
||||
}
|
||||
|
||||
int scanItems(const std::string& itemString, std::vector<T>& values) {
|
||||
return scanItems(itemString, m_itemSize->sizeValue(), values);
|
||||
}
|
||||
// int scanItems(const std::string& itemString, size_t items, std::vector<T>& values) {
|
||||
// std::istringstream inputStream(itemString);
|
||||
// unsigned int itemsRead = 0;
|
||||
//
|
||||
// while (inputStream.good() && itemsRead < items) {
|
||||
// T value;
|
||||
// inputStream >> value;
|
||||
// values.push_back(value);
|
||||
// itemsRead++;
|
||||
// }
|
||||
//
|
||||
// return itemsRead;
|
||||
// }
|
||||
//
|
||||
// int scanItems(const std::string& itemString, std::vector<T>& values) {
|
||||
// return scanItems(itemString, m_itemSize->sizeValue(), values);
|
||||
// }
|
||||
|
||||
|
||||
};
|
||||
// };
|
||||
}
|
||||
|
||||
#endif
|
||||
|
31
opm/parser/eclipse/Parser/ParserRecord.cpp
Normal file
31
opm/parser/eclipse/Parser/ParserRecord.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
ParserRecord::ParserRecord() {
|
||||
|
||||
}
|
||||
|
||||
size_t ParserRecord::size() {
|
||||
return m_items.size();
|
||||
}
|
||||
}
|
@ -20,6 +20,24 @@
|
||||
#ifndef PARSERRECORD_HPP
|
||||
#define PARSERRECORD_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "ParserItem.hpp"
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class ParserRecord {
|
||||
public:
|
||||
ParserRecord();
|
||||
size_t size();
|
||||
private:
|
||||
std::vector<ParserItem> m_items;
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<const ParserRecord> ParserRecordConstPtr;
|
||||
typedef boost::shared_ptr<ParserRecord> ParserRecordPtr;
|
||||
}
|
||||
|
||||
|
||||
#endif /* PARSERRECORD_HPP */
|
||||
|
25
opm/parser/eclipse/Parser/ParserStringItem.cpp
Normal file
25
opm/parser/eclipse/Parser/ParserStringItem.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ParserStringItem.hpp"
|
||||
|
||||
namespace Opm {
|
||||
|
||||
|
||||
}
|
36
opm/parser/eclipse/Parser/ParserStringItem.hpp
Normal file
36
opm/parser/eclipse/Parser/ParserStringItem.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PARSERSTRINGITEM_HPP
|
||||
#define PARSERSTRINGITEM_HPP
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
namespace Opm {
|
||||
|
||||
class ParserStringItem : public ParserItem {
|
||||
public:
|
||||
ParserStringItem(const std::string& itemName, ParserItemSizeConstPtr itemSize) : ParserItem(itemName, itemSize) {};
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* PARSERSTRINGITEM_HPP */
|
||||
|
@ -1,22 +1,27 @@
|
||||
add_executable(runParserTests ParserTests.cpp)
|
||||
add_executable(runParserTestsInternalData ParserTestsInternalData.cpp)
|
||||
add_executable(runParserKWTests ParserKWTests.cpp)
|
||||
add_executable(runParserRecordTests ParserRecordTests.cpp)
|
||||
add_executable(runParserRecordSizeTests ParserRecordSizeTests.cpp)
|
||||
add_executable(runParserRecordItemTests ParserRecordItemTests.cpp)
|
||||
add_executable(runParserItemTests ParserItemTests.cpp)
|
||||
add_executable(runParserItemSizeTests ParserItemSizeTests.cpp)
|
||||
|
||||
target_link_libraries(runParserTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserTestsInternalData Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserKWTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserRecordSizeTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserRecordItemTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserRecordTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserItemTests Parser Logger ${Boost_LIBRARIES})
|
||||
target_link_libraries(runParserItemSizeTests Parser Logger ${Boost_LIBRARIES})
|
||||
|
||||
add_test(NAME runParserTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserTests )
|
||||
add_test(NAME runParserTestsInternalData WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserTestsInternalData)
|
||||
add_test(NAME runParserKWTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserKWTests )
|
||||
add_test(NAME runParserRecordSizeTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserRecordSizeTests )
|
||||
add_test(NAME runParserRecordItemTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserRecordItemTests )
|
||||
add_test(NAME runParserRecordTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserRecordTests )
|
||||
add_test(NAME runParserItemTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserItemTests )
|
||||
add_test(NAME runParserItemSizeTests COMMAND ${EXECUTABLE_OUTPUT_PATH}/runParserItemSizeTests )
|
||||
|
||||
set_tests_properties(runParserTestsInternalData PROPERTIES LABELS Statoil)
|
||||
|
||||
set_property(SOURCE ParserRecordTests.cpp PROPERTY COMPILE_FLAGS "-Wno-error")
|
||||
|
128
opm/parser/eclipse/Parser/tests/ParserItemTests.cpp
Normal file
128
opm/parser/eclipse/Parser/tests/ParserItemTests.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#define BOOST_TEST_MODULE ParserTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserBoolItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserItemSize.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/DeckIntItem.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize) {
|
||||
ParserItemSizeConstPtr itemSize(new ParserItemSize(10));
|
||||
|
||||
BOOST_REQUIRE_NO_THROW(ParserIntItem item1("ITEM1", itemSize));
|
||||
BOOST_REQUIRE_NO_THROW(ParserStringItem item1("ITEM1", itemSize));
|
||||
BOOST_REQUIRE_NO_THROW(ParserBoolItem item1("ITEM1", itemSize));
|
||||
BOOST_REQUIRE_NO_THROW(ParserDoubleItem item1("ITEM1", itemSize));
|
||||
}
|
||||
|
||||
//BOOST_AUTO_TEST_CASE(TestScanInt) {
|
||||
// ParserItemSizeConstPtr itemSize(new ParserItemSize(10));
|
||||
// ParserIntItem itemInt("ITEM2", itemSize);
|
||||
//
|
||||
// std::vector<std::string> singleItem;
|
||||
// singleItem.push_back("100");
|
||||
// DeckIntItemConstPtr deckIntItem = itemInt.scan(singleItem);
|
||||
//
|
||||
// BOOST_REQUIRE_EQUAL(100, deckIntItem->getInt(0));
|
||||
|
||||
// BOOST_REQUIRE(!itemInt.scanItem("200X", value));
|
||||
// BOOST_REQUIRE_EQUAL(value, 100);
|
||||
//
|
||||
// BOOST_REQUIRE(!itemInt.scanItem("", value));
|
||||
// BOOST_REQUIRE_EQUAL(value, 100);
|
||||
//}
|
||||
|
||||
//BOOST_AUTO_TEST_CASE(TestScanDouble) {
|
||||
// ParserItemSizeConstPtr itemSize(new ParserItemSize(10));
|
||||
// ParserDoubleItem itemDouble("ITEM2", itemSize);
|
||||
// double value = 78;
|
||||
//
|
||||
// BOOST_REQUIRE(itemDouble.scanItem("100.25", value));
|
||||
// BOOST_REQUIRE_EQUAL(value, 100.25);
|
||||
//
|
||||
// BOOST_REQUIRE(!itemDouble.scanItem("200X", value));
|
||||
// BOOST_REQUIRE_EQUAL(value, 100.25);
|
||||
//
|
||||
// BOOST_REQUIRE(!itemDouble.scanItem("", value));
|
||||
// BOOST_REQUIRE_EQUAL(value, 100.25);
|
||||
//}
|
||||
//
|
||||
//BOOST_AUTO_TEST_CASE(TestScanString) {
|
||||
// ParserItemSizeConstPtr itemSize(new ParserItemSize(10));
|
||||
// ParserStringItem itemString("ITEM2", itemSize);
|
||||
// std::string value = "Hei";
|
||||
//
|
||||
// BOOST_REQUIRE(itemString.scanItem("100.25", value));
|
||||
// BOOST_REQUIRE_EQUAL(value, "100.25");
|
||||
//
|
||||
// BOOST_REQUIRE(!itemString.scanItem("", value));
|
||||
// BOOST_REQUIRE_EQUAL(value, "100.25");
|
||||
//}
|
||||
//
|
||||
//BOOST_AUTO_TEST_CASE(TestScanBool) {
|
||||
// ParserItemSizeConstPtr itemSize(new ParserItemSize(10));
|
||||
// ParserBoolItem itemString("ITEM2", itemSize);
|
||||
// bool value = true;
|
||||
//
|
||||
// BOOST_REQUIRE(itemString.scanItem("1", value));
|
||||
// BOOST_REQUIRE_EQUAL(value, true);
|
||||
//
|
||||
// BOOST_REQUIRE(itemString.scanItem("0", value));
|
||||
// BOOST_REQUIRE_EQUAL(value, false);
|
||||
//
|
||||
// BOOST_REQUIRE(!itemString.scanItem("", value));
|
||||
// BOOST_REQUIRE_EQUAL(value, false);
|
||||
//
|
||||
// BOOST_REQUIRE(!itemString.scanItem("10", value));
|
||||
// BOOST_REQUIRE_EQUAL(value, false);
|
||||
//}
|
||||
//
|
||||
///*****************************************************************/
|
||||
//
|
||||
//
|
||||
//BOOST_AUTO_TEST_CASE(TestScanItemsFail) {
|
||||
// ParserItemSizeConstPtr itemSize(new ParserItemSize(ITEM_BOX));
|
||||
// ParserIntItem itemInt("ITEM2", itemSize);
|
||||
// std::vector<int> values;
|
||||
//
|
||||
// BOOST_REQUIRE_THROW(itemInt.scanItems("100 100 100", values), std::invalid_argument);
|
||||
//}
|
||||
//
|
||||
//BOOST_AUTO_TEST_CASE(TestScanItemsInt) {
|
||||
// ParserItemSizeConstPtr itemSize(new ParserItemSize(4));
|
||||
// ParserIntItem itemInt("ITEM2", itemSize);
|
||||
// std::vector<int> values;
|
||||
//
|
||||
// BOOST_REQUIRE_EQUAL(itemInt.scanItems("1 2 3 4", values), 4);
|
||||
// BOOST_REQUIRE_EQUAL(values[0], 1);
|
||||
// BOOST_REQUIRE_EQUAL(values[1], 2);
|
||||
// BOOST_REQUIRE_EQUAL(values[2], 3);
|
||||
// BOOST_REQUIRE_EQUAL(values[3], 4);
|
||||
//}
|
||||
|
@ -1,120 +0,0 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#define BOOST_TEST_MODULE ParserTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include "opm/parser/eclipse/Parser/ParserItem.hpp"
|
||||
#include <opm/parser/eclipse/Parser/ParserItemSize.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize) {
|
||||
ParserItemSizeConstPtr itemSize(new ParserItemSize(10));
|
||||
|
||||
BOOST_REQUIRE_NO_THROW(ParserItem<int> item1("ITEM1", itemSize));
|
||||
BOOST_REQUIRE_NO_THROW(ParserItem<std::string> item1("ITEM1", itemSize));
|
||||
BOOST_REQUIRE_NO_THROW(ParserItem<bool> item1("ITEM1", itemSize));
|
||||
BOOST_REQUIRE_NO_THROW(ParserItem<double> item1("ITEM1", itemSize));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestScanInt) {
|
||||
ParserItemSizeConstPtr itemSize(new ParserItemSize(10));
|
||||
ParserItem<int> itemInt("ITEM2", itemSize);
|
||||
int value = 78;
|
||||
|
||||
BOOST_REQUIRE(itemInt.scanItem("100", value));
|
||||
BOOST_REQUIRE_EQUAL(value, 100);
|
||||
|
||||
BOOST_REQUIRE(!itemInt.scanItem("200X", value));
|
||||
BOOST_REQUIRE_EQUAL(value, 100);
|
||||
|
||||
BOOST_REQUIRE(!itemInt.scanItem("", value));
|
||||
BOOST_REQUIRE_EQUAL(value, 100);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestScanDouble) {
|
||||
ParserItemSizeConstPtr itemSize(new ParserItemSize(10));
|
||||
ParserItem<double> itemDouble("ITEM2", itemSize);
|
||||
double value = 78;
|
||||
|
||||
BOOST_REQUIRE(itemDouble.scanItem("100.25", value));
|
||||
BOOST_REQUIRE_EQUAL(value, 100.25);
|
||||
|
||||
BOOST_REQUIRE(!itemDouble.scanItem("200X", value));
|
||||
BOOST_REQUIRE_EQUAL(value, 100.25);
|
||||
|
||||
BOOST_REQUIRE(!itemDouble.scanItem("", value));
|
||||
BOOST_REQUIRE_EQUAL(value, 100.25);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestScanString) {
|
||||
ParserItemSizeConstPtr itemSize(new ParserItemSize(10));
|
||||
ParserItem<std::string> itemString("ITEM2", itemSize);
|
||||
std::string value = "Hei";
|
||||
|
||||
BOOST_REQUIRE(itemString.scanItem("100.25", value));
|
||||
BOOST_REQUIRE_EQUAL(value, "100.25");
|
||||
|
||||
BOOST_REQUIRE(!itemString.scanItem("", value));
|
||||
BOOST_REQUIRE_EQUAL(value, "100.25");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestScanBool) {
|
||||
ParserItemSizeConstPtr itemSize(new ParserItemSize(10));
|
||||
ParserItem<bool> itemString("ITEM2", itemSize);
|
||||
bool value = true;
|
||||
|
||||
BOOST_REQUIRE(itemString.scanItem("1", value));
|
||||
BOOST_REQUIRE_EQUAL(value, true);
|
||||
|
||||
BOOST_REQUIRE(itemString.scanItem("0", value));
|
||||
BOOST_REQUIRE_EQUAL(value, false);
|
||||
|
||||
BOOST_REQUIRE(!itemString.scanItem("", value));
|
||||
BOOST_REQUIRE_EQUAL(value, false);
|
||||
|
||||
BOOST_REQUIRE(!itemString.scanItem("10", value));
|
||||
BOOST_REQUIRE_EQUAL(value, false);
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestScanItemsFail) {
|
||||
ParserItemSizeConstPtr itemSize(new ParserItemSize(ITEM_BOX));
|
||||
ParserItem<int> itemInt("ITEM2", itemSize);
|
||||
std::vector<int> values;
|
||||
|
||||
BOOST_REQUIRE_THROW(itemInt.scanItems("100 100 100", values), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestScanItemsInt) {
|
||||
ParserItemSizeConstPtr itemSize(new ParserItemSize(4));
|
||||
ParserItem<int> itemInt("ITEM2", itemSize);
|
||||
std::vector<int> values;
|
||||
|
||||
BOOST_REQUIRE_EQUAL(itemInt.scanItems("1 2 3 4", values), 4);
|
||||
BOOST_REQUIRE_EQUAL(values[0], 1);
|
||||
BOOST_REQUIRE_EQUAL(values[1], 2);
|
||||
BOOST_REQUIRE_EQUAL(values[2], 3);
|
||||
BOOST_REQUIRE_EQUAL(values[3], 4);
|
||||
}
|
||||
|
41
opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp
Normal file
41
opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#define BOOST_TEST_MODULE ParserTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DefaultConstructor_NoParams_NoThrow) {
|
||||
BOOST_CHECK_NO_THROW(ParserRecord record);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitSharedPointer_NoThrow) {
|
||||
BOOST_CHECK_NO_THROW(ParserRecordConstPtr ptr(new ParserRecord()));
|
||||
BOOST_CHECK_NO_THROW(ParserRecordPtr ptr(new ParserRecord()));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Size_NoElements_ReturnsZero) {
|
||||
ParserRecord record;
|
||||
BOOST_CHECK_EQUAL(0U, record.size());
|
||||
}
|
||||
|
@ -43,11 +43,11 @@ namespace Opm {
|
||||
RawRecord::RawRecord(const std::string& singleRecordString) {
|
||||
if (isTerminatedRecordString(singleRecordString)) {
|
||||
setRecordString(singleRecordString);
|
||||
splitSingleRecordString();
|
||||
} else {
|
||||
throw std::invalid_argument("Input string is not a complete record string,"
|
||||
" offending string: " + singleRecordString);
|
||||
}
|
||||
splitSingleRecordString();
|
||||
}
|
||||
|
||||
const std::vector<std::string>& RawRecord::getItems() const {
|
||||
|
Loading…
Reference in New Issue
Block a user