diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-10-03 18:42:40 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-10-03 18:42:40 +0100 |
commit | 5d9f4d23923cc09cf44eb908354ea2df8d971d0a (patch) | |
tree | a0703a7158baa12b3c438501c66643d73847c8f6 | |
parent | Add method for getting ebuilds with details (archs and uses) (diff) | |
download | gentoobrowse-api-5d9f4d23923cc09cf44eb908354ea2df8d971d0a.tar.bz2 gentoobrowse-api-5d9f4d23923cc09cf44eb908354ea2df8d971d0a.tar.xz gentoobrowse-api-5d9f4d23923cc09cf44eb908354ea2df8d971d0a.zip |
Template PqArray
-rw-r--r-- | gentoobrowse-api/domain/converters.cpp | 39 | ||||
-rw-r--r-- | gentoobrowse-api/domain/converters.h | 14 | ||||
-rw-r--r-- | 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 <string> #include <boost/algorithm/string/join.hpp> +#include <boost/algorithm/string/split.hpp> namespace Slicer { - PqTextArray::PqTextArray(::Gentoo::StringList & sl) : + template<typename T> + PqArray<T>::PqArray(std::vector<T> & l) : + ModelPartForSequence<std::vector<T>>(l) + { + } + + PqArray<std::string>::PqArray(::Gentoo::StringList & sl) : ModelPartForSequence<::Gentoo::StringList>(sl) { } - void PqTextArray::SetValue(ValueSourcePtr s) + template<typename T> + void PqArray<T>::SetValue(ValueSourcePtr s) + { + this->Model.clear(); + std::string v; + s->set(v); + if (v.size() < 3) return; + typedef boost::algorithm::split_iterator<std::string::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<T>(*it)); + } + } + + void PqArray<std::string>::SetValue(ValueSourcePtr s) { Model.clear(); std::string v; @@ -20,7 +41,19 @@ namespace Slicer { l.yylex(); } - void PqTextArray::GetValue(ValueTargetPtr s) + template<typename T> + void PqArray<T>::GetValue(ValueTargetPtr s) + { + if (this->Model.empty()) s->get("{}"); + std::vector<std::string> l2; + l2.reserve(this->Model.size()); + for(const auto & i : this->Model) { + l2.push_back(boost::lexical_cast<std::string>(i)); + } + s->get("{" + boost::algorithm::join(l2, ",") + "}"); + } + + void PqArray<std::string>::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 <slicer/modelPartsTypes.impl.h> namespace Slicer { - class PqTextArray : public ModelPartForSequence<::Gentoo::StringList> { + template<typename T> + class PqArray : public ModelPartForSequence<std::vector<T>> { public: - PqTextArray(::Gentoo::StringList &); + PqArray(std::vector<T> &); + + void SetValue(ValueSourcePtr) override; + void GetValue(ValueTargetPtr) override; + }; + + template<> + class PqArray<std::string> : 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<byte> Image; - [ "slicer:custommodelpart:PqTextArray" ] + [ "slicer:custommodelpart:PqArray<std::string>" ] sequence<string> StringList; class Category { |