includer.h
Go to the documentation of this file.
1 #ifndef cetlib_includer_h
2 #define cetlib_includer_h
3 
4 // ======================================================================
5 //
6 // includer: A container-like data structure that
7 // a) transparently handles #include'd files, and
8 // b) can trace back its iterators
9 //
10 // ======================================================================
11 
12 #include <iosfwd>
13 #include <string>
14 #include <vector>
15 
16 namespace cet {
17  class filepath_maker;
18  class includer;
19 }
20 
21 // ----------------------------------------------------------------------
22 
24  using uint = std::string::size_type;
25 
26 public:
28 
29  explicit includer(std::string const& filename,
30  cet::filepath_maker& abs_filename);
31 
32  explicit includer(std::istream& is, cet::filepath_maker& abs_filename);
33 
35  begin() const
36  {
37  return text_.begin();
38  }
40  end() const
41  {
42  return text_.end();
43  }
45  cbegin() const
46  {
47  return text_.cbegin();
48  }
50  cend() const
51  {
52  return text_.cend();
53  }
54  std::string whereis(const_iterator const& it) const;
56  std::string src_whereis(const_iterator const& it) const;
57 
58 private:
59  struct frame {
64  // The new-line positions are used to determine line numbers
65  // whenever includer::get_posinfo is called.
66  std::vector<size_t> nl_positions{};
67 
68  frame(uint const framenum,
69  std::string const& filename,
70  uint const linenum,
71  size_t const textpos)
72  : including_framenum{framenum}
73  , filename{filename}
74  , starting_linenum{linenum}
75  , starting_textpos{textpos}
76  {}
77  };
78 
79  struct posinfo {
80  uint textpos; // Character position in fully-included text.
81  uint linenum; // Line number (1-based for user info).
82  uint charpos; // Character position in line (1-based for user info).
83  uint framenum; // Inclusion level.
84  };
85 
87  std::vector<frame> frames_;
88  std::vector<std::string> recursionStack_{};
89 
90  void include(int including_framenum,
91  std::string const& filename,
92  cet::filepath_maker& abs_filename);
93 
94  void include(std::istream& is, cet::filepath_maker& abs_filename);
95 
96  std::string backtrace(uint from_frame) const;
97  void debug() const;
98 
99  posinfo get_posinfo(const_iterator const& it) const;
100 
101 }; // includer
102 
103 // ======================================================================
104 
105 #endif /* cetlib_includer_h */
106 
107 // Local variables:
108 // mode: c++
109 // End:
const_iterator end() const
Definition: includer.h:40
std::string string
Definition: nybbler.cc:12
void include(int including_framenum, std::string const &filename, cet::filepath_maker &abs_filename)
Definition: includer.cc:186
std::string::size_type uint
Definition: includer.h:24
const_iterator begin() const
Definition: includer.h:35
std::string backtrace(uint from_frame) const
Definition: includer.cc:323
intermediate_table::const_iterator const_iterator
std::string filename
Definition: includer.h:61
std::string highlighted_whereis(const_iterator const &it) const
Definition: includer.cc:155
string filename
Definition: train.py:213
frame(uint const framenum, std::string const &filename, uint const linenum, size_t const textpos)
Definition: includer.h:68
std::string src_whereis(const_iterator const &it) const
Definition: includer.cc:176
std::string text_
Definition: includer.h:86
size_t starting_textpos
Definition: includer.h:63
void debug() const
Definition: includer.cc:335
std::vector< std::string > recursionStack_
Definition: includer.h:88
std::string whereis(const_iterator const &it) const
Definition: includer.cc:143
const_iterator cbegin() const
Definition: includer.h:45
posinfo get_posinfo(const_iterator const &it) const
Definition: includer.cc:112
std::string::const_iterator const_iterator
Definition: includer.h:27
std::vector< frame > frames_
Definition: includer.h:87
std::vector< size_t > nl_positions
Definition: includer.h:66
const_iterator cend() const
Definition: includer.h:50
includer(std::string const &filename, cet::filepath_maker &abs_filename)
Definition: includer.cc:96