Doxygen
Loading...
Searching...
No Matches
section.h
Go to the documentation of this file.
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#include "construct.h"
25
26class Definition;
27
29{
30 public:
31 static constexpr int Page = 0;
32 static constexpr int MinLevel = 1;
33 static constexpr int Section = 1;
34 static constexpr int Subsection = 2;
35 static constexpr int Subsubsection = 3;
36 static constexpr int Paragraph = 4;
37 static constexpr int Subparagraph = 5;
38 static constexpr int Subsubparagraph = 6;
39 static constexpr int MaxLevel = 6;
40 static constexpr int Anchor = 7;
41 static constexpr int Table = 8;
42 static constexpr int Requirement = 9;
43
44 constexpr SectionType() : m_level(0) {}
45 constexpr SectionType(int lvl) : m_level(lvl) {}
46 constexpr int level() const { return m_level; }
47 constexpr bool isSection() const
48 {
50 }
51
52 private:
54};
55
56//! class that provide information about a section.
58{
59 public:
61 const QCString &title, SectionType type, int level,const QCString &ref) :
64 {
65 //printf("SectionInfo(%p) fileName=%s\n",(void*)this,qPrint(fileName));
66 }
67
68 // getters
69 QCString label() const { return m_label; }
70 QCString title() const { return m_title; }
71 SectionType type() const { return m_type; }
72 QCString ref() const { return m_ref; }
73 int lineNr() const { return m_lineNr; }
74 QCString fileName() const { return m_fileName; }
75 bool generated() const { return m_generated; }
76 int level() const { return m_level; }
77 Definition *definition() const { return m_definition; }
78
79 // setters
80 void setFileName(const QCString &fn) { m_fileName = fn; }
81 void setType(SectionType t) { m_type = t; }
82 void setGenerated(bool b) { m_generated = b; }
84 void setTitle(const QCString &t) { m_title = t; }
85 void setLevel(int l) { m_level = l; }
86 void setReference(const QCString &r) { m_ref = r; }
87 void setLineNr(int l) { m_lineNr = l; }
88
89 private:
96 bool m_generated = false;
99};
100
101//! class that represents a list of constant references to sections.
103{
104 using SectionInfoVec = std::vector<const SectionInfo*>;
105 public:
106 using const_iterator = SectionInfoVec::const_iterator;
107
108 //! Returns a constant pointer to the section info given a section label or nullptr
109 //! if no section with the given label can be found.
110 const SectionInfo *find(const QCString &label) const
111 {
112 auto it = m_lookup.find(label.str());
113 return it!=m_lookup.end() ? it->second : nullptr;
114 }
115
116 //! Adds a non-owning section reference.
117 void add(const SectionInfo *si)
118 {
119 m_lookup.emplace(toStdString(si->label()),si);
120 m_entries.push_back(si);
121 }
122
123 const_iterator begin() const { return m_entries.cbegin(); }
124 const_iterator end() const { return m_entries.cend(); }
125 bool empty() const { return m_entries.empty(); }
126 size_t size() const { return m_entries.size(); }
127
128 private:
130 std::unordered_map< std::string, const SectionInfo* > m_lookup;
131};
132
133//! singleton class that owns the list of all sections
134class SectionManager : public LinkedMap<SectionInfo>
135{
136 public:
137 //! Add a new section given the data of an existing section.
138 //! Returns a non-owning pointer to the newly added section.
140 {
141 //printf("SectionManager::add(%s,%s,%d,%s)\n",qPrint(si.label()),qPrint(si.fileName()),si.lineNr(),qPrint(si.title()));
143 si.lineNr(),si.title(),si.type(),si.level(),si.ref());
144 }
145
146 //! Add a new section
147 //! Return a non-owning pointer to the newly added section
148 SectionInfo *add(const QCString &label, const QCString &fileName, int lineNr,
149 const QCString &title, SectionType type, int level,const QCString &ref=QCString())
150 {
151 //printf("SectionManager::add(%s,%s,%d,%s)\n",qPrint(label),qPrint(fileName),lineNr,qPrint(title));
152 return LinkedMap<SectionInfo>::add(label.data(),fileName,lineNr,title,type,level,ref);
153 }
154
155 //! Replace an existing section with a new one
156 //! Return a non-owning pointer to the newly added section
157 SectionInfo *replace(const QCString &label, const QCString &fileName, int lineNr,
158 const QCString &title, SectionType type, int level,const QCString &ref=QCString())
159 {
160 //printf("SectionManager::replace(%s,%s,%d,%s)\n",qPrint(label),qPrint(fileName),lineNr,qPrint(title));
162 if (si)
163 {
164 si->setFileName(fileName);
165 si->setLineNr(lineNr);
166 si->setTitle(title);
167 si->setType(type);
168 si->setLevel(level);
169 si->setReference(ref);
170 return si;
171 }
172 else
173 {
174 return LinkedMap<SectionInfo>::add(label.data(),fileName,lineNr,title,type,level,ref);
175 }
176 }
177
178 //! returns a reference to the singleton
180 {
181 static SectionManager sm;
182 return sm;
183 }
184
185 private:
186 SectionManager() = default;
187 ~SectionManager() = default;
189};
190
191
192#endif
The common base class of all entity definitions found in the sources.
Definition definition.h:77
Container class representing a vector of objects with keys.
Definition linkedmap.h:36
T * add(const char *k, Args &&... args)
Definition linkedmap.h:90
const T * find(const std::string &key) const
Definition linkedmap.h:47
This is an alternative implementation of QCString.
Definition qcstring.h:101
const std::string & str() const
Definition qcstring.h:552
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:172
class that provide information about a section.
Definition section.h:58
int m_lineNr
Definition section.h:94
void setType(SectionType t)
Definition section.h:81
int m_level
Definition section.h:97
QCString m_ref
Definition section.h:93
QCString label() const
Definition section.h:69
QCString m_fileName
Definition section.h:95
SectionInfo(const QCString &label, const QCString &fileName, int lineNr, const QCString &title, SectionType type, int level, const QCString &ref)
Definition section.h:60
void setLineNr(int l)
Definition section.h:87
QCString m_label
Definition section.h:90
Definition * definition() const
Definition section.h:77
QCString ref() const
Definition section.h:72
void setReference(const QCString &r)
Definition section.h:86
void setDefinition(Definition *d)
Definition section.h:83
SectionType m_type
Definition section.h:92
void setFileName(const QCString &fn)
Definition section.h:80
QCString fileName() const
Definition section.h:74
int lineNr() const
Definition section.h:73
QCString m_title
Definition section.h:91
bool m_generated
Definition section.h:96
void setGenerated(bool b)
Definition section.h:82
bool generated() const
Definition section.h:75
void setLevel(int l)
Definition section.h:85
Definition * m_definition
Definition section.h:98
QCString title() const
Definition section.h:70
SectionType type() const
Definition section.h:71
void setTitle(const QCString &t)
Definition section.h:84
int level() const
Definition section.h:76
SectionInfo * add(const QCString &label, const QCString &fileName, int lineNr, const QCString &title, SectionType type, int level, const QCString &ref=QCString())
Definition section.h:148
SectionInfo * replace(const QCString &label, const QCString &fileName, int lineNr, const QCString &title, SectionType type, int level, const QCString &ref=QCString())
Definition section.h:157
SectionManager()=default
~SectionManager()=default
SectionInfo * add(const SectionInfo &si)
Definition section.h:139
static SectionManager & instance()
returns a reference to the singleton
Definition section.h:179
class that represents a list of constant references to sections.
Definition section.h:103
SectionInfoVec::const_iterator const_iterator
Definition section.h:106
bool empty() const
Definition section.h:125
const_iterator end() const
Definition section.h:124
const_iterator begin() const
Definition section.h:123
const SectionInfo * find(const QCString &label) const
Definition section.h:110
SectionInfoVec m_entries
Definition section.h:129
void add(const SectionInfo *si)
Adds a non-owning section reference.
Definition section.h:117
std::vector< const SectionInfo * > SectionInfoVec
Definition section.h:104
size_t size() const
Definition section.h:126
std::unordered_map< std::string, const SectionInfo * > m_lookup
Definition section.h:130
static constexpr int Anchor
Definition section.h:40
constexpr bool isSection() const
Definition section.h:47
static constexpr int Section
Definition section.h:33
static constexpr int MaxLevel
Definition section.h:39
int m_level
Definition section.h:53
constexpr SectionType()
Definition section.h:44
static constexpr int Subsection
Definition section.h:34
static constexpr int Subsubsection
Definition section.h:35
static constexpr int Table
Definition section.h:41
constexpr int level() const
Definition section.h:46
static constexpr int Requirement
Definition section.h:42
static constexpr int Page
Definition section.h:31
static constexpr int MinLevel
Definition section.h:32
constexpr SectionType(int lvl)
Definition section.h:45
static constexpr int Paragraph
Definition section.h:36
static constexpr int Subsubparagraph
Definition section.h:38
static constexpr int Subparagraph
Definition section.h:37
#define NON_COPYABLE(cls)
Macro to help implementing the rule of 5 for a non-copyable & movable class.
Definition construct.h:37
std::string toStdString(const QCString &s)
Definition qcstring.h:702