formatting

This commit is contained in:
Michael Mandl 2018-05-09 08:56:43 +02:00
parent a0ac1a7975
commit b7c3c4c042
4 changed files with 100 additions and 98 deletions

View file

@ -5,7 +5,7 @@
class DokuWiki class DokuWiki
{ {
public: public:
using error = std::runtime_error; using error = std::runtime_error;
struct PageInfo struct PageInfo
@ -15,8 +15,9 @@ class DokuWiki
std::string timestamp; std::string timestamp;
}; };
public: public:
DokuWiki(const std::string &url, const std::string &username, const std::string &password); DokuWiki(const std::string &url, const std::string &username,
const std::string &password);
~DokuWiki(); ~DokuWiki();
std::string getVersion(); std::string getVersion();
@ -31,8 +32,7 @@ class DokuWiki
void appendToPage(const std::string &pageName, const std::string &content); void appendToPage(const std::string &pageName, const std::string &content);
private: private:
class impl; class impl;
std::unique_ptr<impl> pimpl; std::unique_ptr<impl> pimpl;
}; };

View file

@ -5,7 +5,8 @@
#include <iostream> #include <iostream>
DokuWiki::DokuWiki(const std::string &url, const std::string &username, const std::string &password) DokuWiki::DokuWiki(const std::string &url, const std::string &username,
const std::string &password)
: pimpl{std::make_unique<impl>(url, username, password)} : pimpl{std::make_unique<impl>(url, username, password)}
{ {
} }
@ -52,7 +53,8 @@ void DokuWiki::addPage(const std::string &pageName, const std::string &content)
pimpl->addPage(pageName, content); pimpl->addPage(pageName, content);
} }
void DokuWiki::appendToPage(const std::string &pageName, const std::string &content) void DokuWiki::appendToPage(
const std::string &pageName, const std::string &content)
{ {
pimpl->appendToPage(pageName, content); pimpl->appendToPage(pageName, content);
} }

View file

