- all 15 OakNode* handle types become neutral by-value structs
{ctx, addref, release, abi_version}; shared box in
src/node/c_api/nodehandle.h with owns flag (borrowed accessors
return non-owning boxes; graph insertion flips owns off)
- oaktimeline/oaktask/oakrender call sites and their own public
headers migrated to value handles; identity comparisons in
timeline/task now compare native pointers
- regressions green: oaknode 96, oaktimeline 117, oaktask 106,
oakrender 44, oakcommon 193, oakcodec 18, oakaudio 36
137 lines
3.0 KiB
C++
137 lines
3.0 KiB
C++
/***
|
|
|
|
Oak Video Editor - Non-Linear Video Editor
|
|
Copyright (C) 2026 Oak Team
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
#include "node/factory.h"
|
|
|
|
#include "factory.h"
|
|
|
|
#include "nodehandle.h"
|
|
#include "valueconvert.h"
|
|
|
|
using oaknode_c_api::make_handle;
|
|
|
|
int oaknode_factory_initialize(void)
|
|
{
|
|
try {
|
|
if (olive::NodeFactory::get_library().empty()) {
|
|
olive::NodeFactory::initialize();
|
|
}
|
|
return OAKNODE_OK;
|
|
} catch (...) {
|
|
return OAKNODE_E_FAILED;
|
|
}
|
|
}
|
|
|
|
void oaknode_factory_destroy(void)
|
|
{
|
|
try {
|
|
olive::NodeFactory::destroy();
|
|
} catch (...) {
|
|
}
|
|
}
|
|
|
|
int oaknode_factory_id_count(int *out_count)
|
|
{
|
|
if (!out_count) {
|
|
return OAKNODE_E_INVALID;
|
|
}
|
|
|
|
try {
|
|
if (olive::NodeFactory::get_library().empty()) {
|
|
return OAKNODE_E_STATE;
|
|
}
|
|
*out_count = static_cast<int>(olive::NodeFactory::get_library().size());
|
|
return OAKNODE_OK;
|
|
} catch (...) {
|
|
return OAKNODE_E_FAILED;
|
|
}
|
|
}
|
|
|
|
int oaknode_factory_id_at(int index, char *buf, int buf_size)
|
|
{
|
|
try {
|
|
const std::vector<olive::Node *> &library =
|
|
olive::NodeFactory::get_library();
|
|
if (library.empty()) {
|
|
return OAKNODE_E_STATE;
|
|
}
|
|
if (index < 0 || index >= static_cast<int>(library.size())) {
|
|
return OAKNODE_E_NOT_FOUND;
|
|
}
|
|
return oaknode_c_api::copy_string(library[size_t(index)]->id(), buf,
|
|
buf_size);
|
|
} catch (...) {
|
|
return OAKNODE_E_FAILED;
|
|
}
|
|
}
|
|
|
|
int oaknode_factory_name_from_id(const char *type_id, char *buf,
|
|
int buf_size)
|
|
{
|
|
if (!type_id) {
|
|
return OAKNODE_E_INVALID;
|
|
}
|
|
|
|
try {
|
|
return oaknode_c_api::copy_string(
|
|
olive::NodeFactory::get_name_from_id(type_id), buf, buf_size);
|
|
} catch (...) {
|
|
return OAKNODE_E_FAILED;
|
|
}
|
|
}
|
|
|
|
OakNodeNode oaknode_factory_create_from_id(const char *type_id)
|
|
{
|
|
if (!type_id) {
|
|
return OakNodeNode{};
|
|
}
|
|
|
|
try {
|
|
return make_handle<OakNodeNode>(
|
|
olive::NodeFactory::create_from_id(type_id), true,
|
|
oaknode_c_api::delete_as<olive::Node>);
|
|
} catch (...) {
|
|
return OakNodeNode{};
|
|
}
|
|
}
|
|
|
|
int oaknode_factory_node_at(int index, OakNodeNode *out_node)
|
|
{
|
|
if (!out_node) {
|
|
return OAKNODE_E_INVALID;
|
|
}
|
|
|
|
try {
|
|
const std::vector<olive::Node *> &library =
|
|
olive::NodeFactory::get_library();
|
|
if (library.empty()) {
|
|
return OAKNODE_E_STATE;
|
|
}
|
|
if (index < 0 || index >= static_cast<int>(library.size())) {
|
|
return OAKNODE_E_NOT_FOUND;
|
|
}
|
|
*out_node = make_handle<OakNodeNode>(library[size_t(index)], false,
|
|
nullptr);
|
|
return OAKNODE_OK;
|
|
} catch (...) {
|
|
return OAKNODE_E_FAILED;
|
|
}
|
|
}
|