From d4291caf3c9515eb4bf8d5a1d197deafff00f450 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 27 Jun 2016 22:30:03 +0100 Subject: Move model support code in domain lib --- gentoobrowse-api/domain/Jamfile.jam | 11 +++- gentoobrowse-api/domain/converters.cpp | 42 +++++++++++++++ gentoobrowse-api/domain/converters.h | 26 ++++++++++ gentoobrowse-api/domain/unpackPqTextArray.h | 27 ++++++++++ gentoobrowse-api/domain/unpackPqTextArray.ll | 75 +++++++++++++++++++++++++++ gentoobrowse-api/service/Jamfile.jam | 4 -- gentoobrowse-api/service/converters.cpp | 41 --------------- gentoobrowse-api/service/converters.h | 21 -------- gentoobrowse-api/service/unpackPqTextArray.h | 27 ---------- gentoobrowse-api/service/unpackPqTextArray.ll | 75 --------------------------- 10 files changed, 180 insertions(+), 169 deletions(-) create mode 100644 gentoobrowse-api/domain/converters.cpp create mode 100644 gentoobrowse-api/domain/converters.h create mode 100644 gentoobrowse-api/domain/unpackPqTextArray.h create mode 100644 gentoobrowse-api/domain/unpackPqTextArray.ll delete mode 100644 gentoobrowse-api/service/converters.cpp delete mode 100644 gentoobrowse-api/service/converters.h delete mode 100644 gentoobrowse-api/service/unpackPqTextArray.h delete mode 100644 gentoobrowse-api/service/unpackPqTextArray.ll diff --git a/gentoobrowse-api/domain/Jamfile.jam b/gentoobrowse-api/domain/Jamfile.jam index 1218e03..3fc393b 100644 --- a/gentoobrowse-api/domain/Jamfile.jam +++ b/gentoobrowse-api/domain/Jamfile.jam @@ -1,13 +1,22 @@ +import lex ; + lib gentoobrowse-domain : - [ glob *.ice ] + [ glob *.ice *.ll *.cpp ] : + yes ..//Ice ..//IceUtil ..//pthread + ..//slicer + ..//adhocutil + ..//boost_date_time + . : : ..//Ice ..//IceUtil ..//pthread + ..//slicer + ..//adhocutil . ; diff --git a/gentoobrowse-api/domain/converters.cpp b/gentoobrowse-api/domain/converters.cpp new file mode 100644 index 0000000..9d0b795 --- /dev/null +++ b/gentoobrowse-api/domain/converters.cpp @@ -0,0 +1,42 @@ +#include +#include "converters.h" +#include "unpackPqTextArray.h" +#include +#include + +namespace Slicer { + ::Gentoo::StringList + unpackPqTextArray(const std::string & s) + { + ::Gentoo::StringList list; + std::stringstream ss(s); + ::Portage::Utils::UnpackPqTextArray l(ss, list); + l.yylex(); + return list; + } + + std::string + packPqTextArray(const ::Gentoo::StringList & l) + { + if (l.empty()) return "{}"; + ::Gentoo::StringList l2(l); + for(auto & i : l2) { + boost::algorithm::replace_all(i, "\"", "\\\""); + i = "\"" + i + "\""; + } + return "{" + boost::algorithm::join(l2, ",") + "}"; + } + + boost::posix_time::ptime + shortDateToPosixTime(const std::string & s) + { + return boost::posix_time::ptime(boost::gregorian::from_simple_string(s)); + } + + std::string + posixTimeToShortDate(const boost::posix_time::ptime & s) + { + return boost::gregorian::to_sql_string(s.date()); + } +} + diff --git a/gentoobrowse-api/domain/converters.h b/gentoobrowse-api/domain/converters.h new file mode 100644 index 0000000..5bb9c4b --- /dev/null +++ b/gentoobrowse-api/domain/converters.h @@ -0,0 +1,26 @@ +#ifndef something +#define something + +#include +#include + +namespace Slicer { + DLL_PUBLIC + ::Gentoo::StringList + unpackPqTextArray(const std::string & s); + + DLL_PUBLIC + std::string + packPqTextArray(const ::Gentoo::StringList & l); + + DLL_PUBLIC + boost::posix_time::ptime + shortDateToPosixTime(const std::string & s); + + DLL_PUBLIC + std::string + posixTimeToShortDate(const boost::posix_time::ptime & s); +} + +#endif + diff --git a/gentoobrowse-api/domain/unpackPqTextArray.h b/gentoobrowse-api/domain/unpackPqTextArray.h new file mode 100644 index 0000000..246be71 --- /dev/null +++ b/gentoobrowse-api/domain/unpackPqTextArray.h @@ -0,0 +1,27 @@ +#ifndef JSONFLEXLEXER_H +#define JSONFLEXLEXER_H + +#include +#ifndef yyFlexLexer +#define yyFlexLexer pqBaseFlexLexer +#include +#endif + +namespace Portage { + namespace Utils { + class UnpackPqTextArray : public yyFlexLexer { + public: + UnpackPqTextArray(std::istream &, ::Gentoo::StringList & sl); + + int yylex() override; + void LexerError(const char * msg) override; + + private: + ::Gentoo::StringList & list; + }; + } +} + +#endif + + diff --git a/gentoobrowse-api/domain/unpackPqTextArray.ll b/gentoobrowse-api/domain/unpackPqTextArray.ll new file mode 100644 index 0000000..e4b0ccd --- /dev/null +++ b/gentoobrowse-api/domain/unpackPqTextArray.ll @@ -0,0 +1,75 @@ +%option batch +%option c++ +%option noyywrap +%option 8bit +%option stack +%option yylineno +%option yyclass="Portage::Utils::UnpackPqTextArray" +%option prefix="pqBase" + +%{ +#include "unpackPqTextArray.h" +#include +#pragma GCC diagnostic ignored "-Wsign-compare" +%} + +begin "{" +end "}" +comma , +unquoted [^,\"}]+ +quote \" +esc \\. +char [^"] + +%x FIRST +%x AFTER +%x NEXT +%x QUOTED + +%% + +{begin} { + yy_push_state(FIRST); +} +{end} { + yy_pop_state(); +} +{unquoted} { + list.push_back(YYText()); + BEGIN(AFTER); +} +{quote} { + list.push_back(std::string()); + BEGIN(QUOTED); +} +{comma} { + BEGIN(NEXT); +} +{quote} { + BEGIN(AFTER); +} +{esc} { + list.back().push_back(*(YYText() + 1)); +} +{char} { + list.back().append(YYText()); +} + +%% + +namespace Portage { + namespace Utils { + UnpackPqTextArray::UnpackPqTextArray(std::istream & f, ::Gentoo::StringList & sl) : + yyFlexLexer(&f, NULL), + list(sl) + { + } + + void + UnpackPqTextArray::LexerError(const char * msg) + { + throw std::runtime_error(msg); + } + } +} + diff --git a/gentoobrowse-api/service/Jamfile.jam b/gentoobrowse-api/service/Jamfile.jam index 4cb3ce6..a065393 100644 --- a/gentoobrowse-api/service/Jamfile.jam +++ b/gentoobrowse-api/service/Jamfile.jam @@ -1,4 +1,3 @@ -import lex ; import icetray ; lib icetray : : : : /usr/include/icetray ; @@ -6,11 +5,8 @@ lib git2 ; lib gentoobrowse-service : [ glob-tree *.cpp : bin ] - [ glob *.ll ] [ glob-tree *.sql ] - [ glob ../domain/*.ice ] : - pure ..//adhocutil icetray git2 diff --git a/gentoobrowse-api/service/converters.cpp b/gentoobrowse-api/service/converters.cpp deleted file mode 100644 index e8b19f5..0000000 --- a/gentoobrowse-api/service/converters.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include "unpackPqTextArray.h" -#include -#include - -namespace Slicer { - ::Gentoo::StringList - unpackPqTextArray(const std::string & s) - { - ::Gentoo::StringList list; - std::stringstream ss(s); - ::Portage::Utils::UnpackPqTextArray l(ss, list); - l.yylex(); - return list; - } - - std::string - packPqTextArray(const ::Gentoo::StringList & l) - { - if (l.empty()) return "{}"; - ::Gentoo::StringList l2(l); - for(auto & i : l2) { - boost::algorithm::replace_all(i, "\"", "\\\""); - i = "\"" + i + "\""; - } - return "{" + boost::algorithm::join(l2, ",") + "}"; - } - - boost::posix_time::ptime - shortDateToPosixTime(const std::string & s) - { - return boost::posix_time::ptime(boost::gregorian::from_simple_string(s)); - } - - std::string - posixTimeToShortDate(const boost::posix_time::ptime & s) - { - return boost::gregorian::to_sql_string(s.date()); - } -} - diff --git a/gentoobrowse-api/service/converters.h b/gentoobrowse-api/service/converters.h deleted file mode 100644 index 89a7881..0000000 --- a/gentoobrowse-api/service/converters.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef something -#define something - -#include - -namespace Slicer { - ::Gentoo::StringList - unpackPqTextArray(const std::string & s); - - std::string - packPqTextArray(const ::Gentoo::StringList & l); - - boost::posix_time::ptime - shortDateToPosixTime(const std::string & s); - - std::string - posixTimeToShortDate(const boost::posix_time::ptime & s); -} - -#endif - diff --git a/gentoobrowse-api/service/unpackPqTextArray.h b/gentoobrowse-api/service/unpackPqTextArray.h deleted file mode 100644 index 246be71..0000000 --- a/gentoobrowse-api/service/unpackPqTextArray.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef JSONFLEXLEXER_H -#define JSONFLEXLEXER_H - -#include -#ifndef yyFlexLexer -#define yyFlexLexer pqBaseFlexLexer -#include -#endif - -namespace Portage { - namespace Utils { - class UnpackPqTextArray : public yyFlexLexer { - public: - UnpackPqTextArray(std::istream &, ::Gentoo::StringList & sl); - - int yylex() override; - void LexerError(const char * msg) override; - - private: - ::Gentoo::StringList & list; - }; - } -} - -#endif - - diff --git a/gentoobrowse-api/service/unpackPqTextArray.ll b/gentoobrowse-api/service/unpackPqTextArray.ll deleted file mode 100644 index e4b0ccd..0000000 --- a/gentoobrowse-api/service/unpackPqTextArray.ll +++ /dev/null @@ -1,75 +0,0 @@ -%option batch -%option c++ -%option noyywrap -%option 8bit -%option stack -%option yylineno -%option yyclass="Portage::Utils::UnpackPqTextArray" -%option prefix="pqBase" - -%{ -#include "unpackPqTextArray.h" -#include -#pragma GCC diagnostic ignored "-Wsign-compare" -%} - -begin "{" -end "}" -comma , -unquoted [^,\"}]+ -quote \" -esc \\. -char [^"] - -%x FIRST -%x AFTER -%x NEXT -%x QUOTED - -%% - -{begin} { - yy_push_state(FIRST); -} -{end} { - yy_pop_state(); -} -{unquoted} { - list.push_back(YYText()); - BEGIN(AFTER); -} -{quote} { - list.push_back(std::string()); - BEGIN(QUOTED); -} -{comma} { - BEGIN(NEXT); -} -{quote} { - BEGIN(AFTER); -} -{esc} { - list.back().push_back(*(YYText() + 1)); -} -{char} { - list.back().append(YYText()); -} - -%% - -namespace Portage { - namespace Utils { - UnpackPqTextArray::UnpackPqTextArray(std::istream & f, ::Gentoo::StringList & sl) : - yyFlexLexer(&f, NULL), - list(sl) - { - } - - void - UnpackPqTextArray::LexerError(const char * msg) - { - throw std::runtime_error(msg); - } - } -} - -- cgit v1.2.3