Skip to content

Commit 11780bf

Browse files
authored
Merge pull request #2 from ZenAlgorithms/fix-install
Installation fixed
2 parents b6c452b + 03f7bc1 commit 11780bf

15 files changed

+244
-202
lines changed

.github/workflows/tests.yml renamed to .github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: Tests
1+
name: CI
22

33
on:
44
push:
55

66
jobs:
7-
tests:
7+
build:
88
runs-on: ubuntu-latest
99
steps:
1010
-

CMakeLists.txt

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,42 @@ INCLUDE(FetchContent)
1111
INCLUDE_DIRECTORIES(lib/headers)
1212

1313
FILE(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/lib/sources/*.cpp")
14-
file(GLOB_RECURSE TESTS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cc")
14+
FILE(GLOB_RECURSE TESTS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cc")
1515

1616
ADD_LIBRARY(expressions STATIC ${SOURCES})
1717

18-
TARGET_INCLUDE_DIRECTORIES(expressions PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/lib/headers)
18+
TARGET_INCLUDE_DIRECTORIES(expressions PUBLIC
19+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/headers>
20+
$<INSTALL_INTERFACE:include>
21+
)
1922

20-
INSTALL(TARGETS expressions DESTINATION lib)
21-
INSTALL(DIRECTORY src/headers/ DESTINATION include)
23+
INSTALL(DIRECTORY lib/headers/ DESTINATION include)
24+
25+
INSTALL(TARGETS expressions
26+
EXPORT ExpressionsTargets
27+
LIBRARY DESTINATION lib
28+
ARCHIVE DESTINATION lib
29+
RUNTIME DESTINATION bin
30+
INCLUDES DESTINATION include
31+
)
32+
33+
INSTALL(EXPORT ExpressionsTargets
34+
FILE ExpressionsTargets.cmake
35+
NAMESPACE expressions::
36+
DESTINATION lib/cmake/Expressions
37+
)
38+
39+
INCLUDE(CMakePackageConfigHelpers)
40+
CONFIGURE_PACKAGE_CONFIG_FILE(
41+
cmake/ExpressionsConfig.cmake.in
42+
${CMAKE_CURRENT_BINARY_DIR}/ExpressionsConfig.cmake
43+
INSTALL_DESTINATION lib/cmake/Expressions
44+
)
45+
46+
INSTALL(FILES
47+
${CMAKE_CURRENT_BINARY_DIR}/ExpressionsConfig.cmake
48+
DESTINATION lib/cmake/Expressions
49+
)
2250

2351
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
2452

Dockerfile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ FROM iantorres/boosted:amd64-latest
22

33
COPY . .
44

5-
RUN cmake . -DBUILD_TESTS=ON \
5+
RUN mkdir build \
6+
&& cd build \
7+
&& cmake .. -DBUILD_TESTS=ON \
68
&& make \
7-
&& cd bin \
8-
&& ./tests
9+
&& cd ../bin \
10+
&& ./tests
11+
12+
RUN mkdir install \
13+
&& cd install \
14+
&& cmake .. -DBUILD_TESTS=OFF \
15+
&& make \
16+
&& make install

README.md

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
# Expressions
22

3+
## Usage
4+
5+
![Something to understand how works ...](about.png)
6+
7+
See more [examples](https://github.com/ZenAlgorithms/Expressions/blob/master/tests/implementation_test.cc) ...
8+
39
## Build
410

511
```shell
612
git clone [email protected]:ZenAlgorithms/Expressions.git
713
cd Expressions
8-
cmake .
14+
mkdir build
15+
cd build
16+
cmake ..
917
make
1018
make install
11-
```
12-
13-
## Usage
14-
15-
```c++
16-
#include <expression/expression.hpp>
17-
18-
using namespace std;
19-
20-
auto it = expression::from_string("/api/servers/{server}/status");
21-
22-
auto result = it->query("/api/servers/production/status");
23-
24-
cout << result->matches() << endl;
25-
// 1
26-
27-
cout << result->bindings()->at("server") << endl;
28-
// production
2919
```

about.png

128 KB
Loading

cmake/ExpressionsConfig.cmake.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@PACKAGE_INIT@
2+
3+
INCLUDE(CMakeFindDependencyMacro)
4+
5+
# Incluir el archivo de objetivos
6+
INCLUDE("${CMAKE_CURRENT_LIST_DIR}/ExpressionsTargets.cmake")

lib/headers/expression.hpp

Lines changed: 0 additions & 59 deletions
This file was deleted.

lib/headers/expression_result.hpp

Lines changed: 0 additions & 37 deletions
This file was deleted.

lib/headers/expressions/container.hpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <vector>
5+
#include <memory>
6+
#include <regex>
7+
8+
#include <expressions/result.hpp>
9+
10+
namespace expressions {
11+
class container : public std::enable_shared_from_this<container> {
12+
std::string regex_;
13+
std::vector<std::string> arguments_{};
14+
15+
public:
16+
/**
17+
* Expression constructor
18+
*
19+
* @param regex
20+
* @param arguments
21+
*/
22+
container(
23+
std::string regex,
24+
std::vector<std::string> arguments
25+
);
26+
27+
/**
28+
* Get the regex
29+
*
30+
* @return std::string
31+
*/
32+
std::string
33+
get_regex() const;
34+
35+
/**
36+
* Get the arguments
37+
*
38+
* @return std::vector<std::string>
39+
*/
40+
std::vector<std::string>
41+
get_arguments() const;
42+
43+
/**
44+
* Query the expression
45+
*
46+
* @param input
47+
* @return
48+
*/
49+
std::shared_ptr<result>
50+
query(const std::string &input);
51+
52+
/**
53+
* Creates a expression from strings
54+
*
55+
* @param input
56+
* @return std::shared_ptr<expression>
57+
*/
58+
static std::shared_ptr<container>
59+
from_string(const std::string &input);
60+
};
61+
}

