Update on Configuration and CppCheck refactor

This commit is contained in:
sale 2016-12-21 17:48:38 +00:00
parent 013f69b1ca
commit 02f332c34f
16 changed files with 45 additions and 32 deletions

View File

@ -2,6 +2,9 @@
#include "utils/config/config.hpp"
#include <string>
#include <set>
namespace config
{
@ -15,6 +18,7 @@ class MemgraphConfig
public:
static const char *env_config_key;
static const char *default_file_path;
static std::set<std::string> arguments;
};
// -- all possible Memgraph's keys --
@ -31,6 +35,8 @@ inline size_t to_int(std::string &&s) { return stoull(s); }
// code uses this define for key access
// _KEY_ is value from all possible keys that are listed above
#define CONFIG_REGISTER_ARGS(ARGC, ARGV) \
config::Config<config::MemgraphConfig>::instance().register_args(ARGC, ARGV);
#define CONFIG(_KEY_) config::Config<config::MemgraphConfig>::instance()[_KEY_]
#define CONFIG_INTEGER(_KEY_) config::to_int(CONFIG(_KEY_))

View File

@ -13,12 +13,9 @@ public:
Ast() = default;
Ast(const Ast&) = delete;
Ast(Ast&& other)
Ast(Ast&& other) : root(other.root), items(std::move(other.items))
{
this->root = other.root;
other.root = nullptr;
this->items = std::move(other.items);
}
Ast& operator=(Ast&& other)

View File

@ -24,7 +24,7 @@ public:
class Entry
{
public:
Entry(Printer &printer) : printer(printer), valid(true)
explicit Entry(Printer &printer) : printer(printer), valid(true)
{
printer.level++;
@ -77,7 +77,8 @@ public:
size_t level = 0;
};
PrintVisitor(std::ostream &stream) : printer(stream, "Printing AST") {}
explicit PrintVisitor(std::ostream &stream)
: printer(stream, "Printing AST") {}
void visit(ast::Start &start) override
{

View File

@ -14,7 +14,7 @@ class Pool : Lockable<std::mutex>
public:
using sptr = std::shared_ptr<Pool>;
Pool(size_t n = std::thread::hardware_concurrency()) : alive(true)
explicit Pool(size_t n = std::thread::hardware_concurrency()) : alive(true)
{
threads.reserve(n);

View File

@ -48,8 +48,8 @@ class Config {
// default user configuration
// fetches user configuration folder
std::string homedir;
if ((homedir = getenv("HOME")) == "") {
std::string homedir = std::getenv("HOME");
if ((homedir == "") {
homedir = getpwuid(getuid())->pw_dir;
}
homedir += "/.memgraph/config.yaml";
@ -58,10 +58,6 @@ class Config {
// environment variable configuratoin
if (const char* env_path = std::getenv(Definition::env_config_key))
load_configuration(env_path);
// TODO add program arguments here
// Define how will we pass program args and which ones are we using and how.
// ProgramArguments::instance().get_arg();
}
public:
@ -70,6 +66,15 @@ class Config {
return config;
}
void register_args(int argc, char** argv) {
REGISTER_ARGS(argc, argv);
for (const auto& argument : Definition::arguments) {
dict[argument] = GET_ARG("-" + argument, dict[argument]).get_string();
}
}
std::string operator[](const char* key) {
return dict[key];
}

View File

@ -6,4 +6,13 @@ namespace config
const char *MemgraphConfig::env_config_key = "MEMGRAPH_CONFIG";
const char *MemgraphConfig::default_file_path = "/etc/memgraph/config.yaml";
// configuration for arguments which can be passed threw command line
// TODO add support for shortened names
// Example:
// --cleaning_cycle_sec or -ccs, etc.
std::set<std::string> MemgraphConfig::arguments = {
"cleaning_cycle_sec",
"snapshot_cycle_sec",
};
}

View File

@ -20,9 +20,6 @@ Db &Dbms::active(const std::string &name)
// create db if it doesn't exist
auto it = acc.find(name);
if (it == acc.end()) {
// It doesn't exist.
Snapshoter &snap = snapshoter;
it = acc.emplace(name, std::forward_as_tuple(name),
std::forward_as_tuple(name))
.first;

View File

@ -58,13 +58,13 @@ int main(void) {
exit(1);
});
// CONFIG call
// TODO CONFIG call
io::Socket socket;
try {
socket = io::Socket::bind(interface, port);
} catch (io::NetworkError e) {
} catch (const io::NetworkError& e) {
logger.error("Cannot bind to socket on {} at {}", interface, port);
logger.error("{}", e.what());

View File

@ -1,5 +1,4 @@
#ifndef MEMGRAPH_SERVER_HTTP_HTTP_ERROR_HPP
#define MEMGRAPH_SERVER_HTTP_HTTP_ERROR_HPP
#pragma once
#include <stdexcept>
#include <string>
@ -10,7 +9,7 @@ namespace http
class HttpError : public std::runtime_error
{
public:
HttpError(const std::string& message)
explicit HttpError(const std::string& message)
: std::runtime_error(message) {}
};

View File

@ -22,7 +22,7 @@ class HttpServer
public:
using request_cb_t = std::function<void(Req&, Res&)>;
HttpServer(uv::UvLoop& loop);
explicit HttpServer(uv::UvLoop& loop);
void listen(const Ipv4& ip, request_cb_t callback);

View File

@ -9,8 +9,8 @@ namespace http
static BlockAllocator<65536> buffer_allocator;
template <class Req, class Res>
HttpServer<Req, Res>::HttpServer(uv::UvLoop& loop)
: loop(loop), stream(loop) {}
HttpServer<Req, Res>::HttpServer(uv::UvLoop& l)
: loop(l), stream(l) {}
template <class Req, class Res>
void HttpServer<Req, Res>::listen(const Ipv4& ip, request_cb_t callback)

View File

@ -21,7 +21,7 @@ class Response
using response_t = Response<Req, Res>;
public:
Response(connection_t& connection);
explicit Response(connection_t& connection);
void send(const std::string& body);
void send(Status code, const std::string& body);

View File

@ -12,8 +12,8 @@ namespace http
static BlockAllocator<sizeof(uv_write_t)> write_req_allocator;
template <class Req, class Res>
Response<Req, Res>::Response(connection_t& connection)
: status(Status::Ok), connection(connection), buffer() {}
Response<Req, Res>::Response(connection_t& conn)
: status(Status::Ok), connection(conn), buffer() {}
template <class Req, class Res>
void Response<Req, Res>::send(Status status, const std::string& body)

View File

@ -92,7 +92,7 @@ public:
r3::route* route;
};
R3(size_t capacity)
explicit R3(size_t capacity)
{
root = r3::r3_tree_create(capacity);
}
@ -104,10 +104,8 @@ public:
R3(R3&) = delete;
R3(R3&& other)
R3(R3&& other) : routes(std::move(other.routes), root(other.root)
{
this->routes = std::move(other.routes);
this->root = other.root;
other.root = nullptr;
}

View File

@ -10,7 +10,7 @@ using namespace std;
template <class T>
class ListNode {
public:
ListNode(T value) : value(value) {}
explicit ListNode(T value) : value(value) {}
std::atomic<T> value;
std::atomic<ListNode<T>*> prev;

View File

@ -3,6 +3,7 @@
namespace utils
{
// TODO CPPCheck -> function never used
void str_tolower(std::string& s)
{
// en_US.utf8 localization