diff options
author | Adam Szmigin <smidge@xsco.net> | 2020-08-18 12:54:22 +0100 |
---|---|---|
committer | Adam Szmigin <smidge@xsco.net> | 2020-08-18 20:16:14 +0100 |
commit | 609535ef72ae6d086db4a639db68d99e8bea7b75 (patch) | |
tree | 8447ede9c1e662dbd1c4c514b93598e9ed12e9d4 | |
parent | 401794f3a1a0581ab131ad704598664ab0d70fcb (diff) |
Use std::optional or experimental as available
At build time, the library will now choose `std::optional<T>` or
`std::experimental::optional<T>` (in order of preference), depending on
which one is available. A new alias `djinterop::stdx::optional` is
available for clients to use.
Note that sqlite_modern_cpp performs its own detection of
`std::optional<T>` or its experimental equivalent: in order for the
library to build correctly, both will need to detect the same version of
`std::optional<T>`.
24 files changed, 525 insertions, 486 deletions
diff --git a/example/engine_prime.cpp b/example/engine_prime.cpp index d7b8520..ac81bef 100644 --- a/example/engine_prime.cpp +++ b/example/engine_prime.cpp @@ -54,7 +54,7 @@ int main(int argc, char** argv) tr.set_year(1970); tr.set_title("Some Song"s); tr.set_artist("Some Artist"s); - tr.set_publisher(std::nullopt); // std::nullopt indicates missing metadata + tr.set_publisher(djinterop::stdx::nullopt); // indicates missing metadata tr.set_key(djinterop::musical_key::a_minor); tr.set_bitrate(320); tr.set_average_loudness(0.5); // loudness range (0, 1] @@ -73,7 +73,7 @@ int main(int argc, char** argv) tr.set_adjusted_main_cue(2732); // manually adjusted // There are always 8 hot cues, whereby each can optionally be set - std::array<std::optional<djinterop::hot_cue>, 8> cues; + std::array<djinterop::stdx::optional<djinterop::hot_cue>, 8> cues; cues[0] = djinterop::hot_cue{ "Cue 1", 1377924.5, // position in number of samples el::standard_pad_colors::pad_1}; diff --git a/include/djinterop/crate.hpp b/include/djinterop/crate.hpp index 8a961ce..b0d7d85 100644 --- a/include/djinterop/crate.hpp +++ b/include/djinterop/crate.hpp @@ -23,11 +23,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 { @@ -111,7 +111,7 @@ public: /// /// If the crate doesn't have a parent, then `djinterop::nullopt` is /// returned. - std::optional<crate> parent() const; + stdx::optional<crate> parent() const; /// Removes a track from the crate /// @@ -126,12 +126,12 @@ public: /// /// If `djinterop::nullopt` is given, then this crate will have no parent. /// That is, it becomes a root crate. - void set_parent(std::optional<crate> parent) const; + void set_parent(stdx::optional<crate> parent) const; /// Gets the sub-crate of this one with a given name. /// /// If no such crate is found, then `djinterop::nullopt` is returned. - std::optional<crate> sub_crate_by_name(const std::string& name) const; + stdx::optional<crate> sub_crate_by_name(const std::string& name) const; /// Returns the crate's contained tracks std::vector<track> tracks() const; diff --git a/include/djinterop/database.hpp b/include/djinterop/database.hpp index 9f68d61..b947733 100644 --- a/include/djinterop/database.hpp +++ b/include/djinterop/database.hpp @@ -25,17 +25,12 @@ #include <cstdint> #include <memory> -#include <optional> #include <stdexcept> #include <string> #include <vector> #include <djinterop/config.hpp> - -namespace sqlite -{ -class database; -} +#include <djinterop/optional.hpp> namespace djinterop { @@ -70,9 +65,9 @@ public: /// Returns the crate with the given ID /// - /// If no such crate exists in the database, then `djinterop::std::nullopt` + /// If no such crate exists in the database, then `djinterop::stdx::nullopt` /// is returned. - std::optional<crate> crate_by_id(int64_t id) const; + stdx::optional<crate> crate_by_id(int64_t id) const; /// Returns all crates contained in the database std::vector<crate> crates() const; @@ -125,8 +120,8 @@ public: /// Returns the root-level crate with the given name. /// - /// If no such crate exists, then `djinterop::std::nullopt` is returned. - std::optional<crate> root_crate_by_name(const std::string& name) const; + /// If no such crate exists, then `djinterop::stdx::nullopt` is returned. + stdx::optional<crate> root_crate_by_name(const std::string& name) const; /// Returns all root crates contained in the database /// @@ -135,9 +130,9 @@ public: /// Returns the track with the given id /// - /// If no such track exists in the database, then `djinterop::std::nullopt` + /// If no such track exists in the database, then `djinterop::stdx::nullopt` /// is returned. - std::optional<track> track_by_id(int64_t id) const; + stdx::optional<track> track_by_id(int64_t id) const; /// Returns all tracks whose `relative_path` attribute in the database /// matches the given string diff --git a/include/djinterop/optional.hpp b/include/djinterop/optional.hpp new file mode 100644 index 0000000..6795913 --- /dev/null +++ b/include/djinterop/optional.hpp @@ -0,0 +1,63 @@ +/* + 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/>. + */ + +#pragma once +#ifndef DJINTEROP_OPTIONAL_HPP +#define DJINTEROP_OPTIONAL_HPP + +#include <djinterop/config.hpp> + +#ifdef DJINTEROP_STD_OPTIONAL + +#include <optional> + +namespace djinterop +{ +namespace stdx +{ +using std::bad_optional_access; +using std::in_place; +using std::in_place_t; +using std::make_optional; +using std::nullopt; +using std::nullopt_t; +using std::optional; +} // namespace stdx +} // namespace djinterop + +#elif DJINTEROP_STD_EXPERIMENTAL_OPTIONAL +#include <experimental/optional> + +namespace djinterop +{ +namespace stdx +{ +using std::experimental::bad_optional_access; +using std::experimental::in_place; +using std::experimental::in_place_t; +using std::experimental::make_optional; +using std::experimental::nullopt; +using std::experimental::nullopt_t; +using std::experimental::optional; +} // namespace stdx +} // namespace djinterop + +#else +#error This library requires support for optional<T>, but none was found +#endif + +#endif // DJINTEROP_OPTIONAL_HPP diff --git a/include/djinterop/track.hpp b/include/djinterop/track.hpp index e058fd0..ff649cc 100644 --- a/include/djinterop/track.hpp +++ b/include/djinterop/track.hpp @@ -27,13 +27,13 @@ #include <chrono> #include <cstdint> #include <memory> -#include <optional> #include <stdexcept> #include <string> #include <vector> #include <djinterop/config.hpp> #include <djinterop/musical_key.hpp> +#include <djinterop/optional.hpp> #include <djinterop/performance_data.hpp> #include <djinterop/semantic_version.hpp> @@ -90,10 +90,10 @@ public: void set_adjusted_main_cue(double sample_offset) const; /// Returns the album name (metadata) of the track - std::optional<std::string> album() const; + stdx::optional<std::string> album() const; /// Sets the album name (metadata) of the track - void set_album(std::optional<std::string> album) const; + void set_album(stdx::optional<std::string> album) const; void set_album(std::string album) const; /// Returns the ID of the `album_art` associated to the track @@ -101,51 +101,51 @@ public: /// If the track doesn't have an associated `album_art`, then `nullopt` /// is returned. /// TODO (haslersn): Return an `album_art` object instead. - std::optional<int64_t> album_art_id() const; + stdx::optional<int64_t> album_art_id() const; /// Sets the ID of the `album_art` associated to the track /// TODO (haslersn): Pass an `album_art` object instead. - void set_album_art_id(std::optional<int64_t> album_art_id) const; + void set_album_art_id(stdx::optional<int64_t> album_art_id) const; void set_album_art_id(int64_t album_art_id) const; /// Returns the artist (metadata) of the track - std::optional<std::string> artist() const; + stdx::optional<std::string> artist() const; /// Sets the artist (metadata) of the track - void set_artist(std::optional<std::string> artist) const; + void set_artist(stdx::optional<std::string> artist) const; void set_artist(std::string artist) const; - std::optional<double> average_loudness() const; + stdx::optional<double> average_loudness() const; - void set_average_loudness(std::optional<double> average_loudness) const; + void set_average_loudness(stdx::optional<double> average_loudness) const; void set_average_loudness(double average_loudness) const; /// Returns the bitrate (metadata) of the track - std::optional<int64_t> bitrate() const; + stdx::optional<int64_t> bitrate() const; /// Sets the bitrate (metadata) of the track - void set_bitrate(std::optional<int64_t> bitrate) const; + void set_bitrate(stdx::optional<int64_t> bitrate) const; void set_bitrate(int64_t bitrate) const; /// Returns the BPM (metadata) of the track, rounded to the nearest integer - std::optional<double> bpm() const; + stdx::optional<double> bpm() const; /// Sets the BPM (metadata) of the track, rounded to the nearest integer - void set_bpm(std::optional<double> bpm) const; + void set_bpm(stdx::optional<double> bpm) const; void set_bpm(double bpm) const; /// Returns the comment associated to the track (metadata) - std::optional<std::string> comment() const; + stdx::optional<std::string> comment() const; /// Sets the comment associated to the track (metadata) - void set_comment(std::optional<std::string> comment) const; + void set_comment(stdx::optional<std::string> comment) const; void set_comment(std::string comment) const; /// Returns the composer (metadata) of the track - std::optional<std::string> composer() const; + stdx::optional<std::string> composer() const; /// Sets the composer (metadata) of the track - void set_composer(std::optional<std::string> composer) const; + void set_composer(stdx::optional<std::string> composer) const; void set_composer(std::string composer) const; /// Returns the crates containing the track @@ -163,7 +163,7 @@ public: void set_default_main_cue(double sample_offset) const; /// Returns the duration (metadata) of the track - std::optional<std::chrono::milliseconds> duration() const; + stdx::optional<std::chrono::milliseconds> duration() const; /// Returns the file extension part of `track::relative_path()` /// @@ -175,20 +175,20 @@ public: std::string filename() const; /// Returns the genre (metadata) of the track - std::optional<std::string> genre() const; + stdx::optional<std::string> genre() const; /// Sets the genre (metadata) of the track - void set_genre(std::optional<std::string> genre) const; + void set_genre(stdx::optional<std::string> genre) const; void set_genre(std::string genre) const; - std::optional<hot_cue> hot_cue_at(int32_t index) const; + stdx::optional<hot_cue> hot_cue_at(int32_t index) const; - void set_hot_cue_at(int32_t index, std::optional<hot_cue> cue) const; + void set_hot_cue_at(int32_t index, stdx::optional<hot_cue> cue) const; void set_hot_cue_at(int32_t index, hot_cue cue) const; - std::array<std::optional<hot_cue>, 8> hot_cues() const; + std::array<stdx::optional<hot_cue>, 8> hot_cues() const; - void set_hot_cues(std::array<std::optional<hot_cue>, 8> cues) const; + void set_hot_cues(std::array<stdx::optional<hot_cue>, 8> cues) const; /// Returns the ID of this track /// @@ -197,33 +197,33 @@ public: int64_t id() const; /// TODO (haslersn): Document this method. - std::optional<track_import_info> import_info() const; + stdx::optional<track_import_info> import_info() const; /// TODO (haslersn): Document these methods. void set_import_info( - const std::optional<track_import_info>& import_info) const; + const stdx::optional<track_import_info>& import_info) const; void set_import_info(const track_import_info& import_info) const; /// Returns `true` iff `*this` is valid as described in the class comment bool is_valid() const; /// Returns the key (metadata) of the track - std::optional<musical_key> key() const; + stdx::optional<musical_key> key() const; /// Sets the key (metadata) of the track - void set_key(std::optional<musical_key> key) const; + void set_key(stdx::optional<musical_key> key) const; void set_key(musical_key key) const; /// Get the time at which this track was last accessed /// /// Note that on VFAT filesystems, the access time is ceiled to just a date, /// and loses any time precision. - std::optional<std::chrono::system_clock::time_point> last_accessed_at() + stdx::optional<std::chrono::system_clock::time_point> last_accessed_at() const; /// TODO (haslersn): Document these methods. void set_last_accessed_at( - std::optional<std::chrono::system_clock::time_point> last_accessed_at) + stdx::optional<std::chrono::system_clock::time_point> last_accessed_at) const; void set_last_accessed_at( std::chrono::system_clock::time_point last_accessed_at) const; @@ -232,40 +232,41 @@ public: /// /// Note that this is the attribute modification time, not the data /// modification time, i.e. ctime not mtime. - std::optional<std::chrono::system_clock::time_point> last_modified_at() + stdx::optional<std::chrono::system_clock::time_point> last_modified_at() const; /// TODO (haslersn): Document these methods. void set_last_modified_at( - std::optional<std::chrono::system_clock::time_point> last_modified_at) + stdx::optional<std::chrono::system_clock::time_point> last_modified_at) const; void set_last_modified_at( std::chrono::system_clock::time_point last_modified_at) const; /// Returns the time at which the track was last played - std::optional<std::chrono::system_clock::time_point> last_played_at() const; + stdx::optional<std::chrono::system_clock::time_point> last_played_at() + const; /// Sets the time at which the track was last played void set_last_played_at( - std::optional<std::chrono::system_clock::time_point> time) const; + stdx::optional<std::chrono::system_clock::time_point> time) const; void set_last_played_at(std::chrono::system_clock::time_point time) const; - std::optional<loop> loop_at(int32_t index) const; + stdx::optional<loop> loop_at(int32_t index) const; - void set_loop_at(int32_t index, std::optional<loop> l) const; + void set_loop_at(int32_t index, stdx::optional<loop> l) const; void set_loop_at(int32_t index, loop l) const; - std::array<std::optional<loop>, 8> loops() const; + std::array<stdx::optional<loop>, 8> loops() const; - void set_loops(std::array<std::optional<loop>, 8> loops) const; + void set_loops(std::array<stdx::optional<loop>, 8> loops) const; std::vector<waveform_entry> overview_waveform() const; /// Returns the publisher (metadata) of the track - std::optional<std::string> publisher() const; + stdx::optional<std::string> publisher() const; /// Sets the publisher (metadata) of the track - void set_publisher(std::optional<std::string> publisher) const; + void set_publisher(stdx::optional<std::string> publisher) const; void set_publisher(std::string publisher) const; /// Get the required number of samples per waveform entry. @@ -284,23 +285,23 @@ public: /// TODO (haslersn): Document this method. void set_relative_path(std::string relative_path) const; - std::optional<sampling_info> sampling() const; + stdx::optional<sampling_info> sampling() const; - void set_sampling(std::optional<sampling_info> sample_rate) const; + void set_sampling(stdx::optional<sampling_info> sample_rate) const; void set_sampling(sampling_info sample_rate) const; /// Returns the title (metadata) of the track - std::optional<std::string> title() const; + stdx::optional<std::string> title() const; /// Sets the title (metadata) of the track - void set_title(std::optional<std::string> title) const; + void set_title(stdx::optional<std::string> title) const; void set_title(std::string title) const; /// Returns the track number (metadata) of the track - std::optional<int32_t> track_number() const; + stdx::optional<int32_t> track_number() const; /// Sets the track number (metadata) of the track - void set_track_number(std::optional<int32_t> track_number) const; + void set_track_number(stdx::optional<int32_t> track_number) const; void set_track_number(int32_t track_number) const; std::vector<waveform_entry> waveform() const; @@ -308,10 +309,10 @@ public: void set_waveform(std::vector<waveform_entry> waveform) const; /// Returns the recording year (metadata) of the track - std::optional<int32_t> year() const; + stdx::optional<int32_t> year() const; /// Sets the recording year (metadata) of the track - void set_year(std::optional<int32_t> year) const; + void set_year(stdx::optional<int32_t> year) const; void set_year(int32_t year) const; // TODO (haslersn): non public? diff --git a/include/meson.build b/include/meson.build index f43c8e8..3d6595c 100644 --- a/include/meson.build +++ b/include/meson.build @@ -9,6 +9,7 @@ djinterop_header_files = [ 'djinterop/exceptions.hpp', 'djinterop/enginelibrary.hpp', 'djinterop/musical_key.hpp', + 'djinterop/optional.hpp', 'djinterop/pad_color.hpp', 'djinterop/performance_data.hpp', 'djinterop/semantic_version.hpp', diff --git a/src/djinterop/crate.cpp b/src/djinterop/crate.cpp index 5da4ad3..4f3fdaf 100644 --- a/src/djinterop/crate.cpp +++ b/src/djinterop/crate.cpp @@ -80,7 +80,7 @@ std::string crate::name() const return pimpl_->name(); } -std::optional<crate> crate::parent() const +stdx::optional<crate> crate::parent() const { return pimpl_->parent(); } @@ -95,13 +95,12 @@ void crate::set_name(std::string name) const pimpl_->set_name(name); } -void crate::set_parent(std::optional<crate> parent) const +void crate::set_parent(stdx::optional<crate> parent) const { pimpl_->set_parent(parent); } -std::optional<crate> crate::sub_crate_by_name( - const std::string& name) const +stdx::optional<crate> crate::sub_crate_by_name(const std::string& name) const { return pimpl_->sub_crate_by_name(name); } diff --git a/src/djinterop/database.cpp b/src/djinterop/database.cpp index 1a224f8..fcff0d3 100644 --- a/src/djinterop/database.cpp +++ b/src/djinterop/database.cpp @@ -37,7 +37,7 @@ transaction_guard database::begin_transaction() const return pimpl_->begin_transaction(); } -std::optional<crate> database::crate_by_id(int64_t id) const +stdx::optional<crate> database::crate_by_id(int64_t id) const { return pimpl_->crate_by_id(id); } @@ -92,13 +92,13 @@ std::vector<crate> database::root_crates() const return pimpl_->root_crates(); } -std::optional<crate> database::root_crate_by_name( +stdx::optional<crate> database::root_crate_by_name( const std::string& name) const { return pimpl_->root_crate_by_name(name); } -std::optional<track> database::track_by_id(int64_t id) const +stdx::optional<track> database::track_by_id(int64_t id) const { return pimpl_->track_by_id(id); } diff --git a/src/djinterop/enginelibrary/el_crate_impl.cpp b/src/djinterop/enginelibrary/el_crate_impl.cpp index f3a2360..0567b02 100644 --- a/src/djinterop/enginelibrary/el_crate_impl.cpp +++ b/src/djinterop/enginelibrary/el_crate_impl.cpp @@ -54,7 +54,6 @@ using djinterop::track; // relationship is not written to this table. namespace { - void update_path( sqlite::database& music_db, crate cr, const std::string& parent_path) { @@ -85,8 +84,8 @@ void ensure_valid_name(const std::string& name) } // namespace -el_crate_impl::el_crate_impl(std::shared_ptr<el_storage> storage, int64_t id) - : crate_impl{id}, storage_{std::move(storage)} +el_crate_impl::el_crate_impl(std::shared_ptr<el_storage> storage, int64_t id) : + crate_impl{id}, storage_{std::move(storage)} { } @@ -133,9 +132,7 @@ crate el_crate_impl::create_sub_crate(std::string name) el_transaction_guard_impl trans{storage_}; std::string path; - storage_->db - << "SELECT path FROM Crate WHERE id = ?" - << id() >> + storage_->db << "SELECT path FROM Crate WHERE id = ?" << id() >> [&](std::string path_val) { if (path.empty()) { @@ -157,13 +154,12 @@ crate el_crate_impl::create_sub_crate(std::string name) "crateParentId) VALUES (?, ?)" << sub_id << id(); - storage_->db - << "INSERT INTO CrateHierarchy (crateId, crateIdChild) " - "SELECT crateId, ? FROM CrateHierarchy " - "WHERE crateIdChild = ? " - "UNION " - "SELECT ? AS crateId, ? AS crateIdChild" - << sub_id << id() << id() << sub_id; + storage_->db << "INSERT INTO CrateHierarchy (crateId, crateIdChild) " + "SELECT crateId, ? FROM CrateHierarchy " + "WHERE crateIdChild = ? " + "UNION " + "SELECT ? AS crateId, ? AS crateIdChild" + << sub_id << id() << id() << sub_id; crate cr{std::make_shared<el_crate_impl>(storage_, sub_id)}; @@ -211,7 +207,7 @@ bool el_crate_impl::is_valid() std::string el_crate_impl::name() { - std::optional<std::string> name; + stdx::optional<std::string> name; storage_->db << "SELECT title FROM Crate WHERE id = ?" << id() >> [&](std::string title) { if (!name) @@ -231,9 +227,9 @@ std::string el_crate_impl::name() return *name; } -std::optional<crate> el_crate_impl::parent() +stdx::optional<crate> el_crate_impl::parent() { - std::optional<crate> parent; + stdx::optional<crate> parent; storage_->db << "SELECT crateParentId FROM CrateParentList WHERE crateOriginId " "= ? AND crateParentId <> crateOriginId" @@ -298,7 +294,7 @@ void el_crate_impl::set_name(std::string name) trans.commit(); } -void el_crate_impl::set_parent(std::optional<crate> parent) +void el_crate_impl::set_parent(stdx::optional<crate> parent) { el_transaction_guard_impl trans{storage_}; @@ -323,9 +319,9 @@ void el_crate_impl::set_parent(std::optional<crate> parent) trans.commit(); } -std::optional<crate> el_crate_impl::sub_crate_by_name(const std::string& name) +stdx::optional<crate> el_crate_impl::sub_crate_by_name(const std::string& name) { - std::optional<crate> cr; + stdx::optional<crate> cr; storage_->db << "SELECT cr.id FROM Crate cr " "JOIN CrateParentList cpl ON (cpl.crateOriginId = cr.id) " "WHERE cr.title = ? " diff --git a/src/djinterop/enginelibrary/el_crate_impl.hpp b/src/djinterop/enginelibrary/el_crate_impl.hpp index 55a24df..7b67835 100644 --- a/src/djinterop/enginelibrary/el_crate_impl.hpp +++ b/src/djinterop/enginelibrary/el_crate_impl.hpp @@ -41,11 +41,11 @@ public: std::vector<crate> descendants() override; bool is_valid() override; std::string name() override; - std::optional<crate> parent() override; + stdx::optional<crate> parent() override; void remove_track(track tr) override; void set_name(std::string name) override; - void set_parent(std::optional<crate> parent) override; - std::optional<crate> sub_crate_by_name(const std::string& name) override; + void set_parent(stdx::optional<crate> parent) override; + stdx::optional<crate> sub_crate_by_name(const std::string& name) override; std::vector<track> tracks() override; private: diff --git a/src/djinterop/enginelibrary/el_database_impl.cpp b/src/djinterop/enginelibrary/el_database_impl.cpp index 84193b4..ac723d9 100644 --- a/src/djinterop/enginelibrary/el_database_impl.cpp +++ b/src/djinterop/enginelibrary/el_database_impl.cpp @@ -50,17 +50,16 @@ void ensure_valid_crate_name(const std::string& name) } // namespace - -el_database_impl::el_database_impl(std::string directory) - : storage_{std::make_shared<el_storage>(std::move(directory))} +el_database_impl::el_database_impl(std::string directory) : + storage_{std::make_shared<el_storage>(std::move(directory))} { // TODO (haslersn): On construction, should we check that the database // version is supported? This would give more guarantees to a user that // obtains a database object. } -el_database_impl::el_database_impl(std::shared_ptr<el_storage> storage) - : storage_{std::move(storage)} +el_database_impl::el_database_impl(std::shared_ptr<el_storage> storage) : + storage_{std::move(storage)} { } @@ -70,9 +69,9 @@ transaction_guard el_database_impl::begin_transaction() std::make_unique<el_transaction_guard_impl>(storage_)}; } -std::optional<crate> el_database_impl::crate_by_id(int64_t id) +stdx::optional<crate> el_database_impl::crate_by_id(int64_t id) { - std::optional<crate> cr; + stdx::optional<crate> cr; storage_->db << "SELECT COUNT(*) FROM Crate WHERE id = ?" << id >> [&](int64_t count) { if (count == 1) @@ -162,7 +161,7 @@ track el_database_impl::create_track(std::string relative_path) << "REPLACE INTO MetaData (id, type, text) VALUES (?, ?, ?)"; for (int64_t type : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 15, 16}) { - std::optional<std::string> text; + stdx::optional<std::string> text; switch (type) { case 10: @@ -193,7 +192,7 @@ track el_database_impl::create_track(std::string relative_path) "type, value) VALUES (?, ?, ?)"; for (int64_t type = 1; type <= 11 /* 12 */; ++type) { - std::optional<int64_t> value; + stdx::optional<int64_t> value; switch (type) { case 5: value = 0; break; @@ -258,9 +257,10 @@ std::vector<crate> el_database_impl::root_crates() return results; } -std::optional<crate> el_database_impl::root_crate_by_name(const std::string& name) +stdx::optional<crate> el_database_impl::root_crate_by_name( + const std::string& name) { - std::optional<crate> cr; + stdx::optional<crate> cr; storage_->db << "SELECT cr.id FROM Crate cr " "JOIN CrateParentList cpl ON (cpl.crateOriginId = cr.id) " "WHERE cr.title = ? " @@ -273,9 +273,9 @@ std::optional<crate> el_database_impl::root_crate_by_name(const std::string& nam return cr; } -std::optional<track> el_database_impl::track_by_id(int64_t id) +stdx::optional<track> el_database_impl::track_by_id(int64_t id) { - std::optional<track> tr; + stdx::optional<track> tr; storage_->db << "SELECT COUNT(*) FROM Track WHERE id = ?" << id >> [&](int64_t count) { if (count == 1) diff --git a/src/djinterop/enginelibrary/el_database_impl.hpp b/src/djinterop/enginelibrary/el_database_impl.hpp index 3249bdd..1feda91 100644 --- a/src/djinterop/enginelibrary/el_database_impl.hpp +++ b/src/djinterop/enginelibrary/el_database_impl.hpp @@ -33,7 +33,7 @@ public: el_database_impl(std::shared_ptr<el_storage> storage); transaction_guard begin_transaction() override; - std::optional<djinterop::crate> crate_by_id(int64_t id) override; + stdx::optional<djinterop::crate> crate_by_id(int64_t id) override; std::vector<djinterop::crate> crates() override; std::vector<djinterop::crate> crates_by_name( const std::string& name) override; @@ -45,9 +45,9 @@ public: void remove_crate(djinterop::crate cr) override; void remove_track(djinterop::track tr) override; std::vector<djinterop::crate> root_crates() override; - std::optional<djinterop::crate> root_crate_by_name( + stdx::optional<djinterop::crate> root_crate_by_name( const std::string& name) override; - std::optional<djinterop::track> track_by_id(int64_t id) override; + stdx::optional<djinterop::track> track_by_id(int64_t id) override; std::vector<djinterop::track> tracks() override; std::vector<djinterop::track> tracks_by_relative_path( const std::string& relative_path) override; diff --git a/src/djinterop/enginelibrary/el_track_impl.cpp b/src/djinterop/enginelibrary/el_track_impl.cpp index 7a15837..9ff2915 100644 -- |