commit e86b603f9e187aea5c8c663c2a19beb080240cca Author: Sam Perry Date: Wed Jun 29 19:19:09 2016 +0100 Initial commit. Created basic project structure, begun creating a cmake config and implemented the start of a command line argument parser diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4581ef2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..25f1290 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.5.2) +# Set the project name +project (concatenator) + +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_MULTITHREADED ON) +set(Boost_USE_STATIC_RUNTIME OFF) +find_package(Boost 1.60.0 COMPONENTS program_options) + + +# Set build flags +set(CMAKE_CXX_FLAGS "-g -Wall") +# Set cmake to output executable to the bin directory +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +include_directories(include) + +# Find all the source fies in the src directory +file(GLOB SOURCES "src/*.cpp") + +# Build the executable from the source files found +if(Boost_FOUND) + include_directories(${Boost_INCLUDE_DIRS}) + add_executable(concatenator ${SOURCES}) + target_link_libraries(concatenator ${Boost_LIBRARIES}) +endif() diff --git a/include/argument_parser.h b/include/argument_parser.h new file mode 100644 index 0000000..a48653c --- /dev/null +++ b/include/argument_parser.h @@ -0,0 +1,21 @@ +#include +#include "boost/program_options.hpp" + +namespace po = boost::program_options; + +class ArgumentParser { + public: + ArgumentParser(); + ~ArgumentParser() {}; + ArgumentParser(const ArgumentParser&); + ArgumentParser& operator=(const ArgumentParser&); + int parseargs(int argc, char** argv); + + private: + //Create a positional options object for parsing input, output etc + //positional arguments from command line. + po::positional_options_description positionalOptions; + // + po::variables_map vm; + po::options_description desc; +}; diff --git a/src/argument_parser.cpp b/src/argument_parser.cpp new file mode 100644 index 0000000..0f70de6 --- /dev/null +++ b/src/argument_parser.cpp @@ -0,0 +1,27 @@ +#include "argument_parser.h" +#include + +using namespace std; + +ArgumentParser::ArgumentParser() : desc("Allowed options") { + positionalOptions.add("input_db", 1); + positionalOptions.add("output_db", 1); + + + desc.add_options() + ("help,h", "produce help message") + ("compression", po::value(), "set compression level") + ; +} + +int ArgumentParser::parseargs(int argc, char** argv) { + po::store(po::command_line_parser(argc, argv).options(desc).positional(positionalOptions).run(), vm); + po::notify(vm); + + // If help option is specified then output help message + if (vm.count("help")) { + cout << desc << "\n"; + return 1; + } + return 0; +} diff --git a/src/concatenator.cpp b/src/concatenator.cpp new file mode 100644 index 0000000..22abcd8 --- /dev/null +++ b/src/concatenator.cpp @@ -0,0 +1,13 @@ +#include +#include "argument_parser.h" + +using namespace std; + +int main(int argc, char** argv) { + + // Declare the supported options. + ArgumentParser argparse = ArgumentParser(); + argparse.parseargs(argc, argv); + cout << "Hello world!" << endl; + return 0; +}