From 1972bbcff91a6e3a1041597c1f81875814cbf58b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 3 Oct 2016 18:42:40 +0100 Subject: Template PqArray --- gentoobrowse-api/domain/converters.cpp | 39 +++++++++++++++++++++++++++--- gentoobrowse-api/domain/converters.h | 14 +++++++++-- gentoobrowse-api/domain/portage-models.ice | 2 +- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/gentoobrowse-api/domain/converters.cpp b/gentoobrowse-api/domain/converters.cpp index 9f1f6d8..6cedbcd 100644 --- a/gentoobrowse-api/domain/converters.cpp +++ b/gentoobrowse-api/domain/converters.cpp @@ -3,14 +3,35 @@ #include "unpackPqTextArray.h" #include #include +#include namespace Slicer { - PqTextArray::PqTextArray(::Gentoo::StringList & sl) : + template + PqArray::PqArray(std::vector & l) : + ModelPartForSequence>(l) + { + } + + PqArray::PqArray(::Gentoo::StringList & sl) : ModelPartForSequence<::Gentoo::StringList>(sl) { } - void PqTextArray::SetValue(ValueSourcePtr s) + template + void PqArray::SetValue(ValueSourcePtr s) + { + this->Model.clear(); + std::string v; + s->set(v); + if (v.size() < 3) return; + typedef boost::algorithm::split_iterator string_split_iterator; + string_split_iterator sfi(++v.begin(), --v.end(), boost::algorithm::first_finder(",", boost::algorithm::is_iequal())); + for(auto it = sfi; it != string_split_iterator(); ++it) { + this->Model.push_back(boost::lexical_cast(*it)); + } + } + + void PqArray::SetValue(ValueSourcePtr s) { Model.clear(); std::string v; @@ -20,7 +41,19 @@ namespace Slicer { l.yylex(); } - void PqTextArray::GetValue(ValueTargetPtr s) + template + void PqArray::GetValue(ValueTargetPtr s) + { + if (this->Model.empty()) s->get("{}"); + std::vector l2; + l2.reserve(this->Model.size()); + for(const auto & i : this->Model) { + l2.push_back(boost::lexical_cast(i)); + } + s->get("{" + boost::algorithm::join(l2, ",") + "}"); + } + + void PqArray::GetValue(ValueTargetPtr s) { if (Model.empty()) s->get("{}"); ::Gentoo::StringList l2(Model); diff --git a/gentoobrowse-api/domain/converters.h b/gentoobrowse-api/domain/converters.h index 6efde6f..da3e237 100644 --- a/gentoobrowse-api/domain/converters.h +++ b/gentoobrowse-api/domain/converters.h @@ -7,9 +7,19 @@ #include namespace Slicer { - class PqTextArray : public ModelPartForSequence<::Gentoo::StringList> { + template + class PqArray : public ModelPartForSequence> { public: - PqTextArray(::Gentoo::StringList &); + PqArray(std::vector &); + + void SetValue(ValueSourcePtr) override; + void GetValue(ValueTargetPtr) override; + }; + + template<> + class PqArray : public ModelPartForSequence<::Gentoo::StringList> { + public: + PqArray(::Gentoo::StringList &); void SetValue(ValueSourcePtr) override; void GetValue(ValueTargetPtr) override; diff --git a/gentoobrowse-api/domain/portage-models.ice b/gentoobrowse-api/domain/portage-models.ice index a14dbae..28083e8 100644 --- a/gentoobrowse-api/domain/portage-models.ice +++ b/gentoobrowse-api/domain/portage-models.ice @@ -5,7 +5,7 @@ "slicer:include:converters.h" ] module Gentoo { sequence Image; - [ "slicer:custommodelpart:PqTextArray" ] + [ "slicer:custommodelpart:PqArray" ] sequence StringList; class Category { -- cgit v1.2.3