Skip to content

Commit

Permalink
Use std::optional (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-smidge authored Apr 26, 2024
1 parent f34a8fb commit d2cd0b1
Show file tree
Hide file tree
Showing 66 changed files with 1,194 additions and 1,327 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++17
Standard: c++20
TabWidth: 4
UseTab: Never
...
15 changes: 10 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,28 @@ on:

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
BUILD_TYPE: Debug

jobs:
build:
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-22.04]

runs-on: ${{ matrix.os }}
config: [
{ os: ubuntu-20.04, c_compiler: gcc-10, cpp_compiler: g++-10 },
{ os: ubuntu-22.04, c_compiler: gcc-11, cpp_compiler: g++-11 },
{ os: ubuntu-22.04, c_compiler: gcc-12, cpp_compiler: g++-12 },
{ os: ubuntu-22.04, c_compiler: gcc-13, cpp_compiler: g++-13 },
]

runs-on: ${{ matrix.config.os }}

steps:
- uses: actions/checkout@v3

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=${{matrix.config.c_compiler}} -DCMAKE_CXX_COMPILER=${{matrix.config.cpp_compiler}}

- name: Build
# Build your program with the given configuration
Expand Down
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# The typical build output directory
/build/

# Sub-projects
/subprojects/

# Compilation database
compile_commands.json
.clangd/
Expand Down
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)
project(libdjinterop
VERSION 0.21.0
VERSION 0.22.0
DESCRIPTION "C++ library providing access to DJ record libraries")
set(PROJECT_HOMEPAGE_URL "https://github.com/xsco/libdjinterop")

Expand All @@ -27,7 +27,6 @@ else()
add_compile_options("$<$<CONFIG:DEBUG>:-Wall>")
endif()


# Build shared a library by default.
option(BUILD_SHARED_LIBS "Build shared library" ON)

Expand Down Expand Up @@ -101,10 +100,6 @@ if(DJINTEROP_LIBRARY_TYPE STREQUAL "STATIC_LIBRARY")
endif()

# Generate config.hpp based on build-time environment.
include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX(optional DJINTEROP_STD_OPTIONAL)
CHECK_INCLUDE_FILE_CXX(experimental/optional DJINTEROP_STD_EXPERIMENTAL_OPTIONAL)

