Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit82b5a6e

Browse files
authored
Merge pull request#7 from Z80coder/refactor
Refactor
2 parentse1003a3 +2c733cd commit82b5a6e

File tree

8 files changed

+105
-20
lines changed

8 files changed

+105
-20
lines changed

‎.vscode/tasks.json‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
"label":"build",
88
"type":"shell",
99
"command":"cd build; make",
10-
"problemMatcher": [
11-
"$gcc"
12-
],
10+
"problemMatcher": {
11+
"base":"$gcc",
12+
"fileLocation": ["relative","../"]
13+
},
1314
"group": {
1415
"kind":"build",
1516
"isDefault":true

‎src/CMakeLists.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ add_executable(variable_test ../tests/variable_test.cpp)
3535
target_include_directories(variable_testPUBLIC${CMAKE_CURRENT_SOURCE_DIR})
3636
target_link_libraries(variable_test tests_main)
3737
target_compile_definitions(variable_testPUBLICUNIX)
38+
39+
# tuple_binding_test target
40+
add_executable(tuple_binding_test ../tests/tuple_binding_test.cpp)
41+
target_include_directories(tuple_binding_testPUBLIC${CMAKE_CURRENT_SOURCE_DIR})
42+
target_link_libraries(tuple_binding_test tests_main)
43+
target_compile_definitions(tuple_binding_testPUBLICUNIX)

‎src/Datalog.h‎

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,54 @@
1212
#include<tuple>
1313

1414
#include"tuple_hash.h"
15-
#include"Variable.h"
15+
#include"variable.h"
16+
#include"tuple_binding.h"
1617

1718
namespacedatalog
1819
{
1920

2021
usingnamespacestd;
2122

23+
// High-level API functions
24+
25+
/**
26+
* @brief create a new variable
27+
*
28+
* @tparam T
29+
* @return Variable<T>*
30+
*/
2231
template<typename T>
2332
Variable<T> *var()
2433
{
2534
returnnew Variable<T>();
2635
}
2736

37+
/**
38+
* @brief get the value of a variable
39+
*
40+
* @tparam T
41+
* @param t
42+
* @return T
43+
*/
2844
template<typename T>
2945
Tval(Variable<T> *t)
3046
{
3147
return t->value();
3248
}
3349

50+
/**
51+
* @brief delete a variable
52+
*
53+
* @tparam T
54+
* @param v
55+
*/
3456
template<typename T>
3557
voiddeleteVar(Variable<T> *v)
3658
{
3759
delete v;
3860
}
3961

40-
template<typename T>
41-
voidunbind(Variable<T> *t)
42-
{
43-
t->unbind();
44-
}
45-
46-
template<typename T>
47-
voidunbind(const T &t) {}
48-
49-
template<typename... Ts>
50-
voidunbind(const tuple<Ts...> &tuple)
51-
{
52-
apply([](auto &&... args) { ((unbind(args), ...)); }, tuple);
53-
}
62+
// TODO: all functions below here to be refactored into separate files
5463

5564
template<typename T>
5665
boolbind(const T &a,const T &b)

‎src/tuple_binding.h‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef TUPLES_H
2+
#defineTUPLES_H
3+
4+
#include"variable.h"
5+
6+
namespacedatalog {
7+
8+
// TODO: reify the concept of a tuple of values and pointers to Variables
9+
10+
/**
11+
* @brief unbind a variable
12+
*
13+
* @tparam T
14+
* @param t
15+
*/
16+
template<typename T>
17+
voidunbind(Variable<T> *t)
18+
{
19+
t->unbind();
20+
}
21+
22+
/**
23+
* @brief unbind no-operation for types that are not variables (i.e. values)
24+
*
25+
* @tparam T
26+
* @param t
27+
*/
28+
template<typename T>
29+
voidunbind(const T &t) {
30+
// If t is not a Variable then perform no-op
31+
}
32+
33+
/**
34+
* @brief apply unbind to a tuple of variables and values
35+
*
36+
* @tparam Ts
37+
* @param tuple
38+
*/
39+
template<typename... Ts>
40+
voidunbind(const tuple<Ts...> &tuple)
41+
{
42+
apply([](auto &&... args) { ((unbind(args), ...)); }, tuple);
43+
}
44+
45+
}
46+
47+
#endif// TUPLES_H
File renamed without changes.

‎tests/run_tests.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
22
set -e
33
../build/types_test
4-
../build/variable_test
4+
../build/variable_test
5+
../build/tuple_binding_test

‎tests/tuple_binding_test.cpp‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include"catch.hpp"
2+
#include"Datalog.h"
3+
4+
usingnamespacedatalog;
5+
usingnamespacestd;
6+
7+
boolunbindTest()
8+
{
9+
auto v = var<int>();
10+
v->bind(3);
11+
tuple<decltype(v),int> t{v,3};
12+
v->unbind();
13+
bool returnVal = !get<0>(t)->isBound();
14+
deleteVar(v);
15+
return returnVal;
16+
}
17+
18+
TEST_CASE("tuple binding test","[tuple-binding]")
19+
{
20+
REQUIRE(unbindTest());
21+
}

‎tests/variable_test.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include"catch.hpp"
2-
#include"Variable.h"
2+
#include"variable.h"
33

44
usingnamespacedatalog;
55

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp