summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gentoobrowse-api/domain/converters.cpp39
-rw-r--r--gentoobrowse-api/domain/converters.h14
-rw-r--r--gentoobrowse-api/domain/portage-models.ice2
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 {