configure_file(
include/djinterop/config.hpp.in
include/djinterop/config.hpp)
Expand Down Expand Up @@ -170,7 +165,6 @@ install(FILES
include/djinterop/djinterop.hpp
include/djinterop/exceptions.hpp
include/djinterop/musical_key.hpp
include/djinterop/optional.hpp
include/djinterop/pad_color.hpp
include/djinterop/performance_data.hpp
include/djinterop/semantic_version.hpp
Expand Down
2 changes: 1 addition & 1 deletion example/engine_prime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main()
td.year = 1970;
td.title = "Some Song"s;
td.artist = "Some Artist"s;
td.publisher = djinterop::stdx::nullopt; // indicates missing metadata
td.publisher = std::nullopt; // indicates missing metadata
td.key = djinterop::musical_key::a_minor;
td.bitrate = 320;
td.rating = 60; // note: rating is in the range 0-100
Expand Down
2 changes: 1 addition & 1 deletion include/djinterop/album_art.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace djinterop
class album_art
{
public:
typedef uint_least8_t image_data_type;
using image_data_type = uint_least8_t;

std::string hash_hex_str;
std::vector<image_data_type> image_data;
Expand Down
6 changes: 0 additions & 6 deletions include/djinterop/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@
#endif // DJINTEROP_SOURCE
#define DJINTEROP_LOCAL DJINTEROP_SYMBOL_LOCAL

// Symbols defined after this point represent the environment at the time
// that this library was built. The environment when this library is used must
// be compatible in order to use the library successfully.
#cmakedefine DJINTEROP_STD_OPTIONAL
#cmakedefine DJINTEROP_STD_EXPERIMENTAL_OPTIONAL

#include <cstddef>
static_assert(sizeof(std::byte) == 1,
"Only platforms where sizeof(std::byte) == 1 are supported");
Expand Down
28 changes: 15 additions & 13 deletions include/djinterop/crate.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/*
Tdd!his file is part of libdjinterop.
dd!
ldd!ibdjinterop is free software: you can redistribute it and/or modify
idd!t under the terms of the GNU Lesser General Public License as published
by tdd!he Free Software Foundation, either version 3 of the License, or (dd!at
your option) any later version. dd! ldd!ibdjinterop 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
Lesser General Public License for more details.
This file is part of libdjinterop.
libdjinterop is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libdjinterop 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with libdjinterop. If not, see <http://www.gnu.org/licenses/>.
Expand All @@ -23,11 +25,11 @@ Lesser General Public License for more details.

#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include <djinterop/config.hpp>
#include <djinterop/optional.hpp>

namespace djinterop
{
Expand Down Expand Up @@ -118,7 +120,7 @@ class DJINTEROP_PUBLIC crate
///
/// If the crate doesn't have a parent, then `djinterop::nullopt` is
/// returned.
stdx::optional<crate> parent() const;
std::optional<crate> parent() const;

/// Removes a track from the crate
///
Expand All @@ -133,15 +135,15 @@ class DJINTEROP_PUBLIC crate
///
/// If `djinterop::nullopt` is given, then this crate will have no parent.
/// That is, it becomes a root crate.
void set_parent(stdx::optional<crate> parent) const;
void set_parent(std::optional<crate> parent) const;

/// Gets the sub-crate of this one with a given name.
///
/// Note that descendants of sub-crates are not found by this method, i.e.
/// the search does not recurse into the immediate sub-crates of this crate.
///
/// If no such crate is found, then `djinterop::nullopt` is returned.
stdx::optional<crate> sub_crate_by_name(const std::string& name) const;
std::optional<crate> sub_crate_by_name(const std::string& name) const;

/// Returns the crate's contained tracks.
///
Expand Down
14 changes: 7 additions & 7 deletions include/djinterop/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

#include <cstdint>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <vector>

#include <djinterop/config.hpp>
#include <djinterop/optional.hpp>

namespace djinterop
{
Expand All @@ -55,9 +55,9 @@ class DJINTEROP_PUBLIC database

/// Returns the crate with the given ID
///
/// If no such crate exists in the database, then `djinterop::stdx::nullopt`
/// If no such crate exists in the database, then `std::nullopt`
/// is returned.
stdx::optional<crate> crate_by_id(int64_t id) const;
std::optional<crate> crate_by_id(int64_t id) const;

/// Returns all crates contained in the database
std::vector<crate> crates() const;
Expand Down Expand Up @@ -104,8 +104,8 @@ class DJINTEROP_PUBLIC database

/// Returns the root-level crate with the given name.
///
/// If no such crate exists, then `djinterop::stdx::nullopt` is returned.
stdx::optional<crate> root_crate_by_name(const std::string& name) const;
/// If no such crate exists, then `std::nullopt` is returned.
std::optional<crate> root_crate_by_name(const std::string& name) const;

/// Returns all root crates contained in the database
///
Expand All @@ -114,9 +114,9 @@ class DJINTEROP_PUBLIC database

/// Returns the track with the given id
///
/// If no such track exists in the database, then `djinterop::stdx::nullopt`
/// If no such track exists in the database, then `std::nullopt`
/// is returned.
stdx::optional<track> track_by_id(int64_t id) const;
std::optional<track> track_by_id(int64_t id) const;

/// Returns all tracks whose `relative_path` attribute in the database
/// matches the given string
Expand Down
5 changes: 1 addition & 4 deletions include/djinterop/engine/v2/beat_data_blob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
#include <vector>

#include <djinterop/config.hpp>
#include <djinterop/optional.hpp>
#include <djinterop/pad_color.hpp>
#include <djinterop/performance_data.hpp>

namespace djinterop::engine::v2
{
Expand Down Expand Up @@ -90,7 +87,7 @@ struct DJINTEROP_PUBLIC beat_grid_marker_blob
struct DJINTEROP_PUBLIC beat_data_blob
{
/// Type of collection of beat grid markers.
typedef std::vector<beat_grid_marker_blob> beat_grid_marker_blobs_type;
using beat_grid_marker_blobs_type = std::vector<beat_grid_marker_blob>;

/// Sample rate, in hertz.
double sample_rate;
Expand Down
4 changes: 2 additions & 2 deletions include/djinterop/engine/v2/change_log_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

#include <cstdint>
#include <memory>
#include <optional>
#include <vector>

#include <djinterop/config.hpp>
#include <djinterop/optional.hpp>

namespace djinterop::engine::v2
{
Expand Down Expand Up @@ -86,7 +86,7 @@ class DJINTEROP_PUBLIC change_log_table
/// Get the most recent entry in the changelog.
///
/// \return Returns the last entry.
[[nodiscard]] djinterop::stdx::optional<change_log_row> last() const;
[[nodiscard]] std::optional<change_log_row> last() const;

private:
std::shared_ptr<engine_library_context> context_;
Expand Down
2 changes: 0 additions & 2 deletions include/djinterop/engine/v2/loops_blob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
#include <vector>

#include <djinterop/config.hpp>
#include <djinterop/optional.hpp>
#include <djinterop/pad_color.hpp>
#include <djinterop/performance_data.hpp>

namespace djinterop::engine::v2
{
Expand Down
4 changes: 2 additions & 2 deletions include/djinterop/engine/v2/playlist_entity_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
#include <cstdint>
#include <list>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <vector>

#include <djinterop/config.hpp>
#include <djinterop/optional.hpp>

namespace djinterop::engine::v2
{
Expand Down Expand Up @@ -122,7 +122,7 @@ class DJINTEROP_PUBLIC playlist_entity_table
/// \param list_id Id of playlist.
/// \param track_id Id of track in playlist.
/// \return Returns the optional playlist entity row.
[[nodiscard]] stdx::optional<playlist_entity_row> get(
[[nodiscard]] std::optional<playlist_entity_row> get(
int64_t list_id, int64_t track_id) const;

/// Get a list of entity rows for a given playlist, in playlist order.
Expand Down
15 changes: 7 additions & 8 deletions include/djinterop/engine/v2/playlist_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
#include <cstdint>
#include <list>
#include <memory>
#include <optional>
#include <ostream>
#include <stdexcept>
#include <string>
#include <vector>

#include <djinterop/config.hpp>
#include <djinterop/optional.hpp>
#include <djinterop/stream_helper.hpp>

namespace djinterop::engine::v2
Expand All @@ -42,7 +42,6 @@ struct engine_library_context;
/// operation.
struct DJINTEROP_PUBLIC playlist_row_id_error : public std::runtime_error
{
public:
explicit playlist_row_id_error(const std::string& what_arg) noexcept :
runtime_error{what_arg}
{
Expand All @@ -51,14 +50,14 @@ struct DJINTEROP_PUBLIC playlist_row_id_error : public std::runtime_error

/// Special value for id to indicate that a given row is not currently persisted
/// in the database.
constexpr const int64_t PLAYLIST_ROW_ID_NONE = 0;
constexpr int64_t PLAYLIST_ROW_ID_NONE = 0;

/// Special value for parent id to indicate that a given row is at the root
/// level, and does not have any parent playlist.
constexpr const int64_t PARENT_LIST_ID_NONE = 0;
constexpr int64_t PARENT_LIST_ID_NONE = 0;

/// Special value for next list id to indicate that there is no next list.
constexpr const int64_t PLAYLIST_NO_NEXT_LIST_ID = 0;
constexpr int64_t PLAYLIST_NO_NEXT_LIST_ID = 0;

/// Represents a row in the `PlayList` table.
struct DJINTEROP_PUBLIC playlist_row
Expand Down Expand Up @@ -179,21 +178,21 @@ class DJINTEROP_PUBLIC playlist_table
/// \param parent_id Id of parent playlist.
/// \param title Title of playlist to find.
/// \return Returns the id of the playlist, or none if not found.
[[nodiscard]] stdx::optional<int64_t> find_id(
[[nodiscard]] std::optional<int64_t> find_id(
int64_t parent_id, const std::string& title) const;

/// Find the id of a root playlist, given its title.
///
/// \param title Title of playlist to find.
/// \return Returns the id of the playlist, or none if not found.
[[nodiscard]] stdx::optional<int64_t> find_root_id(
[[nodiscard]] std::optional<int64_t> find_root_id(
const std::string& title) const;

/// Get a playlist by id.
///
/// \param id Id of playlist.
/// \return Returns an optional playlist row.
[[nodiscard]] djinterop::stdx::optional<playlist_row> get(int64_t id) const;
[[nodiscard]] std::optional<playlist_row> get(int64_t id) const;

/// Remove an entry from the table.
///
Expand Down
4 changes: 1 addition & 3 deletions include/djinterop/engine/v2/quick_cues_blob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
#include <vector>

#include <djinterop/config.hpp>
#include <djinterop/optional.hpp>
#include <djinterop/pad_color.hpp>
#include <djinterop/performance_data.hpp>

namespace djinterop::engine::v2
{
Expand Down Expand Up @@ -91,7 +89,7 @@ struct DJINTEROP_PUBLIC quick_cue_blob
struct DJINTEROP_PUBLIC quick_cues_blob
{
/// Type of collection of quick cues.
typedef std::vector<quick_cue_blob> quick_cue_blobs_type;
using quick_cue_blobs_type = std::vector<quick_cue_blob>;

/// List of quick cues.
quick_cue_blobs_type quick_cues;
Expand Down
Loading

0 comments on commit d2cd0b1

Please sign in to comment.