]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/quickbook/src/state.cpp
1 /*=============================================================================
2 Copyright (c) 2002 2004 2006 Joel de Guzman
3 Copyright (c) 2004 Eric Niebler
4 Copyright (c) 2005 Thomas Guest
5 http://spirit.sourceforge.net/
7 Use, modification and distribution is subject to the Boost Software
8 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 http://www.boost.org/LICENSE_1_0.txt)
10 =============================================================================*/
12 #include <boost/foreach.hpp>
13 #include "document_state.hpp"
14 #include "grammar.hpp"
16 #include "phrase_tags.hpp"
17 #include "quickbook.hpp"
18 #include "state_save.hpp"
21 #if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310))
22 #pragma warning(disable : 4355)
27 char const* quickbook_get_date
= "__quickbook_get_date__";
28 char const* quickbook_get_time
= "__quickbook_get_time__";
30 unsigned qbk_version_n
= 0; // qbk_major_version * 100 + qbk_minor_version
33 fs::path
const& filein_
,
34 fs::path
const& xinclude_base_
,
36 document_state
& document_
)
40 , xinclude_base(xinclude_base_
)
45 , warned_about_breaks(false)
51 , explicit_list(false)
58 , source_mode_next_pos()
60 , current_path(filein_
, 0, filein_
.filename())
63 , min_section_level(1)
70 , values(¤t_file
)
72 // add the predefined macros
73 macro
.add("__DATE__", std::string(quickbook_get_date
))(
75 std::string(quickbook_get_time
))("__FILENAME__", std::string());
76 update_filename_macro();
78 boost::scoped_ptr
<quickbook_grammar
> g(new quickbook_grammar(*this));
82 quickbook_grammar
& state::grammar() const { return *grammar_
; }
84 void state::update_filename_macro()
86 *boost::spirit::classic::find(macro
, "__FILENAME__") =
87 detail::encode_string(
88 detail::path_to_generic(current_path
.abstract_file_path
));
91 unsigned state::get_new_order_pos() { return ++order_pos
; }
93 void state::push_output()
97 in_list_save
.push(in_list
);
100 void state::pop_output()
104 in_list
= in_list_save
.top();
108 source_mode_info
state::tagged_source_mode() const
110 source_mode_info result
;
112 BOOST_FOREACH (source_mode_info
const& s
, tagged_source_mode_stack
) {
119 source_mode_info
state::current_source_mode() const
121 source_mode_info result
= source_mode
;
123 result
.update(document
.section_source_mode());
125 BOOST_FOREACH (source_mode_info
const& s
, tagged_source_mode_stack
) {
132 void state::change_source_mode(source_mode_type s
)
134 source_mode
= source_mode_info(s
, get_new_order_pos());
137 void state::push_tagged_source_mode(source_mode_type s
)
139 tagged_source_mode_stack
.push_back(
140 source_mode_info(s
, s
? get_new_order_pos() : 0));
143 void state::pop_tagged_source_mode()
145 assert(!tagged_source_mode_stack
.empty());
146 tagged_source_mode_stack
.pop_back();
149 state_save::state_save(quickbook::state
& state_
, scope_flags scope_
)
152 , qbk_version(qbk_version_n
)
153 , imported(state
.imported
)
154 , current_file(state
.current_file
)
155 , current_path(state
.current_path
)
156 , xinclude_base(state
.xinclude_base
)
157 , source_mode(state
.source_mode
)
159 , template_depth(state
.template_depth
)
160 , min_section_level(state
.min_section_level
)
162 if (scope
& scope_macros
) macro
= state
.macro
;
163 if (scope
& scope_templates
) state
.templates
.push();
164 if (scope
& scope_output
) {
167 state
.values
.builder
.save();
170 state_save::~state_save()
172 state
.values
.builder
.restore();
173 boost::swap(qbk_version_n
, qbk_version
);
174 boost::swap(state
.imported
, imported
);
175 boost::swap(state
.current_file
, current_file
);
176 boost::swap(state
.current_path
, current_path
);
177 boost::swap(state
.xinclude_base
, xinclude_base
);
178 boost::swap(state
.source_mode
, source_mode
);
179 if (scope
& scope_output
) {
182 if (scope
& scope_templates
) state
.templates
.pop();
183 if (scope
& scope_macros
) state
.macro
= macro
;
184 boost::swap(state
.template_depth
, template_depth
);
185 boost::swap(state
.min_section_level
, min_section_level
);