From 49941fca40fb2596542cad7efa23df433bf0c509 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sun, 1 Nov 2015 18:03:15 +0100 Subject: [PATCH] the command line arguments processing is now inside the utils/command_line/arguments --- cypher/Makefile | 2 +- cypher/parser.cpp | 22 +---------------- utils/command_line/arguments.hpp | 41 ++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 22 deletions(-) create mode 100644 utils/command_line/arguments.hpp diff --git a/cypher/Makefile b/cypher/Makefile index d274cb2cd..cb291cdb5 100644 --- a/cypher/Makefile +++ b/cypher/Makefile @@ -1,5 +1,5 @@ CXX = clang++ -CXXFLAGS = -std=c++11 +CXXFLAGS = -std=c++1y INC = -I../ parser: parser.o cypher.o diff --git a/cypher/parser.cpp b/cypher/parser.cpp index 0405a0751..27bcc94a5 100644 --- a/cypher/parser.cpp +++ b/cypher/parser.cpp @@ -5,30 +5,10 @@ #include "compiler.hpp" #include "debug/tree_print.hpp" #include "codegen/cppgen.hpp" +#include "utils/command_line/arguments.hpp" using std::cout; using std::endl; -using vector_str = std::vector; - -// TODO: extract from here -// TODO: write more safe and optimal -vector_str all_arguments(int argc, char *argv[]) -{ - vector_str args(argv + 1, argv + argc); - return args; -} - -std::string get_argument(const vector_str& all, - const std::string& flag, - const std::string& default_value) -{ - auto it = std::find(all.begin(), all.end(), flag); - if (it == all.end()) { - return default_value; - } - auto pos = std::distance(all.begin(), it); - return all[pos + 1]; -} // * QUERY EXAMPLES * // "CREATE (n { name: 'Dominik', age: 24, role: 'CEO' }) return n" diff --git a/utils/command_line/arguments.hpp b/utils/command_line/arguments.hpp new file mode 100644 index 000000000..beeeeda85 --- /dev/null +++ b/utils/command_line/arguments.hpp @@ -0,0 +1,41 @@ +#ifndef MEMGRAPH_UTILS_COMMAND_LINE_ARGUMENTS_HPP +#define MEMGRAPH_UTILS_COMMAND_LINE_ARGUMENTS_HPP + +#include +#include +#include + +namespace +{ + +using std::string; +using std::vector; +using vector_str = vector; + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-function" + +decltype(auto) all_arguments(int argc, char *argv[]) +{ + vector_str args(argv + 1, argv + argc); + return args; +} + +decltype(auto) get_argument(const vector_str& all, + const std::string& flag, + const std::string& default_value) +{ + // TODO: optimize this implementation + auto it = std::find(all.begin(), all.end(), flag); + if (it == all.end()) { + return default_value; + } + auto pos = std::distance(all.begin(), it); + return all[pos + 1]; +} + +#pragma clang diagnostic pop + +} + +#endif