@ -2,7 +2,7 @@
#include <iostream> #include <iostream>
template<> template <>
xmlrpc_c::value DokuWiki::impl::executeCommand(const std::string &command, xmlrpc_c::value DokuWiki::impl::executeCommand(const std::string &command,
const std::list<std::string> &params, const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes) const std::map<std::string, xmlrpc_c::value> &attributes)
@ -29,15 +29,15 @@ xmlrpc_c::value DokuWiki::impl::executeCommand(const std::string &command,
return rpc->getResult(); return rpc->getResult();
} }
template<> template <>
xmlrpc_c::value_struct DokuWiki::impl::executeCommand(const std::string &command, xmlrpc_c::value_struct DokuWiki::impl::executeCommand(
const std::list<std::string> &params, const std::string &command, const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes) const std::map<std::string, xmlrpc_c::value> &attributes)
{ {
try try
{ {
return xmlrpc_c::value_struct(executeCommand<xmlrpc_c::value>( return xmlrpc_c::value_struct(
command, params, attributes)); executeCommand<xmlrpc_c::value>(command, params, attributes));
} }
catch (girerr::error &e) catch (girerr::error &e)
{ {
@ -45,15 +45,15 @@ xmlrpc_c::value_struct DokuWiki::impl::executeCommand(const std::string &command
} }
} }
template<> template <>
std::string DokuWiki::impl::executeCommand(const std::string &command, std::string DokuWiki::impl::executeCommand(const std::string &command,
const std::list<std::string> &params, const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes) const std::map<std::string, xmlrpc_c::value> &attributes)
{ {
try try
{ {
return xmlrpc_c::value_string(executeCommand<xmlrpc_c::value>( return xmlrpc_c::value_string(
command, params, attributes)); executeCommand<xmlrpc_c::value>(command, params, attributes));
} }
catch (girerr::error &e) catch (girerr::error &e)
{ {
@ -61,15 +61,15 @@ std::string DokuWiki::impl::executeCommand(const std::string &command,
} }
} }
template<> template <>
int DokuWiki::impl::executeCommand(const std::string &command, int DokuWiki::impl::executeCommand(const std::string &command,
const std::list<std::string> &params, const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes) const std::map<std::string, xmlrpc_c::value> &attributes)
{ {
try try
{ {
return xmlrpc_c::value_int(executeCommand<xmlrpc_c::value>( return xmlrpc_c::value_int(
command, params, attributes)); executeCommand<xmlrpc_c::value>(command, params, attributes));
} }
catch (girerr::error &e) catch (girerr::error &e)
{ {
@ -77,15 +77,15 @@ int DokuWiki::impl::executeCommand(const std::string &command,
} }
} }
template<> template <>
bool DokuWiki::impl::executeCommand(const std::string &command, bool DokuWiki::impl::executeCommand(const std::string &command,
const std::list<std::string> &params, const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes) const std::map<std::string, xmlrpc_c::value> &attributes)
{ {
try try
{ {
return xmlrpc_c::value_boolean(executeCommand<xmlrpc_c::value>( return xmlrpc_c::value_boolean(
command, params, attributes)); executeCommand<xmlrpc_c::value>(command, params, attributes));
} }
catch (girerr::error &e) catch (girerr::error &e)
{ {
@ -100,9 +100,10 @@ DokuWiki::impl::impl(const std::string &url, const std::string &username,
login(username, password); login(username, password);
} }
void DokuWiki::impl::login(const std::string &username, const std::string &password) void DokuWiki::impl::login(
const std::string &username, const std::string &password)
{ {
if (executeCommand<bool>("dokuwiki.login", { username, password }) == false) if (executeCommand<bool>("dokuwiki.login", {username, password}) == false)
{ {
throw DokuWiki::error("login failed"); throw DokuWiki::error("login failed");
} }
@ -122,7 +123,7 @@ std::string DokuWiki::impl::getTime()
std::string DokuWiki::impl::getPage(const std::string &pageName) std::string DokuWiki::impl::getPage(const std::string &pageName)
{ {
return executeCommand<std::string>("wiki.getPage", { pageName }); return executeCommand<std::string>("wiki.getPage", {pageName});
} }
std::string DokuWiki::impl::getWikiTitle() std::string DokuWiki::impl::getWikiTitle()
@ -133,16 +134,13 @@ std::string DokuWiki::impl::getWikiTitle()
DokuWiki::PageInfo DokuWiki::impl::getPageInfo(const std::string &pageName) DokuWiki::PageInfo DokuWiki::impl::getPageInfo(const std::string &pageName)
{ {
auto values = static_cast<std::map<std::string, xmlrpc_c::value>>( auto values = static_cast<std::map<std::string, xmlrpc_c::value>>(
executeCommand<xmlrpc_c::value_struct>("wiki.getPageInfo", { pageName })); executeCommand<xmlrpc_c::value_struct>("wiki.getPageInfo", {pageName}));
std::time_t modificationTime = xmlrpc_c::value_int(values["version"]); std::time_t modificationTime = xmlrpc_c::value_int(values["version"]);
DokuWiki::PageInfo pageInfo = DokuWiki::PageInfo pageInfo = {xmlrpc_c::value_string(values["name"]),
{
xmlrpc_c::value_string(values["name"]),
xmlrpc_c::value_string(values["author"]), xmlrpc_c::value_string(values["author"]),
std::asctime(std::localtime(&modificationTime)) std::asctime(std::localtime(&modificationTime))};
};
return pageInfo; return pageInfo;
} }
@ -160,17 +158,19 @@ bool DokuWiki::impl::pageExists(const std::string &pageName)
} }
} }
void DokuWiki::impl::putPage(const std::string &pageName, const std::string &content) void DokuWiki::impl::putPage(
const std::string &pageName, const std::string &content)
{ {
if (!executeCommand<bool>("wiki.putPage", { pageName, content }, if (!executeCommand<bool>("wiki.putPage", {pageName, content},
{{ "sum", xmlrpc_c::value_string("Added automatically") }, {{"sum", xmlrpc_c::value_string("Added automatically")},
{"minor", xmlrpc_c::value_boolean(false) }})) {"minor", xmlrpc_c::value_boolean(false)}}))
{ {
throw std::runtime_error("failed to add page"); throw std::runtime_error("failed to add page");
} }
} }
void DokuWiki::impl::addPage(const std::string &pageName, const std::string &content) void DokuWiki::impl::addPage(
const std::string &pageName, const std::string &content)
{ {
if (pageExists(pageName)) if (pageExists(pageName))
{ {
@ -180,13 +180,13 @@ void DokuWiki::impl::addPage(const std::string &pageName, const std::string &con
putPage(pageName, content); putPage(pageName, content);
} }
void DokuWiki::impl::appendToPage(const std::string &pageName, const std::string &content) void DokuWiki::impl::appendToPage(
const std::string &pageName, const std::string &content)
{ {
if (!executeCommand<bool>("dokuwiki.appendPage", { pageName, content }, if (!executeCommand<bool>("dokuwiki.appendPage", {pageName, content},
{{ "sum", xmlrpc_c::value_string("Added automatically") }, {{"sum", xmlrpc_c::value_string("Added automatically")},
{"minor", xmlrpc_c::value_boolean(false) }})) {"minor", xmlrpc_c::value_boolean(false)}}))
{ {
throw std::runtime_error("failed to append to page"); throw std::runtime_error("failed to append to page");
} }
} }

View file

@ -9,12 +9,13 @@
class DokuWiki::impl class DokuWiki::impl
{ {
private: private:
std::string m_url; std::string m_url;
xmlrpc_c::clientXmlTransport_curl m_clientTransport; xmlrpc_c::clientXmlTransport_curl m_clientTransport;
public: public:
impl(const std::string &url, const std::string &username, const std::string &password); impl(const std::string &url, const std::string &username,
const std::string &password);
void login(const std::string &username, const std::string &password); void login(const std::string &username, const std::string &password);
std::string getVersion(); std::string getVersion();
@ -35,4 +36,3 @@ class DokuWiki::impl
const std::list<std::string> &params = {}, const std::list<std::string> &params = {},
const std::map<std::string, xmlrpc_c::value> &attributes = {}); const std::map<std::string, xmlrpc_c::value> &attributes = {});
}; };