diff options
Diffstat (limited to 'gentoobrowse-api/domain/converters.cpp')
-rw-r--r-- | gentoobrowse-api/domain/converters.cpp | 39 |
1 files changed, 36 insertions, 3 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); |