Removed cppast dependency
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <unordered_set>
|
||||
@@ -26,8 +27,89 @@ namespace clanguml::common {
|
||||
|
||||
using id_t = int64_t;
|
||||
|
||||
template <typename T>
|
||||
using optional_ref = std::optional<std::reference_wrapper<T>>;
|
||||
template <typename T> class optional_ref {
|
||||
public:
|
||||
using optional_type = T;
|
||||
|
||||
optional_ref()
|
||||
: value_{nullptr}
|
||||
{
|
||||
}
|
||||
|
||||
optional_ref(T &value) { value_ = &value; }
|
||||
|
||||
optional_ref(const T &value) { value_ = &value; }
|
||||
|
||||
optional_ref(optional_ref &right) { value_ = right.get(); }
|
||||
|
||||
template <typename V,
|
||||
typename = std::enable_if<
|
||||
std::is_base_of_v<optional_type, typename V::optional_type> ||
|
||||
std::is_same_v<optional_type, typename V::optional_type>>>
|
||||
optional_ref(const V &t)
|
||||
{
|
||||
value_ = t.get();
|
||||
}
|
||||
|
||||
template <typename V,
|
||||
typename = std::enable_if<
|
||||
std::is_base_of_v<optional_type, typename V::optional_type> ||
|
||||
std::is_same_v<optional_type, typename V::optional_type>>>
|
||||
optional_ref(V &&t)
|
||||
{
|
||||
value_ = t.get();
|
||||
t.reset();
|
||||
}
|
||||
|
||||
template <typename V,
|
||||
typename = std::enable_if<std::is_base_of_v<optional_type, V>>>
|
||||
optional_ref(const std::reference_wrapper<V> &t)
|
||||
{
|
||||
value_ = &t.get();
|
||||
}
|
||||
|
||||
optional_ref &operator=(const optional_ref &right)
|
||||
{
|
||||
if (this == &right)
|
||||
return *this;
|
||||
|
||||
value_ = right.value_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
optional_ref &operator=(optional_ref &&right) noexcept
|
||||
{
|
||||
if (this == &right)
|
||||
return *this;
|
||||
|
||||
value_ = right.value_;
|
||||
right.reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool has_value() const noexcept { return value_ != nullptr; }
|
||||
|
||||
operator bool() const noexcept { return has_value(); }
|
||||
|
||||
const T &value() const
|
||||
{
|
||||
assert(value_ != nullptr);
|
||||
return *value_;
|
||||
}
|
||||
|
||||
T &value()
|
||||
{
|
||||
assert(value_ != nullptr);
|
||||
return *value_;
|
||||
}
|
||||
|
||||
void reset() { value_ = nullptr; }
|
||||
|
||||
T *get() const { return value_; }
|
||||
|
||||
private:
|
||||
T *value_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using reference_vector = std::vector<std::reference_wrapper<T>>;
|
||||
|
||||
Reference in New Issue
Block a user