From dfefe42d0fe40dd97260d3ec0b3e1cb7690cf669 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Mon, 5 May 2014 15:36:59 +0200 Subject: Cleaned up the api to eliminate some intermediate steps --- fusion_model.hpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'fusion_model.hpp') 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 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 -struct fusion_model> : public FusionModelInterface +struct fusion_model> : public FusionModelInterface { static_assert(friendly_fusion::traits::is_sequence::type::value, "T is not a boost fusion sequence"); typedef std::vector data_type; typedef T row_type; - static constexpr bool has_header_h = true; - static constexpr bool has_header_v = false; - std::vector data; + fusion_model() = default; + + fusion_model(std::vector data) + : data(data) + {} + virtual size_t row_count() const override final { return data.size(); @@ -66,18 +74,21 @@ struct fusion_model> : public FusionModelInterface }; template -struct fusion_model> : public FusionModelInterface +struct fusion_model> : public FusionModelInterface { static_assert(boost::fusion::traits::is_sequence::type::value, "T is not a boost fusion sequence"); typedef std::map data_type; typedef T row_type; - static constexpr bool has_header_h = true; - static constexpr bool has_header_v = true; - std::map data; + fusion_model() = default; + + fusion_model(std::map data) + : data(data) + {} + virtual size_t row_count() const override final { return data.size(); -- cgit v1.2.3-70-g09d2