summaryrefslogtreecommitdiff
path: root/fusion_model.hpp
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2014-05-05 15:36:59 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2014-05-05 15:36:59 +0200
commitdfefe42d0fe40dd97260d3ec0b3e1cb7690cf669 (patch)
tree38db4835d86d4f056395ed731affb9afc2e558aa /fusion_model.hpp
parent13cfd05f9b2bb3c8d7d1bf47fcef037a745bacf8 (diff)
downloadgeneric-gui-dfefe42d0fe40dd97260d3ec0b3e1cb7690cf669.tar.gz
generic-gui-dfefe42d0fe40dd97260d3ec0b3e1cb7690cf669.tar.bz2
generic-gui-dfefe42d0fe40dd97260d3ec0b3e1cb7690cf669.zip
Cleaned up the api to eliminate some intermediate steps
Diffstat (limited to 'fusion_model.hpp')
-rw-r--r--fusion_model.hpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/fusion_model.hpp b/fusion_model.hpp
index 4ccaa5b..3d68d94 100644
--- a/fusion_model.hpp
+++ b/fusion_model.hpp
@@ -17,7 +17,12 @@ private:
fusion_model(T);
};
+template <bool header_h, bool header_v>
struct FusionModelInterface {
+
+ static constexpr bool has_header_h = header_h;
+ static constexpr bool has_header_v = header_v;
+
virtual size_t row_count() const {throw std::runtime_error("\"row_count()\" not implemented for this model");}
virtual size_t column_count() const {throw std::runtime_error("\"column_count()\" not implemented for this model");}
virtual std::string field_name(size_t section) const {throw std::runtime_error("\"field_name(size_t)\" not implemented for this model");}
@@ -27,18 +32,21 @@ struct FusionModelInterface {
};
template <typename T>
-struct fusion_model<std::vector<T>> : public FusionModelInterface
+struct fusion_model<std::vector<T>> : public FusionModelInterface<true, false>
{
static_assert(friendly_fusion::traits::is_sequence<T>::type::value, "T is not a boost fusion sequence");
typedef std::vector<T> data_type;
typedef T row_type;
- static constexpr bool has_header_h = true;
- static constexpr bool has_header_v = false;
-
std::vector<T> data;
+ fusion_model() = default;
+
+ fusion_model(std::vector<T> data)
+ : data(data)
+ {}
+
virtual size_t row_count() const override final
{
return data.size();
@@ -66,18 +74,21 @@ struct fusion_model<std::vector<T>> : public FusionModelInterface
};
template <typename T>
-struct fusion_model<std::map<std::string, T>> : public FusionModelInterface
+struct fusion_model<std::map<std::string, T>> : public FusionModelInterface<true, true>
{
static_assert(boost::fusion::traits::is_sequence<T>::type::value, "T is not a boost fusion sequence");
typedef std::map<std::string, T> data_type;
typedef T row_type;
- static constexpr bool has_header_h = true;
- static constexpr bool has_header_v = true;
-
std::map<std::string, T> data;
+ fusion_model() = default;
+
+ fusion_model(std::map<std::string, T> data)
+ : data(data)
+ {}
+
virtual size_t row_count() const override final
{
return data.size();