1 typedef long unsigned int size_t;
3 template<typename _Tp> _Tp* __addressof(_Tp& __r) {
5 template<class _Sp, class _Tp> struct __traitor {
7 template<typename _Tp> struct __is_integer {
9 template<typename _Tp> struct __is_floating {
11 template<typename _Tp> struct __is_pointer {
13 template<typename _Tp> struct __is_normal_iterator {
15 template<typename _Tp> struct __is_arithmetic : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > {
17 template<typename _Tp> struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > {
19 template<typename _Iterator, bool _HasBase> struct _Iter_base { };
21 template<typename _Iterator> struct _Niter_base : _Iter_base<_Iterator, __is_normal_iterator<_Iterator>::__value> { };
22 template<typename _Iterator> typename _Niter_base<_Iterator>::iterator_type __niter_base(_Iterator __it) { }
23 template<typename _CharT> struct char_traits;
25 public: exception() throw() { }
26 virtual ~exception() throw();
32 template<bool, typename> struct __enable_if { };
33 template<typename _Iterator, typename _Container> class __normal_iterator {
34 protected: _Iterator _M_current;
35 public: typedef _Iterator iterator_type;
36 __normal_iterator() : _M_current(_Iterator()) {
39 template<typename _Tp> class new_allocator {
41 typedef const _Tp* const_pointer;
42 typedef _Tp& reference;
47 template<typename _Tp> class allocator: public __gnu_cxx::new_allocator<_Tp> {
49 template<typename _Tp1> struct rebind {
50 typedef allocator<_Tp1> other;
53 template<typename _InputIterator, typename _ForwardIterator, typename _Allocator> _ForwardIterator __uninitialized_copy_a(_InputIterator __first, _InputIterator __last, _ForwardIterator __result, _Allocator& __alloc) {
62 template<class T> class scoped_ptr {
64 public: typedef T element_type;
65 explicit scoped_ptr( T * p = 0 ): px( p ) {
70 template<typename _CharT, typename _Traits = char_traits<_CharT>, typename _Alloc = allocator<_CharT> > class basic_string;
71 typedef basic_string<char> string;
72 template<> struct char_traits<char> {
73 typedef char char_type;
74 static void assign(char_type& __c1, const char_type& __c2) {
77 __pthread_unwind_buf_t ;
79 typedef int _Atomic_word;
81 static _Atomic_word __exchange_and_add_dispatch(_Atomic_word* __mem, int __val) {
85 template<typename _CharT, typename _Traits, typename _Alloc> class basic_string {
86 typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;
87 public: typedef _Traits traits_type;
88 typedef _Alloc allocator_type;
89 typedef typename _CharT_alloc_type::reference reference;
90 typedef typename _CharT_alloc_type::const_pointer const_pointer;
91 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string> const_iterator;
92 private: struct _Rep_base {
93 _Atomic_word _M_refcount;
95 struct _Rep : _Rep_base {
96 void _M_set_length_and_sharable(size_t __n) {
98 _CharT* _M_refdata() throw() {
99 return reinterpret_cast<_CharT*>(this + 1);
101 void _M_dispose(const _Alloc& __a) {
102 if (__builtin_expect(this != &_S_empty_rep(), false)) {
103 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount, -1) <= 0) {
108 void _M_destroy(const _Alloc&) throw();
110 struct _Alloc_hider : _Alloc {
111 _Alloc_hider(_CharT* __dat, const _Alloc& __a) : _Alloc(__a), _M_p(__dat) {
115 public: static const size_t npos = static_cast<size_t>(-1);
116 private: mutable _Alloc_hider _M_dataplus;
117 _Rep* _M_rep() const {
119 size_t _M_limit(size_t __pos, size_t __off) const {
121 static _Rep& _S_empty_rep() {
123 public: basic_string() : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) {
126 _M_rep()->_M_dispose(this->get_allocator());
128 size_t length() const {
130 reference operator[](size_t __pos) {
132 basic_string& erase(size_t __pos = 0, size_t __n = npos) {
134 allocator_type get_allocator() const {
140 template <typename T> class empty_base {
143 template <class T, class U, class B = ::boost::detail::empty_base<T> > struct less_than_comparable2 : B {
145 template <class T, class U, class B = ::boost::detail::empty_base<T> > struct equality_comparable2 : B {
151 template<class T> struct is_chained_base {
152 typedef ::boost::detail::false_t value;
154 template <class T ,class U = T ,class B = ::boost::detail::empty_base<T> ,class O = typename is_chained_base<U>::value > struct less_than_comparable : less_than_comparable2<T, U, B> {
156 template <class T ,class U = T ,class B = ::boost::detail::empty_base<T> ,class O = typename is_chained_base<U>::value > struct equality_comparable : equality_comparable2<T, U, B> {
158 namespace type_traits {
160 template<class T> class intrusive_ptr {
161 private: typedef intrusive_ptr this_type;
162 public: typedef T element_type;
163 intrusive_ptr(): px( 0 ) {
165 intrusive_ptr( T * p, bool add_ref = true ): px( p ) {
168 if( px != 0 ) intrusive_ptr_release( px );
170 T * operator->() const {
173 typedef T * this_type::*unspecified_bool_type;
174 operator unspecified_bool_type() const {
179 namespace quickbook {
181 struct string_ref : boost::less_than_comparable<string_ref, boost::less_than_comparable<string_ref, std::string, boost::equality_comparable<string_ref, boost::equality_comparable<string_ref, std::string> > > > {
182 public: typedef std::string::const_iterator iterator;
183 private: iterator begin_, end_;
184 public: string_ref() : begin_(), end_() {
187 namespace exception_detail {
191 class bad_cast : public exception { };
193 namespace quickbook {
194 template <typename T> struct intrusive_base {
195 intrusive_base() : ref_count_(0) {
199 friend void intrusive_ptr_release(T* ptr) {
200 if(--ptr->ref_count_ == 0) delete ptr;
202 private: unsigned ref_count_;
206 default_category = 0, numbered, generated, generated_heading, generated_section, generated_doc, explicit_id, explicit_section_id, explicit_anchor_id };
212 private: boost::scoped_ptr<id_state> state;
220 template<typename _Tp, typename _Ref, typename _Ptr> struct _Deque_iterator {
222 template<typename _Tp, typename _Alloc> class _Deque_base {
223 public: typedef _Alloc allocator_type;
224 typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator;
225 _Deque_base() : _M_impl() {
226 _M_initialize_map(0);
228 typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type;
229 struct _Deque_impl : public _Tp_alloc_type {
234 _Deque_impl() : _Tp_alloc_type(), _M_map(0), _M_map_size(0), _M_start(), _M_finish() {
237 protected: void _M_initialize_map(size_t);
240 template<typename _Tp, typename _Alloc = std::allocator<_Tp> > class deque : protected _Deque_base<_Tp, _Alloc> {
243 enum range_check_result {
244 cInRange = 0 , cNegOverflow = 1 , cPosOverflow = 2 }
246 class bad_numeric_cast : public std::bad_cast {
248 class negative_overflow : public bad_numeric_cast {
249 void operator() ( range_check_result r ) {
250 if ( r == cNegOverflow ) throw negative_overflow() ;
256 namespace quickbook {
257 static const size_t max_size = 32;
258 struct id_placeholder {
263 boost::intrusive_ptr<file_info> current_file;
264 std::deque<id_placeholder> placeholders;
265 private: id_placeholder* add_id_to_section( std::string const& id, id_category category, boost::intrusive_ptr<section_info> const& section);
267 struct file_info : intrusive_base<file_info> {
268 boost::intrusive_ptr<file_info> parent;
269 boost::intrusive_ptr<doc_info> document;
271 unsigned compatibility_version;
272 boost::intrusive_ptr<section_info> switched_section;
273 id_placeholder* original_placeholder;
274 std::string doc_id_1_1;
275 file_info(boost::intrusive_ptr<file_info> const& parent, unsigned compatibility_version) : parent(parent), document(parent->document), document_root(false), compatibility_version(compatibility_version), switched_section(), original_placeholder() {
278 struct doc_info : intrusive_base<doc_info> {
279 boost::intrusive_ptr<section_info> current_section;
280 std::string last_title_1_1;
281 std::string section_id_1_1;
283 struct section_info : intrusive_base<section_info> {
284 boost::intrusive_ptr<section_info> parent;
285 unsigned compatibility_version;
288 id_placeholder* placeholder_1_6;
289 section_info(boost::intrusive_ptr<section_info> const& parent, unsigned compatibility_version, std::string const& id) : parent(parent), compatibility_version(compatibility_version), level(parent ? parent->level + 1 : 1), id_1_1(), placeholder_1_6(0) {
292 id_manager::id_manager() : state(new id_state) {
295 std::string normalize_id( std::string src_id, size_t prefix = 0, size_t size = max_size) {
299 if (src >= id.length()) {
300 if (id[src] == '_') {
306 id_placeholder* id_state::add_id_to_section( std::string const& id, id_category category, boost::intrusive_ptr<section_info> const& section) {
307 std::string id_part = id;
308 if (current_file->compatibility_version >= 106u && category.c < id_category::explicit_id) {
309 id_part = normalize_id(id);
311 boost::intrusive_ptr<section_info> parent = current_file->document->current_section;
312 boost::intrusive_ptr<section_info> new_section = new section_info(parent, current_file->compatibility_version, id);