Doxygen
Loading...
Searching...
No Matches
indexlist.h
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2021 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 INDEXLIST_H
17#define INDEXLIST_H
18
19#include <utility>
20#include <vector>
21#include <memory>
22#include <mutex>
23
24#include "qcstring.h"
25#include "construct.h"
26
27class Definition;
28class MemberDef;
29class OutputList;
30
31/** Abstract interface for index generators. */
33{
34 public:
36
37 virtual void initialize() = 0;
38 virtual void finalize() = 0;
39 virtual void incContentsDepth() = 0;
40 virtual void decContentsDepth() = 0;
41 virtual void addContentsItem(bool isDir,
42 const QCString &name,
43 const QCString &ref,
44 const QCString &file,
45 const QCString &anchor,
46 bool separateIndex,
47 bool addToNavIndex,
48 const Definition *def,
49 const QCString &nameAsHtml
50 ) = 0;
51 virtual void addIndexItem(const Definition *context,const MemberDef *md,
52 const QCString &sectionAnchor,const QCString &title) = 0;
53 virtual void addIndexFile(const QCString &name) = 0;
54 virtual void addImageFile(const QCString &) = 0;
55 virtual void addStyleSheetFile(const QCString &) = 0;
56};
57
58/** \brief A list of index interfaces.
59 *
60 * This class itself implements all methods of IndexIntf and
61 * just forwards the calls to all items in the list (composite design pattern).
62 */
64{
65 using IndexPtr = std::unique_ptr<IndexIntf>;
66
67 template<class... Ts,class... As>
68 void foreach(void (IndexIntf::*methodPtr)(Ts...),As&&... args)
69 {
70 for (const auto &intf : m_indices)
71 {
72 (intf.get()->*methodPtr)(std::forward<As>(args)...);
73 }
74 }
75
76 template<class... Ts,class... As>
77 void foreach_locked(void (IndexIntf::*methodPtr)(Ts...),As&&... args)
78 {
79 std::lock_guard<std::mutex> lock(m_mutex);
80 for (const auto &intf : m_indices)
81 {
82 (intf.get()->*methodPtr)(std::forward<As>(args)...);
83 }
84 }
85
86 public:
87 /** disable the indices */
88 void disable()
89 { m_enabled = FALSE; }
90
91 /** enable the indices */
92 void enable()
93 { m_enabled = TRUE; }
94
95 /** returns true iff the indices are enabled */
96 bool isEnabled() const
97 { return m_enabled; }
98
99 /** Add an index generator to the list, using a syntax similar to std::make_unique<T>() */
100 template<class T,class... As>
101 void addIndex(As&&... args)
102 { m_indices.push_back(std::make_unique<T>(std::forward<As>(args)...)); }
103
105 { foreach(&IndexIntf::initialize); }
106
107 void finalize()
108 { foreach(&IndexIntf::finalize); }
109
112
115
116 void addContentsItem(bool isDir, const QCString &name, const QCString &ref,
117 const QCString &file, const QCString &anchor,bool separateIndex=FALSE,bool addToNavIndex=FALSE,
118 const Definition *def=nullptr, const QCString &nameAsHtml = QCString())
119 { if (m_enabled) foreach_locked(&IndexIntf::addContentsItem,isDir,name,ref,file,anchor,separateIndex,addToNavIndex,def,nameAsHtml); }
120
121 void addIndexItem(const Definition *context,const MemberDef *md,const QCString &sectionAnchor=QCString(),const QCString &title=QCString())
122 { if (m_enabled) foreach_locked(&IndexIntf::addIndexItem,context,md,sectionAnchor,title); }
123
126
129
132
133 private:
134 bool m_enabled = true;
135 std::mutex m_mutex;
136 std::vector<IndexPtr> m_indices;
137};
138
139#endif // INDEXLIST_H
The common base class of all entity definitions found in the sources.
Definition definition.h:76
Abstract interface for index generators.
Definition indexlist.h:33
virtual void initialize()=0
virtual void addImageFile(const QCString &)=0
virtual void decContentsDepth()=0
virtual void addIndexItem(const Definition *context, const MemberDef *md, const QCString &sectionAnchor, const QCString &title)=0
virtual void finalize()=0
virtual void incContentsDepth()=0
virtual void addIndexFile(const QCString &name)=0
virtual void addStyleSheetFile(const QCString &)=0
virtual void addContentsItem(bool isDir, const QCString &name, const QCString &ref, const QCString &file, const QCString &anchor, bool separateIndex, bool addToNavIndex, const Definition *def, const QCString &nameAsHtml)=0
A list of index interfaces.
Definition indexlist.h:64
void initialize()
Definition indexlist.h:104
void addStyleSheetFile(const QCString &name)
Definition indexlist.h:130
bool m_enabled
Definition indexlist.h:134
std::unique_ptr< IndexIntf > IndexPtr
Definition indexlist.h:65
std::vector< IndexPtr > m_indices
Definition indexlist.h:136
void decContentsDepth()
Definition indexlist.h:113
void addIndex(As &&... args)
Add an index generator to the list, using a syntax similar to std::make_unique<T>()
Definition indexlist.h:101
void addContentsItem(bool isDir, const QCString &name, const QCString &ref, const QCString &file, const QCString &anchor, bool separateIndex=FALSE, bool addToNavIndex=FALSE, const Definition *def=nullptr, const QCString &nameAsHtml=QCString())
Definition indexlist.h:116
void addIndexFile(const QCString &name)
Definition indexlist.h:124
std::mutex m_mutex
Definition indexlist.h:135
void enable()
enable the indices
Definition indexlist.h:92
void addImageFile(const QCString &name)
Definition indexlist.h:127
bool isEnabled() const
returns true iff the indices are enabled
Definition indexlist.h:96
void foreach_locked(void(IndexIntf::*methodPtr)(Ts...), As &&... args)
Definition indexlist.h:77
void incContentsDepth()
Definition indexlist.h:110
void disable()
disable the indices
Definition indexlist.h:88
void finalize()
Definition indexlist.h:107
void addIndexItem(const Definition *context, const MemberDef *md, const QCString &sectionAnchor=QCString(), const QCString &title=QCString())
Definition indexlist.h:121
A model of a class/file/namespace member symbol.
Definition memberdef.h:48
Class representing a list of output generators that are written to in parallel.
Definition outputlist.h:314
This is an alternative implementation of QCString.
Definition qcstring.h:101
#define ABSTRACT_BASE_CLASS(cls)
Macro to implement rule of 5 for an abstract base class.
Definition construct.h:20
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34