diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a007fea --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..204d722 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.10) + +project(EsriAssignment) + +set(CMAKE_CXX_STANDARD 17) + +find_package(Protobuf REQUIRED) +include_directories(${PROTOBUF_INCLUDE_DIR}) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +add_subdirectory(protocol_buffers_definitions) +include_directories(src) +add_subdirectory(src) + diff --git a/README.md b/README.md new file mode 100644 index 0000000..4c56a2d --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# ESRI C++ code assignment + +## Setup + +``` +aptitude install protobuf-compiler libprotobuf-c-dev ##libprotoc-dev +``` + +## Build + +``` +mkdir build +cd build +cmake .. +make +``` + + +## Links +* https://developers.google.com/protocol-buffers/docs/cpptutorial +* https://github.com/protocolbuffers/protobuf/tree/master/examples +* https://cmake.org/cmake/help/latest/module/FindProtobuf.html + diff --git a/protocol_buffers_definitions/CMakeLists.txt b/protocol_buffers_definitions/CMakeLists.txt new file mode 100644 index 0000000..2b1c98f --- /dev/null +++ b/protocol_buffers_definitions/CMakeLists.txt @@ -0,0 +1,14 @@ +find_package(Protobuf REQUIRED) +include_directories(${PROTOBUF_INCLUDE_DIR}) + +set(PROTO_LIST + locatorevents.proto + positions.proto + recordings.proto + sensors.proto + structures.proto +) +protobuf_generate_cpp(PROTO_SRC PROTO_HEADER ${PROTO_LIST}) +add_library(proto ${PROTO_HEADER} ${PROTO_SRC}) +set_target_properties(proto PROPERTIES PUBLIC_HEADER "${PROTO_HEADER}") + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..66b029f --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,6 @@ + +set(assignment_SOURCES + main.cpp) + +add_executable(main ${assignment_SOURCES}) +target_link_libraries(main proto ${PROTOBUF_LIBRARY}) diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..71e1af2 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,40 @@ +#include +#include + +#include "protocol_buffers_definitions/recordings.pb.h" + + +using namespace ::indoors::proto; + +int main(int argc, char* argv[]) +{ + // Verify that the version of the library that we linked against is + // compatible with the version of the headers we compiled against. + GOOGLE_PROTOBUF_VERIFY_VERSION; + + std::cout << "ESRI C++ code assignment\n"; + + Recording recording; + Position positions; + + std::fstream input(argv[1], std::ios::in | std::ios::binary); + if (!recording.ParseFromIstream(&input)) { + std::cerr << "Failed to parse input file.\n"; + return -1; + } + std::cout.precision(17); + for (int i=0; i < recording.magnetics_size(); i++) { + auto const& s = recording.magnetics(i); + std::cout << s.t() << ": [" << s.x() << ", " << s.y() << ", " << s.z() << "]\n"; + } + for (int i=0; i < recording.positions_size(); i++) { + auto const& s = recording.positions(i); + std::cout << s.t() << ": [" << s.x() << ", " << s.y() << "]\n"; + } + + // Optional: Delete all global objects allocated by libprotobuf. + google::protobuf::ShutdownProtobufLibrary(); + + return 0; +} +