File tree Expand file tree Collapse file tree 8 files changed +105
-20
lines changed Expand file tree Collapse file tree 8 files changed +105
-20
lines changed Original file line number Diff line number Diff line change 7
7
"label" : " build" ,
8
8
"type" : " shell" ,
9
9
"command" : " cd build; make" ,
10
- "problemMatcher" : [
11
- " $gcc"
12
- ],
10
+ "problemMatcher" : {
11
+ "base" : " $gcc" ,
12
+ "fileLocation" : [" relative" , " ../" ]
13
+ },
13
14
"group" : {
14
15
"kind" : " build" ,
15
16
"isDefault" : true
Original file line number Diff line number Diff line change @@ -35,3 +35,9 @@ add_executable(variable_test ../tests/variable_test.cpp)
35
35
target_include_directories (variable_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
36
36
target_link_libraries (variable_test tests_main )
37
37
target_compile_definitions (variable_test PUBLIC UNIX )
38
+
39
+ # tuple_binding_test target
40
+ add_executable (tuple_binding_test ../tests/tuple_binding_test.cpp )
41
+ target_include_directories (tuple_binding_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
42
+ target_link_libraries (tuple_binding_test tests_main )
43
+ target_compile_definitions (tuple_binding_test PUBLIC UNIX )
Original file line number Diff line number Diff line change 12
12
#include < tuple>
13
13
14
14
#include " tuple_hash.h"
15
- #include " Variable.h"
15
+ #include " variable.h"
16
+ #include " tuple_binding.h"
16
17
17
18
namespace datalog
18
19
{
19
20
20
21
using namespace std ;
21
22
23
+ // High-level API functions
24
+
25
+ /* *
26
+ * @brief create a new variable
27
+ *
28
+ * @tparam T
29
+ * @return Variable<T>*
30
+ */
22
31
template <typename T>
23
32
Variable<T> *var ()
24
33
{
25
34
return new Variable<T>();
26
35
}
27
36
37
+ /* *
38
+ * @brief get the value of a variable
39
+ *
40
+ * @tparam T
41
+ * @param t
42
+ * @return T
43
+ */
28
44
template <typename T>
29
45
T val (Variable<T> *t)
30
46
{
31
47
return t->value ();
32
48
}
33
49
50
+ /* *
51
+ * @brief delete a variable
52
+ *
53
+ * @tparam T
54
+ * @param v
55
+ */
34
56
template <typename T>
35
57
void deleteVar (Variable<T> *v)
36
58
{
37
59
delete v;
38
60
}
39
61
40
- template <typename T>
41
- void unbind (Variable<T> *t)
42
- {
43
- t->unbind ();
44
- }
45
-
46
- template <typename T>
47
- void unbind (const T &t) {}
48
-
49
- template <typename ... Ts>
50
- void unbind (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
54
63
55
64
template <typename T>
56
65
bool bind (const T &a, const T &b)
Original file line number Diff line number Diff line change
1
+ #ifndef TUPLES_H
2
+ #define TUPLES_H
3
+
4
+ #include " variable.h"
5
+
6
+ namespace datalog {
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
+ void unbind (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
+ void unbind (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
+ void unbind (const tuple<Ts...> &tuple)
41
+ {
42
+ apply ([](auto &&... args) { ((unbind (args), ...)); }, tuple);
43
+ }
44
+
45
+ }
46
+
47
+ #endif // TUPLES_H
File renamed without changes.
Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
2
set -e
3
3
../build/types_test
4
- ../build/variable_test
4
+ ../build/variable_test
5
+ ../build/tuple_binding_test
Original file line number Diff line number Diff line change
1
+ #include " catch.hpp"
2
+ #include " Datalog.h"
3
+
4
+ using namespace datalog ;
5
+ using namespace std ;
6
+
7
+ bool unbindTest ()
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
+ }
Original file line number Diff line number Diff line change 1
1
#include " catch.hpp"
2
- #include " Variable .h"
2
+ #include " variable .h"
3
3
4
4
using namespace datalog ;
5
5
You can’t perform that action at this time.
0 commit comments