Coverage Report

Created: 2023-12-20 07:15

/src/poco/Foundation/include/Poco/Any.h
Line
Count
Source (jump to first uncovered line)
1
//
2
// Any.h
3
//
4
// Library: Foundation
5
// Package: Core
6
// Module:  Any
7
//
8
// Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved.
9
// Extracted from Boost 1.33.1 lib and adapted for poco: Peter Schojer/AppliedInformatics 2006-02-02
10
//
11
// SPDX-License-Identifier: BSL-1.0
12
//
13
14
15
#ifndef Foundation_Any_INCLUDED
16
#define Foundation_Any_INCLUDED
17
18
19
#include "Poco/Exception.h"
20
#include "Poco/MetaProgramming.h"
21
#include <algorithm>
22
#include <typeinfo>
23
#include <cstring>
24
#include <cstddef>
25
26
27
#define poco_any_assert(cond) do { if (!(cond)) std::abort(); } while (0)
28
29
30
namespace Poco {
31
32
class Any;
33
34
namespace Dynamic {
35
36
class Var;
37
class VarHolder;
38
template <class T> class VarHolderImpl;
39
40
}
41
42
43
template <class T, std::size_t S>
44
struct TypeSizeLE:
45
  std::integral_constant<bool, (sizeof(T) <= S)>{};
46
47
48
template <class T, std::size_t S>
49
struct TypeSizeGT:
50
  std::integral_constant<bool, (sizeof(T) > S)>{};
51
52
53
template <typename PlaceholderT, unsigned int SizeV = POCO_SMALL_OBJECT_SIZE>
54
union Placeholder
55
  /// ValueHolder union (used by Poco::Any and Poco::Dynamic::Var for small
56
  /// object optimization, when enabled).
57
  ///
58
  /// If Holder<Type> fits into POCO_SMALL_OBJECT_SIZE bytes of storage,
59
  /// it will be placement-new-allocated into the local buffer
60
  /// (i.e. there will be no heap-allocation). The local buffer size is one byte
61
  /// larger - [POCO_SMALL_OBJECT_SIZE + 1], additional byte value indicating
62
  /// where the object was allocated (0 => heap, 1 => local).
63
  ///
64
  /// Important: for SOO builds, only same-type (or trivial both-empty no-op)
65
  /// swap operation is allowed.
66
{
67
public:
68
  struct Size
69
  {
70
    enum { value = SizeV };
71
  };
72
73
  Placeholder(const Placeholder&) = delete;
74
  Placeholder(Placeholder&&) = delete;
75
  Placeholder& operator=(const Placeholder&) = delete;
76
  Placeholder& operator=(Placeholder&&) = delete;
77
78
#ifndef POCO_NO_SOO
79
80
  Placeholder(): pHolder(0)
81
4.18M
  {
82
4.18M
    std::memset(holder, 0, sizeof(Placeholder));
83
4.18M
  }
Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::Placeholder()
Line
Count
Source
81
4.18M
  {
82
4.18M
    std::memset(holder, 0, sizeof(Placeholder));
83
4.18M
  }
Unexecuted instantiation: Poco::Placeholder<Poco::Any::ValueHolder, 64u>::Placeholder()
84
85
  ~Placeholder()
86
4.18M
  {
87
4.18M
    destruct(false);
88
4.18M
  }
Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::~Placeholder()
Line
Count
Source
86
4.18M
  {
87
4.18M
    destruct(false);
88
4.18M
  }
Unexecuted instantiation: Poco::Placeholder<Poco::Any::ValueHolder, 64u>::~Placeholder()
89
90
  void swap(Placeholder& other) noexcept
91
0
  {
92
0
    if (!isEmpty() || !other.isEmpty())
93
0
      std::swap(holder, other.holder);
94
0
  }
Unexecuted instantiation: Poco::Placeholder<Poco::Any::ValueHolder, 64u>::swap(Poco::Placeholder<Poco::Any::ValueHolder, 64u>&)
Unexecuted instantiation: Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::swap(Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>&)
95
96
  void erase()
97
4.80M
  {
98
4.80M
    destruct(true);
99
4.80M
  }
Unexecuted instantiation: Poco::Placeholder<Poco::Any::ValueHolder, 64u>::erase()
Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::erase()
Line
Count
Source
97
4.80M
  {
98
4.80M
    destruct(true);
99
4.80M
  }
100
101
  bool isEmpty() const
102
8.99M
  {
103
8.99M
    static char buf[SizeV+1] = {};
104
8.99M
    return 0 == std::memcmp(holder, buf, SizeV+1);
105
8.99M
  }
Unexecuted instantiation: Poco::Placeholder<Poco::Any::ValueHolder, 64u>::isEmpty() const
Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::isEmpty() const
Line
Count
Source
102
8.99M
  {
103
8.99M
    static char buf[SizeV+1] = {};
104
8.99M
    return 0 == std::memcmp(holder, buf, SizeV+1);
105
8.99M
  }
106
107
  bool isLocal() const
108
17.1M
  {
109
17.1M
    return holder[SizeV] != 0;
110
17.1M
  }
Unexecuted instantiation: Poco::Placeholder<Poco::Any::ValueHolder, 64u>::isLocal() const
Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::isLocal() const
Line
Count
Source
108
17.1M
  {
109
17.1M
    return holder[SizeV] != 0;
110
17.1M
  }
111
112
  template<typename T, typename V,
113
    typename std::enable_if<TypeSizeLE<T, Placeholder::Size::value>::value>::type* = nullptr>
114
  PlaceholderT* assign(const V& value)
115
4.48M
  {
116
4.48M
    erase();
117
4.48M
    new (reinterpret_cast<PlaceholderT*>(holder)) T(value);
118
4.48M
    setLocal(true);
119
4.48M
    return reinterpret_cast<PlaceholderT*>(holder);
120
4.48M
  }
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<signed char>, signed char, (void*)0>(signed char const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<short>, short, (void*)0>(short const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<int>, int, (void*)0>(int const&)
Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<long>, long, (void*)0>(long const&)
Line
Count
Source
115
3.14M
  {
116
3.14M
    erase();
117
3.14M
    new (reinterpret_cast<PlaceholderT*>(holder)) T(value);
118
3.14M
    setLocal(true);
119
3.14M
    return reinterpret_cast<PlaceholderT*>(holder);
120
3.14M
  }
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<unsigned char>, unsigned char, (void*)0>(unsigned char const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<unsigned short>, unsigned short, (void*)0>(unsigned short const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<unsigned int>, unsigned int, (void*)0>(unsigned int const&)
Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<unsigned long>, unsigned long, (void*)0>(unsigned long const&)
Line
Count
Source
115
3.85k
  {
116
3.85k
    erase();
117
3.85k
    new (reinterpret_cast<PlaceholderT*>(holder)) T(value);
118
3.85k
    setLocal(true);
119
3.85k
    return reinterpret_cast<PlaceholderT*>(holder);
120
3.85k
  }
Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<bool>, bool, (void*)0>(bool const&)
Line
Count
Source
115
1.41k
  {
116
1.41k
    erase();
117
1.41k
    new (reinterpret_cast<PlaceholderT*>(holder)) T(value);
118
1.41k
    setLocal(true);
119
1.41k
    return reinterpret_cast<PlaceholderT*>(holder);
120
1.41k
  }
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<float>, float, (void*)0>(float const&)
Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<double>, double, (void*)0>(double const&)
Line
Count
Source
115
42.6k
  {
116
42.6k
    erase();
117
42.6k
    new (reinterpret_cast<PlaceholderT*>(holder)) T(value);
118
42.6k
    setLocal(true);
119
42.6k
    return reinterpret_cast<PlaceholderT*>(holder);
120
42.6k
  }
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<char>, char, (void*)0>(char const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<std::__1::basic_string<unsigned short, Poco::UTF16CharTraits, std::__1::allocator<unsigned short> > >, std::__1::basic_string<unsigned short, Poco::UTF16CharTraits, std::__1::allocator<unsigned short> >, (void*)0>(std::__1::basic_string<unsigned short, Poco::UTF16CharTraits, std::__1::allocator<unsigned short> > const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<long long>, long long, (void*)0>(long long const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<unsigned long long>, unsigned long long, (void*)0>(unsigned long long const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<Poco::DateTime>, Poco::DateTime, (void*)0>(Poco::DateTime const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<Poco::LocalDateTime>, Poco::LocalDateTime, (void*)0>(Poco::LocalDateTime const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<Poco::Timestamp>, Poco::Timestamp, (void*)0>(Poco::Timestamp const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<Poco::UUID>, Poco::UUID, (void*)0>(Poco::UUID const&)
Unexecuted instantiation: Poco::Any::ValueHolder* Poco::Placeholder<Poco::Any::ValueHolder, 64u>::assign<Poco::Any::Holder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, (void*)0>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, (void*)0>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
115
3.12k
  {
116
3.12k
    erase();
117
3.12k
    new (reinterpret_cast<PlaceholderT*>(holder)) T(value);
118
3.12k
    setLocal(true);
119
3.12k
    return reinterpret_cast<PlaceholderT*>(holder);
120
3.12k
  }
Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<Poco::SharedPtr<Poco::JSON::Array, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::JSON::Array> > >, Poco::SharedPtr<Poco::JSON::Array, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::JSON::Array> >, (void*)0>(Poco::SharedPtr<Poco::JSON::Array, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::JSON::Array> > const&)
Line
Count
Source
115
781k
  {
116
781k
    erase();
117
781k
    new (reinterpret_cast<PlaceholderT*>(holder)) T(value);
118
781k
    setLocal(true);
119
781k
    return reinterpret_cast<PlaceholderT*>(holder);
120
781k
  }
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<Poco::JSON::Array>, Poco::JSON::Array, (void*)0>(Poco::JSON::Array const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<Poco::Dynamic::Struct<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, Poco::Dynamic::Var> > >, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > >, Poco::Dynamic::Struct<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, Poco::Dynamic::Var> > >, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >, (void*)0>(Poco::Dynamic::Struct<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, Poco::Dynamic::Var> > >, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<Poco::Dynamic::Struct<int, std::__1::map<int, Poco::Dynamic::Var, std::__1::less<int>, std::__1::allocator<std::__1::pair<int const, Poco::Dynamic::Var> > >, std::__1::set<int, std::__1::less<int>, std::__1::allocator<int> > > >, Poco::Dynamic::Struct<int, std::__1::map<int, Poco::Dynamic::Var, std::__1::less<int>, std::__1::allocator<std::__1::pair<int const, Poco::Dynamic::Var> > >, std::__1::set<int, std::__1::less<int>, std::__1::allocator<int> > >, (void*)0>(Poco::Dynamic::Struct<int, std::__1::map<int, Poco::Dynamic::Var, std::__1::less<int>, std::__1::allocator<std::__1::pair<int const, Poco::Dynamic::Var> > >, std::__1::set<int, std::__1::less<int>, std::__1::allocator<int> > > const&)
Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<Poco::SharedPtr<Poco::JSON::Object, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::JSON::Object> > >, Poco::SharedPtr<Poco::JSON::Object, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::JSON::Object> >, (void*)0>(Poco::SharedPtr<Poco::JSON::Object, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::JSON::Object> > const&)
Line
Count
Source
115
514k
  {
116
514k
    erase();
117
514k
    new (reinterpret_cast<PlaceholderT*>(holder)) T(value);
118
514k
    setLocal(true);
119
514k
    return reinterpret_cast<PlaceholderT*>(holder);
120
514k
  }
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<std::__1::vector<Poco::Dynamic::Var, std::__1::allocator<Poco::Dynamic::Var> > >, std::__1::vector<Poco::Dynamic::Var, std::__1::allocator<Poco::Dynamic::Var> >, (void*)0>(std::__1::vector<Poco::Dynamic::Var, std::__1::allocator<Poco::Dynamic::Var> > const&)
Unexecuted instantiation: Poco::Any::ValueHolder* Poco::Placeholder<Poco::Any::ValueHolder, 64u>::assign<Poco::Any::Holder<short>, short, (void*)0>(short const&)
Unexecuted instantiation: Poco::Any::ValueHolder* Poco::Placeholder<Poco::Any::ValueHolder, 64u>::assign<Poco::Any::Holder<int>, int, (void*)0>(int const&)
121
122
  template<typename T, typename V,
123
    typename std::enable_if<TypeSizeGT<T, Placeholder::Size::value>::value>::type* = nullptr>
124
  PlaceholderT* assign(const V& value)
125
0
  {
126
0
    erase();
127
0
    pHolder = new T(value);
128
0
    setLocal(false);
129
0
    return pHolder;
130
0
  }
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<Poco::Dynamic::Struct<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, tsl::ordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var> >, std::__1::deque<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var>, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var> > > >, tsl::ordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::deque<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > > >, Poco::Dynamic::Struct<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, tsl::ordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var> >, std::__1::deque<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var>, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var> > > >, tsl::ordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::deque<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > >, (void*)0>(Poco::Dynamic::Struct<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, tsl::ordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var> >, std::__1::deque<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var>, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, Poco::Dynamic::Var> > > >, tsl::ordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::deque<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > > const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<Poco::Dynamic::Struct<int, tsl::ordered_map<int, Poco::Dynamic::Var, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<std::__1::pair<int, Poco::Dynamic::Var> >, std::__1::deque<std::__1::pair<int, Poco::Dynamic::Var>, std::__1::allocator<std::__1::pair<int, Poco::Dynamic::Var> > > >, tsl::ordered_set<int, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<int>, std::__1::deque<int, std::__1::allocator<int> > > > >, Poco::Dynamic::Struct<int, tsl::ordered_map<int, Poco::Dynamic::Var, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<std::__1::pair<int, Poco::Dynamic::Var> >, std::__1::deque<std::__1::pair<int, Poco::Dynamic::Var>, std::__1::allocator<std::__1::pair<int, Poco::Dynamic::Var> > > >, tsl::ordered_set<int, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<int>, std::__1::deque<int, std::__1::allocator<int> > > >, (void*)0>(Poco::Dynamic::Struct<int, tsl::ordered_map<int, Poco::Dynamic::Var, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<std::__1::pair<int, Poco::Dynamic::Var> >, std::__1::deque<std::__1::pair<int, Poco::Dynamic::Var>, std::__1::allocator<std::__1::pair<int, Poco::Dynamic::Var> > > >, tsl::ordered_set<int, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<int>, std::__1::deque<int, std::__1::allocator<int> > > > const&)
Unexecuted instantiation: Poco::Dynamic::VarHolder* Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::assign<Poco::Dynamic::VarHolderImpl<Poco::JSON::Object>, Poco::JSON::Object, (void*)0>(Poco::JSON::Object const&)
131
132
  PlaceholderT* content() const
133
12.6M
  {
134
12.6M
    if (isLocal())
135
12.6M
      return reinterpret_cast<PlaceholderT*>(holder);
136
2.11k
    else
137
2.11k
      return pHolder;
138
12.6M
  }
Unexecuted instantiation: Poco::Placeholder<Poco::Any::ValueHolder, 64u>::content() const
Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::content() const
Line
Count
Source
133
12.6M
  {
134
12.6M
    if (isLocal())
135
12.6M
      return reinterpret_cast<PlaceholderT*>(holder);
136
2.11k
    else
137
2.11k
      return pHolder;
138
12.6M
  }
139
140
private:
141
  typedef std::max_align_t AlignerType;
142
  static_assert(sizeof(AlignerType) <= SizeV + 1, "Aligner type is bigger than the actual storage, so SizeV should be made bigger otherwise you simply waste unused memory.");
143
144
  void setLocal(bool local) const
145
4.48M
  {
146
4.48M
    holder[SizeV] = local ? 1 : 0;
147
4.48M
  }
Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::setLocal(bool) const
Line
Count
Source
145
4.48M
  {
146
4.48M
    holder[SizeV] = local ? 1 : 0;
147
4.48M
  }
Unexecuted instantiation: Poco::Placeholder<Poco::Any::ValueHolder, 64u>::setLocal(bool) const
148
149
  void destruct(bool clear)
150
8.99M
  {
151
8.99M
    if (!isEmpty())
152
4.48M
    {
153
4.48M
      if (!isLocal())
154
0
        delete pHolder;
155
4.48M
      else
156
4.48M
        reinterpret_cast<PlaceholderT*>(holder)->~PlaceholderT();
157
158
4.48M
      if (clear) std::memset(holder, 0, sizeof(Placeholder));
159
4.48M
    }
160
8.99M
  }
Unexecuted instantiation: Poco::Placeholder<Poco::Any::ValueHolder, 64u>::destruct(bool)
Poco::Placeholder<Poco::Dynamic::VarHolder, 64u>::destruct(bool)
Line
Count
Source
150
8.99M
  {
151
8.99M
    if (!isEmpty())
152
4.48M
    {
153
4.48M
      if (!isLocal())
154
0
        delete pHolder;
155
4.48M
      else
156
4.48M
        reinterpret_cast<PlaceholderT*>(holder)->~PlaceholderT();
157
158
4.48M
      if (clear) std::memset(holder, 0, sizeof(Placeholder));
159
4.48M
    }
160
8.99M
  }
161
162
  mutable unsigned char holder[SizeV+1];
163
  AlignerType           aligner;
164
165
#else // POCO_NO_SOO
166
167
  Placeholder(): pHolder(0)
168
  {
169
  }
170
171
  ~Placeholder()
172
  {
173
    delete pHolder;
174
  }
175
176
  void swap(Placeholder& other) noexcept
177
  {
178
    std::swap(pHolder, other.pHolder);
179
  }
180
181
  void erase()
182
  {
183
    delete pHolder;
184
    pHolder = 0;
185
  }
186
187
  bool isEmpty() const
188
  {
189
    return 0 == pHolder;
190
  }
191
192
  bool isLocal() const
193
  {
194
    return false;
195
  }
196
197
  template <typename T, typename V>
198
  PlaceholderT* assign(const V& value)
199
  {
200
    erase();
201
    return pHolder = new T(value);
202
  }
203
204
  PlaceholderT* content() const
205
  {
206
    return pHolder;
207
  }
208
209
private:
210
#endif // POCO_NO_SOO
211
  PlaceholderT* pHolder;
212
};
213
214
215
class Any
216
  /// Any class represents a general type and is capable of storing any type, supporting type-safe extraction
217
  /// of the internally stored data.
218
  ///
219
  /// Code taken from the Boost 1.33.1 library. Original copyright by Kevlin Henney. Modified for Poco
220
  /// by Applied Informatics.
221
  ///
222
  /// Modified for small object optimization support (optionally supported through conditional compilation)
223
  /// by Alex Fabijanic.
224
{
225
public:
226
227
  Any()
228
    /// Creates an empty any type.
229
0
  {
230
0
  }
231
232
  template<typename ValueType>
233
  Any(const ValueType & value)
234
    /// Creates an any which stores the init parameter inside.
235
    ///
236
    /// Example:
237
    ///   Any a(13);
238
    ///   Any a(string("12345"));
239
0
  {
240
0
    construct(value);
241
0
  }
Unexecuted instantiation: Poco::Any::Any<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Unexecuted instantiation: Poco::Any::Any<short>(short const&)
Unexecuted instantiation: Poco::Any::Any<int>(int const&)
242
243
  Any(const Any& other)
244
    /// Copy constructor, works with both empty and initialized Any values.
245
0
  {
246
0
    if ((this != &other) && !other.empty())
247
0
      construct(other);
248
0
  }
249
250
  ~Any()
251
    /// Destructor. If Any is locally held, calls ValueHolder destructor;
252
    /// otherwise, deletes the placeholder from the heap.
253
0
  {
254
0
  }
255
256
  Any& swap(Any& other) noexcept
257
    /// Swaps the content of the two Anys.
258
    ///
259
    /// If an exception occurs during swapping, the program
260
    /// execution is aborted.
261
0
  {
262
0
    if (this == &other) return *this;
263
0
264
0
    if (!_valueHolder.isLocal() && !other._valueHolder.isLocal())
265
0
    {
266
0
      _valueHolder.swap(other._valueHolder);
267
0
    }
268
0
    else
269
0
    {
270
0
      try
271
0
      {
272
0
        Any tmp(*this);
273
0
        construct(other);
274
0
        other = tmp;
275
0
      }
276
0
      catch (...)
277
0
      {
278
0
        std::abort();
279
0
      }
280
0
    }
281
0
282
0
    return *this;
283
0
  }
284
285
  template<typename ValueType>
286
  Any& operator = (const ValueType& rhs)
287
    /// Assignment operator for all types != Any.
288
    ///
289
    /// Example:
290
    ///   Any a = 13;
291
    ///   Any a = string("12345");
292
  {
293
    construct(rhs);
294
    return *this;
295
  }
296
297
  Any& operator = (const Any& rhs)
298
    /// Assignment operator for Any.
299
0
  {
300
0
    if ((this != &rhs) && !rhs.empty())
301
0
      construct(rhs);
302
0
    else if ((this != &rhs) && rhs.empty())
303
0
      _valueHolder.erase();
304
305
0
    return *this;
306
0
  }
307
308
  bool empty() const
309
    /// Returns true if the Any is empty.
310
0
  {
311
0
    return _valueHolder.isEmpty();
312
0
  }
313
314
  const std::type_info& type() const
315
    /// Returns the type information of the stored content.
316
    /// If the Any is empty typeid(void) is returned.
317
    /// It is recommended to always query an Any for its type info before
318
    /// trying to extract data via an AnyCast/RefAnyCast.
319
0
  {
320
0
    return empty() ? typeid(void) : content()->type();
321
0
  }
322
323
  bool local() const
324
    /// Returns true if data is held locally (ie. not allocated on the heap).
325
    /// If POCO_NO_SOO is defined, it always return false.
326
    /// The main purpose of this function is use for testing.
327
0
  {
328
0
    return _valueHolder.isLocal();
329
0
  }
330
331
private:
332
  class ValueHolder
333
  {
334
  public:
335
0
    virtual ~ValueHolder() = default;
336
337
    virtual const std::type_info & type() const = 0;
338
    virtual void clone(Placeholder<ValueHolder>*) const = 0;
339
  };
340
341
  template<typename ValueType>
342
  class Holder : public ValueHolder
343
  {
344
  public:
345
    Holder(const ValueType & value) : _held(value)
346
0
    {
347
0
    }
Unexecuted instantiation: Poco::Any::Holder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::Holder(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Unexecuted instantiation: Poco::Any::Holder<short>::Holder(short const&)
Unexecuted instantiation: Poco::Any::Holder<int>::Holder(int const&)
348
349
    virtual const std::type_info& type() const
350
0
    {
351
0
      return typeid(ValueType);
352
0
    }
Unexecuted instantiation: Poco::Any::Holder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::type() const
Unexecuted instantiation: Poco::Any::Holder<short>::type() const
Unexecuted instantiation: Poco::Any::Holder<int>::type() const
353
354
    virtual void clone(Placeholder<ValueHolder>* pPlaceholder) const
355
0
    {
356
0
      pPlaceholder->assign<Holder<ValueType>, ValueType>(_held);
357
0
    }
Unexecuted instantiation: Poco::Any::Holder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::clone(Poco::Placeholder<Poco::Any::ValueHolder, 64u>*) const
Unexecuted instantiation: Poco::Any::Holder<short>::clone(Poco::Placeholder<Poco::Any::ValueHolder, 64u>*) const
Unexecuted instantiation: Poco::Any::Holder<int>::clone(Poco::Placeholder<Poco::Any::ValueHolder, 64u>*) const
358
359
    ValueType _held;
360
361
  private:
362
363
    Holder & operator = (const Holder &);
364
  };
365
366
  ValueHolder* content() const
367
0
  {
368
0
    return _valueHolder.content();
369
0
  }
370
371
  template<typename ValueType>
372
  void construct(const ValueType& value)
373
0
  {
374
0
    _valueHolder.assign<Holder<ValueType>, ValueType>(value);
375
0
  }
Unexecuted instantiation: void Poco::Any::construct<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Unexecuted instantiation: void Poco::Any::construct<short>(short const&)
Unexecuted instantiation: void Poco::Any::construct<int>(int const&)
376
377
  void construct(const Any& other)
378
0
  {
379
0
    if (!other.empty())
380
0
      other.content()->clone(&_valueHolder);
381
0
    else
382
0
      _valueHolder.erase();
383
0
  }
384
385
  Placeholder<ValueHolder> _valueHolder;
386
387
  template <typename ValueType>
388
  friend ValueType* AnyCast(Any*);
389
390
  template <typename ValueType>
391
  friend ValueType* UnsafeAnyCast(Any*);
392
393
  template <typename ValueType>
394
  friend const ValueType& RefAnyCast(const Any&);
395
396
  template <typename ValueType>
397
  friend ValueType& RefAnyCast(Any&);
398
399
  template <typename ValueType>
400
  friend ValueType AnyCast(Any&);
401
};
402
403
404
template <typename ValueType>
405
ValueType* AnyCast(Any* operand)
406
  /// AnyCast operator used to extract the ValueType from an Any*. Will return a pointer
407
  /// to the stored value.
408
  ///
409
  /// Example Usage:
410
  ///  MyType* pTmp = AnyCast<MyType*>(pAny).
411
  /// Will return NULL if the cast fails, i.e. types don't match.
412
0
{
413
0
  return operand && operand->type() == typeid(ValueType)
414
0
        ? &static_cast<Any::Holder<ValueType>*>(operand->content())->_held
415
0
        : 0;
416
0
}
Unexecuted instantiation: bool* Poco::AnyCast<bool>(Poco::Any*)
Unexecuted instantiation: char* Poco::AnyCast<char>(Poco::Any*)
Unexecuted instantiation: long* Poco::AnyCast<long>(Poco::Any*)
Unexecuted instantiation: short* Poco::AnyCast<short>(Poco::Any*)
Unexecuted instantiation: signed char* Poco::AnyCast<signed char>(Poco::Any*)
Unexecuted instantiation: unsigned char* Poco::AnyCast<unsigned char>(Poco::Any*)
Unexecuted instantiation: int* Poco::AnyCast<int>(Poco::Any*)
Unexecuted instantiation: unsigned long* Poco::AnyCast<unsigned long>(Poco::Any*)
Unexecuted instantiation: unsigned short* Poco::AnyCast<unsigned short>(Poco::Any*)
Unexecuted instantiation: unsigned int* Poco::AnyCast<unsigned int>(Poco::Any*)
Unexecuted instantiation: long double* Poco::AnyCast<long double>(Poco::Any*)
Unexecuted instantiation: float* Poco::AnyCast<float>(Poco::Any*)
Unexecuted instantiation: double* Poco::AnyCast<double>(Poco::Any*)
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* Poco::AnyCast<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(Poco::Any*)
417
418
419
template <typename ValueType>
420
const ValueType* AnyCast(const Any* operand)
421
  /// AnyCast operator used to extract a const ValueType pointer from an const Any*. Will return a const pointer
422
  /// to the stored value.
423
  ///
424
  /// Example Usage:
425
  ///  const MyType* pTmp = AnyCast<MyType*>(pAny).
426
  /// Will return NULL if the cast fails, i.e. types don't match.
427
{
428
  return AnyCast<ValueType>(const_cast<Any*>(operand));
429
}
430
431
432
template <typename ValueType>
433
ValueType AnyCast(Any& operand)
434
  /// AnyCast operator used to extract a copy of the ValueType from an Any&.
435
  ///
436
  /// Example Usage:
437
  ///  MyType tmp = AnyCast<MyType>(anAny).
438
  /// Will throw a BadCastException if the cast fails.
439
  /// Do not use an AnyCast in combination with references, i.e. MyType& tmp = ... or const MyType& tmp = ...
440
  /// Some compilers will accept this code although a copy is returned. Use the RefAnyCast in
441
  /// these cases.
442
0
{
443
0
  typedef typename TypeWrapper<ValueType>::TYPE NonRef;
444
445
0
  NonRef* result = AnyCast<NonRef>(&operand);
446
0
  if (!result)
447
0
  {
448
0
    std::string s = "RefAnyCast: Failed to convert between Any types ";
449
0
    if (operand.content())
450
0
    {
451
0
      s.append(1, '(');
452
0
      s.append(operand.content()->type().name());
453
0
      s.append(" => ");
454
0
      s.append(typeid(ValueType).name());
455
0
      s.append(1, ')');
456
0
    }
457
0
    throw BadCastException(s);
458
0
  }
459
0
  return *result;
460
0
}
Unexecuted instantiation: bool& Poco::AnyCast<bool&>(Poco::Any&)
Unexecuted instantiation: char& Poco::AnyCast<char&>(Poco::Any&)
Unexecuted instantiation: long& Poco::AnyCast<long&>(Poco::Any&)
Unexecuted instantiation: short& Poco::AnyCast<short&>(Poco::Any&)
Unexecuted instantiation: signed char& Poco::AnyCast<signed char&>(Poco::Any&)
Unexecuted instantiation: unsigned char& Poco::AnyCast<unsigned char&>(Poco::Any&)
Unexecuted instantiation: int& Poco::AnyCast<int&>(Poco::Any&)
Unexecuted instantiation: unsigned long& Poco::AnyCast<unsigned long&>(Poco::Any&)
Unexecuted instantiation: unsigned short& Poco::AnyCast<unsigned short&>(Poco::Any&)
Unexecuted instantiation: unsigned int& Poco::AnyCast<unsigned int&>(Poco::Any&)
Unexecuted instantiation: long double& Poco::AnyCast<long double&>(Poco::Any&)
Unexecuted instantiation: float& Poco::AnyCast<float&>(Poco::Any&)
Unexecuted instantiation: double& Poco::AnyCast<double&>(Poco::Any&)
461
462
463
template <typename ValueType>
464
ValueType AnyCast(const Any& operand)
465
  /// AnyCast operator used to extract a copy of the ValueType from an const Any&.
466
  ///
467
  /// Example Usage:
468
  ///  MyType tmp = AnyCast<MyType>(anAny).
469
  /// Will throw a BadCastException if the cast fails.
470
  /// Do not use an AnyCast in combination with references, i.e. MyType& tmp = ... or const MyType& = ...
471
  /// Some compilers will accept this code although a copy is returned. Use the RefAnyCast in
472
  /// these cases.
473
0
{
474
0
  typedef typename TypeWrapper<ValueType>::TYPE NonRef;
475
476
0
  return AnyCast<NonRef&>(const_cast<Any&>(operand));
477
0
}
Unexecuted instantiation: bool Poco::AnyCast<bool>(Poco::Any const&)
Unexecuted instantiation: char Poco::AnyCast<char>(Poco::Any const&)
Unexecuted instantiation: long Poco::AnyCast<long>(Poco::Any const&)
Unexecuted instantiation: short Poco::AnyCast<short>(Poco::Any const&)
Unexecuted instantiation: signed char Poco::AnyCast<signed char>(Poco::Any const&)
Unexecuted instantiation: unsigned char Poco::AnyCast<unsigned char>(Poco::Any const&)
Unexecuted instantiation: int Poco::AnyCast<int>(Poco::Any const&)
Unexecuted instantiation: unsigned long Poco::AnyCast<unsigned long>(Poco::Any const&)
Unexecuted instantiation: unsigned short Poco::AnyCast<unsigned short>(Poco::Any const&)
Unexecuted instantiation: unsigned int Poco::AnyCast<unsigned int>(Poco::Any const&)
Unexecuted instantiation: long double Poco::AnyCast<long double>(Poco::Any const&)
Unexecuted instantiation: float Poco::AnyCast<float>(Poco::Any const&)
Unexecuted instantiation: double Poco::AnyCast<double>(Poco::Any const&)
478
479
480
template <typename ValueType>
481
const ValueType& RefAnyCast(const Any & operand)
482
  /// AnyCast operator used to return a const reference to the internal data.
483
  ///
484
  /// Example Usage:
485
  ///  const MyType& tmp = RefAnyCast<MyType>(anAny);
486
0
{
487
0
  ValueType* result = AnyCast<ValueType>(const_cast<Any*>(&operand));
488
0
  if (!result)
489
0
  {
490
0
    std::string s = "RefAnyCast: Failed to convert between Any types ";
491
0
    if (operand.content())
492
0
    {
493
0
      s.append(1, '(');
494
0
      s.append(operand.content()->type().name());
495
0
      s.append(" => ");
496
0
      s.append(typeid(ValueType).name());
497
0
      s.append(1, ')');
498
0
    }
499
0
    throw BadCastException(s);
500
0
  }
501
0
  return *result;
502
0
}
503
504
505
template <typename ValueType>
506
ValueType& RefAnyCast(Any& operand)
507
  /// AnyCast operator used to return a reference to the internal data.
508
  ///
509
  /// Example Usage:
510
  ///  MyType& tmp = RefAnyCast<MyType>(anAny);
511
{
512
  ValueType* result = AnyCast<ValueType>(&operand);
513
  if (!result)
514
  {
515
    std::string s = "RefAnyCast: Failed to convert between Any types ";
516
    if (operand.content())
517
    {
518
      s.append(1, '(');
519
      s.append(operand.content()->type().name());
520
      s.append(" => ");
521
      s.append(typeid(ValueType).name());
522
      s.append(1, ')');
523
    }
524
    throw BadCastException(s);
525
  }
526
  return *result;
527
}
528
529
530
template <typename ValueType>
531
ValueType* UnsafeAnyCast(Any* operand)
532
  /// The "unsafe" versions of AnyCast are not part of the
533
  /// public interface and may be removed at any time. They are
534
  /// required where we know what type is stored in the any and can't
535
  /// use typeid() comparison, e.g., when our types may travel across
536
  /// different shared libraries.
537
{
538
  return &static_cast<Any::Holder<ValueType>*>(operand->content())->_held;
539
}
540
541
542
template <typename ValueType>
543
const ValueType* UnsafeAnyCast(const Any* operand)
544
  /// The "unsafe" versions of AnyCast are not part of the
545
  /// public interface and may be removed at any time. They are
546
  /// required where we know what type is stored in the any and can't
547
  /// use typeid() comparison, e.g., when our types may travel across
548
  /// different shared libraries.
549
{
550
  return AnyCast<ValueType>(const_cast<Any*>(operand));
551
}
552
553
554
} // namespace Poco
555
556
557
#endif