From 894ef67bc0778b46d04d08a24c9d376190b38b05 Mon Sep 17 00:00:00 2001
From: Marko Budiselic <mbudiselicbuda@gmail.com>
Date: Mon, 6 Jun 2016 11:29:52 +0200
Subject: [PATCH] clang format was applied on src/memgraph and on some files at
 the src/query_engine folder

---
 src/memgraph.cpp                      |  7 +--
 src/query_engine/code_compiler.hpp    | 21 ++++---
 src/query_engine/code_generator.hpp   | 23 +++-----
 src/query_engine/debug.hpp            | 10 ++--
 src/query_engine/i_code_cpu.hpp       |  8 +--
 src/query_engine/program_executor.hpp |  8 +--
 src/query_engine/program_loader.hpp   | 26 ++++-----
 src/query_engine/query_engine.hpp     |  5 +-
 src/query_engine/query_program.hpp    | 11 ++--
 src/query_engine/query_result.hpp     | 34 ++++-------
 src/query_engine/query_stripped.hpp   | 12 ++--
 src/query_engine/query_stripper.hpp   | 81 ++++++++++++++-------------
 src/query_engine/traverser/code.hpp   |  6 +-
 src/query_engine/util.hpp             |  5 +-
 14 files changed, 117 insertions(+), 140 deletions(-)

diff --git a/src/memgraph.cpp b/src/memgraph.cpp
index 0dba9ef7e..92b8a2548 100644
--- a/src/memgraph.cpp
+++ b/src/memgraph.cpp
@@ -6,18 +6,17 @@
 
 #include "database/db.hpp"
 
-#include "speedy/speedy.hpp"
 #include "api/resources/include.hpp"
+#include "speedy/speedy.hpp"
 
 #include "threading/pool.hpp"
 #include "threading/task.hpp"
 
 #include "utils/terminate_handler.hpp"
 
-int main(int argc, char* argv[])
+int main(int argc, char *argv[])
 {
-    if(argc < 2)
-    {
+    if (argc < 2) {
         std::cout << "Port not defined" << std::endl;
         std::exit(0);
     }
diff --git a/src/query_engine/code_compiler.hpp b/src/query_engine/code_compiler.hpp
index 27a4e8c78..92bb0a110 100644
--- a/src/query_engine/code_compiler.hpp
+++ b/src/query_engine/code_compiler.hpp
@@ -7,18 +7,17 @@
 class CodeCompiler
 {
 public:
-
-    void compile(const std::string& in_file, const std::string& out_file)
+    void compile(const std::string &in_file, const std::string &out_file)
     {
-        auto compile_command = utils::prints(
-            "clang++",
-            // "-std=c++1y -O2 -DNDEBUG",     // compile flags
-            "-std=c++1y",     // compile flags
-            in_file,          // input file
-            "-o", out_file,   // ouput file
-            "-I../",          // include paths
-            "-shared -fPIC"   // shared library flags
-        );
+        auto compile_command =
+            utils::prints("clang++",
+                          // "-std=c++1y -O2 -DNDEBUG",     // compile flags
+                          "-std=c++1y",   // compile flags
+                          in_file,        // input file
+                          "-o", out_file, // ouput file
+                          "-I../",        // include paths
+                          "-shared -fPIC" // shared library flags
+                          );
 
         // synchronous call
         system(compile_command.c_str());
diff --git a/src/query_engine/code_generator.hpp b/src/query_engine/code_generator.hpp
index 600c43cd0..b68e1cab5 100644
--- a/src/query_engine/code_generator.hpp
+++ b/src/query_engine/code_generator.hpp
@@ -1,20 +1,19 @@
 #pragma once
 
+#include "config/config.hpp"
 #include "cypher/ast/ast.hpp"
 #include "cypher/compiler.hpp"
-#include "utils/string/file.hpp"
 #include "template_engine/engine.hpp"
-#include "config/config.hpp"
 #include "traverser/code_traverser.hpp"
+#include "utils/string/file.hpp"
 
 using std::string;
 
 class CodeGenerator
 {
 public:
-    void generate_cpp(const std::string& query, 
-                      const uint64_t stripped_hash,
-                      const std::string& path)
+    void generate_cpp(const std::string &query, const uint64_t stripped_hash,
+                      const std::string &path)
     {
         // get paths
         string template_path = CONFIG(config::TEMPLATE_CPU_CPP_PATH);
@@ -27,19 +26,15 @@ public:
 
         // save the code
         string generated = template_engine.render(
-            template_file,
-            {
-                {"class_name", "CodeCPU"},
-                {"stripped_hash", std::to_string(stripped_hash)},
-                {"query", query},
-                {"code", code_traverser.code}
-            }
-        );
+            template_file, {{"class_name", "CodeCPU"},
+                            {"stripped_hash", std::to_string(stripped_hash)},
+                            {"query", query},
+                            {"code", code_traverser.code}});
         utils::write_file(generated, path);
     }
 
 private:
-    template_engine::TemplateEngine template_engine;  
+    template_engine::TemplateEngine template_engine;
     ast::Ast tree;
     cypher::Compiler compiler;
     CodeTraverser code_traverser;
diff --git a/src/query_engine/debug.hpp b/src/query_engine/debug.hpp
index 87209a9db..ba52c323d 100644
--- a/src/query_engine/debug.hpp
+++ b/src/query_engine/debug.hpp
@@ -2,14 +2,14 @@
 
 #include <iostream>
 
-#include "storage/model/properties/traversers/jsonwriter.hpp"
 #include "storage/model/properties/properties.hpp"
+#include "storage/model/properties/traversers/jsonwriter.hpp"
 
 using std::cout;
 using std::endl;
 
-void print_props(const Properties& properties)
-{       
+void print_props(const Properties &properties)
+{
     StringBuffer buffer;
     JsonWriter<StringBuffer> writer(buffer);
     properties.accept(writer);
@@ -17,7 +17,7 @@ void print_props(const Properties& properties)
 }
 
 #ifdef DEBUG
-#   define PRINT_PROPS(_PROPS_) print_props(_PROPS_);
+#define PRINT_PROPS(_PROPS_) print_props(_PROPS_);
 #else
-#   define PRINT_PROPS(_)
+#define PRINT_PROPS(_)
 #endif
diff --git a/src/query_engine/i_code_cpu.hpp b/src/query_engine/i_code_cpu.hpp
index 585f98404..200de8483 100644
--- a/src/query_engine/i_code_cpu.hpp
+++ b/src/query_engine/i_code_cpu.hpp
@@ -1,15 +1,15 @@
 #pragma once
 
+#include "database/db.hpp"
 #include "query_engine/query_result.hpp"
 #include "query_stripped.hpp"
-#include "database/db.hpp"
 
 class ICodeCPU
 {
 public:
-    virtual QueryResult::sptr run(Db& db, code_args_t& args) = 0;
+    virtual QueryResult::sptr run(Db &db, code_args_t &args) = 0;
     virtual ~ICodeCPU() {}
 };
 
-using produce_t = ICodeCPU*(*)();
-using destruct_t = void (*)(ICodeCPU*);
+using produce_t = ICodeCPU *(*)();
+using destruct_t = void (*)(ICodeCPU *);
diff --git a/src/query_engine/program_executor.hpp b/src/query_engine/program_executor.hpp
index 819389176..cc7423514 100644
--- a/src/query_engine/program_executor.hpp
+++ b/src/query_engine/program_executor.hpp
@@ -2,10 +2,10 @@
 
 #include <string>
 
-#include "query_program.hpp"
 #include "database/db.hpp"
-#include "utils/log/logger.hpp"
 #include "query_engine/debug.hpp"
+#include "query_program.hpp"
+#include "utils/log/logger.hpp"
 
 //  preparations before execution
 //  execution
@@ -14,8 +14,7 @@
 class ProgramExecutor
 {
 public:
-
-    auto execute(QueryProgram& program)
+    auto execute(QueryProgram &program)
     {
         auto result = program.code->run(db, program.stripped.arguments);
         PRINT_PROPS(*result->data["n"]->data[0]);
@@ -23,6 +22,5 @@ public:
     }
 
 public:
-
     Db db;
 };
diff --git a/src/query_engine/program_loader.hpp b/src/query_engine/program_loader.hpp
index ea924418a..c1706789c 100644
--- a/src/query_engine/program_loader.hpp
+++ b/src/query_engine/program_loader.hpp
@@ -1,34 +1,35 @@
 #pragma once
 
+#include <memory>
 #include <string>
 #include <unordered_map>
-#include <memory>
 
 #define NOT_LOG_INFO
 
-#include "memgraph_dynamic_lib.hpp"
-#include "query_stripper.hpp"
 #include "code_compiler.hpp"
 #include "code_generator.hpp"
-#include "utils/hashing/fnv.hpp"
 #include "config/config.hpp"
-#include "utils/log/logger.hpp"
+#include "memgraph_dynamic_lib.hpp"
 #include "query_program.hpp"
+#include "query_stripper.hpp"
+#include "utils/hashing/fnv.hpp"
+#include "utils/log/logger.hpp"
 
 using std::string;
 using std::cout;
 using std::endl;
 
 class ProgramLoader
-{    
+{
 public:
-
     using sptr_code_lib = std::shared_ptr<CodeLib>;
 
     ProgramLoader()
-        : stripper(make_query_stripper(TK_INT, TK_FLOAT, TK_STR, TK_BOOL)) {}
+        : stripper(make_query_stripper(TK_INT, TK_FLOAT, TK_STR, TK_BOOL))
+    {
+    }
 
-    auto load(const string& query)
+    auto load(const string &query)
     {
         auto stripped = stripper.strip(query);
         LOG_INFO("stripped_query=" + stripped.query);
@@ -51,8 +52,8 @@ public:
         auto base_path = config::Config::instance()[config::COMPILE_CPU_PATH];
         auto path_cpp = base_path + hash_string + ".cpp";
         code_generator.generate_cpp(query, stripped_hash, path_cpp);
-       
-        //  TODO compile generated code 
+
+        //  TODO compile generated code
         auto path_so = base_path + hash_string + ".so";
         code_compiler.compile(path_cpp, path_so);
 
@@ -65,7 +66,6 @@ public:
     }
 
 private:
-
     //  TODO somehow remove int.. from here
     QueryStripper<int, int, int, int> stripper;
     // TODO ifdef MEMGRAPH64 problem, how to use this kind
@@ -76,7 +76,7 @@ private:
     CodeGenerator code_generator;
     CodeCompiler code_compiler;
 
-    sptr_code_lib load_code_lib(const string& path)
+    sptr_code_lib load_code_lib(const string &path)
     {
         sptr_code_lib code_lib = std::make_shared<CodeLib>(path);
         code_lib->load();
diff --git a/src/query_engine/query_engine.hpp b/src/query_engine/query_engine.hpp
index 3bb8bc84e..4ea368741 100644
--- a/src/query_engine/query_engine.hpp
+++ b/src/query_engine/query_engine.hpp
@@ -1,7 +1,7 @@
 #pragma once
 
-#include "program_loader.hpp"
 #include "program_executor.hpp"
+#include "program_loader.hpp"
 #include "query_result.hpp"
 
 //
@@ -12,8 +12,7 @@
 class QueryEngine
 {
 public:
-
-    auto execute(const std::string& query)
+    auto execute(const std::string &query)
     {
         auto program = program_loader.load(query);
         auto result = program_executor.execute(program);
diff --git a/src/query_engine/query_program.hpp b/src/query_engine/query_program.hpp
index bc9079218..8a35b5376 100644
--- a/src/query_engine/query_program.hpp
+++ b/src/query_engine/query_program.hpp
@@ -5,12 +5,13 @@
 
 struct QueryProgram
 {
-    QueryProgram(ICodeCPU* code, QueryStripped&& stripped) :
-        code(code),
-        stripped(std::forward<QueryStripped>(stripped)) {}
+    QueryProgram(ICodeCPU *code, QueryStripped &&stripped)
+        : code(code), stripped(std::forward<QueryStripped>(stripped))
+    {
+    }
 
-    QueryProgram(QueryProgram& other) = delete;
-    QueryProgram(QueryProgram&& other) = default;
+    QueryProgram(QueryProgram &other) = delete;
+    QueryProgram(QueryProgram &&other) = default;
 
     ICodeCPU *code;
     QueryStripped stripped;
diff --git a/src/query_engine/query_result.hpp b/src/query_engine/query_result.hpp
index b6bafeb71..f59e3578b 100644
--- a/src/query_engine/query_result.hpp
+++ b/src/query_engine/query_result.hpp
@@ -1,30 +1,25 @@
 #pragma once
 
-#include <string>
-#include <vector>
 #include <memory>
+#include <string>
 #include <unordered_map>
+#include <vector>
 
 #include "storage/model/properties/properties.hpp"
 
 struct ResultList
 {
     using sptr = std::shared_ptr<ResultList>;
-    using data_t = std::vector<const Properties*>;
+    using data_t = std::vector<const Properties *>;
 
     ResultList() = default;
-    ResultList(ResultList& other) = delete;
-    ResultList(ResultList&& other) = default;
+    ResultList(ResultList &other) = delete;
+    ResultList(ResultList &&other) = default;
+    ResultList(data_t &&data) : data(std::forward<data_t>(data)) {}
 
-    ResultList(data_t&& data) :
-        data(std::forward<data_t>(data)) {}
+    explicit operator bool() const { return data.size() > 0; }
 
-    explicit operator bool() const
-    {
-        return data.size() > 0;
-    }
-
-    std::vector<const Properties*> data;
+    std::vector<const Properties *> data;
 };
 
 struct QueryResult
@@ -33,16 +28,11 @@ struct QueryResult
     using data_t = std::unordered_map<std::string, ResultList::sptr>;
 
     QueryResult() = default;
-    QueryResult(QueryResult& other) = delete;
-    QueryResult(QueryResult&& other) = default;
+    QueryResult(QueryResult &other) = delete;
+    QueryResult(QueryResult &&other) = default;
+    QueryResult(data_t &&data) : data(std::forward<data_t>(data)) {}
 
-    QueryResult(data_t&& data) :
-        data(std::forward<data_t>(data)) {}
-
-    explicit operator bool() const
-    {
-        return data.size() > 0;
-    }
+    explicit operator bool() const { return data.size() > 0; }
 
     data_t data;
 };
diff --git a/src/query_engine/query_stripped.hpp b/src/query_engine/query_stripped.hpp
index fe3bf5557..bfea73ef3 100644
--- a/src/query_engine/query_stripped.hpp
+++ b/src/query_engine/query_stripped.hpp
@@ -8,12 +8,14 @@ using code_args_t = std::vector<Property::sptr>;
 
 struct QueryStripped
 {
-    QueryStripped(const std::string&& query, code_args_t&& arguments) :
-        query(std::forward<const std::string>(query)),
-        arguments(std::forward<code_args_t>(arguments)) {}
+    QueryStripped(const std::string &&query, code_args_t &&arguments)
+        : query(std::forward<const std::string>(query)),
+          arguments(std::forward<code_args_t>(arguments))
+    {
+    }
 
-    QueryStripped(QueryStripped& other) = delete;
-    QueryStripped(QueryStripped&& other) = default;
+    QueryStripped(QueryStripped &other) = delete;
+    QueryStripped(QueryStripped &&other) = default;
 
     std::string query;
     code_args_t arguments;
diff --git a/src/query_engine/query_stripper.hpp b/src/query_engine/query_stripper.hpp
index 8b7e4b40d..a4e4cb5ce 100644
--- a/src/query_engine/query_stripper.hpp
+++ b/src/query_engine/query_stripper.hpp
@@ -2,40 +2,43 @@
 
 #include <string>
 #include <tuple>
-#include <utility>
 #include <unordered_map>
+#include <utility>
 
-#include "utils/string/transform.hpp"
 #include "cypher/cypher.h"
 #include "cypher/tokenizer/cypher_lexer.hpp"
-#include "utils/variadic/variadic.hpp"
-#include "storage/model/properties/all.hpp"
 #include "query_stripped.hpp"
+#include "storage/model/properties/all.hpp"
+#include "utils/string/transform.hpp"
+#include "utils/variadic/variadic.hpp"
 
 #include <iostream>
 
-template<class T, class V>
-void store_query_param(code_args_t& arguments, V&& v)
+template <class T, class V>
+void store_query_param(code_args_t &arguments, V &&v)
 {
     arguments.emplace_back(std::make_shared<T>(std::forward<V>(v)));
 }
 
-template<typename ...Ts>
+template <typename... Ts>
 class QueryStripper
 {
 public:
+    QueryStripper(Ts &&... strip_types)
+        : strip_types(std::make_tuple(std::forward<Ts>(strip_types)...)),
+          lexer(std::make_unique<CypherLexer>())
+    {
+    }
 
-    QueryStripper(Ts&&... strip_types) :
-        strip_types(std::make_tuple(std::forward<Ts>(strip_types)...)),
-        lexer(std::make_unique<CypherLexer>()) {}
+    QueryStripper(QueryStripper &other) = delete;
 
-    QueryStripper(QueryStripper& other) = delete;
+    QueryStripper(QueryStripper &&other)
+        : strip_types(std::move(other.strip_types)),
+          lexer(std::move(other.lexer))
+    {
+    }
 
-    QueryStripper(QueryStripper&& other) :
-        strip_types(std::move(other.strip_types)),
-        lexer(std::move(other.lexer)) {}
-
-    auto strip(const std::string& query)
+    auto strip(const std::string &query)
     {
         //  TODO write this more optimal (resplace string
         //  concatenation with something smarter)
@@ -51,30 +54,27 @@ public:
         std::string stripped_query;
         stripped_query.reserve(query.size());
 
-        while (auto token = tokenizer.lookup())
-        {
+        while (auto token = tokenizer.lookup()) {
             // TODO: better implementation
             if (_or(token.id, strip_types, std::make_index_sequence<size>{})) {
                 auto index = counter++;
                 switch (token.id) {
-                    case TK_INT:
-                        store_query_param<Int32>(stripped_arguments,
-                                                 std::stoi(token.value));
-                        break;
-                    case TK_STR:
-                        store_query_param<String>(stripped_arguments,
-                                                  token.value);
-                        break;
-                    case TK_BOOL: {
-                        bool value = token.value[0] == 'T' ||
-                                     token.value[0] == 't';
-                        store_query_param<Bool>(stripped_arguments, value);
-                        break;
-                    }
-                    case TK_FLOAT:
-                        store_query_param<Float>(stripped_arguments,
-                                                 std::stof(token.value));
-                        break;
+                case TK_INT:
+                    store_query_param<Int32>(stripped_arguments,
+                                             std::stoi(token.value));
+                    break;
+                case TK_STR:
+                    store_query_param<String>(stripped_arguments, token.value);
+                    break;
+                case TK_BOOL: {
+                    bool value = token.value[0] == 'T' || token.value[0] == 't';
+                    store_query_param<Bool>(stripped_arguments, value);
+                    break;
+                }
+                case TK_FLOAT:
+                    store_query_param<Float>(stripped_arguments,
+                                             std::stof(token.value));
+                    break;
                 }
                 stripped_query += std::to_string(index);
             } else {
@@ -91,15 +91,16 @@ private:
     std::tuple<Ts...> strip_types;
     CypherLexer::uptr lexer;
 
-    template<typename Value, typename Tuple, std::size_t ...index>
-    bool _or(Value&& value, Tuple&& tuple, std::index_sequence<index...>)
+    template <typename Value, typename Tuple, std::size_t... index>
+    bool _or(Value &&value, Tuple &&tuple, std::index_sequence<index...>)
     {
         return or_vargs(std::forward<Value>(value),
                         std::get<index>(std::forward<Tuple>(tuple))...);
     }
 };
 
-template<typename ...Ts>
-decltype(auto) make_query_stripper(Ts&&... ts) {
+template <typename... Ts>
+decltype(auto) make_query_stripper(Ts &&... ts)
+{
     return QueryStripper<Ts...>(std::forward<Ts>(ts)...);
 }
diff --git a/src/query_engine/traverser/code.hpp b/src/query_engine/traverser/code.hpp
index de9c7040b..5af6bfbc2 100644
--- a/src/query_engine/traverser/code.hpp
+++ b/src/query_engine/traverser/code.hpp
@@ -4,11 +4,7 @@
 
 struct Code
 {
-    void reset()
-    {
-        code = "";
-    }
+    void reset() { code = ""; }
 
     std::string code;
 };
-
diff --git a/src/query_engine/util.hpp b/src/query_engine/util.hpp
index 74cac8f5b..b84448298 100644
--- a/src/query_engine/util.hpp
+++ b/src/query_engine/util.hpp
@@ -2,7 +2,4 @@
 
 #include <string>
 
-std::string line(std::string line)
-{
-    return "\t\t" + line + "\n";
-}
+std::string line(std::string line) { return "\t\t" + line + "\n"; }