diff options
56 files changed, 3287 insertions, 2339 deletions
diff --git a/include/djinterop/enginelibrary/album_art.hpp b/include/djinterop/album_art.hpp index e03c5df..7202f77 100644 --- a/include/djinterop/enginelibrary/album_art.hpp +++ b/include/djinterop/album_art.hpp @@ -19,8 +19,8 @@ #error This library needs at least a C++11 compliant compiler #endif -#ifndef DJINTEROP_ENGINELIBRARY_ALBUM_ART_HPP -#define DJINTEROP_ENGINELIBRARY_ALBUM_ART_HPP +#ifndef DJINTEROP_ALBUM_ART_HPP +#define DJINTEROP_ALBUM_ART_HPP #include <chrono> #include <cstdint> @@ -29,15 +29,14 @@ #include <string> #include <vector> -#include "database.hpp" +#include <djinterop/database.hpp> namespace djinterop { -namespace enginelibrary -{ // Artwork for tracks -struct album_art +class album_art { +public: typedef uint_least8_t image_data_type; std::string hash_hex_str; @@ -46,7 +45,6 @@ struct album_art // TODO - implement rest of album_art class }; -} // namespace enginelibrary } // namespace djinterop -#endif // DJINTEROP_ENGINELIBRARY_ALBUM_ART_HPP +#endif // DJINTEROP_ALBUM_ART_HPP diff --git a/include/djinterop/enginelibrary/crate.hpp b/include/djinterop/crate.hpp index 512600f..e1dbdf2 100644 --- a/include/djinterop/enginelibrary/crate.hpp +++ b/include/djinterop/crate.hpp @@ -19,8 +19,8 @@ #error This library needs at least a C++11 compliant compiler #endif -#ifndef DJINTEROP_ENGINELIBRARY_CRATE_HPP -#define DJINTEROP_ENGINELIBRARY_CRATE_HPP +#ifndef DJINTEROP_CRATE_HPP +#define DJINTEROP_CRATE_HPP #include <memory> #include <stdexcept> @@ -29,53 +29,16 @@ #include <vector> #include <boost/optional.hpp> +#include <boost/utility/string_view.hpp> -#include <djinterop/enginelibrary/schema_version.hpp> +#include <djinterop/semantic_version.hpp> namespace djinterop { -namespace enginelibrary -{ class database; +class crate_impl; class track; -/// The `crate_deleted` exception is thrown when an invalid `crate` object is -/// used, i.e. one that does not exist in the database anymore. -class crate_deleted : public std::runtime_error -{ -public: - /// Constructs the exception for a given crate ID - explicit crate_deleted(int64_t id) noexcept - : runtime_error{"Crate does not exist in database anymore"}, id_{id} - { - } - - /// Returns the crate ID that was deemed non-existent - int64_t id() const noexcept { return id_; } - -private: - int64_t id_; -}; - -/// The `crate_database_inconsistency` exception is thrown when a database -/// inconsistency is found that correlates to a crate. -class crate_database_inconsistency : public database_inconsistency -{ -public: - /// Construct the exception for a given crate ID - explicit crate_database_inconsistency( - const std::string& what_arg, int64_t id) noexcept - : database_inconsistency{what_arg.c_str()}, id_{id} - { - } - - /// Get the crate ID that was deemed inconsistent - int64_t id() const noexcept { return id_; } - -private: - int64_t id_; -}; - /// A `crate` object is a handle to a crate stored in a database. As long as it /// lives, the corresponding database connection is kept open. /// @@ -146,7 +109,7 @@ public: void remove_track(track tr) const; /// Sets the crate's name - void set_name(const std::string& name) const; + void set_name(boost::string_view name) const; /// Sets this crate's parent /// @@ -157,17 +120,16 @@ public: /// Returns the crate's contained tracks std::vector<track> tracks() const; -private: - crate(database db, int64_t id); + // TODO (haslersn): non public? + crate(std::shared_ptr<crate_impl> pimpl); - struct impl; - std::shared_ptr<impl> pimpl_; +private: + std::shared_ptr<crate_impl> pimpl_; friend class database; friend class track; }; -} // namespace enginelibrary } // namespace djinterop -#endif // DJINTEROP_ENGINELIBRARY_CRATE_HPP +#endif // DJINTEROP_CRATE_HPP diff --git a/include/djinterop/enginelibrary/database.hpp b/include/djinterop/database.hpp index 6ed414c..f6b321d 100644 --- a/include/djinterop/enginelibrary/database.hpp +++ b/include/djinterop/database.hpp @@ -19,19 +19,14 @@ #error This library needs at least a C++11 compliant compiler #endif -#ifndef DJINTEROP_ENGINELIBRARY_DATABASE_HPP -#define DJINTEROP_ENGINELIBRARY_DATABASE_HPP +#ifndef DJINTEROP_DATABASE_HPP +#define DJINTEROP_DATABASE_HPP #include <memory> -#include <stdexcept> -#include <string> #include <vector> #include <boost/optional.hpp> - -#include <djinterop/enginelibrary/crate.hpp> -#include <djinterop/enginelibrary/schema_version.hpp> -#include <djinterop/enginelibrary/track.hpp> +#include <boost/utility/string_view.hpp> namespace sqlite { @@ -40,9 +35,10 @@ class database; namespace djinterop { -namespace enginelibrary -{ +class crate; class database_impl; +class semantic_version; +class track; class database_not_found : public std::runtime_error { @@ -56,10 +52,6 @@ public: class database { public: - /// Constructs an Engine Prime database, given the path to the Engine - /// library directory - explicit database(const std::string& directory); - /// Copy constructor database(const database& db); @@ -78,18 +70,18 @@ public: std::vector<crate> crates() const; /// Returns all crates with the given name - std::vector<crate> crates_by_name(const std::string& name) const; + std::vector<crate> crates_by_name(boost::string_view name) const; /// Creates a new crate with the given name /// /// The created crate has no parent. - crate create_crate(const std::string& name) const; + crate create_crate(boost::string_view name) const; /// Creates a new track associated to a given music file /// /// The music file is given by its relative path from the Engine library /// directory. The created track is not contained in any crates. - track create_track(const std::string& relative_path) const; + track create_track(boost::string_view relative_path) const; /// Returns the path to the Engine library directory of the database std::string directory() const; @@ -112,7 +104,7 @@ public: void verify() const; /// Returns the schema version of the database - schema_version version() const; + semantic_version version() const; /// Removes a crate from the database /// @@ -137,25 +129,18 @@ public: /// Returns all tracks whose `relative_path` attribute in the database /// matches the given string std::vector<track> tracks_by_relative_path( - const std::string& relative_path) const; + boost::string_view relative_path) const; /// Returns all tracks contained in the database std::vector<track> tracks() const; + // TODO (haslersn): non public? + database(std::shared_ptr<database_impl> pimpl); + private: std::shared_ptr<database_impl> pimpl_; - - friend class crate; - friend class track; }; -/// Creates a new, empty database in a given directory and using a specified -/// schema version -database make_database( - const std::string& dir_path, - const schema_version& default_version = version_latest); - -} // namespace enginelibrary } // namespace djinterop -#endif // DJINTEROP_ENGINELIBRARY_DATABASE_HPP +#endif // DJINTEROP_DATABASE_HPP diff --git a/include/djinterop/djinterop.hpp b/include/djinterop/djinterop.hpp new file mode 100644 index 0000000..5e78144 --- /dev/null +++ b/include/djinterop/djinterop.hpp @@ -0,0 +1,16 @@ +#pragma once + +#if __cplusplus < 201103L && _MSVC_LANG < 201103L +#error This library needs at least a C++11 compliant compiler +#endif + +#include <djinterop/album_art.hpp> +#include <djinterop/crate.hpp> +#include <djinterop/database.hpp> +#include <djinterop/enginelibrary.hpp> +#include <djinterop/exceptions.hpp> +#include <djinterop/musical_key.hpp> +#include <djinterop/pad_color.hpp> +#include <djinterop/performance_data.hpp> +#include <djinterop/semantic_version.hpp> +#include <djinterop/track.hpp>
\ No newline at end of file diff --git a/include/djinterop/enginelibrary.hpp b/include/djinterop/enginelibrary.hpp index 07e0b9c..35705a3 100644 --- a/include/djinterop/enginelibrary.hpp +++ b/include/djinterop/enginelibrary.hpp @@ -1,28 +1,28 @@ -/* - 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 #if __cplusplus < 201103L && _MSVC_LANG < 201103L #error This library needs at least a C++11 compliant compiler #endif -#ifndef DJINTEROP_ENGINELIBRARY_HPP -#define DJINTEROP_ENGINELIBRARY_HPP +#include <djinterop/semantic_version.hpp> + +namespace djinterop +{ +class database; + +namespace enginelibrary +{ +static constexpr semantic_version version_1_6_0{1, 6, 0}; +static constexpr semantic_version version_1_7_1{1, 7, 1}; +static constexpr semantic_version version_latest = version_1_7_1; + +database load_database(std::string directory); -#include <djinterop/enginelibrary/database.hpp> -#include <djinterop/enginelibrary/performance_data.hpp> +/// Creates a new, empty database in a given directory and using a specified +/// schema version +database make_database( + std::string directory, + const semantic_version& default_version = version_latest); -#endif // DJINTEROP_ENGINELIBRARY_HPP +} // namespace enginelibrary +} // namespace djinterop diff --git a/include/djinterop/enginelibrary/schema_version.hpp b/include/djinterop/enginelibrary/schema_version.hpp deleted file mode 100644 index 2746b12..0000000 --- a/include/djinterop/enginelibrary/schema_version.hpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - 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/>. - */ - -#if __cplusplus < 201103L && _MSVC_LANG < 201103L -#error This library needs at least a C++11 compliant compiler -#endif - -#ifndef DJINTEROP_ENGINELIBRARY_SCHEMA_VERSION_HPP -#define DJINTEROP_ENGINELIBRARY_SCHEMA_VERSION_HPP - -#include <ostream> - -namespace djinterop -{ -namespace enginelibrary -{ -struct schema_version -{ - int maj; - int min; - int pat; -}; - -static constexpr schema_version version_1_6_0{1, 6, 0}; -static constexpr schema_version version_1_7_1{1, 7, 1}; -static constexpr schema_version version_latest = version_1_7_1; - -/** - * The `database_inconsistency` exception is thrown when the schema of a - * database does not match the expectations suggested by its reported version - * number. - */ -class database_inconsistency : public std::runtime_error -{ -public: - explicit database_inconsistency(const std::string &what_arg) noexcept - : runtime_error{what_arg} - { - } -}; - -/// The `track_database_inconsistency` exception is thrown when a database -/// inconsistency is found that correlates to a track. -class track_database_inconsistency : public database_inconsistency -{ -public: - /// Construct the exception for a given track ID - explicit track_database_inconsistency( - const std::string &what_arg, int64_t id) noexcept - : database_inconsistency{what_arg}, id_{id} - { - } - - /// Get the track ID that is the subject of this exception - int64_t id() const noexcept { return id_; } - -private: - int64_t id_; -}; - -/** - * The `unsupported_database_version` exception is thrown when a database schema - * version is encountered that is not yet supported by this version of the - * library. - */ -class unsupported_database_version : public std::runtime_error -{ -public: - explicit unsupported_database_version(const schema_version version) noexcept - : runtime_error{"Unsupported database version"}, version_{version} - { - } - - explicit unsupported_database_version( - const std::string &what_arg, const schema_version version) noexcept - : runtime_error{what_arg}, version_{version} - { - } - - const schema_version version() const { return version_; } - -private: - schema_version version_; -}; - -inline std::ostream &operator<<(std::ostream &os, const schema_version &version) -{ - return os << version.maj << "." << version.min << "." << version.pat; -} - -inline bool operator==(const schema_version &a, const schema_version &b) -{ - return a.maj == b.maj && a.min == b.min && a.pat == b.pat; -} - -inline bool operator!=(const schema_version &a, const schema_version &b) -{ - return !(a.maj == b.maj && a.min == b.min && a.pat == b.pat); -} - -inline bool operator>=(const schema_version &a, const schema_version &b) -{ - if (a.maj != b.maj) - return a.maj > b.maj; - if (a.min != b.min) - return a.min > b.min; - return a.pat >= b.pat; -} - -inline bool operator>(const schema_version &a, const schema_version &b) -{ - if (a.maj != b.maj) - return a.maj > b.maj; - if (a.min != b.min) - return a.min > b.min; - return a.pat > b.pat; -} - -inline bool operator<=(const schema_version &a, const schema_version &b) -{ - if (a.maj != b.maj) - return a.maj < b.maj; - if (a.min != b.min) - return a.min < b.min; - return a.pat <= b.pat; -} - -inline bool operator<(const schema_version &a, const schema_version &b) -{ - if (a.maj != b.maj) - return a.maj < b.maj; - if (a.min != b.min) - return a.min < b.min; - return a.pat < b.pat; -} - -} // namespace enginelibrary -} // namespace djinterop - -#endif // DJINTEROP_ENGINELIBRARY_DATABASE_HPP diff --git a/include/djinterop/exceptions.hpp b/include/djinterop/exceptions.hpp new file mode 100644 index 0000000..2373760 --- /dev/null +++ b/include/djinterop/exceptions.hpp @@ -0,0 +1,121 @@ +#pragma once + +#if __cplusplus < 201103L && _MSVC_LANG < 201103L +#error This library needs at least a C++11 compliant compiler +#endif + +#include <djinterop/semantic_version.hpp> + +namespace djinterop +{ +/// The `database_inconsistency` exception is thrown when the schema of a +/// database does not match the expectations suggested by its reported version +/// number. +class database_inconsistency : public std::runtime_error +{ +public: + explicit database_inconsistency(const std::string &what_arg) noexcept + : runtime_error{what_arg} + { + } +}; + +/// The `unsupported_database_version` exception is thrown when a database +/// schema version is encountered that is not yet supported by this version of +/// the library. +class unsupported_database_version : public std::runtime_error +{ +public: + explicit unsupported_database_version( + const semantic_version version) noexcept + : runtime_error{"Unsupported database version"}, version_{version} + { + } + + explicit unsupported_database_version( + const std::string &what_arg, const semantic_version version) noexcept + : runtime_error{what_arg}, version_{version} + { + } + + const semantic_version version() const { return version_; } + +private: + semantic_version version_; +}; + +/// The `crate_deleted` exception is thrown when an invalid `crate` object is +/// used, i.e. one that does not exist in the database anymore. +class crate_deleted : public std::runtime_error +{ +public: + /// Constructs the exception for a given crate ID + explicit crate_deleted(int64_t id) noexcept + : runtime_error{"Crate does not exist in database anymore"}, id_{id} + { + } + + /// Returns the crate ID that was deemed non-existent + int64_t id() const noexcept { return id_; } + +private: + int64_t id_; +}; + +/// The `crate_database_inconsistency` exception is thrown when a database +/// inconsistency is found that correlates to a crate. +class crate_database_inconsistency : public database_inconsistency +{ +public: + /// Construct the exception for a given crate ID + explicit crate_database_inconsistency( + const std::string &what_arg, int64_t id) noexcept + : database_inconsistency{what_arg.c_str()}, id_{id} + { + } + + /// Get the crate ID that was deemed inconsistent + int64_t id() const noexcept { return id_; } + +private: + int64_t id_; +}; + +/// The `track_deleted` exception is thrown when an invalid `track` object is +/// used, i.e. one that does not exist in the database anymore. +class track_deleted : public std::invalid_argument +{ +public: + /// Constructs the exception for a given track ID + explicit track_deleted(int64_t id) noexcept + : invalid_argument{"Track does not exist in database"}, id_{id} + { + } + + /// Returns the track ID that was found to be non-existent + int64_t id() const noexcept { return id_; } + +private: + int64_t id_; +}; + +/// The `track_database_inconsistency` exception is thrown when a database +/// inconsistency is found that correlates to a track. +class track_database_inconsistency : public database_inconsistency +{ +public: + /// Construct the exception for a given track ID + explicit track_database_inconsistency( + const std::string &what_arg, int64_t id) noexcept + : database_inconsistency{what_arg}, id_{id} + { + } + + /// Get the track ID that is the subject of this exception + int64_t id() const noexcept { return id_; } + +private: + int64_t id_; +}; + +} // namespace djinterop diff --git a/include/djinterop/enginelibrary/musical_key.hpp b/include/djinterop/musical_key.hpp index bd2678b..db3b032 100644 --- a/include/djinterop/enginelibrary/musical_key.hpp +++ b/include/djinterop/musical_key.hpp @@ -19,13 +19,11 @@ #error This library needs at least a C++11 compliant compiler #endif -#ifndef DJINTEROP_ENGINELIBRARY_MUSICAL_KEY_HPP -#define DJINTEROP_ENGINELIBRARY_MUSICAL_KEY_HPP +#ifndef DJINTEROP_MUSICAL_KEY_HPP +#define DJINTEROP_MUSICAL_KEY_HPP namespace djinterop { -namespace enginelibrary -{ /** * The `musical_key` enumeration contains a list all known musical keys that a * track may be detected to initially follow. @@ -58,7 +56,6 @@ enum class musical_key c_major }; -} // namespace enginelibrary } // namespace djinterop -#endif // DJINTEROP_ENGINELIBRARY_MUSICAL_KEY_HPP +#endif // DJINTEROP_MUSICAL_KEY_HPP diff --git a/include/djinterop/enginelibrary/pad_color |