summaryrefslogtreecommitdiffstats
path: root/include/djinterop
diff options
context:
space:
mode:
Diffstat (limited to 'include/djinterop')
-rw-r--r--include/djinterop/crate.hpp8
-rw-r--r--include/djinterop/database.hpp19
-rw-r--r--include/djinterop/optional.hpp63
-rw-r--r--include/djinterop/track.hpp97
4 files changed, 123 insertions, 64 deletions
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?