47 #ifndef _THROW_ALLOCATOR_H
48 #define _THROW_ALLOCATOR_H 1
59 #ifdef __GXX_EXPERIMENTAL_CXX0X__
63 # include <tr1/functional>
64 # include <tr1/random>
67 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
69 _GLIBCXX_BEGIN_NAMESPACE_VERSION
80 __throw_forced_error()
113 insert(
void* p,
size_t size)
117 std::string error(
"annotate_base::insert null insert!\n");
118 log_to_string(error, make_entry(p, size));
119 std::__throw_logic_error(error.
c_str());
122 const_iterator found = map().
find(p);
123 if (found != map().
end())
125 std::string error(
"annotate_base::insert double insert!\n");
126 log_to_string(error, make_entry(p, size));
127 log_to_string(error, *found);
128 std::__throw_logic_error(error.
c_str());
131 map().
insert(make_entry(p, size));
135 erase(
void* p,
size_t size)
137 check_allocated(p, size);
143 check_allocated(
void* p,
size_t size)
145 const_iterator found = map().
find(p);
146 if (found == map().
end())
148 std::string error(
"annotate_base::check_allocated by value "
150 log_to_string(error, make_entry(p, size));
151 std::__throw_logic_error(error.
c_str());
154 if (found->second.second != size)
156 std::string error(
"annotate_base::check_allocated by value "
157 "wrong-size erase!\n");
158 log_to_string(error, make_entry(p, size));
159 log_to_string(error, *found);
160 std::__throw_logic_error(error.
c_str());
166 check_allocated(
size_t label)
168 const_iterator beg = map().
begin();
169 const_iterator
end = map().
end();
173 if (beg->second.first == label)
174 log_to_string(found, *beg);
180 std::string error(
"annotate_base::check_allocated by label\n");
182 std::__throw_logic_error(error.
c_str());
190 typedef map_type::const_iterator const_iterator;
191 typedef map_type::const_reference const_reference;
197 make_entry(
void* p,
size_t size)
204 const char tab(
'\t');
206 unsigned long l =
static_cast<unsigned long>(ref.second.first);
207 __builtin_sprintf(buf,
"%lu", l);
211 l =
static_cast<unsigned long>(ref.second.second);
212 __builtin_sprintf(buf,
"%lu", l);
216 __builtin_sprintf(buf,
"%p", ref.first);
241 base_type::const_iterator beg = __b.map().
begin();
242 base_type::const_iterator
end = __b.map().
end();
243 for (; beg !=
end; ++beg)
244 __b.log_to_string(error, *beg);
272 const size_t _M_orig;
275 adjustor_base() : _M_orig(limit()) { }
278 ~adjustor_base() { set_limit(_M_orig); }
302 throw_conditionally()
304 if (count() == limit())
305 __throw_forced_error();
312 static size_t _S_count(0);
325 set_limit(
const size_t __l)
344 const double _M_orig;
347 adjustor_base() : _M_orig(probability()) { }
349 virtual ~adjustor_base()
350 { set_probability(_M_orig); }
357 { set_probability(1 -
std::pow(
double(1 - probability()),
358 double(0.5 / (size + 1))));
381 set_probability(
double __p)
382 { probability() = __p; }
385 throw_conditionally()
387 if (generate() < probability())
388 __throw_forced_error();
392 seed(
unsigned long __s)
393 { engine().seed(__s); }
396 #ifdef __GXX_EXPERIMENTAL_CXX0X__
400 typedef std::tr1::uniform_real<double> distribution_type;
407 #ifdef __GXX_EXPERIMENTAL_CXX0X__
408 const distribution_type distribution(0, 1);
409 static auto generator =
std::bind(distribution, engine());
412 typedef std::tr1::variate_generator<engine_type, distribution_type> gen_t;
413 distribution_type distribution(0, 1);
414 static gen_t generator(engine(), distribution);
417 double random = generator();
418 if (random < distribution.min() || random > distribution.max())
422 __s +=
"random number generated is: ";
424 __builtin_sprintf(buf,
"%f", random);
426 std::__throw_out_of_range(__s.c_str());
442 static engine_type _S_e;
454 template<
typename _Cond>
457 typedef _Cond condition_type;
459 using condition_type::throw_conditionally;
463 #ifndef _GLIBCXX_IS_AGGREGATE
465 { throw_conditionally(); }
468 { throw_conditionally(); }
471 { throw_conditionally(); }
477 throw_conditionally();
485 throw_conditionally();
491 template<
typename _Cond>
496 throw_value::throw_conditionally();
497 throw_value orig(__a);
503 template<
typename _Cond>
505 operator==(
const throw_value_base<_Cond>& __a,
506 const throw_value_base<_Cond>& __b)
508 typedef throw_value_base<_Cond> throw_value;
509 throw_value::throw_conditionally();
510 bool __ret = __a._M_i == __b._M_i;
514 template<
typename _Cond>
516 operator<(const throw_value_base<_Cond>& __a,
517 const throw_value_base<_Cond>& __b)
519 typedef throw_value_base<_Cond> throw_value;
520 throw_value::throw_conditionally();
521 bool __ret = __a._M_i < __b._M_i;
526 template<
typename _Cond>
527 inline throw_value_base<_Cond>
528 operator+(
const throw_value_base<_Cond>& __a,
529 const throw_value_base<_Cond>& __b)
531 typedef throw_value_base<_Cond> throw_value;
532 throw_value::throw_conditionally();
533 throw_value __ret(__a._M_i + __b._M_i);
537 template<
typename _Cond>
538 inline throw_value_base<_Cond>
539 operator-(
const throw_value_base<_Cond>& __a,
540 const throw_value_base<_Cond>& __b)
542 typedef throw_value_base<_Cond> throw_value;
543 throw_value::throw_conditionally();
544 throw_value __ret(__a._M_i - __b._M_i);
548 template<
typename _Cond>
549 inline throw_value_base<_Cond>
550 operator*(
const throw_value_base<_Cond>& __a,
551 const throw_value_base<_Cond>& __b)
553 typedef throw_value_base<_Cond> throw_value;
554 throw_value::throw_conditionally();
555 throw_value __ret(__a._M_i * __b._M_i);
565 #ifndef _GLIBCXX_IS_AGGREGATE
569 : base_type(__other._M_i) { }
580 #ifndef _GLIBCXX_IS_AGGREGATE
584 : base_type(__other._M_i) { }
599 template<
typename _Tp,
typename _Cond>
604 typedef size_t size_type;
605 typedef ptrdiff_t difference_type;
606 typedef _Tp value_type;
607 typedef value_type* pointer;
608 typedef const value_type* const_pointer;
609 typedef value_type& reference;
610 typedef const value_type& const_reference;
613 typedef _Cond condition_type;
617 using condition_type::throw_conditionally;
621 max_size()
const _GLIBCXX_USE_NOEXCEPT
622 {
return _M_allocator.max_size(); }
625 address(reference __x)
const _GLIBCXX_NOEXCEPT
629 address(const_reference __x)
const _GLIBCXX_NOEXCEPT
635 if (__n > this->max_size())
636 std::__throw_bad_alloc();
638 throw_conditionally();
639 pointer
const a = _M_allocator.allocate(__n, hint);
640 insert(a,
sizeof(value_type) * __n);
644 #ifdef __GXX_EXPERIMENTAL_CXX0X__
645 template<
typename _Up,
typename... _Args>
647 construct(_Up* __p, _Args&&... __args)
648 {
return _M_allocator.construct(__p, std::forward<_Args>(__args)...); }
650 template<
typename _Up>
653 { _M_allocator.destroy(__p); }
656 construct(pointer __p,
const value_type& val)
657 {
return _M_allocator.construct(__p, val); }
661 { _M_allocator.destroy(__p); }
665 deallocate(pointer __p, size_type __n)
667 erase(__p,
sizeof(value_type) * __n);
668 _M_allocator.deallocate(__p, __n);
672 check_allocated(pointer __p, size_type __n)
674 size_type __t =
sizeof(value_type) * __n;
675 annotate_base::check_allocated(__p, __t);
679 check_allocated(size_type __n)
680 { annotate_base::check_allocated(__n); }
683 template<
typename _Tp,
typename _Cond>
689 template<
typename _Tp,
typename _Cond>
691 operator!=(
const throw_allocator_base<_Tp, _Cond>&,
692 const throw_allocator_base<_Tp, _Cond>&)
696 template<
typename _Tp>
700 template<
typename _Tp1>
707 _GLIBCXX_USE_NOEXCEPT { }
709 template<
typename _Tp1>
711 _GLIBCXX_USE_NOEXCEPT { }
717 template<
typename _Tp>
721 template<
typename _Tp1>
728 _GLIBCXX_USE_NOEXCEPT { }
730 template<
typename _Tp1>
732 _GLIBCXX_USE_NOEXCEPT { }
737 _GLIBCXX_END_NAMESPACE_VERSION
740 #ifdef __GXX_EXPERIMENTAL_CXX0X__
744 namespace std _GLIBCXX_VISIBILITY(default)
748 struct hash<__gnu_cxx::throw_value_limit>
755 size_t __result = __h(__val._M_i);
762 struct hash<__gnu_cxx::throw_value_random>
769 size_t __result = __h(__val._M_i);
iterator end() _GLIBCXX_NOEXCEPT
bool empty() const _GLIBCXX_NOEXCEPT
iterator find(const key_type &__x)
Tries to locate an element in a map.
Uniform continuous distribution for random numbers.
Allocator throwing via random condition.
iterator erase(const_iterator __position)
Erases an element from a map.
const _CharT * c_str() const _GLIBCXX_NOEXCEPT
Return const pointer to null-terminated contents.
Template class basic_ostream.This is the base class for all output streams. It provides text formatti...
Properties of fundamental types.
Type throwing via random condition.
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
reference_wrapper< _Tp > ref(_Tp &__t) noexcept
Denotes a reference should be taken to a variable.
std::mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL >
Never enter the condition.
Allocator throwing via limit condition.
_Bind_helper< __is_socketlike< _Func >::value, _Func, _BoundArgs...>::type bind(_Func &&__f, _BoundArgs &&...__args)
Function template for std::bind.
Never enter the condition.
Base struct for condition policy.
Always enter the condition.
Thown by exception safety machinery.
mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL > mt19937
Type throwing via limit condition.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initilizer_list.
Base class for all library exceptions.
iterator begin() _GLIBCXX_NOEXCEPT
Base class for incremental control and throw.
Struct holding two objects of arbitrary type.
complex< _Tp > pow(const complex< _Tp > &, const _Tp &)
Return x to the y'th power.
Allocator class with logging and exception generation control. Intended to be used as an allocator_ty...
Base class for random probability control and throw.
Base class for checking address and label information about allocations. Create a std::map between th...
Class with exception generation control. Intended to be used as a value_type in templatized code...
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
_Tp * __addressof(_Tp &__r) _GLIBCXX_NOEXCEPT
Same as C++11 std::addressof.
Always enter the condition.
Primary class template hash.
std::pair< iterator, bool > insert(const value_type &__x)
Attempts to insert a std::pair into the map.
constexpr size_t size() const _GLIBCXX_NOEXCEPT
Returns the total number of bits.