summaryrefslogtreecommitdiff
path: root/tools/quickbook/src/id_manager.hpp
blob: 9410d23808b868b454029c04e1269889f0b0cd98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*=============================================================================
    Copyright (c) 2011 Daniel James

    Use, modification and distribution is subject to the Boost Software
    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/

#if !defined(BOOST_QUICKBOOK_ID_MANAGER_HPP)
#define BOOST_QUICKBOOK_ID_MANAGER_HPP

#include <boost/scoped_ptr.hpp>
#include <boost/utility/string_ref.hpp>
#include <string>
#include "values.hpp"

namespace quickbook
{
    // id_category
    //
    // Higher categories get priority over lower ones.

    struct id_category
    {
        enum categories
        {
            default_category = 0,
            numbered,           // Just used to avoid random docbook ids
            generated,          // Generated ids for other elements.
            generated_heading,  // Generated ids for headings.
            generated_section,  // Generated ids for sections.
            generated_doc,      // Generated ids for document.
            explicit_id,        // Explicitly given by user
            explicit_section_id,
            explicit_anchor_id
        };

        id_category() : c(default_category) {}
        id_category(categories c) : c(c) {}
        explicit id_category(int c) : c(categories(c)) {}

        bool operator==(id_category rhs) const { return c == rhs.c; }

        categories c;
    };

    struct id_state;
    struct section_manager;

    struct id_manager
    {
        id_manager();
        ~id_manager();

        std::string start_file_with_docinfo(
                unsigned compatibility_version,
                boost::string_ref include_doc_id,
                boost::string_ref id,
                value const& title);

        void start_file(
                unsigned compatibility_version,
                boost::string_ref include_doc_id,
                boost::string_ref id,
                value const& title);

        void end_file();

        std::string begin_section(boost::string_ref, id_category);
        void end_section();
        int section_level() const;

        std::string old_style_id(boost::string_ref, id_category);
        std::string add_id(boost::string_ref, id_category);
        std::string add_anchor(boost::string_ref, id_category);

        std::string replace_placeholders_with_unresolved_ids(
                boost::string_ref) const;
        std::string replace_placeholders(boost::string_ref) const;
        
        unsigned compatibility_version() const;
    private:
        boost::scoped_ptr<id_state> state;
    };
}

#endif