Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,48 @@
namespace Platform::Data::Exceptions
/// @file ArgumentLinkDoesNotExistsException.h
/// @brief Exception thrown when a referenced link does not exist.

namespace Platform::Data::Exceptions
{
/// @brief Generic template declaration for ArgumentLinkDoesNotExistsException.
template <typename ...> class ArgumentLinkDoesNotExistsException;

/// @brief Exception thrown when attempting to use a link address that doesn't exist.
/// @tparam TLinkAddress The type used for link addressing.
///
/// This exception is thrown when operations reference a link that is not present
/// in the storage system, indicating an invalid link address was used.
template <typename TLinkAddress> class ArgumentLinkDoesNotExistsException<TLinkAddress> : public std::invalid_argument
{
/// @brief Constructs exception with link address and argument name.
/// @param link The non-existent link address.
/// @param argumentName The name of the argument that contained the invalid link.
public: ArgumentLinkDoesNotExistsException(TLinkAddress link, std::string argumentName) : std::invalid_argument(FormatMessage(link, argumentName), argumentName) { }

/// @brief Constructs exception with link address only.
/// @param link The non-existent link address.
public: ArgumentLinkDoesNotExistsException(TLinkAddress link) : std::invalid_argument(FormatMessage(link)) { }

/// @brief Constructs exception with custom message and inner exception.
/// @param message Custom error message.
/// @param innerException The underlying exception that caused this error.
public: ArgumentLinkDoesNotExistsException(std::string message, const std::exception& innerException) : std::invalid_argument(message, innerException) { }

/// @brief Constructs exception with custom message.
/// @param message Custom error message.
public: ArgumentLinkDoesNotExistsException(std::string message) : std::invalid_argument(message) { }

/// @brief Default constructor.
public: ArgumentLinkDoesNotExistsException() { }

/// @brief Formats error message with link and argument name (in Russian).
/// @param link The non-existent link address.
/// @param argumentName The argument name.
/// @return Formatted error message.
private: static std::string FormatMessage(TLinkAddress link, std::string argumentName) { return std::string("Связь [").append(Platform::Converters::To<std::string>(link)).append("] переданная в аргумент [").append(argumentName).append("] не существует."); }

/// @brief Formats error message with link only (in Russian).
/// @param link The non-existent link address.
/// @return Formatted error message.
private: static std::string FormatMessage(TLinkAddress link) { return std::string("Связь [").append(Platform::Converters::To<std::string>(link)).append("] переданная в качестве аргумента не существует."); }
};
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,48 @@
namespace Platform::Data::Exceptions
/// @file ArgumentLinkHasDependenciesException.h
/// @brief Exception for links that cannot be modified due to dependencies.

namespace Platform::Data::Exceptions
{
/// @brief Generic template declaration for ArgumentLinkHasDependenciesException.
template <typename ...> class ArgumentLinkHasDependenciesException;

/// @brief Exception thrown when attempting to modify a link that has dependencies.
/// @tparam TLinkAddress The type used for link addressing.
///
/// This exception indicates that a link cannot be modified or deleted because
/// other links depend on it, which would break referential integrity.
template <typename TLinkAddress> class ArgumentLinkHasDependenciesException<TLinkAddress> : public std::invalid_argument
{
/// @brief Constructs exception with link address and parameter name.
/// @param link The link that has dependencies.
/// @param paramName The parameter name that contained the link.
public: ArgumentLinkHasDependenciesException(TLinkAddress link, std::string paramName) : std::invalid_argument(FormatMessage(link, paramName), paramName) { }

/// @brief Constructs exception with link address only.
/// @param link The link that has dependencies.
public: ArgumentLinkHasDependenciesException(TLinkAddress link) : std::invalid_argument(FormatMessage(link)) { }

/// @brief Constructs exception with custom message and inner exception.
/// @param message Custom error message.
/// @param innerException The underlying exception.
public: ArgumentLinkHasDependenciesException(std::string message, const std::exception& innerException) : std::invalid_argument(message, innerException) { }

/// @brief Constructs exception with custom message.
/// @param message Custom error message.
public: ArgumentLinkHasDependenciesException(std::string message) : std::invalid_argument(message) { }

/// @brief Default constructor.
public: ArgumentLinkHasDependenciesException() { }

/// @brief Formats error message with link and parameter name (in Russian).
/// @param link The link that has dependencies.
/// @param paramName The parameter name.
/// @return Formatted error message.
private: static std::string FormatMessage(TLinkAddress link, std::string paramName) { return std::string("У связи [").append(Platform::Converters::To<std::string>(link)).append("] переданной в аргумент [").append(paramName).append("] присутствуют зависимости, которые препятствуют изменению её внутренней структуры."); }

/// @brief Formats error message with link only (in Russian).
/// @param link The link that has dependencies.
/// @return Formatted error message.
private: static std::string FormatMessage(TLinkAddress link) { return std::string("У связи [").append(Platform::Converters::To<std::string>(link)).append("] переданной в качестве аргумента присутствуют зависимости, которые препятствуют изменению её внутренней структуры."); }
};
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
namespace Platform::Data::Exceptions
/// @file LinkWithSameValueAlreadyExistsException.h
/// @brief Exception for duplicate link creation attempts.

namespace Platform::Data::Exceptions
{
/// @brief Exception thrown when attempting to create a link that already exists.
///
/// This exception is raised when the system prevents creation of duplicate links
/// with the same value, typically when uniqueness constraints are enforced.
class LinkWithSameValueAlreadyExistsException : public std::exception
{
/// @brief Default error message in Russian.
public: inline static std::string DefaultMessage = "Связь с таким же значением уже существует.";

/// @brief Constructs exception with custom message and inner exception.
/// @param message Custom error message.
/// @param innerException The underlying exception.
public: LinkWithSameValueAlreadyExistsException(std::string message, const std::exception& innerException) : base(message, innerException) { }

/// @brief Constructs exception with custom message.
/// @param message Custom error message.
public: LinkWithSameValueAlreadyExistsException(std::string message) : base(message) { }

/// @brief Default constructor using default message.
public: LinkWithSameValueAlreadyExistsException() : base(DefaultMessage) { }
};
}
20 changes: 19 additions & 1 deletion cpp/Platform.Data/Exceptions/LinksLimitReachedException.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
namespace Platform::Data::Exceptions
/// @file LinksLimitReachedException.h
/// @brief Typed exception for link storage limit violations.

namespace Platform::Data::Exceptions
{
/// @brief Generic template declaration for LinksLimitReachedException.
template <typename ...> class LinksLimitReachedException;

/// @brief Typed exception thrown when link storage limits are reached.
/// @tparam TLinkAddress The type used for link addressing.
template <typename TLinkAddress> class LinksLimitReachedException<TLinkAddress> : public LinksLimitReachedExceptionBase
{
/// @brief Constructs exception with specific limit value.
/// @param limit The limit value that was reached.
public: LinksLimitReachedException(TLinkAddress limit) : this(FormatMessage(limit)) { }

/// @brief Constructs exception with custom message and inner exception.
/// @param message Custom error message.
/// @param innerException The underlying exception.
public: LinksLimitReachedException(std::string message, const std::exception& innerException) : LinksLimitReachedExceptionBase(message, innerException) { }

/// @brief Constructs exception with custom message.
/// @param message Custom error message.
public: LinksLimitReachedException(std::string message) : LinksLimitReachedExceptionBase(message) { }

/// @brief Default constructor using base class default message.
public: LinksLimitReachedException() : LinksLimitReachedExceptionBase(DefaultMessage) { }

/// @brief Formats error message with limit value (in Russian).
/// @param limit The limit value that was reached.
/// @return Formatted error message.
private: static std::string FormatMessage(TLinkAddress limit) { return std::string("Достигнут лимит количества связей в хранилище (").append(Platform::Converters::To<std::string>(limit)).append(")."); }
};
}
15 changes: 14 additions & 1 deletion cpp/Platform.Data/Exceptions/LinksLimitReachedExceptionBase.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
namespace Platform::Data::Exceptions
/// @file LinksLimitReachedExceptionBase.h
/// @brief Base class for exceptions thrown when link storage limits are exceeded.

namespace Platform::Data::Exceptions
{
/// @brief Base exception class for link storage limit violations.
///
/// This exception is thrown when operations would exceed the maximum
/// number of links that can be stored in the system.
class LinksLimitReachedExceptionBase : public std::exception
{
/// @brief Default error message in Russian.
public: inline static std::string DefaultMessage = "Достигнут лимит количества связей в хранилище.";

/// @brief Protected constructor with custom message and inner exception.
/// @param message Custom error message.
/// @param innerException The underlying exception.
protected: LinksLimitReachedExceptionBase(std::string message, const std::exception& innerException) : base(message, innerException) { }

/// @brief Protected constructor with custom message.
/// @param message Custom error message.
protected: LinksLimitReachedExceptionBase(std::string message) : base(message) { }
};
}
50 changes: 44 additions & 6 deletions cpp/Platform.Data/ILinks.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,63 @@
namespace Platform::Data
{
using namespace Platform::Interfaces;

/// @brief Core interface for managing links in a data structure.
/// @tparam TLinksOptions Template parameter specifying the configuration options for links,
/// including address type, link type, and handler types.
///
/// This interface defines the fundamental CRUD (Create, Read, Update, Delete) operations
/// for working with links. A link represents a connection or relationship between data elements.
template<typename TLinksOptions>
struct ILinks
{
public:
using LinksOptionsType = TLinksOptions;
using LinkAddressType = typename LinksOptionsType::LinkAddressType;
static constexpr LinksConstants<LinkAddressType> Constants = LinksOptionsType::Constants;
using LinkType = typename LinksOptionsType::LinkType;
using ReadHandlerType = typename LinksOptionsType::ReadHandlerType;
using WriteHandlerType = typename LinksOptionsType::WriteHandlerType;
/// @brief Type alias for the links options configuration.
using LinksOptionsType = TLinksOptions;

/// @brief Type alias for link addresses used to identify links.
using LinkAddressType = typename LinksOptionsType::LinkAddressType;

/// @brief Constants used throughout the links system.
static constexpr LinksConstants<LinkAddressType> Constants = LinksOptionsType::Constants;

/// @brief Type alias for link data structures.
using LinkType = typename LinksOptionsType::LinkType;

/// @brief Type alias for read operation handler functions.
using ReadHandlerType = typename LinksOptionsType::ReadHandlerType;

/// @brief Type alias for write operation handler functions.
using WriteHandlerType = typename LinksOptionsType::WriteHandlerType;

/// @brief Counts the number of links matching the specified restriction.
/// @param restriction Vector of link addresses defining search criteria.
/// @return Number of links matching the restriction.
virtual LinkAddressType Count(const std::vector<LinkAddressType>& restriction) const = 0;

/// @brief Iterates through links matching the restriction and applies a handler to each.
/// @param restriction Vector of link addresses defining search criteria.
/// @param handler Function to be called for each matching link.
/// @return Result code from the iteration operation.
virtual LinkAddressType Each(const std::vector<LinkAddressType>& restriction, const ReadHandlerType& handler) const = 0;

/// @brief Creates a new link with the specified substitution values.
/// @param substitution Vector of link addresses specifying the new link's properties.
/// @param handler Function to handle the creation operation.
/// @return Address of the created link or result code.
virtual LinkAddressType Create(const std::vector<LinkAddressType>& substitution, const WriteHandlerType& handler) = 0;

/// @brief Updates existing links matching the restriction with new substitution values.
/// @param restriction Vector of link addresses defining which links to update.
/// @param substitution Vector of link addresses specifying the new values.
/// @param handler Function to handle the update operation.
/// @return Result code from the update operation.
virtual LinkAddressType Update(const std::vector<LinkAddressType>& restriction, const std::vector<LinkAddressType>& substitution, const WriteHandlerType& handler) = 0;

/// @brief Deletes links matching the specified restriction.
/// @param restriction Vector of link addresses defining which links to delete.
/// @param handler Function to handle the deletion operation.
/// @return Result code from the delete operation.
virtual LinkAddressType Delete(const std::vector<LinkAddressType>& restriction, const WriteHandlerType& handler) = 0;
};
}
15 changes: 14 additions & 1 deletion cpp/Platform.Data/ISynchronizedLinks.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
namespace Platform::Data
/// @file ISynchronizedLinks.h
/// @brief Thread-safe interface for link operations.

namespace Platform::Data
{
/// @brief Generic template declaration for ISynchronizedLinks.
// TODO: rework Platform.Threading
template <typename ...> class ISynchronizedLinks;

/// @brief Interface combining thread synchronization with link operations.
/// @tparam TLinkAddress The type used for link addressing.
/// @tparam TLinks The underlying links implementation type.
/// @tparam TConstants The constants type for link operations.
///
/// This interface provides thread-safe access to link operations by combining
/// synchronization primitives with the core ILinks interface.
template <typename TLinkAddress, typename TLinks, typename TConstants> class ISynchronizedLinks<TLinkAddress, TLinks, TConstants> : public ISynchronized<TLinks>, ILinks<TLinkAddress, TConstants>
where TLinks : ILinks<TLinkAddress, TConstants>
where TConstants : LinksConstants<TLinkAddress>
{
public:
/// @brief Empty interface body - functionality provided by base classes.
}
}
Loading
Loading