the command line arguments processing is now inside the utils/command_line/arguments

This commit is contained in:
Marko Budiselic 2015-11-01 18:03:15 +01:00
parent e4efc799b0
commit 49941fca40
3 changed files with 43 additions and 22 deletions

View File

@ -1,5 +1,5 @@
CXX = clang++
CXXFLAGS = -std=c++11
CXXFLAGS = -std=c++1y
INC = -I../
parser: parser.o cypher.o

View File

@ -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<std::string>;
// 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"

View File

@ -0,0 +1,41 @@
#ifndef MEMGRAPH_UTILS_COMMAND_LINE_ARGUMENTS_HPP
#define MEMGRAPH_UTILS_COMMAND_LINE_ARGUMENTS_HPP
#include <string>
#include <vector>
#include <algorithm>
namespace
{
using std::string;
using std::vector;
using vector_str = vector<string>;
#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