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

Refactor#7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Z80coder merged 3 commits intomasterfromrefactor
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions.vscode/tasks.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,9 +7,10 @@
"label": "build",
"type": "shell",
"command": "cd build; make",
"problemMatcher": [
"$gcc"
],
"problemMatcher": {
"base": "$gcc",
"fileLocation": ["relative", "../"]
},
"group": {
"kind": "build",
"isDefault": true
Expand Down
6 changes: 6 additions & 0 deletionssrc/CMakeLists.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,3 +35,9 @@ add_executable(variable_test ../tests/variable_test.cpp)
target_include_directories(variable_testPUBLIC${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(variable_test tests_main)
target_compile_definitions(variable_testPUBLICUNIX)

# tuple_binding_test target
add_executable(tuple_binding_test ../tests/tuple_binding_test.cpp)
target_include_directories(tuple_binding_testPUBLIC${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(tuple_binding_test tests_main)
target_compile_definitions(tuple_binding_testPUBLICUNIX)
39 changes: 24 additions & 15 deletionssrc/Datalog.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,45 +12,54 @@
#include <tuple>

#include "tuple_hash.h"
#include "Variable.h"
#include "variable.h"
#include "tuple_binding.h"

namespace datalog
{

using namespace std;

// High-level API functions

/**
* @brief create a new variable
*
* @tparam T
* @return Variable<T>*
*/
template <typename T>
Variable<T> *var()
{
return new Variable<T>();
}

/**
* @brief get the value of a variable
*
* @tparam T
* @param t
* @return T
*/
template <typename T>
T val(Variable<T> *t)
{
return t->value();
}

/**
* @brief delete a variable
*
* @tparam T
* @param v
*/
template <typename T>
void deleteVar(Variable<T> *v)
{
delete v;
}

template <typename T>
void unbind(Variable<T> *t)
{
t->unbind();
}

template <typename T>
void unbind(const T &t) {}

template <typename... Ts>
void unbind(const tuple<Ts...> &tuple)
{
apply([](auto &&... args) { ((unbind(args), ...)); }, tuple);
}
// TODO: all functions below here to be refactored into separate files

template <typename T>
bool bind(const T &a, const T &b)
Expand Down
47 changes: 47 additions & 0 deletionssrc/tuple_binding.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
#ifndef TUPLES_H
#define TUPLES_H

#include "variable.h"

namespace datalog {

// TODO: reify the concept of a tuple of values and pointers to Variables

/**
* @brief unbind a variable
*
* @tparam T
* @param t
*/
template <typename T>
void unbind(Variable<T> *t)
{
t->unbind();
}

/**
* @brief unbind no-operation for types that are not variables (i.e. values)
*
* @tparam T
* @param t
*/
template <typename T>
void unbind(const T &t) {
// If t is not a Variable then perform no-op
}

/**
* @brief apply unbind to a tuple of variables and values
*
* @tparam Ts
* @param tuple
*/
template <typename... Ts>
void unbind(const tuple<Ts...> &tuple)
{
apply([](auto &&... args) { ((unbind(args), ...)); }, tuple);
}

}

#endif // TUPLES_H
File renamed without changes.
3 changes: 2 additions & 1 deletiontests/run_tests.sh
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -e
../build/types_test
../build/variable_test
../build/variable_test
../build/tuple_binding_test
21 changes: 21 additions & 0 deletionstests/tuple_binding_test.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
#include "catch.hpp"
#include "Datalog.h"

using namespace datalog;
using namespace std;

bool unbindTest()
{
auto v = var<int>();
v->bind(3);
tuple<decltype(v), int> t{v, 3};
v->unbind();
bool returnVal = !get<0>(t)->isBound();
deleteVar(v);
return returnVal;
}

TEST_CASE("tuple binding test", "[tuple-binding]")
{
REQUIRE(unbindTest());
}
2 changes: 1 addition & 1 deletiontests/variable_test.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
#include "catch.hpp"
#include "Variable.h"
#include "variable.h"

using namespace datalog;

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp