From 6480ca58a000e0de8c9fc2b3b7da2031afdc516d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 9 Feb 2019 11:51:51 +0000 Subject: Use string_view in interfaces --- gentoobrowse-api/api/Jamfile.jam | 2 ++ gentoobrowse-api/api/gb-base.ice | 10 +++++++++ gentoobrowse-api/api/portage.ice | 35 ++++++++++++++++++-------------- gentoobrowse-api/api/users.ice | 14 ++++++------- gentoobrowse-api/service/portageimpl.cpp | 28 ++++++++++++------------- gentoobrowse-api/service/portageimpl.h | 28 ++++++++++++------------- gentoobrowse-api/service/usersimpl.cpp | 14 ++++++------- gentoobrowse-api/service/usersimpl.h | 14 ++++++------- 8 files changed, 81 insertions(+), 64 deletions(-) create mode 100644 gentoobrowse-api/api/gb-base.ice diff --git a/gentoobrowse-api/api/Jamfile.jam b/gentoobrowse-api/api/Jamfile.jam index 6cd2480..b87967e 100644 --- a/gentoobrowse-api/api/Jamfile.jam +++ b/gentoobrowse-api/api/Jamfile.jam @@ -10,10 +10,12 @@ lib gentoobrowse-api : ..//dbppcore ../domain//gentoobrowse-domain /usr/share/slicer/ice + /usr/include/icetray slicer-db ../domain//gentoobrowse-domain : : . + /usr/include/icetray slicer-db ../domain//gentoobrowse-domain ../domain//gentoobrowse-domain diff --git a/gentoobrowse-api/api/gb-base.ice b/gentoobrowse-api/api/gb-base.ice new file mode 100644 index 0000000..e262a77 --- /dev/null +++ b/gentoobrowse-api/api/gb-base.ice @@ -0,0 +1,10 @@ +#ifndef GENTOO_BASE +#define GENTOO_BASE + +#include + +[["cpp:include:string_view_support.h"]] +#define stringview ["cpp:view-type:std::string_view"] string + +#endif + diff --git a/gentoobrowse-api/api/portage.ice b/gentoobrowse-api/api/portage.ice index 1366b38..e79ecff 100644 --- a/gentoobrowse-api/api/portage.ice +++ b/gentoobrowse-api/api/portage.ice @@ -1,21 +1,24 @@ +#ifndef GENTOO_PORTAGE +#define GENTOO_PORTAGE + +#include "gb-base.ice" #include #include -#include module Gentoo { interface Portage { idempotent Category getCategory(int id) throws Slicer::NoRowsReturned; - idempotent Category findCategory(string name) throws Slicer::NoRowsReturned; + idempotent Category findCategory(stringview name) throws Slicer::NoRowsReturned; idempotent Categories getAllCategories(); - idempotent Categories getCategoriesInSuper(string super); + idempotent Categories getCategoriesInSuper(stringview super); idempotent OverviewCategoriesBySuper getAllOverviewCategories(); - idempotent OverviewCategories getOverviewCategoriesInSuper(string super); + idempotent OverviewCategories getOverviewCategoriesInSuper(stringview super); idempotent Package getPackage(int id) throws Slicer::NoRowsReturned; - idempotent Package findPackage(string category, string package) throws Slicer::NoRowsReturned; + idempotent Package findPackage(stringview category, stringview package) throws Slicer::NoRowsReturned; idempotent Packages getAllPackages(); idempotent Packages getPackagesInCategory(int id); - idempotent SearchResultPackages getPackagesSearch(string query); + idempotent SearchResultPackages getPackagesSearch(stringview query); idempotent Ebuilds getPackageVersions(int id); idempotent EbuildDetails getPackageVersionDetails(int id); idempotent ChangeLog getPackageChangeLog(int id); @@ -31,22 +34,22 @@ module Gentoo { idempotent Packages getUserTrackedPackages(int userid); idempotent Ebuilds getUserTrackedRecentVersions(int userid, int limit); idempotent StringList getPackageUrls(int id); - idempotent Ebuilds getEbuildsByFilter(string filter); + idempotent Ebuilds getEbuildsByFilter(stringview filter); - idempotent Use getUse(string flag) throws Slicer::NoRowsReturned; + idempotent Use getUse(stringview flag) throws Slicer::NoRowsReturned; idempotent Uses getGlobalUses(); - idempotent Uses getGroupUses(string group); + idempotent Uses getGroupUses(stringview group); idempotent StringList getUseGroups(); - idempotent Uses getUseUsage(string flag); - idempotent Packages getUsePackages(string flag); - idempotent Uses getUsesSearch(string query); + idempotent Uses getUseUsage(stringview flag); + idempotent Packages getUsePackages(stringview flag); + idempotent Uses getUsesSearch(stringview query); idempotent Bug getBug(int id) throws Slicer::NoRowsReturned; idempotent Bugs getPackageBugs(int packageId); - idempotent SearchResultBugs getBugsSearch(string query); + idempotent SearchResultBugs getBugsSearch(stringview query); - idempotent NewsItem getNewsItem(string newsid) throws Slicer::NoRowsReturned; - idempotent News getNewsSearch(string query); + idempotent NewsItem getNewsItem(stringview newsid) throws Slicer::NoRowsReturned; + idempotent News getNewsSearch(stringview query); idempotent News getNewsRecent(int items); idempotent Repository getRepository(int id) throws Slicer::NoRowsReturned; @@ -54,3 +57,5 @@ module Gentoo { }; }; +#endif + diff --git a/gentoobrowse-api/api/users.ice b/gentoobrowse-api/api/users.ice index 8dd72a2..f6a444e 100644 --- a/gentoobrowse-api/api/users.ice +++ b/gentoobrowse-api/api/users.ice @@ -1,22 +1,22 @@ #ifndef GENTOO_USERS #define GENTOO_USERS +#include "gb-base.ice" #include -#include module Gentoo { sequence PackageIds; interface Users { - User authenticate(string username, string password) throws Slicer::NoRowsReturned; - User verify(string username, string verifyguid) throws Slicer::NoRowsReturned; + User authenticate(stringview username, stringview password) throws Slicer::NoRowsReturned; + User verify(stringview username, stringview verifyguid) throws Slicer::NoRowsReturned; User get(int id) throws Slicer::NoRowsReturned; - NewUser getNew(string username, string password) throws Slicer::NoRowsReturned; - User find(string username) throws Slicer::NoRowsReturned; - NewUser create(string username, string password, string realname, string email) throws DuplicateDetails; + NewUser getNew(stringview username, stringview password) throws Slicer::NoRowsReturned; + User find(stringview username) throws Slicer::NoRowsReturned; + NewUser create(stringview username, stringview password, stringview realname, stringview email) throws DuplicateDetails; void mailshotsent(int id); - void remove(int id, string password) throws Slicer::NoRowsReturned; + void remove(int id, stringview password) throws Slicer::NoRowsReturned; void prune(); void track(int userId, int packageId); diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp index f779649..79757e3 100644 --- a/gentoobrowse-api/service/portageimpl.cpp +++ b/gentoobrowse-api/service/portageimpl.cpp @@ -56,7 +56,7 @@ Portage::getCategory(Ice::Int id, const Ice::Current &) } Gentoo::CategoryPtr -Portage::findCategory(const std::string name, const Ice::Current &) +Portage::findCategory(const std::string_view name, const Ice::Current &) { return fetchCache(sql::portage::findCategory, 30, name); } @@ -68,7 +68,7 @@ Portage::getAllCategories(const Ice::Current &) } Gentoo::Categories -Portage::getCategoriesInSuper(const std::string super, const Ice::Current &) +Portage::getCategoriesInSuper(const std::string_view super, const Ice::Current &) { return fetchCache(sql::portage::getCategoriesInSuper, 30, super); } @@ -86,7 +86,7 @@ Portage::getAllOverviewCategories(const Ice::Current &) } Gentoo::OverviewCategories -Portage::getOverviewCategoriesInSuper(const std::string super, const Ice::Current &) +Portage::getOverviewCategoriesInSuper(const std::string_view super, const Ice::Current &) { return fetchCache(sql::portage::getOverviewCategoriesInSuper, 30, super); } @@ -98,7 +98,7 @@ Portage::getPackage(Ice::Int id, const Ice::Current &) } Gentoo::PackagePtr -Portage::findPackage(const std::string cat, const std::string pkg, const Ice::Current &) +Portage::findPackage(const std::string_view cat, const std::string_view pkg, const Ice::Current &) { return fetchCache(sql::portage::findPackage, 30, cat, pkg); } @@ -116,7 +116,7 @@ Portage::getPackagesInCategory(Ice::Int id, const Ice::Current &) } Gentoo::SearchResultPackages -Portage::getPackagesSearch(const std::string query, const Ice::Current &) +Portage::getPackagesSearch(const std::string_view query, const Ice::Current &) { return fetchCache(sql::portage::getPackagesSearch, 30, query, query); } @@ -176,7 +176,7 @@ Portage::getPackageUrls(Ice::Int id, const Ice::Current &) } Gentoo::Ebuilds -Portage::getEbuildsByFilter(const std::string filter, const Ice::Current &) +Portage::getEbuildsByFilter(const std::string_view filter, const Ice::Current &) { return fetchCache(sql::portage::getEbuildsByFilter, 30, filter); } @@ -218,7 +218,7 @@ Portage::getPackageUses(Ice::Int id, const Ice::Current &) } Gentoo::UsePtr -Portage::getUse(const std::string use, const Ice::Current &) +Portage::getUse(const std::string_view use, const Ice::Current &) { return fetchCache(sql::portage::getUse, 30, use, use); } @@ -230,7 +230,7 @@ Portage::getGlobalUses(const Ice::Current &) } Gentoo::Uses -Portage::getGroupUses(const std::string group, const Ice::Current &) +Portage::getGroupUses(const std::string_view group, const Ice::Current &) { return fetchCache(sql::portage::getGroupUses, 30, group); } @@ -242,19 +242,19 @@ Portage::getUseGroups(const Ice::Current &) } Gentoo::Uses -Portage::getUseUsage(const std::string use, const Ice::Current &) +Portage::getUseUsage(const std::string_view use, const Ice::Current &) { return fetchCache(sql::portage::getUseUsage, 30, use, use, use, use); } Gentoo::Packages -Portage::getUsePackages(const std::string use, const Ice::Current &) +Portage::getUsePackages(const std::string_view use, const Ice::Current &) { return fetchCache(sql::portage::getUsePackages, 30, use, use); } Gentoo::Uses -Portage::getUsesSearch(const std::string query, const Ice::Current &) +Portage::getUsesSearch(const std::string_view query, const Ice::Current &) { return fetchCache(sql::portage::getUsesSearch, 30, query); } @@ -272,19 +272,19 @@ Portage::getPackageBugs(Ice::Int packageId, const Ice::Current &) } Gentoo::SearchResultBugs -Portage::getBugsSearch(const std::string query, const Ice::Current &) +Portage::getBugsSearch(const std::string_view query, const Ice::Current &) { return fetchCache(sql::portage::getBugsSearch, 30, query, query); } Gentoo::NewsItemPtr -Portage::getNewsItem(const std::string id, const Ice::Current &) +Portage::getNewsItem(const std::string_view id, const Ice::Current &) { return fetchCache(sql::portage::getNewsItem, 30, id); } Gentoo::News -Portage::getNewsSearch(const std::string query, const Ice::Current &) +Portage::getNewsSearch(const std::string_view query, const Ice::Current &) { return fetchCache(sql::portage::getNewsSearch, 30, query); } diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h index 06721e8..ee72665 100644 --- a/gentoobrowse-api/service/portageimpl.h +++ b/gentoobrowse-api/service/portageimpl.h @@ -12,17 +12,17 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, IceTray::AbstractCachingDatab Portage(const DB::ConnectionPoolPtr & d); Gentoo::CategoryPtr getCategory(Ice::Int id, const Ice::Current &) override; - Gentoo::CategoryPtr findCategory(const std::string name, const Ice::Current &) override; + Gentoo::CategoryPtr findCategory(const std::string_view name, const Ice::Current &) override; Gentoo::Categories getAllCategories(const Ice::Current &) override; - Gentoo::Categories getCategoriesInSuper(const std::string, const Ice::Current &) override; + Gentoo::Categories getCategoriesInSuper(const std::string_view, const Ice::Current &) override; Gentoo::OverviewCategoriesBySuper getAllOverviewCategories(const Ice::Current &) override; - Gentoo::OverviewCategories getOverviewCategoriesInSuper(const std::string, const Ice::Current &) override; + Gentoo::OverviewCategories getOverviewCategoriesInSuper(const std::string_view, const Ice::Current &) override; Gentoo::PackagePtr getPackage(Ice::Int id, const Ice::Current &) override; - Gentoo::PackagePtr findPackage(const std::string, const std::string, const Ice::Current &) override; + Gentoo::PackagePtr findPackage(const std::string_view, const std::string_view, const Ice::Current &) override; Gentoo::Packages getPackagesInCategory(Ice::Int id, const Ice::Current &) override; Gentoo::Packages getAllPackages(const Ice::Current &) override; - Gentoo::SearchResultPackages getPackagesSearch(const std::string query, const Ice::Current &) override; + Gentoo::SearchResultPackages getPackagesSearch(const std::string_view query, const Ice::Current &) override; Gentoo::Ebuilds getPackageVersions(Ice::Int id, const Ice::Current &) override; Gentoo::EbuildDetails getPackageVersionDetails(Ice::Int id, const Ice::Current &) override; Gentoo::ChangeLog getPackageChangeLog(Ice::Int id, const Ice::Current &) override; @@ -38,22 +38,22 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, IceTray::AbstractCachingDatab Gentoo::Packages getUserTrackedPackages(Ice::Int userid, const Ice::Current &) override; Gentoo::Ebuilds getUserTrackedRecentVersions(Ice::Int userid, Ice::Int limit, const Ice::Current &) override; Gentoo::StringList getPackageUrls(Ice::Int id, const Ice::Current &) override; - Gentoo::Ebuilds getEbuildsByFilter(const std::string, const Ice::Current &) override; + Gentoo::Ebuilds getEbuildsByFilter(const std::string_view, const Ice::Current &) override; - Gentoo::UsePtr getUse(const std::string, const Ice::Current &) override; + Gentoo::UsePtr getUse(const std::string_view, const Ice::Current &) override; Gentoo::Uses getGlobalUses(const Ice::Current &) override; - Gentoo::Uses getGroupUses(const std::string, const Ice::Current &) override; + Gentoo::Uses getGroupUses(const std::string_view, const Ice::Current &) override; Gentoo::StringList getUseGroups(const Ice::Current &) override; - Gentoo::Uses getUseUsage(const std::string, const Ice::Current &) override; - Gentoo::Packages getUsePackages(const std::string, const Ice::Current &) override; - Gentoo::Uses getUsesSearch(const std::string, const Ice::Current &) override; + Gentoo::Uses getUseUsage(const std::string_view, const Ice::Current &) override; + Gentoo::Packages getUsePackages(const std::string_view, const Ice::Current &) override; + Gentoo::Uses getUsesSearch(const std::string_view, const Ice::Current &) override; Gentoo::BugPtr getBug(Ice::Int id, const Ice::Current &) override; Gentoo::Bugs getPackageBugs(Ice::Int packageId, const Ice::Current &) override; - Gentoo::SearchResultBugs getBugsSearch(const std::string query, const Ice::Current &) override; + Gentoo::SearchResultBugs getBugsSearch(const std::string_view query, const Ice::Current &) override; - Gentoo::NewsItemPtr getNewsItem(const std::string, const Ice::Current &) override; - Gentoo::News getNewsSearch(const std::string, const Ice::Current &) override; + Gentoo::NewsItemPtr getNewsItem(const std::string_view, const Ice::Current &) override; + Gentoo::News getNewsSearch(const std::string_view, const Ice::Current &) override; Gentoo::News getNewsRecent(Ice::Int, const Ice::Current &) override; Gentoo::Repository getRepository(Ice::Int, const Ice::Current &) override; diff --git a/gentoobrowse-api/service/usersimpl.cpp b/gentoobrowse-api/service/usersimpl.cpp index 446d61c..e50076d 100644 --- a/gentoobrowse-api/service/usersimpl.cpp +++ b/gentoobrowse-api/service/usersimpl.cpp @@ -24,13 +24,13 @@ Users::Users(const DB::ConnectionPoolPtr & d) : } Gentoo::UserPtr -Users::authenticate(const std::string username, const std::string password, const Ice::Current &) +Users::authenticate(const std::string_view username, const std::string_view password, const Ice::Current &) { return fetchCache(sql::users::authenticate, 30, username, password); } Gentoo::UserPtr -Users::verify(const std::string username, const std::string verifyguid, const Ice::Current &) +Users::verify(const std::string_view username, const std::string_view verifyguid, const Ice::Current &) { return fetch(sql::users::verify, username, verifyguid); } @@ -42,19 +42,19 @@ Users::get(Ice::Int id, const Ice::Current &) } Gentoo::NewUserPtr -Users::getNew(const std::string username, const std::string password, const Ice::Current &) +Users::getNew(const std::string_view username, const std::string_view password, const Ice::Current &) { return fetch(sql::users::getNew, username, password); } Gentoo::UserPtr -Users::find(const std::string username, const Ice::Current &) +Users::find(const std::string_view username, const Ice::Current &) { return fetch(sql::users::find, username); } Gentoo::NewUserPtr -Users::authOrCreate(const std::string & username, const std::string & password, const std::string & realname, const std::string & email) +Users::authOrCreate(const std::string_view & username, const std::string_view & password, const std::string_view & realname, const std::string_view & email) { auto existing = fetch>(sql::users::getNew, username, password); if (existing && *existing) { @@ -64,7 +64,7 @@ Users::authOrCreate(const std::string & username, const std::string & password, } Gentoo::NewUserPtr -Users::create(const std::string username, const std::string password, const std::string realname, const std::string email, const Ice::Current & current) +Users::create(const std::string_view username, const std::string_view password, const std::string_view realname, const std::string_view email, const Ice::Current & current) { auto notifications = Ice::checkedCast(current.adapter->getCommunicator()->stringToProxy("notifications")); BOOST_ASSERT(notifications); @@ -93,7 +93,7 @@ Users::mailshotsent(Ice::Int id, const Ice::Current &) } void -Users::remove(Ice::Int id, const std::string password, const Ice::Current &) +Users::remove(Ice::Int id, const std::string_view password, const Ice::Current &) { auto dbc = db->get(); auto del = sql::users::safeDelete.modify(dbc.get()); diff --git a/gentoobrowse-api/service/usersimpl.h b/gentoobrowse-api/service/usersimpl.h index 5baec3b..e85c305 100644 --- a/gentoobrowse-api/service/usersimpl.h +++ b/gentoobrowse-api/service/usersimpl.h @@ -11,15 +11,15 @@ class DLL_PUBLIC Users : public Gentoo::Users, IceTray::AbstractCachingDatabaseC public: Users(const DB::ConnectionPoolPtr & d); - Gentoo::UserPtr authenticate(const std::string, const std::string, const Ice::Current &) override; - Gentoo::UserPtr verify(const std::string, const std::string, const Ice::Current &) override; + Gentoo::UserPtr authenticate(const std::string_view, const std::string_view, const Ice::Current &) override; + Gentoo::UserPtr verify(const std::string_view, const std::string_view, const Ice::Current &) override; Gentoo::UserPtr get(Ice::Int id, const Ice::Current &) override; - Gentoo::NewUserPtr getNew(const std::string, const std::string, const Ice::Current &) override; - Gentoo::UserPtr find(const std::string username, const Ice::Current &) override; - Gentoo::NewUserPtr create(const std::string, const std::string, const std::string, const std::string, const Ice::Current &) override; + Gentoo::NewUserPtr getNew(const std::string_view, const std::string_view, const Ice::Current &) override; + Gentoo::UserPtr find(const std::string_view username, const Ice::Current &) override; + Gentoo::NewUserPtr create(const std::string_view, const std::string_view, const std::string_view, const std::string_view, const Ice::Current &) override; void mailshotsent(Ice::Int id, const Ice::Current &) override; - void remove(Ice::Int id, const std::string, const Ice::Current &) override; + void remove(Ice::Int id, const std::string_view, const Ice::Current &) override; void prune(const Ice::Current &) override; void track(Ice::Int, Ice::Int, const Ice::Current &) override; @@ -27,7 +27,7 @@ class DLL_PUBLIC Users : public Gentoo::Users, IceTray::AbstractCachingDatabaseC Gentoo::PackageIds tracked(Ice::Int, const Ice::Current &) override; private: - DLL_PRIVATE Gentoo::NewUserPtr authOrCreate(const std::string &, const std::string &, const std::string &, const std::string &); + DLL_PRIVATE Gentoo::NewUserPtr authOrCreate(const std::string_view &, const std::string_view &, const std::string_view &, const std::string_view &); }; } } -- cgit v1.2.3