Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/v0.17.0 - AWSF Dev Days #59

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion OpenTimelineIO
31 changes: 5 additions & 26 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.
//
// SPDX-License-Identifier: Apache-2.0
Expand All @@ -11,41 +11,19 @@ let package = Package(
platforms: [.macOS(.v10_13),
.iOS(.v11)],
products: [
.library(name: "any", targets: ["any"]),
.library(name: "OpenTime_CXX", targets: ["OpenTime_CXX"]),
.library(name: "OpenTimelineIO_CXX", targets: ["OpenTimelineIO_CXX"]),
.library(name: "OpenTimelineIO", targets: ["OpenTimelineIO"])
],

dependencies: [],
targets: [
.target(name: "any",
path: ".",
exclude: [
"CONTRIBUTORS.md", "NOTICE.txt", "CONTRIBUTING.md", "LICENSE.txt", "CODE_OF_CONDUCT.md",
"OTIO_CLA_Corporate.pdf", "OTIO_CLA_Individual.pdf",
"README.md", "Sources/shims/optionallite-shim.cpp", "Sources/shims/otio_header_root-shim.cpp",
"Examples", "OpenTimelineIO", "Tests", "Sources/objc", "Sources/swift"],
sources: ["Sources/shims/any-shim.cpp"],
publicHeadersPath:"OpenTimelineIO/src/deps"),

.target(name: "optionallite",
path: ".",
exclude: [
"CONTRIBUTORS.md", "NOTICE.txt", "CONTRIBUTING.md", "LICENSE.txt", "CODE_OF_CONDUCT.md",
"OTIO_CLA_Corporate.pdf", "OTIO_CLA_Individual.pdf",
"README.md", "Sources/shims/any-shim.cpp", "Sources/shims/otio_header_root-shim.cpp",
"Examples", "OpenTimelineIO", "Tests", "Sources/objc", "Sources/swift"],
sources: ["Sources/shims/optionallite-shim.cpp"],
publicHeadersPath:"OpenTimelineIO/src/deps/optional-lite/include"),

.target(name: "otio_header_root",
path: ".",
exclude: [
"CONTRIBUTORS.md", "NOTICE.txt", "CONTRIBUTING.md", "LICENSE.txt", "CODE_OF_CONDUCT.md",
"OTIO_CLA_Corporate.pdf", "OTIO_CLA_Individual.pdf",
"README.md", "Sources/shims/any-shim.cpp", "Sources/shims/optionallite-shim.cpp",
"Examples", "OpenTimelineIO", "Tests", "Sources/objc", "Sources/swift"],
"README.md", "Examples", "OpenTimelineIO", "Tests", "Sources/objc", "Sources/swift"],
sources: ["Sources/shims/otio_header_root-shim.cpp"],
publicHeadersPath:"OpenTimelineIO/src"),

Expand All @@ -58,13 +36,14 @@ let package = Package(
cxxSettings: [ .headerSearchPath(".")]),

.target(name: "OpenTimelineIO_CXX",
dependencies: ["OpenTime_CXX", "any", "optionallite"],
dependencies: ["OpenTime_CXX"],
path: "OpenTimelineIO/src/opentimelineio",
exclude: ["CMakeLists.txt", "CORE_VERSION_MAP.last.cpp", "OpenTimelineIOConfig.cmake.in"],
sources: ["."],
publicHeadersPath: ".",
cxxSettings: [
.headerSearchPath("."),
.headerSearchPath("../deps/any/"),
.headerSearchPath("../deps/Imath/src/Imath"),
.headerSearchPath("../../../Sources/cpp"),
.headerSearchPath("../deps/rapidjson/include")]),
Expand Down Expand Up @@ -93,5 +72,5 @@ let package = Package(
sources: ["OpenTimelineIOTests"],
resources: [ .copy("data") ])
],
cxxLanguageStandard: CXXLanguageStandard.cxx14
cxxLanguageStandard: CXXLanguageStandard.cxx17
)
76 changes: 38 additions & 38 deletions Sources/objc/CxxAny.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,101 +11,101 @@
#include <opentimelineio/stringUtils.h>
#include <opentimelineio/serializableObject.h>

otio::any cxx_any_to_otio_any(CxxAny const& cxxAny) {
std::any cxx_any_to_otio_any(CxxAny const& cxxAny) {
switch(cxxAny.type_code) {
case CxxAny::NONE:
return otio::any();
return std::any();
case CxxAny::BOOL_:
return otio::any(cxxAny.value.b);
return std::any(cxxAny.value.b);
case CxxAny::INT:
if (cxxAny.value.i < -INT_MIN || cxxAny.value.i > INT_MAX) {
return otio::any(cxxAny.value.i);
return std::any(cxxAny.value.i);
}
else {
return otio::any(int(cxxAny.value.i));
return std::any(int(cxxAny.value.i));
}
case CxxAny::DOUBLE:
return otio::any(cxxAny.value.d);
return std::any(cxxAny.value.d);
case CxxAny::STRING:
return otio::any(std::string(cxxAny.value.s));
return std::any(std::string(cxxAny.value.s));
case CxxAny::SERIALIZABLE_OBJECT:
{ auto so = reinterpret_cast<otio::SerializableObject*>(cxxAny.value.ptr);
return otio::any(otio::SerializableObject::Retainer<>(so));
return std::any(otio::SerializableObject::Retainer<>(so));
}
case CxxAny::RATIONAL_TIME:
return otio::any(*((otio::RationalTime const*)(&cxxAny.value.rt)));
return std::any(*((otio::RationalTime const*)(&cxxAny.value.rt)));
case CxxAny::TIME_RANGE:
return otio::any(*((otio::TimeRange const*)(&cxxAny.value.tr)));
return std::any(*((otio::TimeRange const*)(&cxxAny.value.tr)));
case CxxAny::TIME_TRANSFORM:
return otio::any(*((otio::TimeTransform const*)(&cxxAny.value.tt)));
return std::any(*((otio::TimeTransform const*)(&cxxAny.value.tt)));
case CxxAny::VECTOR:
return otio::any(*reinterpret_cast<otio::AnyVector*>(cxxAny.value.ptr));
return std::any(*reinterpret_cast<otio::AnyVector*>(cxxAny.value.ptr));
case CxxAny::DICTIONARY:
return otio::any(*reinterpret_cast<otio::AnyDictionary*>(cxxAny.value.ptr));
return std::any(*reinterpret_cast<otio::AnyDictionary*>(cxxAny.value.ptr));
default:
return otio::SerializableObject::UnknownType { opentime::string_printf("%s <Swift Type>", cxxAny.value.s) };
}
}

namespace {
struct _ToCxxAny {
std::map<std::type_index, std::function<void (otio::any const&, CxxAny*)>> function_map;
std::map<std::type_index, std::function<void (std::any const&, CxxAny*)>> function_map;

_ToCxxAny() {
auto& m = function_map;
m[std::type_index(typeid(void))] = [](otio::any const& a, CxxAny* cxxAny) {
m[std::type_index(typeid(void))] = [](std::any const& a, CxxAny* cxxAny) {
cxxAny->type_code = CxxAny::NONE;

};
m[std::type_index(typeid(bool))] = [](otio::any const& a, CxxAny* cxxAny) {
m[std::type_index(typeid(bool))] = [](std::any const& a, CxxAny* cxxAny) {
cxxAny->type_code = CxxAny::BOOL_;
cxxAny->value.b = otio::any_cast<bool>(a);
cxxAny->value.b = std::any_cast<bool>(a);
};
m[std::type_index(typeid(int))] = [](otio::any const& a, CxxAny* cxxAny) {
m[std::type_index(typeid(int))] = [](std::any const& a, CxxAny* cxxAny) {
cxxAny->type_code = CxxAny::INT;
cxxAny->value.i = otio::any_cast<int>(a);
cxxAny->value.i = std::any_cast<int>(a);
};
m[std::type_index(typeid(int64_t))] = [](otio::any const& a, CxxAny* cxxAny) {
m[std::type_index(typeid(int64_t))] = [](std::any const& a, CxxAny* cxxAny) {
cxxAny->type_code = CxxAny::INT;
cxxAny->value.i = otio::any_cast<int64_t>(a);
cxxAny->value.i = std::any_cast<int64_t>(a);
};
m[std::type_index(typeid(double))] = [](otio::any const& a, CxxAny* cxxAny) {
m[std::type_index(typeid(double))] = [](std::any const& a, CxxAny* cxxAny) {
cxxAny->type_code = CxxAny::DOUBLE;
cxxAny->value.d = otio::any_cast<double>(a);
cxxAny->value.d = std::any_cast<double>(a);
};
m[std::type_index(typeid(std::string))] = [](otio::any const& a, CxxAny* cxxAny) {
m[std::type_index(typeid(std::string))] = [](std::any const& a, CxxAny* cxxAny) {
cxxAny->type_code = CxxAny::STRING;
cxxAny->value.s = otio::any_cast<std::string const&>(a).c_str();
cxxAny->value.s = std::any_cast<std::string const&>(a).c_str();
};
m[std::type_index(typeid(otio::RationalTime))] = [](otio::any const& a, CxxAny* cxxAny) {
m[std::type_index(typeid(otio::RationalTime))] = [](std::any const& a, CxxAny* cxxAny) {
cxxAny->type_code = CxxAny::RATIONAL_TIME;
cxxAny->value.rt = *((CxxRationalTime*)&otio::any_cast<otio::RationalTime const&>(a));
cxxAny->value.rt = *((CxxRationalTime*)&std::any_cast<otio::RationalTime const&>(a));
};
m[std::type_index(typeid(otio::TimeRange))] = [](otio::any const& a, CxxAny* cxxAny) {
m[std::type_index(typeid(otio::TimeRange))] = [](std::any const& a, CxxAny* cxxAny) {
cxxAny->type_code = CxxAny::TIME_RANGE;
cxxAny->value.tr = *((CxxTimeRange*)&otio::any_cast<otio::TimeRange const&>(a));
cxxAny->value.tr = *((CxxTimeRange*)&std::any_cast<otio::TimeRange const&>(a));
};
m[std::type_index(typeid(otio::TimeTransform))] = [](otio::any const& a, CxxAny* cxxAny) {
m[std::type_index(typeid(otio::TimeTransform))] = [](std::any const& a, CxxAny* cxxAny) {
cxxAny->type_code = CxxAny::TIME_TRANSFORM;
cxxAny->value.tt = *((CxxTimeTransform*)&otio::any_cast<otio::TimeTransform const&>(a));
cxxAny->value.tt = *((CxxTimeTransform*)&std::any_cast<otio::TimeTransform const&>(a));
};
m[std::type_index(typeid(otio::SerializableObject::Retainer<>))] = [](otio::any const& a, CxxAny* cxxAny) {
m[std::type_index(typeid(otio::SerializableObject::Retainer<>))] = [](std::any const& a, CxxAny* cxxAny) {
cxxAny->type_code = CxxAny::SERIALIZABLE_OBJECT;
cxxAny->value.ptr = otio::any_cast<otio::SerializableObject::Retainer<> const&>(a).value;
cxxAny->value.ptr = std::any_cast<otio::SerializableObject::Retainer<> const&>(a).value;
};
m[std::type_index(typeid(otio::AnyVector))] = [](otio::any const& a, CxxAny* cxxAny) {
m[std::type_index(typeid(otio::AnyVector))] = [](std::any const& a, CxxAny* cxxAny) {
cxxAny->type_code = CxxAny::VECTOR;
cxxAny->value.ptr = (void*) &otio::any_cast<otio::AnyVector const&>(a);
cxxAny->value.ptr = (void*) &std::any_cast<otio::AnyVector const&>(a);
};
m[std::type_index(typeid(otio::AnyDictionary))] = [](otio::any const& a, CxxAny* cxxAny) {
m[std::type_index(typeid(otio::AnyDictionary))] = [](std::any const& a, CxxAny* cxxAny) {
cxxAny->type_code = CxxAny::DICTIONARY;
cxxAny->value.ptr = (void*) &otio::any_cast<otio::AnyDictionary const&>(a);
cxxAny->value.ptr = (void*) &std::any_cast<otio::AnyDictionary const&>(a);
};
}
};
}

void otio_any_to_cxx_any(otio::any const& a, CxxAny* cxxAny) {
void otio_any_to_cxx_any(std::any const& a, CxxAny* cxxAny) {
static auto toCxxAny = _ToCxxAny();
auto e = toCxxAny.function_map.find(std::type_index(a.type()));

Expand Down
4 changes: 2 additions & 2 deletions Sources/objc/CxxAnyDictionaryIterator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static bool lookup(CxxAnyDictionaryIterator* dictionaryIterator, T* result) {
if (auto dict = ms->any_dictionary) {
if (dictionaryIterator.iterator != dict->end()) {
if (dictionaryIterator.iterator->second.type() == typeid(T)) {
*result = otio::any_cast<T>(dictionaryIterator.iterator->second);
*result = std::any_cast<T>(dictionaryIterator.iterator->second);
return true;
}
}
Expand Down Expand Up @@ -90,7 +90,7 @@ - (void) store:(CxxAny) cxxAny {
if (ms->stamp == self.startingStamp) {
if (auto dict = ms->any_dictionary) {
if (self.iterator != dict->end()) {
otio::any a = cxx_any_to_otio_any(cxxAny);
std::any a = cxx_any_to_otio_any(cxxAny);
std::swap(self.iterator->second, a);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/objc/CxxAnyDictionaryMutationStamp.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static bool lookup(otio::AnyDictionary::MutationStamp* mutationStamp, NSString*
auto it = dict->find(std::string(key.UTF8String));
if (it != dict->end()) {
if (it->second.type() == typeid(T)) {
*result = otio::any_cast<T>(it->second);
*result = std::any_cast<T>(it->second);
return true;
}
}
Expand Down Expand Up @@ -73,7 +73,7 @@ - (void) store:(NSString*) key
auto skey = std::string(key.UTF8String);
auto it = dict->find(skey);
if (it != dict->end()) {
otio::any a = cxx_any_to_otio_any(cxxAny);
std::any a = cxx_any_to_otio_any(cxxAny);
std::swap(it->second, a);
}
else {
Expand Down
6 changes: 3 additions & 3 deletions Sources/objc/CxxAnyVectorMutationStamp.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static bool lookup(otio::AnyVector::MutationStamp* mutationStamp, int index, T*
if (auto v = mutationStamp->any_vector) {
if (index < v->size()) {
if ((*v)[index].type() == typeid(T)) {
*result = otio::any_cast<T>(v[index]);
*result = std::any_cast<T>(v[index]);
return true;
}
}
Expand Down Expand Up @@ -67,7 +67,7 @@ - (void) store:(int) index
value:(CxxAny) cxxAny {
if (auto v = self.mutationStamp->any_vector) {
if (index >= 0 && index < v->size()) {
otio::any a = cxx_any_to_otio_any(cxxAny);
std::any a = cxx_any_to_otio_any(cxxAny);
std::swap((*v)[index], a);
}
else {
Expand All @@ -94,7 +94,7 @@ - (void) shrinkOrGrow:(int) n
if (auto v = self.mutationStamp->any_vector) {
if (grow) {
for (int i = 0; i < n; i++) {
v->push_back(otio::any());
v->push_back(std::any());
}
}
else {
Expand Down
11 changes: 3 additions & 8 deletions Sources/objc/include/CxxAny.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@

#import "opentime.h"

#if defined(__cplusplus)
#import <opentimelineio/any.h>
namespace otio = opentimelineio::OPENTIMELINEIO_VERSION;
#endif


typedef union CxxAnyValue {
bool b;
int64_t i;
Expand Down Expand Up @@ -45,6 +39,7 @@ typedef struct CxxAny {
} CxxAny;

#if defined(__cplusplus)
void otio_any_to_cxx_any(otio::any const&, CxxAny*);
otio::any cxx_any_to_otio_any(CxxAny const&);
#import <any>
void otio_any_to_cxx_any(std::any const&, CxxAny*);
std::any cxx_any_to_otio_any(CxxAny const&);
#endif
1 change: 1 addition & 0 deletions Sources/objc/include/CxxAnyDictionaryIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright Contributors to the OpenTimelineIO project

#import <Foundation/Foundation.h>
#import "CxxAny.h"
#import "opentime.h"
#import "CxxAnyDictionaryMutationStamp.h"

Expand Down
6 changes: 3 additions & 3 deletions Sources/objc/opentimelineio.mm
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void item_set_source_range(CxxRetainer* self , CxxTimeRange tr) {

void item_set_source_range_to_null(CxxRetainer* self) {
auto item = SO_cast<otio::Item>(self);
item->set_source_range(otio::optional<otio::TimeRange>());
item->set_source_range(std::optional<otio::TimeRange>());
}

CxxTimeRange item_available_range(CxxRetainer* self, CxxErrorStruct* cxxErr) {
Expand Down Expand Up @@ -628,7 +628,7 @@ void media_reference_set_available_range(CxxRetainer* self, CxxTimeRange tr) {
}

void media_reference_clear_available_range(CxxRetainer* self) {
SO_cast<otio::MediaReference>(self)->set_available_range(otio::nullopt);
SO_cast<otio::MediaReference>(self)->set_available_range(std::nullopt);
}

// MARK: - Timeline
Expand All @@ -655,7 +655,7 @@ void timeline_set_global_start_time(CxxRetainer* self, CxxRationalTime rt) {
}

void timeline_clear_global_start_time(CxxRetainer* self) {
SO_cast<otio::Timeline>(self)->set_global_start_time(otio::nullopt);
SO_cast<otio::Timeline>(self)->set_global_start_time(std::nullopt);
}

CxxRationalTime timeline_duration(CxxRetainer* self, CxxErrorStruct* cxxErr) {
Expand Down
7 changes: 0 additions & 7 deletions Sources/shims/any-shim.cpp

This file was deleted.

7 changes: 0 additions & 7 deletions Sources/shims/optionallite-shim.cpp

This file was deleted.