Coverage Report

Created: 2023-06-07 06:59

/src/valijson/include/valijson/internal/custom_allocator.hpp
Line
Count
Source (jump to first uncovered line)
1
#pragma once
2
3
#include <limits>
4
5
namespace valijson {
6
namespace internal {
7
8
template<class T>
9
class CustomAllocator
10
{
11
public:
12
    /// Typedef for custom new-/malloc-like function
13
    typedef void * (*CustomAlloc)(size_t size);
14
15
    /// Typedef for custom free-like function
16
    typedef void (*CustomFree)(void *);
17
18
    // Standard allocator typedefs
19
    typedef T value_type;
20
    typedef T* pointer;
21
    typedef const T* const_pointer;
22
    typedef T& reference;
23
    typedef const T& const_reference;
24
    typedef std::size_t size_type;
25
    typedef std::ptrdiff_t difference_type;
26
27
    template<typename U>
28
    struct rebind
29
    {
30
        typedef CustomAllocator<U> other;
31
    };
32
33
    CustomAllocator()
34
0
      : m_allocFn([](size_t size) { return ::operator new(size, std::nothrow); }),
35
0
        m_freeFn(::operator delete) { }
36
37
    CustomAllocator(CustomAlloc allocFn, CustomFree freeFn)
38
      : m_allocFn(allocFn),
39
        m_freeFn(freeFn) { }
40
41
    CustomAllocator(const CustomAllocator &other)
42
      : m_allocFn(other.m_allocFn),
43
0
        m_freeFn(other.m_freeFn) { }
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::Subschema const*>::CustomAllocator(valijson::internal::CustomAllocator<valijson::Subschema const*> const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<void*>::CustomAllocator(valijson::internal::CustomAllocator<void*> const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >, valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > > > >, void*> >::CustomAllocator(valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >, valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > > > >, void*> > const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, valijson::Subschema const*>, void*> >::CustomAllocator(valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, valijson::Subschema const*>, void*> > const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<char>::CustomAllocator(valijson::internal::CustomAllocator<char> const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, void*> >::CustomAllocator(valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, void*> > const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::adapters::FrozenValue const*>::CustomAllocator(valijson::internal::CustomAllocator<valijson::adapters::FrozenValue const*> const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<valijson::constraints::TypeConstraint::JsonType, void*> >::CustomAllocator(valijson::internal::CustomAllocator<std::__1::__tree_node<valijson::constraints::TypeConstraint::JsonType, void*> > const&)
44
45
    template<typename U>
46
    CustomAllocator(CustomAllocator<U> const &other)
47
      : m_allocFn(other.m_allocFn),
48
0
        m_freeFn(other.m_freeFn) { }
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::Subschema const*>::CustomAllocator<void*>(valijson::internal::CustomAllocator<void*> const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > const, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >, valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > > > > >::CustomAllocator<void*>(valijson::internal::CustomAllocator<void*> const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >, valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > > > > >::CustomAllocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > const, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >, valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > > > > >(valijson::internal::CustomAllocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > const, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >, valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > > > > > const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >, valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > > > >, void*> >::CustomAllocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >, valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > > > > >(valijson::internal::CustomAllocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >, valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > > > > > const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > const, valijson::Subschema const*> >::CustomAllocator<void*>(valijson::internal::CustomAllocator<void*> const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, valijson::Subschema const*> >::CustomAllocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > const, valijson::Subschema const*> >(valijson::internal::CustomAllocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > const, valijson::Subschema const*> > const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, valijson::Subschema const*>, void*> >::CustomAllocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, valijson::Subschema const*> >(valijson::internal::CustomAllocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, valijson::Subschema const*> > const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<char>::CustomAllocator<void*>(valijson::internal::CustomAllocator<void*> const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >::CustomAllocator<void*>(valijson::internal::CustomAllocator<void*> const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, void*> >::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >(valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > > const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::adapters::FrozenValue const*>::CustomAllocator<void*>(valijson::internal::CustomAllocator<void*> const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::constraints::TypeConstraint::JsonType>::CustomAllocator<void*>(valijson::internal::CustomAllocator<void*> const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<valijson::constraints::TypeConstraint::JsonType, void*> >::CustomAllocator<valijson::constraints::TypeConstraint::JsonType>(valijson::internal::CustomAllocator<valijson::constraints::TypeConstraint::JsonType> const&)
49
50
    CustomAllocator & operator=(const CustomAllocator &other)
51
    {
52
        m_allocFn = other.m_allocFn;
53
        m_freeFn = other.m_freeFn;
54
55
        return *this;
56
    }
57
58
    pointer address(reference r)
59
    {
60
        return &r;
61
    }
62
63
    const_pointer address(const_reference r)
64
    {
65
        return &r;
66
    }
67
68
    pointer allocate(size_type cnt, const void * = nullptr)
69
0
    {
70
0
        return reinterpret_cast<pointer>(m_allocFn(cnt * sizeof(T)));
71
0
    }
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::Subschema const*>::allocate(unsigned long, void const*)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >, valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > > > >, void*> >::allocate(unsigned long, void const*)
Unexecuted instantiation: valijson::internal::CustomAllocator<char>::allocate(unsigned long, void const*)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, void*> >::allocate(unsigned long, void const*)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, valijson::Subschema const*>, void*> >::allocate(unsigned long, void const*)
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::adapters::FrozenValue const*>::allocate(unsigned long, void const*)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<valijson::constraints::TypeConstraint::JsonType, void*> >::allocate(unsigned long, void const*)
72
73
    void deallocate(pointer p, size_type)
74
0
    {
75
0
        m_freeFn(p);
76
0
    }
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::Subschema const*>::deallocate(valijson::Subschema const**, unsigned long)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, void*> >::deallocate(std::__1::__tree_node<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, void*>*, unsigned long)
Unexecuted instantiation: valijson::internal::CustomAllocator<char>::deallocate(char*, unsigned long)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >, valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > > > >, void*> >::deallocate(std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > >, valijson::internal::CustomAllocator<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> > > > >, void*>*, unsigned long)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, valijson::Subschema const*>, void*> >::deallocate(std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, valijson::internal::CustomAllocator<char> >, valijson::Subschema const*>, void*>*, unsigned long)
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::adapters::FrozenValue const*>::deallocate(valijson::adapters::FrozenValue const**, unsigned long)
Unexecuted instantiation: valijson::internal::CustomAllocator<std::__1::__tree_node<valijson::constraints::TypeConstraint::JsonType, void*> >::deallocate(std::__1::__tree_node<valijson::constraints::TypeConstraint::JsonType, void*>*, unsigned long)
77
78
    size_type max_size() const
79
0
    {
80
0
        return std::numeric_limits<size_type>::max() / sizeof(T);
81
0
    }
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::Subschema const*>::max_size() const
Unexecuted instantiation: valijson::internal::CustomAllocator<char>::max_size() const
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::adapters::FrozenValue const*>::max_size() const
82
83
    void construct(pointer p, const T& t)
84
0
    {
85
0
        new(p) T(t);
86
0
    }
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::Subschema const*>::construct(valijson::Subschema const**, valijson::Subschema const* const&)
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::adapters::FrozenValue const*>::construct(valijson::adapters::FrozenValue const**, valijson::adapters::FrozenValue const* const&)
87
88
    void destroy(pointer p)
89
0
    {
90
0
        p->~T();
91
0
    }
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::Subschema const*>::destroy(valijson::Subschema const**)
Unexecuted instantiation: valijson::internal::CustomAllocator<valijson::adapters::FrozenValue const*>::destroy(valijson::adapters::FrozenValue const**)
92
93
    bool operator==(const CustomAllocator &other) const
94
    {
95
        return other.m_allocFn == m_allocFn && other.m_freeFn == m_freeFn;
96
    }
97
98
    bool operator!=(const CustomAllocator &other) const
99
    {
100
        return !operator==(other);
101
    }
102
103
    CustomAlloc m_allocFn;
104
105
    CustomFree m_freeFn;
106
};
107
108
} // end namespace internal
109
} // end namespace valijson