formatting

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

View File

@ -5,34 +5,34 @@
class DokuWiki
{
public:
using error = std::runtime_error;
public:
using error = std::runtime_error;
struct PageInfo
{
std::string name;
std::string author;
std::string timestamp;
};
struct PageInfo
{
std::string name;
std::string author;
std::string timestamp;
};
public:
DokuWiki(const std::string &url, const std::string &username, const std::string &password);
~DokuWiki();
public:
DokuWiki(const std::string &url, const std::string &username,
const std::string &password);
~DokuWiki();
std::string getVersion();
std::string getTime();
std::string getPage(const std::string &pageName);
std::string getWikiTitle();
PageInfo getPageInfo(const std::string &pageName);
std::string getVersion();
std::string getTime();
std::string getPage(const std::string &pageName);
std::string getWikiTitle();
PageInfo getPageInfo(const std::string &pageName);
bool pageExists(const std::string &pageName);
void putPage(const std::string &pageName, const std::string &content);
void addPage(const std::string &pageName, const std::string &content);
bool pageExists(const std::string &pageName);
void putPage(const std::string &pageName, const std::string &content);
void addPage(const std::string &pageName, const std::string &content);
void appendToPage(const std::string &pageName, const std::string &content);
void appendToPage(const std::string &pageName, const std::string &content);
private:
class impl;
std::unique_ptr<impl> pimpl;
private:
class impl;
std::unique_ptr<impl> pimpl;
};

View File

@ -5,7 +5,8 @@
#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)}
{
}
@ -52,7 +53,8 @@ void DokuWiki::addPage(const std::string &pageName, const std::string &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);
}

View File

@ -2,10 +2,10 @@
#include <iostream>
template<>
template <>
xmlrpc_c::value DokuWiki::impl::executeCommand(const std::string &command,
const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes)
const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes)
{
xmlrpc_c::client_xml client(&m_clientTransport);
@ -29,15 +29,15 @@ xmlrpc_c::value DokuWiki::impl::executeCommand(const std::string &command,
return rpc->getResult();
}
template<>
xmlrpc_c::value_struct DokuWiki::impl::executeCommand(const std::string &command,
const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes)
template <>
xmlrpc_c::value_struct DokuWiki::impl::executeCommand(
const std::string &command, const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes)
{
try
{
return xmlrpc_c::value_struct(executeCommand<xmlrpc_c::value>(
command, params, attributes));
return xmlrpc_c::value_struct(
executeCommand<xmlrpc_c::value>(command, params, attributes));
}
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,
const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes)
const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes)
{
try
{
return xmlrpc_c::value_string(executeCommand<xmlrpc_c::value>(
command, params, attributes));
return xmlrpc_c::value_string(
executeCommand<xmlrpc_c::value>(command, params, attributes));
}
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,
const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes)
const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes)
{
try
{
return xmlrpc_c::value_int(executeCommand<xmlrpc_c::value>(
command, params, attributes));
return xmlrpc_c::value_int(
executeCommand<xmlrpc_c::value>(command, params, attributes));
}
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,
const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes)
const std::list<std::string> &params,
const std::map<std::string, xmlrpc_c::value> &attributes)
{
try
{
return xmlrpc_c::value_boolean(executeCommand<xmlrpc_c::value>(
command, params, attributes));
return xmlrpc_c::value_boolean(
executeCommand<xmlrpc_c::value>(command, params, attributes));
}
catch (girerr::error &e)
{
@ -94,15 +94,16 @@ bool DokuWiki::impl::executeCommand(const std::string &command,
}
DokuWiki::impl::impl(const std::string &url, const std::string &username,
const std::string &password)
const std::string &password)
: m_url(url)
{
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");
}
@ -122,7 +123,7 @@ std::string DokuWiki::impl::getTime()
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()
@ -133,16 +134,13 @@ std::string DokuWiki::impl::getWikiTitle()
DokuWiki::PageInfo DokuWiki::impl::getPageInfo(const std::string &pageName)
{
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"]);
DokuWiki::PageInfo pageInfo =
{
xmlrpc_c::value_string(values["name"]),
DokuWiki::PageInfo pageInfo = {xmlrpc_c::value_string(values["name"]),
xmlrpc_c::value_string(values["author"]),
std::asctime(std::localtime(&modificationTime))
};
std::asctime(std::localtime(&modificationTime))};
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 },
{{ "sum", xmlrpc_c::value_string("Added automatically") },
{"minor", xmlrpc_c::value_boolean(false) }}))
if (!executeCommand<bool>("wiki.putPage", {pageName, content},
{{"sum", xmlrpc_c::value_string("Added automatically")},
{"minor", xmlrpc_c::value_boolean(false)}}))
{
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))
{
@ -180,13 +180,13 @@ void DokuWiki::impl::addPage(const std::string &pageName, const std::string &con
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 },
{{ "sum", xmlrpc_c::value_string("Added automatically") },
{"minor", xmlrpc_c::value_boolean(false) }}))
if (!executeCommand<bool>("dokuwiki.appendPage", {pageName, content},
{{"sum", xmlrpc_c::value_string("Added automatically")},
{"minor", xmlrpc_c::value_boolean(false)}}))
{
throw std::runtime_error("failed to append to page");
}
}

View File

@ -9,30 +9,30 @@
class DokuWiki::impl
{
private:
std::string m_url;
xmlrpc_c::clientXmlTransport_curl m_clientTransport;
private:
std::string m_url;
xmlrpc_c::clientXmlTransport_curl m_clientTransport;
public:
impl(const std::string &url, const std::string &username, const std::string &password);
public:
impl(const std::string &url, const std::string &username,
const std::string &password);
void login(const std::string &username, const std::string &password);
std::string getVersion();
std::string getTime();
std::string getPage(const std::string &pageName);
std::string getWikiTitle();
void login(const std::string &username, const std::string &password);
std::string getVersion();
std::string getTime();
std::string getPage(const std::string &pageName);
std::string getWikiTitle();
DokuWiki::PageInfo getPageInfo(const std::string &pageName);
DokuWiki::PageInfo getPageInfo(const std::string &pageName);
bool pageExists(const std::string &pageName);
void putPage(const std::string &pageName, const std::string &content);
void addPage(const std::string &pageName, const std::string &content);
bool pageExists(const std::string &pageName);
void putPage(const std::string &pageName, const std::string &content);
void addPage(const std::string &pageName, const std::string &content);
void appendToPage(const std::string &pageName, const std::string &content);
void appendToPage(const std::string &pageName, const std::string &content);
template <typename ReturnType>
ReturnType executeCommand(const std::string &command,
const std::list<std::string> &params = {},
const std::map<std::string, xmlrpc_c::value> &attributes = {});
template <typename ReturnType>
ReturnType executeCommand(const std::string &command,
const std::list<std::string> &params = {},
const std::map<std::string, xmlrpc_c::value> &attributes = {});
};