47 #ifndef _THROW_ALLOCATOR_H
48 #define _THROW_ALLOCATOR_H 1
59 #ifdef __GXX_EXPERIMENTAL_CXX0X__
60 # include <functional>
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)
201 log_to_string(
std::string& s, const_reference ref)
const
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);
231 static map_type _S_map;
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 throw()
622 {
return _M_allocator.max_size(); }
625 address(reference __x)
const {
return std::__addressof(__x); }
628 address(const_reference __x)
const {
return std::__addressof(__x); }
633 if (__n > this->max_size())
634 std::__throw_bad_alloc();
636 throw_conditionally();
637 pointer
const a = _M_allocator.allocate(__n, hint);
638 insert(a,
sizeof(value_type) * __n);
643 construct(pointer __p,
const value_type& val)
644 {
return _M_allocator.construct(__p, val); }
646 #ifdef __GXX_EXPERIMENTAL_CXX0X__
647 template<
typename... _Args>
649 construct(pointer __p, _Args&&... __args)
650 {
return _M_allocator.construct(__p, std::forward<_Args>(__args)...); }
655 { _M_allocator.destroy(__p); }
658 deallocate(pointer __p, size_type __n)
660 erase(__p,
sizeof(value_type) * __n);
661 _M_allocator.deallocate(__p, __n);
665 check_allocated(pointer __p, size_type __n)
667 size_type __t =
sizeof(value_type) * __n;
668 annotate_base::check_allocated(__p, __t);
672 check_allocated(size_type __n)
673 { annotate_base::check_allocated(__n); }
676 template<
typename _Tp,
typename _Cond>
682 template<
typename _Tp,
typename _Cond>
684 operator!=(
const throw_allocator_base<_Tp, _Cond>&,
685 const throw_allocator_base<_Tp, _Cond>&)
689 template<
typename _Tp>
693 template<
typename _Tp1>
701 template<
typename _Tp1>
708 template<
typename _Tp>
712 template<
typename _Tp1>
720 template<
typename _Tp1>
726 _GLIBCXX_END_NAMESPACE_VERSION
729 #ifdef __GXX_EXPERIMENTAL_CXX0X__
733 namespace std _GLIBCXX_VISIBILITY(default)
744 size_t __result = __h(__val._M_i);
758 size_t __result = __h(__val._M_i);
const _CharT * c_str() const
Return const pointer to null-terminated contents.
Uniform continuous distribution for random numbers.
Allocator throwing via limit condition.
std::pair< iterator, bool > insert(const value_type &__x)
Attempts to insert a std::pair into the map.
Base class for incremental control and throw.
const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
Type throwing via limit condition.
Base struct for condition policy.
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
Allocator class with logging and exception generation control. Intended to be used as an allocator_ty...
Always enter the condition.
iterator erase(const_iterator __position)
Erases an element from a map.
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.
Class with exception generation control. Intended to be used as a value_type in templatized code...
Base class for checking address and label information about allocations. Create a std::map between th...
Primary class template hash.
ISO C++ entities toplevel namespace is std.
GNU extensions for public use.
basic_string< _CharT, _Traits, _Alloc > operator+(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Concatenate two strings.
auto end(_Container &__cont) -> decltype(__cont.end())
Return an iterator pointing to one past the last element of the container.
Always enter the condition.
Thown by exception safety machinery.
Allocator throwing via random condition.
Never enter the condition.
Type throwing via random condition.
iterator find(const key_type &__x)
Tries to locate an element in a map.
mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL > mt19937
Struct holding two objects of arbitrary type.
Never enter the condition.
Base class for random probability control and throw.