From 0f2f2011ea41a8285fa48572e413a4441b69a7ea Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 25 Sep 2016 00:18:45 +0100 Subject: Use a custom model part to read string lists in bulk from the DB --- gentoobrowse-api/domain/converters.cpp | 26 ++++++++++++++++++++++ gentoobrowse-api/domain/converters.h | 10 +++++++++ gentoobrowse-api/domain/portage-models.ice | 8 +++---- .../service/maintenancePackageTree.cpp | 1 + 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/gentoobrowse-api/domain/converters.cpp b/gentoobrowse-api/domain/converters.cpp index 9d0b795..9f1f6d8 100644 --- a/gentoobrowse-api/domain/converters.cpp +++ b/gentoobrowse-api/domain/converters.cpp @@ -5,6 +5,32 @@ #include namespace Slicer { + PqTextArray::PqTextArray(::Gentoo::StringList & sl) : + ModelPartForSequence<::Gentoo::StringList>(sl) + { + } + + void PqTextArray::SetValue(ValueSourcePtr s) + { + Model.clear(); + std::string v; + s->set(v); + std::stringstream ss(v); + ::Portage::Utils::UnpackPqTextArray l(ss, Model); + l.yylex(); + } + + void PqTextArray::GetValue(ValueTargetPtr s) + { + if (Model.empty()) s->get("{}"); + ::Gentoo::StringList l2(Model); + for(auto & i : l2) { + boost::algorithm::replace_all(i, "\"", "\\\""); + i = "\"" + i + "\""; + } + s->get("{" + boost::algorithm::join(l2, ",") + "}"); + } + ::Gentoo::StringList unpackPqTextArray(const std::string & s) { diff --git a/gentoobrowse-api/domain/converters.h b/gentoobrowse-api/domain/converters.h index 5bb9c4b..6efde6f 100644 --- a/gentoobrowse-api/domain/converters.h +++ b/gentoobrowse-api/domain/converters.h @@ -2,9 +2,19 @@ #define something #include +#include #include +#include namespace Slicer { + class PqTextArray : public ModelPartForSequence<::Gentoo::StringList> { + public: + PqTextArray(::Gentoo::StringList &); + + void SetValue(ValueSourcePtr) override; + void GetValue(ValueTargetPtr) override; + }; + DLL_PUBLIC ::Gentoo::StringList unpackPqTextArray(const std::string & s); diff --git a/gentoobrowse-api/domain/portage-models.ice b/gentoobrowse-api/domain/portage-models.ice index dc4a57e..a14dbae 100644 --- a/gentoobrowse-api/domain/portage-models.ice +++ b/gentoobrowse-api/domain/portage-models.ice @@ -1,10 +1,11 @@ #ifndef GENTOO_PORTAGE_MODELS #define GENTOO_PORTAGE_MODELS -[["cpp:include:boost/date_time/posix_time/posix_time.hpp"]] - +[ "slicer:include:boost/date_time/posix_time/posix_time.hpp", + "slicer:include:converters.h" ] module Gentoo { sequence Image; + [ "slicer:custommodelpart:PqTextArray" ] sequence StringList; class Category { @@ -71,13 +72,10 @@ module Gentoo { string title; [ "slicer:conversion:boost.posix_time.ptime:posixTimeToShortDate:shortDateToPosixTime" ] string posted; - [ "slicer:conversion:std.string:unpackPqTextArray:packPqTextArray" ] StringList body; optional(0) string authorname; optional(1) string authoremail; - [ "slicer:conversion:std.string:unpackPqTextArray:packPqTextArray" ] StringList atomspec; - [ "slicer:conversion:std.string:unpackPqTextArray:packPqTextArray" ] StringList urls; }; diff --git a/gentoobrowse-api/service/maintenancePackageTree.cpp b/gentoobrowse-api/service/maintenancePackageTree.cpp index a78c41d..df06de7 100644 --- a/gentoobrowse-api/service/maintenancePackageTree.cpp +++ b/gentoobrowse-api/service/maintenancePackageTree.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3