| 803 | #endif |
| 804 | |
| 805 | class any final { |
| 806 | template <typename T> |
| 807 | friend class operators::handler; |
| 808 | template <std::size_t align_size, template <typename> class allocator_t> |
| 809 | friend class basic_var; |
| 810 | |
| 811 | struct proxy |
| 812 | { |
| 813 | std::uint32_t refcount = 1; |
| 814 | std::int8_t protect_level = 0; |
| 815 | basic_var<CS_VAR_SVO_ALIGN> data; |
| 816 | |
| 817 | proxy() = default; |
| 818 | |
| 819 | template <typename T> |
| 820 | proxy(std::uint32_t rc, T &&d) : refcount(rc), data(std::forward<T>(d)) |
| 821 | { |
| 822 | } |
| 823 | |
| 824 | template <typename T> |
| 825 | proxy(std::uint8_t pl, std::uint32_t rc, T &&d) : protect_level(pl), refcount(rc), data(std::forward<T>(d)) |
| 826 | { |
| 827 | } |
| 828 | }; |
| 829 | |
| 830 | using allocator_t = cs::allocator_type<proxy, CS_ALLOCATOR_BUFFER_MAX * CS_VAR_ALLOC_MULTIPLIER, default_allocator_provider>; |
| 831 | |
| 832 | static inline allocator_t &get_allocator() |
| 833 | { |
| 834 | static allocator_t allocator; |
| 835 | return allocator; |
| 836 | } |
| 837 | |
| 838 | proxy *mDat = nullptr; |
| 839 | |
| 840 | template <typename T> |
| 841 | COVSCRIPT_ALWAYS_INLINE T &unchecked_get() const noexcept |
| 842 | { |
| 843 | return mDat->data.unchecked_get<T>(); |
| 844 | } |
| 845 | |
| 846 | proxy *duplicate() const noexcept |
| 847 | { |
| 848 | if (mDat != nullptr) |
| 849 | { |
| 850 | ++mDat->refcount; |
| 851 | } |
| 852 | return mDat; |
| 853 | } |
| 854 | |
| 855 | void recycle() noexcept |
| 856 | { |
| 857 | if (mDat != nullptr) |
| 858 | { |
| 859 | if (--mDat->refcount == 0) { |
| 860 | get_allocator().free(mDat); |
| 861 | mDat = nullptr; |
| 862 | } |
no test coverage detected