diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-09-25 00:18:45 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-09-25 00:18:45 +0100 |
commit | cb11e21e012c166b6e010f6b5529422f3bdf27ed (patch) | |
tree | fd0d054a18a79ee68984eff0894852ef682233e0 | |
parent | Throw and transport ICE exceptions when things aren't found (diff) | |
download | gentoobrowse-api-cb11e21e012c166b6e010f6b5529422f3bdf27ed.tar.bz2 gentoobrowse-api-cb11e21e012c166b6e010f6b5529422f3bdf27ed.tar.xz gentoobrowse-api-cb11e21e012c166b6e010f6b5529422f3bdf27ed.zip |
Use a custom model part to read string lists in bulk from the DB
-rw-r--r-- | gentoobrowse-api/domain/converters.cpp | 26 | ||||
-rw-r--r-- | gentoobrowse-api/domain/converters.h | 10 | ||||
-rw-r--r-- | gentoobrowse-api/domain/portage-models.ice | 8 | ||||
-rw-r--r-- | gentoobrowse-api/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 <boost/algorithm/string/join.hpp> 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 <portage-models.h> +#include <boost/date_time/posix_time/posix_time.hpp> #include <visibility.h> +#include <slicer/modelPartsTypes.impl.h> 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<byte> Image; + [ "slicer:custommodelpart:PqTextArray" ] sequence<string> 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 <buffer.h> #include <scopeExit.h> #include <boost/filesystem/operations.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/algorithm/string/predicate.hpp> #include <sql/maintenance/fileListCreateRaw.sql.h> #include <sql/maintenance/fileListCreate.sql.h> |