|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83124 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2013-02-24 06:23:37
Author: danieljames
Date: 2013-02-24 06:23:35 EST (Sun, 24 Feb 2013)
New Revision: 83124
URL: http://svn.boost.org/trac/boost/changeset/83124
Log:
Move dependency tracking into a separate class.
Added:
trunk/tools/quickbook/src/dependency_tracker.cpp (contents, props changed)
trunk/tools/quickbook/src/dependency_tracker.hpp (contents, props changed)
Text files modified:
trunk/tools/quickbook/src/Jamfile.v2 | 1 +
trunk/tools/quickbook/src/actions.cpp | 8 ++++----
trunk/tools/quickbook/src/quickbook.cpp | 17 +++--------------
trunk/tools/quickbook/src/state.cpp | 38 --------------------------------------
trunk/tools/quickbook/src/state.hpp | 8 ++------
5 files changed, 10 insertions(+), 62 deletions(-)
Modified: trunk/tools/quickbook/src/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/src/Jamfile.v2 (original)
+++ trunk/tools/quickbook/src/Jamfile.v2 2013-02-24 06:23:35 EST (Sun, 24 Feb 2013)
@@ -27,6 +27,7 @@
actions.cpp
doc_info_actions.cpp
state.cpp
+ dependency_tracker.cpp
utils.cpp
files.cpp
input_path.cpp
Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2013-02-24 06:23:35 EST (Sun, 24 Feb 2013)
@@ -939,7 +939,7 @@
// Now load the SVG file:
//
std::string svg_text;
- if (state.add_dependency(img)) {
+ if (state.dependencies.add_dependency(img)) {
fs::ifstream fs(img);
std::stringstream buffer;
buffer << fs.rdbuf();
@@ -1877,7 +1877,7 @@
state.current_file->path.parent_path() / path;
// See if it can be found locally first.
- if (state.add_dependency(local_path))
+ if (state.dependencies.add_dependency(local_path))
{
result.insert(include_search_return(
local_path,
@@ -1889,7 +1889,7 @@
{
full /= path;
- if (state.add_dependency(full))
+ if (state.dependencies.add_dependency(full))
{
result.insert(include_search_return(full, path));
return result;
@@ -1898,7 +1898,7 @@
}
else
{
- if (state.add_dependency(path)) {
+ if (state.dependencies.add_dependency(path)) {
result.insert(include_search_return(path, path));
return result;
}
Added: trunk/tools/quickbook/src/dependency_tracker.cpp
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/src/dependency_tracker.cpp 2013-02-24 06:23:35 EST (Sun, 24 Feb 2013)
@@ -0,0 +1,71 @@
+/*=============================================================================
+ Copyright (c) 2013 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)
+=============================================================================*/
+
+#include "dependency_tracker.hpp"
+#include "input_path.hpp"
+#include <boost/filesystem/operations.hpp>
+#include <boost/foreach.hpp>
+
+namespace quickbook
+{
+ bool dependency_tracker::add_dependency(fs::path const& f) {
+ fs::path p = fs::absolute(f);
+ bool found = fs::exists(fs::status(p));
+
+ // Pop path sections from path until we find an existing
+ // path, adjusting for any dot path sections.
+ fs::path extra;
+ int parent_count = 0;
+ while (!fs::exists(fs::status(p))) {
+ fs::path name = p.filename();
+ p = p.parent_path();
+ if (name == "..") {
+ ++parent_count;
+ }
+ else if (name == ".") {
+ }
+ else if (parent_count) {
+ --parent_count;
+ }
+ else {
+ extra = name / extra;
+ }
+ }
+
+ // If there are any left over ".." sections, then add them
+ // on to the end of the real path, and trust Boost.Filesystem
+ // to sort them out.
+ while (parent_count) {
+ p = p / "..";
+ --parent_count;
+ }
+
+ p = fs::canonical(p) / extra;
+ dependencies[p] |= found;
+ return found;
+ }
+
+ void dependency_tracker::write_dependencies(std::ostream& out)
+ {
+ BOOST_FOREACH(dependency_list::value_type const& d, dependencies)
+ {
+ if (d.second) {
+ out << detail::path_to_generic(d.first) << std::endl;
+ }
+ }
+ }
+
+ void dependency_tracker::write_checked_locations(std::ostream& out)
+ {
+ BOOST_FOREACH(dependency_list::value_type const& d, dependencies)
+ {
+ out << (d.second ? "+ " : "- ")
+ << detail::path_to_generic(d.first) << std::endl;
+ }
+ }
+}
Added: trunk/tools/quickbook/src/dependency_tracker.hpp
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/src/dependency_tracker.hpp 2013-02-24 06:23:35 EST (Sun, 24 Feb 2013)
@@ -0,0 +1,37 @@
+/*=============================================================================
+ Copyright (c) 2013 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(QUICKBOOK_DEPENDENCY_TRACKER_HPP)
+#define QUICKBOOK_DEPENDENCY_TRACKER_HPP
+
+#include <map>
+#include <iosfwd>
+#include <boost/filesystem/path.hpp>
+
+namespace quickbook
+{
+ namespace fs = boost::filesystem;
+
+ struct dependency_tracker {
+ private:
+
+ typedef std::map<fs::path, bool> dependency_list;
+ dependency_list dependencies;
+
+ public:
+
+ // Call this before loading any file so that it will be included in the
+ // list of dependencies. Returns true if file exists.
+ bool add_dependency(fs::path const&);
+
+ void write_dependencies(std::ostream&);
+ void write_checked_locations(std::ostream&);
+ };
+}
+
+#endif
Modified: trunk/tools/quickbook/src/quickbook.cpp
==============================================================================
--- trunk/tools/quickbook/src/quickbook.cpp (original)
+++ trunk/tools/quickbook/src/quickbook.cpp 2013-02-24 06:23:35 EST (Sun, 24 Feb 2013)
@@ -132,7 +132,7 @@
set_macros(state);
if (state.error_count == 0) {
- state.add_dependency(filein_);
+ state.dependencies.add_dependency(filein_);
state.current_file = load(filein_); // Throws load_error
parse_file(state);
@@ -148,24 +148,13 @@
if (!deps_out_.empty())
{
fs::ofstream out(deps_out_);
- BOOST_FOREACH(quickbook::state::dependency_list::value_type
- const& d, state.dependencies)
- {
- if (d.second) {
- out << detail::path_to_generic(d.first) << std::endl;
- }
- }
+ state.dependencies.write_dependencies(out);
}
if (!locations_out_.empty())
{
fs::ofstream out(locations_out_);
- BOOST_FOREACH(quickbook::state::dependency_list::value_type
- const& d, state.dependencies)
- {
- out << (d.second ? "+ " : "- ")
- << detail::path_to_generic(d.first) << std::endl;
- }
+ state.dependencies.write_checked_locations(out);
}
}
catch (load_error& e) {
Modified: trunk/tools/quickbook/src/state.cpp
==============================================================================
--- trunk/tools/quickbook/src/state.cpp (original)
+++ trunk/tools/quickbook/src/state.cpp 2013-02-24 06:23:35 EST (Sun, 24 Feb 2013)
@@ -13,7 +13,6 @@
#include "quickbook.hpp"
#include "grammar.hpp"
#include "input_path.hpp"
-#include <boost/filesystem/operations.hpp>
#if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310))
#pragma warning(disable:4355)
@@ -71,43 +70,6 @@
return *grammar_;
}
- bool state::add_dependency(fs::path const& f) {
- fs::path p = fs::absolute(f);
- bool found = fs::exists(fs::status(p));
-
- // Pop path sections from path until we find an existing
- // path, adjusting for any dot path sections.
- fs::path extra;
- int parent_count = 0;
- while (!fs::exists(fs::status(p))) {
- fs::path name = p.filename();
- p = p.parent_path();
- if (name == "..") {
- ++parent_count;
- }
- else if (name == ".") {
- }
- else if (parent_count) {
- --parent_count;
- }
- else {
- extra = name / extra;
- }
- }
-
- // If there are any left over ".." sections, then add them
- // on to the end of the real path, and trust Boost.Filesystem
- // to sort them out.
- while (parent_count) {
- p = p / "..";
- --parent_count;
- }
-
- p = fs::canonical(p) / extra;
- dependencies[p] |= found;
- return found;
- }
-
file_state::file_state(quickbook::state& state, scope_flags scope)
: state(state)
, scope(scope)
Modified: trunk/tools/quickbook/src/state.hpp
==============================================================================
--- trunk/tools/quickbook/src/state.hpp (original)
+++ trunk/tools/quickbook/src/state.hpp 2013-02-24 06:23:35 EST (Sun, 24 Feb 2013)
@@ -17,6 +17,7 @@
#include "collector.hpp"
#include "template_stack.hpp"
#include "symbols.hpp"
+#include "dependency_tracker.hpp"
namespace quickbook
{
@@ -37,7 +38,6 @@
///////////////////////////////////////////////////////////////////////////
typedef std::vector<std::string> string_list;
- typedef std::map<fs::path, bool> dependency_list;
static int const max_template_depth = 100;
@@ -51,7 +51,7 @@
id_manager& ids;
value_builder callouts; // callouts are global as
int callout_depth; // they don't nest.
- dependency_list dependencies;
+ dependency_tracker dependencies;
// state saved for files and templates.
bool imported;
@@ -78,10 +78,6 @@
// actions
///////////////////////////////////////////////////////////////////////////
- // Call this before loading any file so that it will be included in the
- // list of dependencies. Returns true if file exists.
- bool add_dependency(fs::path const&);
-
void start_list(char mark);
void end_list(char mark);
void start_list_item();
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk