Skip to content

Commit 4fdfde4

Browse files
authored
Add files via upload
1 parent 664d1db commit 4fdfde4

27 files changed

+2303
-0
lines changed

deps/CMakeLists.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
include(ExternalProject)
2+
3+
set(DEPS_PREFIX ${CMAKE_CURRENT_BINARY_DIR})
4+
set(DEPS_INCLUDE_DIR ${DEPS_PREFIX}/include)
5+
set(DEPS_LIBRARY_DIR ${DEPS_PREFIX}/lib)
6+
7+
set(DEPS_COMMON_CMAKE_ARGS
8+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
9+
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
10+
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
11+
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
12+
-DCMAKE_INSTALL_PREFIX=${DEPS_PREFIX}
13+
)
14+
15+
macro(get_library_filename library filename)
16+
set(_prefix ${CMAKE_STATIC_LIBRARY_PREFIX})
17+
set(_suffix ${CMAKE_STATIC_LIBRARY_SUFFIX})
18+
set(${filename} ${_prefix}${library}${_suffix})
19+
endmacro()
20+
21+
externalproject_add(configreader-external
22+
PREFIX ${DEPS_PREFIX}
23+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/configreader
24+
CMAKE_ARGS ${DEPS_COMMON_CMAKE_ARGS})
25+
26+
add_library(configreader STATIC IMPORTED GLOBAL)
27+
add_dependencies(configreader configreader-external)
28+
29+
get_library_filename(configreader CONFIGREADER_FILENAME)
30+
set_target_properties(configreader PROPERTIES
31+
IMPORTED_LOCATION ${DEPS_LIBRARY_DIR}/${CONFIGREADER_FILENAME})
32+
33+
externalproject_add(subhook-external
34+
PREFIX ${DEPS_PREFIX}
35+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/subhook
36+
CMAKE_ARGS -DSUBHOOK_STATIC=ON
37+
-DSUBHOOK_TESTS=OFF
38+
${DEPS_COMMON_CMAKE_ARGS})
39+
40+
add_library(subhook STATIC IMPORTED GLOBAL)
41+
add_dependencies(subhook subhook-external)
42+
43+
get_library_filename(subhook SUBHOOK_FILENAME)
44+
set_target_properties(subhook PROPERTIES
45+
IMPORTED_LOCATION ${DEPS_LIBRARY_DIR}/${SUBHOOK_FILENAME})
46+
47+
list(APPEND DEPS_DEFINITIONS SUBHOOK_STATIC)
48+
49+
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} APPEND PROPERTY
50+
COMPILE_DEFINITIONS ${DEPS_DEFINITIONS})
51+
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} APPEND PROPERTY
52+
INCLUDE_DIRECTORIES ${DEPS_INCLUDE_DIR})
53+
54+
foreach(target configreader-external subhook-external)
55+
file(RELATIVE_PATH folder ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
56+
set_property(TARGET ${target} PROPERTY FOLDER ${folder})
57+
endforeach()

deps/configreader/CMakeLists.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
project(configreader)
3+
4+
set(CONFIGREADER_VERSION_MAJOR 1)
5+
set(CONFIGREADER_VERSION_MINOR 0)
6+
set(CONFIGREADER_VERSION_PATCH 1)
7+
8+
set(CONFIGREADER_VERSION ${CONFIGREADER_VERSION_MAJOR})
9+
set(CONFIGREADER_VERSION ${CONFIGREADER_VERSION}.${CONFIGREADER_VERSION_MINOR})
10+
set(CONFIGREADER_VERSION ${CONFIGREADER_VERSION}.${CONFIGREADER_VERSION_PATCH})
11+
12+
set(CONFIGREADER_HEADERS configreader.h)
13+
set(CONFIGREADER_SOURCES configreader.cpp)
14+
15+
add_library(configreader STATIC
16+
${CONFIGREADER_HEADERS}
17+
${CONFIGREADER_SOURCES}
18+
)
19+
20+
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
21+
set_property(DIRECTORY ${CMAKE_SOURCE_DIR}
22+
APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR})
23+
24+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
25+
26+
if(NOT CONFIGREADER_NO_INSTALL)
27+
install(TARGETS configreader LIBRARY DESTINATION lib
28+
ARCHIVE DESTINATION lib
29+
RUNTIME DESTINATION bin)
30+
install(FILES ${CONFIGREADER_HEADERS} DESTINATION include)
31+
endif()
32+
33+
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
34+
set(CPACK_PACKAGE_VERSION_MAJOR ${CONFIGREADER_VERSION_MAJOR})
35+
set(CPACK_PACKAGE_VERSION_MINOR ${CONFIGREADER_VERSION_MINOR})
36+
set(CPACK_PACKAGE_VERSION_PATCH ${CONFIGREADER_VERSION_PATCH})
37+
38+
include(CPack)
39+
include(CTest)
40+
41+
if(BUILD_TESTING AND NOT CONFIGREADER_NO_TESTS)
42+
enable_testing()
43+
44+
add_executable(configreader_tests configreader_tests.cpp)
45+
target_link_libraries(configreader_tests configreader)
46+
47+
add_test(NAME all_tests COMMAND $<TARGET_FILE:configreader_tests>)
48+
endif()

deps/configreader/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Config Reader
2+
3+
[![Build Status][build_status]][build]
4+
[![Build Status - Windows][build_status_win]][build_win]
5+
6+
A small library to read space-separated key-value configuration files like this:
7+
8+
```
9+
int_var 1
10+
float_var 1.5
11+
string_var some string here
12+
vector_var 1 2 3 4 5
13+
```
14+
15+
Building
16+
--------
17+
18+
You can CMake to build this library from source:
19+
20+
```bash
21+
cd configreader
22+
mkdir build && cd build
23+
cmake ../ -DCMAKE_BUILD_TYPE=Release
24+
make
25+
```
26+
27+
Or you can simply drop `configreader.h` and `configreader.cpp` in your project.
28+
29+
Usage
30+
-----
31+
32+
See [this file][example] for some examples of using ConfigReader.
33+
34+
License
35+
-------
36+
37+
```
38+
Copyright (c) 2016 Zeex
39+
All rights reserved.
40+
41+
Redistribution and use in source and binary forms, with or without
42+
modification, are permitted provided that the following conditions are met:
43+
44+
1. Redistributions of source code must retain the above copyright notice,
45+
this list of conditions and the following disclaimer.
46+
2. Redistributions in binary form must reproduce the above copyright notice,
47+
this list of conditions and the following disclaimer in the documentation
48+
and/or other materials provided with the distribution.
49+
50+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
51+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
54+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
55+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
56+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
57+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
58+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
59+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
60+
POSSIBILITY OF SUCH DAMAGE.
61+
```
62+
63+
[example]: https://github.com/Zeex/configreader/blob/master/configreader_tests.cpp
64+
[build]: https://travis-ci.org/Zeex/configreader
65+
[build_status]: https://travis-ci.org/Zeex/configreader.svg?branch=master
66+
[build_win]: https://ci.appveyor.com/project/Zeex/configreader/branch/master
67+
[build_status_win]: https://ci.appveyor.com/api/projects/status/4msd2wh1qihitiy4?svg=true

deps/configreader/appveyor.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '{build}'
2+
3+
configuration:
4+
- Release
5+
6+
environment:
7+
CTEST_OUTPUT_ON_FAILURE: ON
8+
9+
before_build:
10+
- cmake .
11+
12+
build_script:
13+
- cmake --build . --config %CONFIGURATION%
14+
15+
test_script:
16+
- ctest --build-config %CONFIGURATION%

deps/configreader/configreader.cpp

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright (c) 2016 Zeex
2+
// All rights reserved.
3+
//
4+
// Redistribution and use in source and binary forms, with or without
5+
// modification, are permitted provided that the following conditions are met:
6+
//
7+
// 1. Redistributions of source code must retain the above copyright notice,
8+
// this list of conditions and the following disclaimer.
9+
// 2. Redistributions in binary form must reproduce the above copyright notice,
10+
// this list of conditions and the following disclaimer in the documentation
11+
// and/or other materials provided with the distribution.
12+
//
13+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
17+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23+
// POSSIBILITY OF SUCH DAMAGE.
24+
25+
#include <algorithm>
26+
#include <cctype>
27+
#include <cstdlib>
28+
#include <fstream>
29+
#include <functional>
30+
#include <iostream>
31+
#include <sstream>
32+
#include <string>
33+
34+
#include "configreader.h"
35+
36+
namespace {
37+
38+
struct is_space : public std::unary_function<char, bool> {
39+
bool operator()(char c) const {
40+
return std::isspace(c) != 0;
41+
}
42+
};
43+
44+
inline std::string &TrimStringLeft(std::string &s) {
45+
s.erase(s.begin(),
46+
std::find_if(s.begin(), s.end(), std::not1(is_space())));
47+
return s;
48+
}
49+
50+
inline std::string &TrimStringRight(std::string &s) {
51+
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(is_space())).base(),
52+
s.end());
53+
return s;
54+
}
55+
56+
inline std::string &TrimString(std::string &s) {
57+
return TrimStringLeft(TrimStringRight(s));
58+
}
59+
60+
} // anonymous namespace
61+
62+
ConfigReader::ConfigReader() {
63+
}
64+
65+
ConfigReader::ConfigReader(const std::string &filename) {
66+
ReadFromFile(filename);
67+
}
68+
69+
ConfigReader::ConfigReader(std::istream &stream) {
70+
ReadFromStream(stream);
71+
}
72+
73+
bool ConfigReader::ReadFromFile(const std::string &filename) {
74+
std::ifstream stream(filename.c_str());
75+
76+
if (!stream.is_open()) {
77+
return false;
78+
}
79+
80+
ReadFromStream(stream);
81+
return true;
82+
}
83+
84+
void ConfigReader::ReadFromString(const std::string &config) {
85+
std::istringstream stream(config);
86+
ReadFromStream(stream);
87+
}
88+
89+
void ConfigReader::ReadFromStream(std::istream &stream) {
90+
std::string line;
91+
92+
while (std::getline(stream, line)) {
93+
TrimString(line);
94+
95+
std::string::iterator delimIter =
96+
std::find_if(line.begin(), line.end(), is_space());
97+
if (delimIter == line.end()) {
98+
continue;
99+
}
100+
101+
std::string::iterator valueIter =
102+
std::find_if(delimIter, line.end(), std::not1(is_space()));
103+
if (valueIter == line.end()) {
104+
continue;
105+
}
106+
107+
std::string name = std::string(line.begin(), delimIter);
108+
std::string value = std::string(valueIter, line.end());
109+
110+
options_.insert(std::make_pair(name, value));
111+
}
112+
}
113+
114+
void ConfigReader::GetValue(const std::string &name,
115+
std::string &value) const {
116+
value = GetValueWithDefault(name, value);
117+
}
118+
119+
std::string ConfigReader::GetValueWithDefault(
120+
const std::string &name,
121+
const std::string &defaultValue) const
122+
{
123+
option_map::const_iterator iterator = options_.find(name);
124+
if (iterator != options_.end()) {
125+
return iterator->second;
126+
}
127+
return defaultValue;
128+
}

0 commit comments

Comments
 (0)