Doxygen
section.h
浏览该文件的文档.
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2020 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby
7  * granted. No representations are made about the suitability of this software
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  */
15 
16 #ifndef SECTION_H
17 #define SECTION_H
18 
19 #include <string>
20 #include <unordered_map>
21 
22 #include "qcstring.h"
23 #include "linkedmap.h"
24 
25 class Definition;
26 
27 //! enum representing the various types of sections and entities that can be referred to.
28 enum class SectionType
29 {
30  Page = 0,
31  Section = 1,
32  Subsection = 2,
33  Subsubsection = 3,
34  Paragraph = 4,
35  Anchor = 5,
36  Table = 6
37 };
38 
39 //! return true if type is a section, and false if it is a page, anchor or table.
40 inline constexpr bool isSection(SectionType type)
41 {
42  return (type==SectionType::Section ||
46 }
47 
48 //! class that provide information about a section.
50 {
51  public:
53  const QCString &title, SectionType type, int level,const QCString &ref) :
56  {
57  //printf("SectionInfo(%p)\n",this);
58  }
60  {
61  //printf("~SectionInfo(%p)\n",this);
62  }
63 
64  // getters
65  QCString label() const { return m_label; }
66  QCString title() const { return m_title; }
67  SectionType type() const { return m_type; }
68  QCString ref() const { return m_ref; }
69  int lineNr() const { return m_lineNr; }
70  QCString fileName() const { return m_fileName; }
71  bool generated() const { return m_generated; }
72  int level() const { return m_level; }
73  Definition *definition() const { return m_definition; }
74 
75  // setters
76  void setFileName(const QCString &fn) { m_fileName = fn; }
77  void setType(SectionType t) { m_type = t; }
78  void setGenerated(bool b) { m_generated = b; }
80  void setTitle(const QCString &t) { m_title = t; }
81  void setLevel(int l) { m_level = l; }
82  void setReference(const QCString &r) { m_ref = r; }
83  void setLineNr(int l) { m_lineNr = l; }
84 
85  private:
90  int m_lineNr;
92  bool m_generated = false;
93  int m_level;
95 };
96 
97 //! class that represents a list of constant references to sections.
99 {
100  using SectionInfoVec = std::vector<const SectionInfo*>;
101  public:
102  using const_iterator = SectionInfoVec::const_iterator;
103 
104  //! Returns a constant pointer to the section info given a section label or nullptr
105  //! if no section with the given label can be found.
106  const SectionInfo *find(const QCString &label) const
107  {
108  auto it = m_lookup.find(label.str());
109  return it!=m_lookup.end() ? it->second : nullptr;
110  }
111 
112  //! Adds a non-owning section reference.
113  void add(const SectionInfo *si)
114  {
115  m_lookup.insert({toStdString(si->label()),si});
116  m_entries.push_back(si);
117  }
118 
119  const_iterator begin() const { return m_entries.cbegin(); }
120  const_iterator end() const { return m_entries.cend(); }
121  bool empty() const { return m_entries.empty(); }
122  size_t size() const { return m_entries.size(); }
123 
124  private:
126  std::unordered_map< std::string, const SectionInfo* > m_lookup;
127 };
128 
129 //! singleton class that owns the list of all sections
130 class SectionManager : public LinkedMap<SectionInfo>
131 {
132  public:
133  //! Add a new section given the data of an existing section.
134  //! Returns a non-owning pointer to the newly added section.
136  {
137  return LinkedMap<SectionInfo>::add(si.label(),si.fileName(),
138  si.lineNr(),si.title(),si.type(),si.level(),si.ref());
139  }
140 
141  //! Add a new section
142  //! Return a non-owning pointer to the newly added section
143  SectionInfo *add(const QCString &label, const QCString &fileName, int lineNr,
144  const QCString &title, SectionType type, int level,const QCString &ref=QCString())
145  {
146  return LinkedMap<SectionInfo>::add(label.data(),fileName,lineNr,title,type,level,ref);
147  }
148 
149  //! Replace an existing section with a new one
150  //! Return a non-owning pointer to the newly added section
151  SectionInfo *replace(const QCString &label, const QCString &fileName, int lineNr,
152  const QCString &title, SectionType type, int level,const QCString &ref=QCString())
153  {
155  if (si)
156  {
157  si->setFileName(fileName);
158  si->setLineNr(lineNr);
159  si->setTitle(title);
160  si->setType(type);
161  si->setLevel(level);
162  si->setReference(ref);
163  return si;
164  }
165  else
166  {
167  return LinkedMap<SectionInfo>::add(label.data(),fileName,lineNr,title,type,level,ref);
168  }
169  }
170 
171  //! returns a reference to the singleton
173  {
174  static SectionManager sm;
175  return sm;
176  }
177 
178  private:
180  SectionManager(const SectionManager &other) = delete;
181  SectionManager &operator=(const SectionManager &other) = delete;
182 };
183 
184 
185 #endif
SectionType::Paragraph
@ Paragraph
SectionInfo::m_label
QCString m_label
Definition: section.h:86
SectionManager::SectionManager
SectionManager()
Definition: section.h:179
SectionRefs::size
size_t size() const
Definition: section.h:122
SectionInfo::setLineNr
void setLineNr(int l)
Definition: section.h:83
SectionInfo::setReference
void setReference(const QCString &r)
Definition: section.h:82
Definition
The common base class of all entity definitions found in the sources.
Definition: definition.h:76
SectionRefs::add
void add(const SectionInfo *si)
Adds a non-owning section reference.
Definition: section.h:113
SectionInfo::definition
Definition * definition() const
Definition: section.h:73
SectionInfo::SectionInfo
SectionInfo(const QCString &label, const QCString &fileName, int lineNr, const QCString &title, SectionType type, int level, const QCString &ref)
Definition: section.h:52
LinkedMap::add
T * add(const char *k, Args &&... args)
Adds a new object to the ordered vector if it was not added already.
Definition: linkedmap.h:103
QCString::str
std::string str() const
Definition: qcstring.h:442
SectionInfo::m_fileName
QCString m_fileName
Definition: section.h:91
SectionInfo::~SectionInfo
~SectionInfo()
Definition: section.h:59
toStdString
std::string toStdString(const QCString &s)
Definition: qcstring.h:604
SectionRefs::end
const_iterator end() const
Definition: section.h:120
SectionInfo::lineNr
int lineNr() const
Definition: section.h:69
SectionType::Table
@ Table
qcstring.h
SectionInfo::generated
bool generated() const
Definition: section.h:71
SectionRefs::const_iterator
SectionInfoVec::const_iterator const_iterator
Definition: section.h:102
SectionType
SectionType
enum representing the various types of sections and entities that can be referred to.
Definition: section.h:28
linkedmap.h
SectionInfo::setDefinition
void setDefinition(Definition *d)
Definition: section.h:79
SectionInfo::label
QCString label() const
Definition: section.h:65
SectionManager::replace
SectionInfo * replace(const QCString &label, const QCString &fileName, int lineNr, const QCString &title, SectionType type, int level, const QCString &ref=QCString())
Replace an existing section with a new one Return a non-owning pointer to the newly added section
Definition: section.h:151
SectionInfo::ref
QCString ref() const
Definition: section.h:68
SectionInfo::m_lineNr
int m_lineNr
Definition: section.h:90
SectionInfo::m_definition
Definition * m_definition
Definition: section.h:94
SectionRefs::empty
bool empty() const
Definition: section.h:121
SectionInfo::level
int level() const
Definition: section.h:72
SectionType::Subsubsection
@ Subsubsection
SectionRefs::begin
const_iterator begin() const
Definition: section.h:119
SectionRefs::m_entries
SectionInfoVec m_entries
Definition: section.h:125
SectionRefs::m_lookup
std::unordered_map< std::string, const SectionInfo * > m_lookup
Definition: section.h:126
SectionManager
singleton class that owns the list of all sections
Definition: section.h:130
SectionInfo::setGenerated
void setGenerated(bool b)
Definition: section.h:78
SectionInfo::m_title
QCString m_title
Definition: section.h:87
SectionInfo::setType
void setType(SectionType t)
Definition: section.h:77
SectionInfo::fileName
QCString fileName() const
Definition: section.h:70
LinkedMap::find
const T * find(const std::string &key) const
Find an object given the key.
Definition: linkedmap.h:60
SectionRefs::SectionInfoVec
std::vector< const SectionInfo * > SectionInfoVec
Definition: section.h:100
SectionType::Page
@ Page
SectionInfo::m_level
int m_level
Definition: section.h:93
SectionInfo::title
QCString title() const
Definition: section.h:66
SectionType::Subsection
@ Subsection
SectionManager::add
SectionInfo * add(const SectionInfo &si)
Add a new section given the data of an existing section.
Definition: section.h:135
SectionInfo::setFileName
void setFileName(const QCString &fn)
Definition: section.h:76
SectionInfo::m_generated
bool m_generated
Definition: section.h:92
SectionType::Anchor
@ Anchor
SectionInfo::setTitle
void setTitle(const QCString &t)
Definition: section.h:80
SectionRefs::find
const SectionInfo * find(const QCString &label) const
Returns a constant pointer to the section info given a section label or nullptr if no section with th...
Definition: section.h:106
SectionManager::instance
static SectionManager & instance()
returns a reference to the singleton
Definition: section.h:172
SectionInfo::m_type
SectionType m_type
Definition: section.h:88
SectionType::Section
@ Section
SectionRefs
class that represents a list of constant references to sections.
Definition: section.h:98
isSection
constexpr bool isSection(SectionType type)
return true if type is a section, and false if it is a page, anchor or table.
Definition: section.h:40
SectionInfo
class that provide information about a section.
Definition: section.h:49
QCString::data
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string
Definition: qcstring.h:153
LinkedMap
Container class representing a vector of objects with keys.
Definition: linkedmap.h:35
SectionInfo::m_ref
QCString m_ref
Definition: section.h:89
SectionManager::add
SectionInfo * add(const QCString &label, const QCString &fileName, int lineNr, const QCString &title, SectionType type, int level, const QCString &ref=QCString())
Add a new section Return a non-owning pointer to the newly added section
Definition: section.h:143
SectionInfo::setLevel
void setLevel(int l)
Definition: section.h:81
SectionInfo::type
SectionType type() const
Definition: section.h:67
SectionManager::operator=
SectionManager & operator=(const SectionManager &other)=delete
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108