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 ) = 0;
50 virtual void addIndexItem(const Definition *context,const MemberDef *md,
51 const QCString &sectionAnchor,const QCString &title) = 0;
52 virtual void addIndexFile(const QCString &name) = 0;
53 virtual void addImageFile(const QCString &) = 0;
54 virtual void addStyleSheetFile(const QCString &) = 0;
55};
56
57/** \brief A list of index interfaces.
58 *
59 * This class itself implements all methods of IndexIntf and
60 * just forwards the calls to all items in the list (composite design pattern).
61 */
63{
64 using IndexPtr = std::unique_ptr<IndexIntf>;
65
66 template<class... Ts,class... As>
67 void foreach(void (IndexIntf::*methodPtr)(Ts...),As&&... args)
68 {
69 for (const auto &intf : m_indices)
70 {
71 (intf.get()->*methodPtr)(std::forward<As>(args)...);
72 }
73 }
74
75 template<class... Ts,class... As>
76 void foreach_locked(void (IndexIntf::*methodPtr)(Ts...),As&&... args)
77 {
78 std::lock_guard<std::mutex> lock(m_mutex);
79 for (const auto &intf : m_indices)
80 {
81 (intf.get()->*methodPtr)(std::forward<As>(args)...);
82 }
83 }
84
85 public:
86 /** disable the indices */
87 void disable()
88 { m_enabled = FALSE; }
89
90 /** enable the indices */
91 void enable()
92 { m_enabled = TRUE; }
93
94 /** returns true iff the indices are enabled */
95 bool isEnabled() const
96 { return m_enabled; }
97
98 /** Add an index generator to the list, using a syntax similar to std::make_unique<T>() */
99 template<class T,class... As>
100 void addIndex(As&&... args)
101 { m_indices.push_back(std::make_unique<T>(std::forward<As>(args)...)); }
102
104 { foreach(&IndexIntf::initialize); }
105
106 void finalize()
107 { foreach(&IndexIntf::finalize); }
108
111
114
115 void addContentsItem(bool isDir, const QCString &name, const QCString &ref,
116 const QCString &file, const QCString &anchor,bool separateIndex=FALSE,bool addToNavIndex=FALSE,
117 const Definition *def=nullptr)
118 { if (m_enabled) foreach_locked(&IndexIntf::addContentsItem,isDir,name,ref,file,anchor,separateIndex,addToNavIndex,def); }
119
120 void addIndexItem(const Definition *context,const MemberDef *md,const QCString &sectionAnchor=QCString(),const QCString &title=QCString())
121 { if (m_enabled) foreach_locked(&IndexIntf::addIndexItem,context,md,sectionAnchor,title); }
122
125
128
131
132 private:
133 bool m_enabled = true;
134 std::mutex m_mutex;
135 std::vector<IndexPtr> m_indices;
136};
137
138#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 addContentsItem(bool isDir, const QCString &name, const QCString &ref, const QCString &file, const QCString &anchor, bool separateIndex, bool addToNavIndex, const Definition *def)=0
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
A list of index interfaces.
Definition indexlist.h:63
void initialize()
Definition indexlist.h:103
void addStyleSheetFile(const QCString &name)
Definition indexlist.h:129
bool m_enabled
Definition indexlist.h:133
std::unique_ptr< IndexIntf > IndexPtr
Definition indexlist.h:64
std::vector< IndexPtr > m_indices
Definition indexlist.h:135
void decContentsDepth()
Definition indexlist.h:112
void addIndex(As &&... args)
Add an index generator to the list, using a syntax similar to std::make_unique<T>()
Definition indexlist.h:100
void addIndexFile(const QCString &name)
Definition indexlist.h:123
std::mutex m_mutex
Definition indexlist.h:134
void enable()
enable the indices
Definition indexlist.h:91
void addImageFile(const QCString &name)
Definition indexlist.h:126
bool isEnabled() const
returns true iff the indices are enabled
Definition indexlist.h:95
void foreach_locked(void(IndexIntf::*methodPtr)(Ts...), As &&... args)
Definition indexlist.h:76
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)
Definition indexlist.h:115
void incContentsDepth()
Definition indexlist.h:109
void disable()
disable the indices
Definition indexlist.h:87
void finalize()
Definition indexlist.h:106
void addIndexItem(const Definition *context, const MemberDef *md, const QCString &sectionAnchor=QCString(), const QCString &title=QCString())
Definition indexlist.h:120
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