Skip to content
Snippets Groups Projects
Commit 620c8a5b authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Change storage strategy of output named variables

This finally closes #27

Also add a test to check that used names are unique
parent d7fa66ca
No related branches found
No related tags found
1 merge request!145git subrepo clone git@gitlab.com:OlMon/org-themes.git packages/org-themes
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
#include <algebra/TinyMatrix.hpp> #include <algebra/TinyMatrix.hpp>
#include <algebra/TinyVector.hpp> #include <algebra/TinyVector.hpp>
#include <utils/Exceptions.hpp>
#include <map> #include <sstream>
#include <string> #include <string>
#include <variant> #include <variant>
...@@ -96,7 +97,9 @@ class OutputNamedItemDataSet ...@@ -96,7 +97,9 @@ class OutputNamedItemDataSet
CellArray<const double>>; CellArray<const double>>;
private: private:
std::map<std::string, ItemDataVariant> m_name_itemvariant_map; // We do not use a map, we want variables to be written in the
// provided order
std::vector<std::pair<std::string, ItemDataVariant>> m_name_itemvariant_list;
template <typename DataType, template <typename DataType,
ItemType item_type, ItemType item_type,
...@@ -107,10 +110,15 @@ class OutputNamedItemDataSet ...@@ -107,10 +110,15 @@ class OutputNamedItemDataSet
PUGS_FORCEINLINE constexpr void PUGS_FORCEINLINE constexpr void
_doInsert(const NamedItemData<DataType, item_type, ConnectivityPtr, ItemDataT>& named_item_data) _doInsert(const NamedItemData<DataType, item_type, ConnectivityPtr, ItemDataT>& named_item_data)
{ {
if (m_name_itemvariant_map.find(named_item_data.name()) == m_name_itemvariant_map.end()) { for (auto& [name, itemvariant] : m_name_itemvariant_list) {
m_name_itemvariant_map[named_item_data.name()] = named_item_data.itemData(); if (name == named_item_data.name()) {
std::ostringstream error_msg;
error_msg << "duplicate name '" << rang::fgB::yellow << name << rang::fg::reset << "' in name output list";
throw NormalError(error_msg.str());
} }
} }
m_name_itemvariant_list.push_back(std::make_pair(named_item_data.name(), named_item_data.itemData()));
}
template <typename DataType, template <typename DataType,
ItemType item_type, ItemType item_type,
...@@ -132,13 +140,13 @@ class OutputNamedItemDataSet ...@@ -132,13 +140,13 @@ class OutputNamedItemDataSet
auto auto
begin() const begin() const
{ {
return m_name_itemvariant_map.begin(); return m_name_itemvariant_list.begin();
} }
auto auto
end() const end() const
{ {
return m_name_itemvariant_map.end(); return m_name_itemvariant_list.end();
} }
template <typename DataType, template <typename DataType,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment