Skip to content

Commit

Permalink
Support for C++17 (#1713)
Browse files Browse the repository at this point in the history
* Use std::any and std::optional
* Update Python bindings
* Fix missing std::any_cast
* Set minimum OSX version to 10.13

---------

Signed-off-by: Darby Johnston <[email protected]>
  • Loading branch information
darbyjohnston authored Mar 28, 2024
1 parent afcb552 commit ddb39f5
Show file tree
Hide file tree
Showing 61 changed files with 675 additions and 742 deletions.
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
[submodule "src/deps/optional-lite"]
path = src/deps/optional-lite
url = https://github.com/martinmoene/optional-lite
[submodule "src/deps/pybind11"]
path = src/deps/pybind11
url = https://github.com/pybind/pybind11.git
[submodule "src/deps/rapidjson"]
path = src/deps/rapidjson
url = https://github.com/Tencent/rapidjson.git
[submodule "src/deps/any"]
path = src/deps/any
url = https://github.com/thelink2012/any.git
[submodule "src/deps/Imath"]
path = src/deps/Imath
url = https://github.com/AcademySoftwareFoundation/Imath
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(OTIO_AUTHOR_EMAIL "[email protected]")
set(OTIO_LICENSE "Modified Apache 2.0 License")

set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "Minimum OS X deployment version")

project(OpenTimelineIO VERSION ${OTIO_VERSION} LANGUAGES C CXX)

Expand Down Expand Up @@ -142,7 +143,7 @@ endif()
# Global language settings

if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
endif()

set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
9 changes: 1 addition & 8 deletions src/deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#----- Other dependencies

# detect if the submodules haven't been updated
set(DEPS_SUBMODULES any optional-lite pybind11 rapidjson)
set(DEPS_SUBMODULES pybind11 rapidjson)
foreach(submodule IN LISTS DEPS_SUBMODULES)
file(GLOB SUBMOD_CONTENTS ${submodule})
list(LENGTH SUBMOD_CONTENTS SUBMOD_CONTENT_LEN)
Expand All @@ -20,13 +20,6 @@ if(OTIO_PYTHON_INSTALL)
add_subdirectory(pybind11)
endif()

if(OTIO_CXX_INSTALL AND OTIO_DEPENDENCIES_INSTALL)
install(FILES any/any.hpp
DESTINATION "${OTIO_RESOLVED_CXX_INSTALL_DIR}/include/opentimelineio/deps/any")
install(FILES optional-lite/include/nonstd/optional.hpp
DESTINATION "${OTIO_RESOLVED_CXX_INSTALL_DIR}/include/opentimelineio/deps/nonstd")
endif()

if (USE_DEPS_IMATH)
# preserve BUILD_SHARED_LIBS options for this project, but set it off for Imath
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
Expand Down
1 change: 0 additions & 1 deletion src/deps/any
Submodule any deleted from bfc77f
1 change: 0 additions & 1 deletion src/deps/optional-lite
Submodule optional-lite deleted from be720e
3 changes: 0 additions & 3 deletions src/opentimelineio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# opentimelineio/CMakeLists.txt

set(OPENTIMELINEIO_HEADER_FILES
any.h
anyDictionary.h
anyVector.h
clip.h
Expand All @@ -22,7 +21,6 @@ set(OPENTIMELINEIO_HEADER_FILES
marker.h
mediaReference.h
missingReference.h
optional.h
safely_typed_any.h
serializableCollection.h
serializableObject.h
Expand Down Expand Up @@ -83,7 +81,6 @@ target_include_directories(opentimelineio
PRIVATE "${IMATH_INCLUDES}"
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/src/deps"
"${PROJECT_SOURCE_DIR}/src/deps/optional-lite/include"
"${PROJECT_SOURCE_DIR}/src/deps/rapidjson/include"
"${IMATH_INCLUDES}")

Expand Down
14 changes: 0 additions & 14 deletions src/opentimelineio/any.h

This file was deleted.

12 changes: 6 additions & 6 deletions src/opentimelineio/anyDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#pragma once

#include "opentimelineio/any.h"
#include "opentimelineio/version.h"

#include <any>
#include <assert.h>
#include <map>
#include <string>
Expand All @@ -14,7 +14,7 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {

/**
* An AnyDictionary has exactly the same API as
* std::map<std::string, any>
* std::map<std::string, std::any>
*
* except that it records a "time-stamp" that bumps monotonically every time an
* operation that would invalidate iterators is performed.
Expand All @@ -26,7 +26,7 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
* and take steps to safe-guard themselves from causing a crash. (Yes,
* I'm talking to you, Python...)
*/
class AnyDictionary : private std::map<std::string, any>
class AnyDictionary : private std::map<std::string, std::any>
{
public:
using map::map;
Expand Down Expand Up @@ -125,7 +125,7 @@ class AnyDictionary : private std::map<std::string, any>
/// @TODO: remove all of these @{

// if key is in this, and the type of key matches the type of result, then
// set result to the value of any_cast<type>(this[key]) and return true,
// set result to the value of std::any_cast<type>(this[key]) and return true,
// otherwise return false
template <typename containedType>
bool get_if_set(const std::string& key, containedType* result) const
Expand All @@ -141,7 +141,7 @@ class AnyDictionary : private std::map<std::string, any>
&& (it->second.type().hash_code()
== typeid(containedType).hash_code()))
{
*result = any_cast<containedType>(it->second);
*result = std::any_cast<containedType>(it->second);
return true;
}
else
Expand Down Expand Up @@ -171,7 +171,7 @@ class AnyDictionary : private std::map<std::string, any>
&& (d_it->second.type().hash_code()
== typeid(containedType).hash_code()))
{
*result = any_cast<containedType>(d_it->second);
*result = std::any_cast<containedType>(d_it->second);
return true;
}
else
Expand Down
7 changes: 4 additions & 3 deletions src/opentimelineio/anyVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@

#pragma once

#include "opentimelineio/any.h"
#include "opentimelineio/version.h"

#include <any>
#include <assert.h>
#include <vector>

namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {

/**
* An AnyVector has exactly the same API as
* std::vector<any>
* std::vector<std::any>
*
* except that it records a "time-stamp" that
* lets external observers know when the vector has been destroyed (which includes
Expand All @@ -22,7 +23,7 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
* and take steps to safe-guard themselves from causing a crash.
*/

class AnyVector : private std::vector<any>
class AnyVector : private std::vector<std::any>
{
public:
using vector::vector;
Expand Down
16 changes: 8 additions & 8 deletions src/opentimelineio/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
char constexpr Clip::default_media_key[];

Clip::Clip(
std::string const& name,
MediaReference* media_reference,
optional<TimeRange> const& source_range,
AnyDictionary const& metadata,
std::string const& active_media_reference_key)
std::string const& name,
MediaReference* media_reference,
std::optional<TimeRange> const& source_range,
AnyDictionary const& metadata,
std::string const& active_media_reference_key)
: Parent{ name, source_range, metadata }
, _active_media_reference_key(active_media_reference_key)
{
Expand Down Expand Up @@ -184,7 +184,7 @@ Clip::available_range(ErrorStatus* error_status) const
return active_media->available_range().value();
}

optional<IMATH_NAMESPACE::Box2d>
std::optional<IMATH_NAMESPACE::Box2d>
Clip::available_image_bounds(ErrorStatus* error_status) const
{
auto active_media = media_reference();
Expand All @@ -194,7 +194,7 @@ Clip::available_image_bounds(ErrorStatus* error_status) const
ErrorStatus::CANNOT_COMPUTE_BOUNDS,
"No image bounds set on clip",
this);
return optional<IMATH_NAMESPACE::Box2d>();
return std::optional<IMATH_NAMESPACE::Box2d>();
}

if (!active_media->available_image_bounds())
Expand All @@ -203,7 +203,7 @@ Clip::available_image_bounds(ErrorStatus* error_status) const
ErrorStatus::CANNOT_COMPUTE_BOUNDS,
"No image bounds set on media reference on clip",
this);
return optional<IMATH_NAMESPACE::Box2d>();
return std::optional<IMATH_NAMESPACE::Box2d>();
}

return active_media->available_image_bounds();
Expand Down
12 changes: 6 additions & 6 deletions src/opentimelineio/clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class Clip : public Item
using Parent = Item;

Clip(
std::string const& name = std::string(),
MediaReference* media_reference = nullptr,
optional<TimeRange> const& source_range = nullopt,
AnyDictionary const& metadata = AnyDictionary(),
std::string const& active_media_reference_key = default_media_key);
std::string const& name = std::string(),
MediaReference* media_reference = nullptr,
std::optional<TimeRange> const& source_range = std::nullopt,
AnyDictionary const& metadata = AnyDictionary(),
std::string const& active_media_reference_key = default_media_key);

void set_media_reference(MediaReference* media_reference);
MediaReference* media_reference() const noexcept;
Expand All @@ -48,7 +48,7 @@ class Clip : public Item
TimeRange
available_range(ErrorStatus* error_status = nullptr) const override;

optional<IMATH_NAMESPACE::Box2d>
std::optional<IMATH_NAMESPACE::Box2d>
available_image_bounds(ErrorStatus* error_status) const override;

protected:
Expand Down
4 changes: 2 additions & 2 deletions src/opentimelineio/composable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ Composable::duration(ErrorStatus* error_status) const
return RationalTime();
}

optional<IMATH_NAMESPACE::Box2d>
std::optional<IMATH_NAMESPACE::Box2d>
Composable::available_image_bounds(ErrorStatus* error_status) const
{
*error_status = ErrorStatus::NOT_IMPLEMENTED;
return optional<IMATH_NAMESPACE::Box2d>();
return std::optional<IMATH_NAMESPACE::Box2d>();
}

}} // namespace opentimelineio::OPENTIMELINEIO_VERSION
2 changes: 1 addition & 1 deletion src/opentimelineio/composable.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Composable : public SerializableObjectWithMetadata

virtual RationalTime duration(ErrorStatus* error_status = nullptr) const;

virtual optional<IMATH_NAMESPACE::Box2d>
virtual std::optional<IMATH_NAMESPACE::Box2d>
available_image_bounds(ErrorStatus* error_status) const;

protected:
Expand Down
Loading

0 comments on commit ddb39f5

Please sign in to comment.