Add a C++ wrapper around TC FFI
This uses CMake to build a simple Rust library (in `src/tc/rust`) that just re-exports everything from the `taskchampion-lib` crate. The C++ wrappers then wrap this into C++ objects with proper lifecycle maintenance, in the `tc` namespace. The C++ wrappers are incomplete, and missing methods are tagged with "TODO". These will be added as needed.
This commit is contained in:
committed by
Tomas Babej
parent
fd03169314
commit
8c30400af3
98
src/tc/WorkingSet.cpp
Normal file
98
src/tc/WorkingSet.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2022, Dustin J. Mitchell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// https://www.opensource.org/licenses/mit-license.php
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmake.h>
|
||||
#include <format.h>
|
||||
#include "tc/WorkingSet.h"
|
||||
#include "tc/Task.h"
|
||||
#include "tc/util.h"
|
||||
|
||||
using namespace tc::ffi;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
tc::WorkingSet::WorkingSet (WorkingSet &&other) noexcept
|
||||
{
|
||||
// move inner from other
|
||||
inner = unique_tcws_ptr (
|
||||
other.inner.release (),
|
||||
[](TCWorkingSet* ws) { tc_working_set_free (ws); });
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
tc::WorkingSet& tc::WorkingSet::operator= (WorkingSet &&other) noexcept
|
||||
{
|
||||
if (this != &other) {
|
||||
// move inner from other
|
||||
inner = unique_tcws_ptr (
|
||||
other.inner.release (),
|
||||
[](TCWorkingSet* ws) { tc_working_set_free (ws); });
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
tc::WorkingSet::WorkingSet (tc::ffi::TCWorkingSet* tcws)
|
||||
{
|
||||
inner = unique_tcws_ptr (
|
||||
tcws,
|
||||
[](TCWorkingSet* ws) { tc_working_set_free (ws); });
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
size_t tc::WorkingSet::len () const noexcept
|
||||
{
|
||||
return tc_working_set_len (&*inner);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
size_t tc::WorkingSet::largest_index () const noexcept
|
||||
{
|
||||
return tc_working_set_largest_index (&*inner);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::optional<std::string> tc::WorkingSet::by_index (size_t index) const noexcept
|
||||
{
|
||||
TCUuid uuid;
|
||||
if (tc_working_set_by_index (&*inner, index, &uuid)) {
|
||||
return std::make_optional (tc2uuid (uuid));
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::optional<size_t> tc::WorkingSet::by_uuid (const std::string &uuid) const noexcept
|
||||
{
|
||||
auto index = tc_working_set_by_uuid (&*inner, uuid2tc (uuid));
|
||||
if (index > 0) {
|
||||
return std::make_optional (index);
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Reference in New Issue
Block a user