8000 pull out tuple binding · Z80coder/datalog-cpp@8bbc896 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8bbc896

Browse files
committed
pull out tuple binding
1 parent ad0f8f9 commit 8bbc896

File tree

4 files changed

+67
-17
lines changed

4 files changed

+67
-17
lines changed

src/Datalog.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,51 @@
1212
#include <tuple>
1313

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

1718
namespace datalog
1819
{
1920

2021
using namespace std;
2122

23+
/**
24+
* @brief create a new variable
25+
*
26+
* @tparam T
27+
* @return Variable<T>*
28+
*/
2229
template <typename T>
2330
Variable<T> *var()
2431
{
2532
return new Variable<T>();
2633
}
2734

35+
/**
36+
* @brief get the value of a variable
37+
*
38+
* @tparam T
39+
* @param 10000 t
40+
* @return T
41+
*/
2842
template <typename T>
2943
T val(Variable<T> *t)
3044
{
3145
return t->value();
3246
}
3347

48+
/**
49+
* @brief delete a variable
50+
*
51+
* @tparam T
52+
* @param v
53+
*/
3454
template <typename T>
3555
void deleteVar(Variable<T> *v)
3656
{
3757
delete v;
3858
}
3959

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-
}
54-
5560
template <typename T>
5661
bool bind(const T &a, const T &b)
5762
{

src/tuple_binding.h

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

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
using namespace datalog;
55

0 commit comments

Comments
 (0)
0