/*
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 .
*/
#pragma once
#ifndef DJINTEROP_DATABASE_HPP
#define DJINTEROP_DATABASE_HPP
#if __cplusplus < 201703L
#error This library needs at least a C++17 compliant compiler
#endif
#include
#include
#include
#include
#include
#include
#include
namespace djinterop
{
class crate;
class database_impl;
struct semantic_version;
class track;
class transaction_guard;
class database_not_found : public std::runtime_error
{
public:
explicit database_not_found(const std::string& what_arg) noexcept
: runtime_error{what_arg}
{
}
};
class DJINTEROP_PUBLIC database
{
public:
/// Copy constructor
database(const database& db);
/// Destructor
~database();
/// Copy assignment operator
database& operator=(const database& db);
transaction_guard begin_transaction() const;
/// Returns the crate with the given ID
///
/// If no such crate exists in the database, then `djinterop::stdx::nullopt`
/// is returned.
stdx::optional crate_by_id(int64_t id) const;
/// Returns all crates contained in the database
std::vector crates() const;
/// Returns all crates with the given name
std::vector crates_by_name(const std::string& name) const;
/// Creates a new root crate with the given name.
///
/// The created crate has no parent.
crate create_root_crate(std::string name) const;
/// Creates a new track associated to a given music file
///
/// The music file is given by its relative path from the directory passed
/// to the `database` constructor. The created track is not contained in any
/// crates.
track create_track(std::string relative_path) const;
/// Returns the path directory of the database
///
/// This is the same as the directory passed to the `database` constructor.
std::string directory() const;
/// Returns true iff the database version is supported by this version of
/// `libdjinterop` or not
bool is_supported() const;
/// Returns the UUID of the database
std::string uuid() const;
/// Verifies the consistency of the internal storage of the database.
///
/// A `database_inconsistency` (or some exception derived from it) is thrown
/// if any kind of inconsistency is found.
void verify() const;
/// Returns the schema version of the database
semantic_version version() const;
/// Returns a descriptive name for the database version.
std::string version_name() const;
/// Removes a crate from the database
///
/// All handles to that crate become invalid.
void remove_crate(crate cr) const;
/// Removes a track from the database
///
/// All handles to that track become invalid.
void remove_track(track tr) const;
/// Returns the root-level crate with the given name.
///
/// If no such crate exists, then `djinterop::stdx::nullopt` is returned.
stdx::optional root_crate_by_name(const std::string& name) const;
/// Returns all root crates contained in the database
///
/// A root crate is a crate that has no parent.
std::vector root_crates() const;
/// Returns the track with the given id
///
/// If no such track exists in the database, then `djinterop::stdx::nullopt`
/// is returned.
stdx::optional