<commit_before>//
//  yas_base.h
//  Copyright (c) 2015 <NAME>.
//

#pragma once

#include <memory>
#include <map>

namespace yas
{
    class base
    {
       public:
        class impl
        {
           public:
            virtual ~impl() = default;
        };

        explicit base(std::nullptr_t) : _impl(nullptr)
        {
        }

        virtual ~base() = default;

        base(const base &) = default;
        base(base &&) = default;
        base &operator=(const base &) = default;
        base &operator=(base &&) = default;

        bool operator==(const base &other) const
        {
            return _impl && other._impl && _impl == other._impl;
        }

        bool operator!=(const base &other) const
        {
            return !_impl || !other._impl || _impl != other._impl;
        }

        bool operator<(const base &other) const
        {
            if (_impl && other._impl) {
                return _impl < other._impl;
            }
            return false;
        }

        operator bool() const
        {
            return _impl != nullptr;
        }

        bool expired() const
        {
            return !_impl;
        }

        uintptr_t identifier() const
        {
            return reinterpret_cast<uintptr_t>(&*_impl);
        }

        template <typename T, typename I = typename T::impl>
        T cast() const
        {
            static_assert(std::is_base_of<base, T>(), "base class is not base.");

            auto obj = T(nullptr);
            obj.set_impl_ptr(std::dynamic_pointer_cast<I>(_impl));
            return obj;
        }

        std::shared_ptr<impl> &impl_ptr()
        {
            return _impl;
        }

        template <typename T = class impl>
        const std::shared_ptr<T> impl_ptr() const
        {
            return std::static_pointer_cast<T>(_impl);
        }

        void set_impl_ptr(const std::shared_ptr<impl> &impl)
        {
            _impl = impl;
        }

       protected:
        base(const std::shared_ptr<class impl> &impl) : _impl(impl)
        {
        }

       private:
        std::shared_ptr<class impl> _impl;
    };

    template <typename T>
    class weak
    {
       public:
        weak() : _impl()
        {
        }

        weak(const T &obj) : _impl(obj.impl_ptr())
        {
        }

        weak<T>(const weak<T> &) = default;
        weak<T>(weak<T> &&) = default;
        weak<T> &operator=(const weak<T> &) = default;
        weak<T> &operator=(weak<T> &&) = default;

        weak<T> &operator=(const T &obj)
        {
            _impl = obj.impl_ptr();

            return *this;
        }

        explicit operator bool() const
        {
            return !_impl.expired();
        }

        T lock() const
        {
            if (_impl.expired()) {
                return T{nullptr};
            } else {
                T obj{nullptr};
                obj.set_impl_ptr(_impl.lock());
                return obj;
            }
        }

        void reset()
        {
            _impl.reset();
        }

       private:
        std::weak_ptr<base::impl> _impl;<commit_msg>update base<commit_after>//
//  yas_base.h
//  Copyright (c) 2015 <NAME>.
//

#pragma once

#include <memory>
#include <map>

namespace yas
{
    class base
    {
       public:
        class impl
        {
           public:
            virtual ~impl() = default;
        };

        explicit base(std::nullptr_t) : _impl(nullptr)
        {
        }

        virtual ~base() = default;

        base(const base &) = default;
        base(base &&) = default;
        base &operator=(const base &) = default;
        base &operator=(base &&) = default;

        bool operator==(const base &other) const
        {
            return _impl && other._impl && _impl == other._impl;
        }

        bool operator!=(const base &other) const
        {
            return !_impl || !other._impl || _impl != other._impl;
        }

        bool operator<(const base &other) const
        {
            if (_impl && other._impl) {
                return _impl < other._impl;
            }
            return false;
        }

        operator bool() const
        {
            return _impl != nullptr;
        }

        bool expired() const
        {
            return !_impl;
        }

        uintptr_t identifier() const
        {
            return reinterpret_cast<uintptr_t>(&*_impl);
        }

        template <typename T, typename I = typename T::impl>
        T cast() const
        {
            static_assert(std::is_base_of<base, T>(), "base class is not base.");

            auto obj = T(nullptr);
            obj.set_impl_ptr(std::dynamic_pointer_cast<I>(_impl));
            return obj;
        }

        std::shared_ptr<impl> &impl_ptr()
        {
            return _impl;
        }

        template <typename T = class impl>
        const std::shared_ptr<T> impl_ptr() const
        {
            return std::static_pointer_cast<T>(_impl);
        }

        void set_impl_ptr(const std::shared_ptr<impl> &impl)
        {
            _impl = impl;
        }

       protected:
        base(const std::shared_ptr<class impl> &impl) : _impl(impl)
        {
        }

       private:
        std::shared_ptr<class impl> _impl;
    };

    template <typename T>
    class weak
    {
       public:
        weak() : _impl()
        {
        }

        weak(const T &obj) : _impl(obj.impl_ptr())
        {
        }

        weak<T>(const weak<T> &) = default;
        weak<T>(weak<T> &&) = default;
        weak<T> &operator=(const weak<T> &) = default;
        weak<T> &operator=(weak<T> &&) = default;

        weak<T> &operator=(const T &obj)
        {
            _impl = obj.impl_ptr();

            return *this;
        }

        explicit operator bool() const
        {
            return !_impl.expired();
        }

        bool operator==(const weak &other) const
        {
            if (_impl.expired() || other._impl.expired()) {
                return false;
            } else {
                auto impl = _impl.lock();
                auto other_impl = other._impl.lock();
                return impl == other_impl;
            }
        }

        bool operator!=(const weak &other) const
        {
            if (_impl.expired() || other._impl.expired()) {
                return true;
            } else {
                auto impl = _impl.lock();
                auto other_impl = other._impl.lock();
                return impl != other_impl;
            }
        }

        T lock() const
        {
            if (_impl.expired()) {
                return T{nullptr};
            } else {
                T obj{nullptr};
                obj.set_impl_ptr(_impl.lock());
                return obj;
            }
        }

        void reset()
        {
            _impl.reset();
        }

       private:
        std::weak_ptr<base::impl> _impl;
{'fraction_non_alphanumeric': 0.12108076867504695, 'fraction_numerical': 0.0011559023262534315, 'mean_word_length': 1.3228187919463088, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7428002', 'n_tokens_mistral': 2042, 'n_tokens_neox': 1970, 'n_words': 442}