| 1 | // inspector header --------------------------------------------------------// |
|---|
| 2 | |
|---|
| 3 | // Copyright Beman Dawes 2002. |
|---|
| 4 | // Copyright Rene Rivera 2004. |
|---|
| 5 | // Distributed under the Boost Software License, Version 1.0. |
|---|
| 6 | // (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 8 | |
|---|
| 9 | #ifndef BOOST_INSPECTOR_HPP |
|---|
| 10 | #define BOOST_INSPECTOR_HPP |
|---|
| 11 | |
|---|
| 12 | #include <string> |
|---|
| 13 | #include <iostream> |
|---|
| 14 | #include <set> |
|---|
| 15 | #include <boost/filesystem/path.hpp> |
|---|
| 16 | |
|---|
| 17 | using std::string; |
|---|
| 18 | using boost::filesystem::path; |
|---|
| 19 | |
|---|
| 20 | namespace boost |
|---|
| 21 | { |
|---|
| 22 | namespace inspect |
|---|
| 23 | { |
|---|
| 24 | typedef std::set< string > string_set; |
|---|
| 25 | |
|---|
| 26 | class inspector |
|---|
| 27 | { |
|---|
| 28 | public: |
|---|
| 29 | virtual ~inspector() {} |
|---|
| 30 | |
|---|
| 31 | virtual const char * name() const = 0; // example: "tab-check" |
|---|
| 32 | virtual const char * desc() const = 0; // example: "verify no tabs" |
|---|
| 33 | |
|---|
| 34 | // always called: |
|---|
| 35 | virtual void inspect( |
|---|
| 36 | const string & library_name, // "filesystem" |
|---|
| 37 | const path & full_path ) {} // "c:/foo/boost/filesystem/path.hpp" |
|---|
| 38 | |
|---|
| 39 | // called only for registered leaf() signatures: |
|---|
| 40 | virtual void inspect( |
|---|
| 41 | const string & library_name, // "filesystem" |
|---|
| 42 | const path & full_path, // "c:/foo/boost/filesystem/path.hpp" |
|---|
| 43 | const string & contents ) {} // contents of file |
|---|
| 44 | |
|---|
| 45 | // called after all paths visited, but still in time to call error(): |
|---|
| 46 | virtual void close() {} |
|---|
| 47 | |
|---|
| 48 | // callback used by constructor to register leaf() signature. |
|---|
| 49 | // Signature can be a full file name (Jamfile) or partial (.cpp) |
|---|
| 50 | void register_signature( const string & signature ); |
|---|
| 51 | const string_set & signatures() const { return m_signatures; } |
|---|
| 52 | |
|---|
| 53 | // report error callback (from inspect(), close() ): |
|---|
| 54 | void error( |
|---|
| 55 | const string & library_name, |
|---|
| 56 | const path & full_path, |
|---|
| 57 | const string & msg ); |
|---|
| 58 | |
|---|
| 59 | private: |
|---|
| 60 | string_set m_signatures; |
|---|
| 61 | }; |
|---|
| 62 | |
|---|
| 63 | // for inspection of source code of one form or other |
|---|
| 64 | class source_inspector : public inspector |
|---|
| 65 | { |
|---|
| 66 | public: |
|---|
| 67 | // registers the basic set of known source signatures |
|---|
| 68 | source_inspector(); |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | // for inspection of hypertext, specifically html |
|---|
| 72 | class hypertext_inspector : public inspector |
|---|
| 73 | { |
|---|
| 74 | public: |
|---|
| 75 | // registers the set of known html source signatures |
|---|
| 76 | hypertext_inspector(); |
|---|
| 77 | }; |
|---|
| 78 | |
|---|
| 79 | inline string relative_to( const path & src_arg, const path & base_arg ) |
|---|
| 80 | { |
|---|
| 81 | path src( src_arg ); |
|---|
| 82 | src.normalize(); |
|---|
| 83 | path base( base_arg ); |
|---|
| 84 | base.normalize(); |
|---|
| 85 | string::size_type pos( base.string().size() ); |
|---|
| 86 | return src.string().substr( |
|---|
| 87 | pos + ( pos < src.string().size() ? 1 : 0 ) ); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | string impute_library( const path & full_dir_path ); |
|---|
| 91 | |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | #endif // BOOST_INSPECTOR_HPP |
|---|
| 96 | |
|---|