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