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 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
Original file line number Diff line number Diff line change @@ -35,3 +35,9 @@ add_executable(variable_test ../tests/variable_test.cpp)
3535target_include_directories (variable_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
3636target_link_libraries (variable_test tests_main)
3737target_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 1212#include < tuple>
1313
1414#include " tuple_hash.h"
15- #include " Variable.h"
15+ #include " variable.h"
16+ #include " tuple_binding.h"
1617
1718namespace datalog
1819{
1920
2021using namespace std ;
2122
23+ // High-level API functions
24+
25+ /* *
26+ * @brief create a new variable
27+ *
28+ * @tparam T
29+ * @return Variable<T>*
30+ */
2231template <typename T>
2332Variable<T> *var ()
2433{
2534 return new Variable<T>();
2635}
2736
37+ /* *
38+ * @brief get the value of a variable
39+ *
40+ * @tparam T
41+ * @param t
42+ * @return T
43+ */
2844template <typename T>
2945T val (Variable<T> *t)
3046{
3147 return t->value ();
3248}
3349
50+ /* *
51+ * @brief delete a variable
52+ *
53+ * @tparam T
54+ * @param v
55+ */
3456template <typename T>
3557void deleteVar (Variable<T> *v)
3658{
3759 delete v;
3860}
3961
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
5463
5564template <typename T>
5665bool 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 11#! /bin/bash
22set -e
33../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 11#include " catch.hpp"
2- #include " Variable .h"
2+ #include " variable .h"
33
44using namespace datalog ;
55
You can’t perform that action at this time.
0 commit comments