lib/headers/expressions/result.hpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <unordered_map>
5+
6+
namespace expressions {
7+
class result : public std::enable_shared_from_this<result> {
8+
bool _matches = false;
9+
std::unordered_map<std::string, std::string> _bindings;
10+
11+
public:
12+
/**
13+
* Expression result constructor
14+
*
15+
* @param matches
16+
* @param bindings
17+
*/
18+
result(
19+
bool matches,
20+
std::unordered_map<std::string, std::string> bindings
21+
);
22+
23+
/**
24+
* Get matches
25+
*
26+
* @return
27+
*/
28+
bool
29+
matches() const;
30+
31+
/**
32+
* Get bindings
33+
*
34+
* @return
35+
*/
36+
std::unordered_map<std::string, std::string>
37+
bindings() const;
38+
};
39+
}

lib/sources/container.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <expressions/container.hpp>
2+
3+
namespace expressions {
4+
container::container(std::string regex, std::vector<std::string> arguments)
5+
: regex_(std::move(regex)), arguments_(std::move(arguments)) {
6+
}
7+
8+
std::string container::get_regex() const {
9+
return regex_;
10+
}
11+
12+
std::vector<std::string> container::get_arguments() const {
13+
return arguments_;
14+
}
15+
16+
std::shared_ptr<result> container::query(const std::string &input) {
17+
std::unordered_map<std::string, std::string> _bindings;
18+
const std::regex _pattern(regex_);
19+
bool _matches = false;
20+
if (std::smatch _match; std::regex_match(input, _match, _pattern)) {
21+
_matches = true;
22+
auto _iterator = _match.begin();
23+
++_iterator;
24+
for (auto &_key: arguments_) {
25+
_bindings[_key] = *_iterator;
26+
++_iterator;
27+
}
28+
}
29+
return std::make_shared<result>(_matches, _bindings);
30+
}
31+
32+
std::shared_ptr<container> container::from_string(const std::string &input) {
33+
std::size_t _open = input.find('{');
34+
std::size_t _close = input.find('}');
35+
std::size_t _position = 0;
36+
37+
std::vector<std::string> _arguments;
38+
std::string _regex;
39+
40+
if (_open == std::string::npos && _close == std::string::npos)
41+
return std::make_shared<container>(std::string{input.data()}, _arguments);
42+
43+
while (_open != std::string::npos && _close != std::string::npos) {
44+
_regex.append(input.substr(_position, _open - _position));
45+
std::string _value{input.substr(_open + 1, _close - _open - 1)};
46+
47+
if (std::find(_arguments.begin(), _arguments.end(), _value) != _arguments.end())
48+
throw std::runtime_error("groups can't be repeated ... ");
49+
50+
_regex.append(R"(([a-zA-Z0-9\-_]+))");
51+
_arguments.emplace_back(_value);
52+
53+
_position = _close + 1;
54+
_open = input.find('{', _close);
55+
_close = input.find('}', _open);
56+
57+
if (_open == std::string::npos && _close == std::string::npos && _position != input.size())
58+
_regex.append(input.substr(_position, input.size() - _position));
59+
}
60+
61+
return std::make_shared<container>(_regex, _arguments);
62+
}
63+
}

0 commit comments

Comments
 (0)