2019-11-09 15:33:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-11-18 20:54:18 +00:00
|
|
|
#include <Access/Common/AccessEntityType.h>
|
2019-11-09 15:33:07 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2021-11-18 20:54:18 +00:00
|
|
|
#include <base/types.h>
|
2019-11-09 15:33:07 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-05-03 03:12:03 +00:00
|
|
|
|
2019-11-09 15:33:07 +00:00
|
|
|
/// Access entity is a set of data which have a name and a type. Access entity control something related to the access control.
|
|
|
|
/// Entities can be stored to a file or another storage, see IAccessStorage.
|
|
|
|
struct IAccessEntity
|
|
|
|
{
|
|
|
|
IAccessEntity() = default;
|
|
|
|
IAccessEntity(const IAccessEntity &) = default;
|
|
|
|
virtual ~IAccessEntity() = default;
|
|
|
|
virtual std::shared_ptr<IAccessEntity> clone() const = 0;
|
|
|
|
|
2021-11-18 20:54:18 +00:00
|
|
|
virtual AccessEntityType getType() const = 0;
|
2020-05-03 03:12:03 +00:00
|
|
|
|
2021-11-18 20:54:18 +00:00
|
|
|
const AccessEntityTypeInfo & getTypeInfo() const { return AccessEntityTypeInfo::get(getType()); }
|
|
|
|
String formatTypeWithName() const { return getTypeInfo().formatEntityNameWithType(getName()); }
|
2020-05-03 03:12:03 +00:00
|
|
|
|
|
|
|
template <typename EntityClassT>
|
|
|
|
bool isTypeOf() const { return isTypeOf(EntityClassT::TYPE); }
|
2021-11-18 20:54:18 +00:00
|
|
|
bool isTypeOf(AccessEntityType type) const { return type == getType(); }
|
2019-11-09 15:33:07 +00:00
|
|
|
|
2020-05-02 22:30:28 +00:00
|
|
|
virtual void setName(const String & name_) { name = name_; }
|
|
|
|
const String & getName() const { return name; }
|
2019-11-09 15:33:07 +00:00
|
|
|
|
|
|
|
friend bool operator ==(const IAccessEntity & lhs, const IAccessEntity & rhs) { return lhs.equal(rhs); }
|
|
|
|
friend bool operator !=(const IAccessEntity & lhs, const IAccessEntity & rhs) { return !(lhs == rhs); }
|
|
|
|
|
2020-06-06 07:21:02 +00:00
|
|
|
struct LessByName
|
|
|
|
{
|
|
|
|
bool operator()(const IAccessEntity & lhs, const IAccessEntity & rhs) const { return (lhs.getName() < rhs.getName()); }
|
|
|
|
bool operator()(const std::shared_ptr<const IAccessEntity> & lhs, const std::shared_ptr<const IAccessEntity> & rhs) const { return operator()(*lhs, *rhs); }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LessByTypeAndName
|
|
|
|
{
|
|
|
|
bool operator()(const IAccessEntity & lhs, const IAccessEntity & rhs) const { return (lhs.getType() < rhs.getType()) || ((lhs.getType() == rhs.getType()) && (lhs.getName() < rhs.getName())); }
|
|
|
|
bool operator()(const std::shared_ptr<const IAccessEntity> & lhs, const std::shared_ptr<const IAccessEntity> & rhs) const { return operator()(*lhs, *rhs); }
|
|
|
|
};
|
|
|
|
|
2019-11-09 15:33:07 +00:00
|
|
|
protected:
|
2020-05-02 22:30:28 +00:00
|
|
|
String name;
|
2019-11-09 15:33:07 +00:00
|
|
|
|
|
|
|
virtual bool equal(const IAccessEntity & other) const;
|
|
|
|
|
|
|
|
/// Helper function to define clone() in the derived classes.
|
2020-05-03 03:12:03 +00:00
|
|
|
template <typename EntityClassT>
|
2019-11-09 15:33:07 +00:00
|
|
|
std::shared_ptr<IAccessEntity> cloneImpl() const
|
|
|
|
{
|
2020-05-03 03:12:03 +00:00
|
|
|
return std::make_shared<EntityClassT>(typeid_cast<const EntityClassT &>(*this));
|
2019-11-09 15:33:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using AccessEntityPtr = std::shared_ptr<const IAccessEntity>;
|
2020-05-03 03:12:03 +00:00
|
|
|
|
2019-11-09 15:33:07 +00:00
|
|
|
}
|