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 "cetlib/filepath_maker.h"
13 
14 #include <string>
15 #include <vector>
16 
17 namespace cet {
18  class includer;
19 }
20 
21 // ----------------------------------------------------------------------
22 
25 
26 public:
27  using const_iterator = std::string::const_iterator;
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 
65  frame(uint framenum, std::string filename, uint linenum, size_t textpos)
66  : including_framenum(framenum)
67  , filename(filename)
68  , starting_linenum(linenum)
69  , starting_textpos(textpos)
70  {}
71  };
72 
73  struct posinfo {
74  uint textpos; // Character position in fully-included text.
75  uint linenum; // Line number (1-based for user info).
76  uint charpos; // Character position in line (1-based for user info).
77  uint framenum; // Inclusion level.
78  };
79 
81  std::vector<frame> frames;
82  std::vector<std::string> recursion_stack{};
83 
84  void include(int including_framenum,
85  std::string const& filename,
86  cet::filepath_maker& abs_filename);
87 
88  void include(std::istream& is, cet::filepath_maker& abs_filename);
89 
90  std::string backtrace(uint from_frame) const;
91  void debug() const;
92 
93  posinfo get_posinfo(const_iterator const& it) const;
94 
95 }; // includer
96 
97 // ======================================================================
98 
99 #endif /* cetlib_includer_h */
100 
101 // Local variables:
102 // mode: c++
103 // End:
const_iterator end() const
Definition: includer.h:40
set< int >::iterator it
std::string src_whereis(const_iterator const &it) const
frame(uint framenum, std::string filename, uint linenum, size_t textpos)
Definition: includer.h:65
posinfo get_posinfo(const_iterator const &it) const
std::string::size_type uint
Definition: includer.h:24
const_iterator begin() const
Definition: includer.h:35
string filename
Definition: shutoffs.py:106
std::string filename
Definition: includer.h:61
void debug() const
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Definition: typedefs.hpp:11
std::string highlighted_whereis(const_iterator const &it) const
void include(int including_framenum, std::string const &filename, cet::filepath_maker &abs_filename)
std::string text
Definition: includer.h:80
size_t starting_textpos
Definition: includer.h:63
std::string backtrace(uint from_frame) const
includer(std::string const &filename, cet::filepath_maker &abs_filename)
std::vector< frame > frames
Definition: includer.h:81
std::vector< std::string > recursion_stack
Definition: includer.h:82
std::string whereis(const_iterator const &it) const
const_iterator cbegin() const
Definition: includer.h:45
std::string::const_iterator const_iterator
Definition: includer.h:27
const_iterator cend() const
Definition: includer.h:50
enum BeamMode string