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