51 for (
const auto& [name, value] :
init_list)
52 this->add(name, value);
60 result.index_map = {{
"test1", 1}, {
"test2", 4}};
66 return this->index_map.empty();
69 std::size_t size()
const {
70 return this->m_data.size();
73 T& add(
const std::string& name, T&& value) {
74 if (index_map.count(name) != 0)
75 throw std::logic_error(
"An object with name: " + name +
" already exists in container");
77 this->index_map.emplace(name, this->m_data.size());
78 this->m_data.push_back(std::forward<T>(value));
79 return this->m_data.back();
82 T& add(
const std::string& name,
const T& value) {
83 if (index_map.count(name) != 0)
84 throw std::logic_error(
"An object with name: " + name +
" already exists in container");
86 this->index_map.emplace(name, this->m_data.size());
87 this->m_data.push_back(value);
88 return this->m_data.back();
91 bool has(
const std::string& name)
const {
92 return (index_map.count(name) != 0);
100 if (this->index_map == other.index_map)
101 this->m_data = other.m_data;
103 for (
const auto& [name, index] : this->index_map)
104 this->update_if(index, name, other);
112 void copy_welldata(
const WellContainer<T>& other,
const std::string& name) {
118 T& operator[](std::size_t index) {
119 return this->m_data.at(index);
122 const T& operator[](std::size_t index)
const {
123 return this->m_data.at(index);
126 T& operator[](
const std::string& name) {
127 auto index = this->index_map.at(name);
128 return this->m_data[index];
131 const T& operator[](
const std::string& name)
const {
132 auto index = this->index_map.at(name);
133 return this->m_data[index];
137 this->m_data.clear();
138 this->index_map.clear();
141 typename std::vector<T>::const_iterator begin()
const {
142 return this->m_data.begin();
145 typename std::vector<T>::const_iterator end()
const {
146 return this->m_data.end();
149 const std::vector<T>& data()
const {
153 std::optional<int> well_index(
const std::string&
wname)
const {
161 const std::string& well_name(std::size_t well_index)
const {
162 for (
const auto& [
wname,
windex] : this->index_map) {
166 throw std::logic_error(
"No such well");
169 std::vector<std::string> wells()
const {
170 std::vector<std::string>
wlist;
171 for (
const auto& [
wname,
_] : this->index_map) {
178 template<
class Serializer>
187 return this->m_data == rhs.m_data &&
188 this->index_map == rhs.index_map;
192 void update_if(std::size_t index,
const std::string& name,
const WellContainer<T>& other) {
202 std::vector<T> m_data;
203 std::unordered_map<std::string, std::size_t> index_map;
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242