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
This commit is contained in:
Teon Banek 2017-04-11 14:55:57 +02:00
parent 36129cdcae
commit 6ed297e1d9
2 changed files with 31 additions and 87 deletions

View File

@ -4,10 +4,39 @@
#include <experimental/filesystem>
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;
}
}

View File

@ -1,85 +0,0 @@
#pragma once
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <experimental/filesystem>
#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 <typename... Args>
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;
};
}