From 6ed297e1d9fdaa66934583ee3658786f9430b9ee Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Tue, 11 Apr 2017 14:55:57 +0200 Subject: [PATCH] Remove src/query/util.hpp Summary: `query/util.hpp` isn't used anywhere, but in `copy_hardcoded_queries.cpp`. That file may be removed in the future, but for now it is needed. Reviewers: mislav.bradac, florijan, buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D261 --- src/copy_hardcoded_queries.cpp | 33 ++++++++++++- src/query/util.hpp | 85 ---------------------------------- 2 files changed, 31 insertions(+), 87 deletions(-) delete mode 100644 src/query/util.hpp diff --git a/src/copy_hardcoded_queries.cpp b/src/copy_hardcoded_queries.cpp index 719a15b4f..bcfcb3abb 100644 --- a/src/copy_hardcoded_queries.cpp +++ b/src/copy_hardcoded_queries.cpp @@ -4,10 +4,39 @@ #include namespace fs = std::experimental::filesystem; + #include "logging/streams/stdout.hpp" #include "query/preprocessor.hpp" -#include "query/util.hpp" #include "utils/command_line/arguments.hpp" +#include "utils/exceptions/basic_exception.hpp" +#include "utils/file.hpp" +#include "utils/string/file.hpp" +#include "utils/string/trim.hpp" + +std::string extract_query(const fs::path &path) { + auto comment_mark = std::string("// "); + auto query_mark = comment_mark + std::string("Query: "); + auto lines = utils::read_lines(path); + // find the line with a query (the query can be split across multiple + // lines) + for (int i = 0; i < (int)lines.size(); ++i) { + // find query in the line + auto &line = lines[i]; + auto pos = line.find(query_mark); + // if query doesn't exist pass + if (pos == std::string::npos) continue; + auto query = utils::trim(line.substr(pos + query_mark.size())); + while (i + 1 < (int)lines.size() && + lines[i + 1].find(comment_mark) != std::string::npos) { + query += lines[i + 1].substr(lines[i + 1].find(comment_mark) + + comment_mark.length()); + ++i; + } + return query; + } + + throw BasicException("Unable to find query!"); +} int main(int argc, char **argv) { logging::init_sync(); @@ -46,4 +75,4 @@ int main(int argc, char **argv) { } return 0; -} \ No newline at end of file +} diff --git a/src/query/util.hpp b/src/query/util.hpp deleted file mode 100644 index 494589099..000000000 --- a/src/query/util.hpp +++ /dev/null @@ -1,85 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include -#include "fmt/format.h" -#include "logging/default.hpp" -namespace fs = std::experimental::filesystem; -#include "utils/file.hpp" -#include "utils/string/file.hpp" -#include "utils/string/trim.hpp" -#include "utils/types/byte.hpp" -#include "query/exceptions.hpp" - -using std::cout; -using std::endl; - -// this is a nice way how to avoid multiple definition problem with -// headers because it will create a unique namespace for each compilation unit -// http://stackoverflow.com/questions/2727582/multiple-definition-in-header-file -// but sometimes that might be a problem -namespace { - -std::string extract_query(const fs::path &path) { - auto comment_mark = std::string("// "); - auto query_mark = comment_mark + std::string("Query: "); - auto lines = utils::read_lines(path); - // find the line with a query (the query can be split across multiple - // lines) - for (int i = 0; i < (int)lines.size(); ++i) { - // find query in the line - auto &line = lines[i]; - auto pos = line.find(query_mark); - // if query doesn't exist pass - if (pos == std::string::npos) continue; - auto query = utils::trim(line.substr(pos + query_mark.size())); - while (i + 1 < (int)lines.size() && - lines[i + 1].find(comment_mark) != std::string::npos) { - query += lines[i + 1].substr(lines[i + 1].find(comment_mark) + - comment_mark.length()); - ++i; - } - return query; - } - - throw BasicException("Unable to find query!"); -} - -template -std::string format(const std::string &format_str, const Args &... args) { - return fmt::format(format_str, args...); -} - -class CoutSocket { - public: - CoutSocket() : logger(logging::log->logger("Cout Socket")) {} - - int write(const std::string &str) { - logger.info(str); - return str.size(); - } - - int write(const char *data, size_t len) { - logger.info(std::string(data, len)); - return len; - } - - int write(const byte *data, size_t len) { - std::stringstream ss; - for (int i = 0; i < len; i++) { - ss << data[i]; - } - std::string output(ss.str()); - cout << output << endl; - logger.info(output); - return len; - } - - private: - Logger logger; -}; -}