diff --git a/.gitignore b/.gitignore index eb4c6612d..8925c849d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.swo *.out *.so +*.o *.dSYM/ memgraph *~ diff --git a/include/logging/streams/format.hpp b/include/logging/streams/format.hpp index 94cd1fc33..bd0d18c40 100644 --- a/include/logging/streams/format.hpp +++ b/include/logging/streams/format.hpp @@ -10,8 +10,8 @@ namespace logging { namespace format { - std::string out = "{} {:<5} [{}] {}\n"; - std::string err = out; + static const std::string out = "{} {:<5} [{}] {}\n"; + static const std::string err = out; // TODO: configurable formats } diff --git a/include/query_engine/code_generator/cypher_state.hpp b/include/query_engine/code_generator/cypher_state.hpp index 9cac08287..207194999 100644 --- a/include/query_engine/code_generator/cypher_state.hpp +++ b/include/query_engine/code_generator/cypher_state.hpp @@ -46,13 +46,19 @@ enum class EntitySource : uint8_t MainStorage }; +// TODO: reduce copying class CypherStateData { +public: + using tags_type = std::vector; + using properties_type = std::map; + private: std::map entity_status; std::map entity_type; std::map entity_source; - std::map> entity_tags; + std::map entity_tags; + std::map entity_properties; public: bool exist(const std::string &name) const @@ -83,14 +89,7 @@ public: return entity_source.at(name); } - auto tags(const std::string& name) const - { - if (entity_tags.find(name) == entity_tags.end()) - throw CppGeneratorException("No tags for specified entity"); - return entity_tags.at(name); - } - - const std::map &all_typed_enteties() + const std::map &all_typed_enteties() { return entity_type; } @@ -123,8 +122,16 @@ public: { entity_source[name] = source; } + + // entity tags + auto tags(const std::string& name) const + { + if (entity_tags.find(name) == entity_tags.end()) + throw CppGeneratorException("No tags for specified entity"); + return entity_tags.at(name); + } - void tags(const std::string& name, std::vector tags) + void tags(const std::string& name, tags_type tags) { entity_tags[name] = tags; } @@ -137,4 +144,40 @@ public: } entity_tags[name].emplace_back(new_tag); } + + // entity properties + auto properties(const std::string& name) const + { + if (entity_properties.find(name) == entity_properties.end()) + throw CppGeneratorException("No properties for specified entity"); + return entity_properties.at(name); + } + + void properties(const std::string& name, properties_type properties) + { + entity_properties[name] = properties; + } + + void index(const std::string& entity, const std::string& property, int64_t index) + { + if (entity_properties.find(entity) != entity_properties.end()) + { + entity_properties[entity] = properties_type{}; + } + entity_properties[entity][property] = index; + } + + auto index(const std::string& entity, const std::string& property_name) + { + if (entity_properties.find(entity) != entity_properties.end()) + throw CppGeneratorException("No properties for specified entity"); + + auto properties = entity_properties.at(entity); + + if (properties.find(property_name) != properties.end()) + throw CppGeneratorException("No property for specified property name"); + + return properties[property_name]; + } + }; diff --git a/include/query_engine/code_generator/handlers/return.hpp b/include/query_engine/code_generator/handlers/return.hpp index 259ae9f1e..b5b254899 100644 --- a/include/query_engine/code_generator/handlers/return.hpp +++ b/include/query_engine/code_generator/handlers/return.hpp @@ -48,6 +48,8 @@ auto return_query_action = code += code_line(code::find_and_write_vertices_by_label, entity, label); } + + // TODO: 16/10/2016 create match code if properties exist } if (cypher_data.source(entity) == EntitySource::TypeIndex) diff --git a/include/query_engine/traverser/cpp_traverser.hpp b/include/query_engine/traverser/cpp_traverser.hpp index 788404b59..ac077d6d0 100644 --- a/include/query_engine/traverser/cpp_traverser.hpp +++ b/include/query_engine/traverser/cpp_traverser.hpp @@ -409,9 +409,14 @@ public: auto prop = property_state.property_name; auto index = property_state.property_index; - auto &data = generator.action_data(); - data.parameter_index.emplace(ParameterIndexKey(entity, prop), index); - data.add_entitiy_property(entity, prop); + // update action data + auto &action_data = generator.action_data(); + action_data.parameter_index.emplace(ParameterIndexKey(entity, prop), index); + action_data.add_entitiy_property(entity, prop); + + // update cypher data + auto &cypher_data = generator.cypher_data(); + cypher_data.index(entity, prop, index); clear_state(); } diff --git a/tests/try/glibcpp_problem/Makefile b/tests/try/glibcpp_problem/Makefile new file mode 100644 index 000000000..c047682f7 --- /dev/null +++ b/tests/try/glibcpp_problem/Makefile @@ -0,0 +1,48 @@ +# compiler +CXX=clang++ + +# compile flags +CFLAGS=-std=c++1y -pthread -g2 # -D_GLIBCXX_DEBUG + +# includes and libraries +INCLUDE_PATHS=-I../../../include -I../../../libs/fmt -I../../../src +LIB_PATHS=-L../../../libs/fmt/fmt +LDFLAGS=-lfmt + +# source and executable +LOG_SRC_PATH=../../.. +SOURCES=main.cpp async_log.o sync_log.o stderr.o stdout.o default.o levels.o log.o +EXECUTABLE=a.out + +# release target +all: $(EXECUTABLE) + +$(EXECUTABLE): $(SOURCES) + $(CXX) $(CFLAGS) $(INCLUDE_PATHS) $(SOURCES) -o $(EXECUTABLE) $(LIB_PATHS) $(LDFLAGS) + +# TODO: auto +async_log.o: ../../../src/logging/logs/async_log.cpp + $(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/logs/async_log.cpp + +sync_log.o: ../../../src/logging/logs/sync_log.cpp + $(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/logs/sync_log.cpp + +stderr.o: ../../../src/logging/streams/stderr.cpp + $(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/streams/stderr.cpp + +stdout.o: ../../../src/logging/streams/stdout.cpp + $(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/streams/stdout.cpp + +default.o: ../../../src/logging/default.cpp + $(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/default.cpp + +levels.o: ../../../src/logging/levels.cpp + $(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/levels.cpp + +log.o: ../../../src/logging/log.cpp + $(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/log.cpp + +.PHONY: +clean: + rm -f a.out + rm -f *.o diff --git a/tests/try/glibcpp_problem/main.cpp b/tests/try/glibcpp_problem/main.cpp new file mode 100644 index 000000000..730695f64 --- /dev/null +++ b/tests/try/glibcpp_problem/main.cpp @@ -0,0 +1,20 @@ +#include + +#include "logging/default.hpp" +#include "logging/streams/stdout.hpp" + +int main(void) +{ + // init logging + logging::init_sync(); + logging::log->pipe(std::make_unique()); + + // get Main logger + Logger logger; + logger = logging::log->logger("Main"); + logger.info("{}", logging::log->type()); + + std::string* test = new std::string("test_value"); + + return 0; +}