definition.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  *
4  *
5  * Copyright (C) 1997-2015 by Dimitri van Heesch.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation under the terms of the GNU General Public License is hereby
9  * granted. No representations are made about the suitability of this software
10  * for any purpose. It is provided "as is" without express or implied warranty.
11  * See the GNU General Public License for more details.
12  *
13  * Documents produced by Doxygen are derivative works derived from the
14  * input used in their production; they are not affected by this license.
15  *
16  */
17 
18 #ifndef DEFINITION_H
19 #define DEFINITION_H
20 
21 #include <qlist.h>
22 #include <qdict.h>
23 
24 #include "types.h"
25 
26 class FileDef;
27 class OutputList;
28 class SectionDict;
29 class MemberSDict;
30 class MemberDef;
31 class GroupDef;
32 class GroupList;
33 struct ListItemInfo;
34 struct SectionInfo;
35 class Definition;
36 class DefinitionImpl;
37 class FTextStream;
38 
39 /** Data associated with a detailed description. */
40 struct DocInfo
41 {
43  int line;
45 };
46 
47 /** Data associated with a brief description. */
48 struct BriefInfo
49 {
52  int line;
54 };
55 
56 /** Data associated with description found in the body. */
57 struct BodyInfo
58 {
59  int startLine; //!< line number of the start of the definition
60  int endLine; //!< line number of the end of the definition
61  FileDef *fileDef; //!< file definition containing the function body
62 };
63 
64 /** Abstract interface for a Definition or DefinitionList */
66 {
67  public:
69  virtual ~DefinitionIntf() {}
70  /*! Types of derived classes */
71  enum DefType
72  {
73  TypeClass = 0,
74  TypeFile = 1,
75  TypeNamespace = 2,
76  TypeMember = 3,
77  TypeGroup = 4,
78  TypePackage = 5,
79  TypePage = 6,
80  TypeDir = 7,
81  TypeSymbolList = 8
82  };
83  /*! Use this for dynamic inspection of the type of the derived class */
84  virtual DefType definitionType() const = 0;
85 };
86 
87 /** The common base class of all entity definitions found in the sources.
88  *
89  * This can be a class or a member function, or a file, or a namespace, etc.
90  * Use definitionType() to find which type of definition this is.
91  */
92 class Definition : public DefinitionIntf
93 {
94  public:
95  struct Cookie
96  {
97  virtual ~Cookie() {}
98  };
99 
100  /*! Create a new definition */
101  Definition(
102  const char *defFileName,int defLine,int defColumn,
103  const char *name,const char *b=0,const char *d=0,
104  bool isSymbol=TRUE);
105 
106  /*! Destroys the definition */
107  virtual ~Definition();
108 
109  //-----------------------------------------------------------------------------------
110  // ---- getters -----
111  //-----------------------------------------------------------------------------------
112 
113  /*! Returns the name of the definition */
114  const QCString& name() const { return m_name; }
115 
116  /*! Returns the name of the definition as it appears in the output */
117  virtual QCString displayName(bool includeScope=TRUE) const = 0;
118 
119  /*! Returns the local name without any scope qualifiers. */
120  QCString localName() const;
121 
122  /*! Returns the fully qualified name of this definition
123  */
124  virtual QCString qualifiedName() const;
125 
126  /*! Returns the name of this definition as it appears in the symbol map.
127  */
128  QCString symbolName() const;
129 
130  /*! Returns the base file name (without extension) of this definition.
131  * as it is referenced to/written to disk.
132  */
133  virtual QCString getOutputFileBase() const = 0;
134 
135  /*! Returns the anchor within a page where this item can be found */
136  virtual QCString anchor() const = 0;
137 
138  /*! Returns the name of the source listing of this definition. */
139  virtual QCString getSourceFileBase() const;
140 
141  /*! Returns the anchor of the source listing of this definition. */
142  virtual QCString getSourceAnchor() const;
143 
144  /*! Returns the detailed description of this definition */
145  virtual QCString documentation() const;
146 
147  /*! Returns the line number at which the detailed documentation was found. */
148  int docLine() const;
149 
150  /*! Returns the file in which the detailed documentation block was found.
151  * This can differ from getDefFileName().
152  */
153  QCString docFile() const;
154 
155  /*! Returns the brief description of this definition. This can include commands. */
156  virtual QCString briefDescription(bool abbreviate=FALSE) const;
157 
158  /*! Returns a plain text version of the brief description suitable for use
159  * as a tool tip.
160  */
161  QCString briefDescriptionAsTooltip() const;
162 
163  /*! Returns the line number at which the brief description was found. */
164  int briefLine() const;
165 
166  /*! Returns the documentation found inside the body of a member */
167  QCString inbodyDocumentation() const;
168 
169  /*! Returns the file in which the in body documentation was found */
170  QCString inbodyFile() const;
171 
172  /*! Returns the line at which the first in body documentation
173  part was found */
174  int inbodyLine() const;
175 
176  /*! Returns the file in which the brief description was found.
177  * This can differ from getDefFileName().
178  */
179  QCString briefFile() const;
180 
181  /*! returns the file in which this definition was found */
182  QCString getDefFileName() const;
183 
184  /*! returns the extension of the file in which this definition was found */
185  QCString getDefFileExtension() const;
186 
187  /*! returns the line number at which the definition was found */
188  int getDefLine() const { return m_defLine; }
189 
190  /*! returns the column number at which the definition was found */
191  int getDefColumn() const { return m_defColumn; }
192 
193  /*! Returns TRUE iff the definition is documented
194  * (which could be generated documentation)
195  * @see hasUserDocumentation()
196  */
197  virtual bool hasDocumentation() const;
198 
199  /*! Returns TRUE iff the definition is documented by the user. */
200  virtual bool hasUserDocumentation() const;
201 
202  /*! Returns TRUE iff it is possible to link to this item within this
203  * project.
204  */
205  virtual bool isLinkableInProject() const = 0;
206 
207  /*! Returns TRUE iff it is possible to link to this item. This can
208  * be a link to another project imported via a tag file.
209  */
210  virtual bool isLinkable() const = 0;
211 
212  /*! Returns TRUE iff the name is part of this project and
213  * may appear in the output
214  */
215  virtual bool isVisibleInProject() const;
216 
217  /*! Returns TRUE iff the name may appear in the output */
218  virtual bool isVisible() const;
219 
220  /*! Returns TRUE iff this item is supposed to be hidden from the output. */
221  bool isHidden() const;
222 
223  /*! returns TRUE if this entity was artificially introduced, for
224  * instance because it is used to show a template instantiation relation.
225  */
226  bool isArtificial() const;
227 
228  /*! If this definition was imported via a tag file, this function
229  * returns the tagfile for the external project. This can be
230  * translated into an external link target via
231  * Doxygen::tagDestinationDict
232  */
233  virtual QCString getReference() const;
234 
235  /*! Returns TRUE if this definition is imported via a tag file. */
236  virtual bool isReference() const;
237 
238  /*! Convenience method to return a resolved external link */
239  QCString externalReference(const QCString &relPath) const;
240 
241  /*! Returns the first line of the body of this item (applicable to classes and
242  * functions).
243  */
244  int getStartBodyLine() const;
245 
246  /*! Returns the last line of the body of this item (applicable to classes and
247  * functions).
248  */
249  int getEndBodyLine() const;
250 
251  /*! Returns the file in which the body of this item is located or 0 if no
252  * body is available.
253  */
254  FileDef *getBodyDef() const;
255 
256  /** Returns the programming language this definition was written in. */
257  SrcLangExt getLanguage() const;
258 
259  GroupList *partOfGroups() const;
260 
261  QList<ListItemInfo> *xrefListItems() const;
262 
263  virtual Definition *findInnerCompound(const char *name);
264  virtual Definition *getOuterScope() const;
265 
266  MemberSDict *getReferencesMembers() const;
267  MemberSDict *getReferencedByMembers() const;
268 
269  bool hasSections() const;
270  bool hasSources() const;
271 
272  /** returns TRUE if this class has a brief description */
273  bool hasBriefDescription() const;
274 
275  QCString id() const;
276 
277  //-----------------------------------------------------------------------------------
278  // ---- setters -----
279  //-----------------------------------------------------------------------------------
280 
281  /*! Sets a new \a name for the definition */
282  virtual void setName(const char *name);
283 
284  /*! Sets a unique id for the symbol. Used for libclang integration. */
285  void setId(const char *name);
286 
287  /*! Sets the documentation of this definition to \a d. */
288  virtual void setDocumentation(const char *d,const char *docFile,int docLine,bool stripWhiteSpace=TRUE);
289 
290  /*! Sets the brief description of this definition to \a b.
291  * A dot is added to the sentence if not available.
292  */
293  virtual void setBriefDescription(const char *b,const char *briefFile,int briefLine);
294 
295  /*! Set the documentation that was found inside the body of an item.
296  * If there was already some documentation set, the new documentation
297  * will be appended.
298  */
299  virtual void setInbodyDocumentation(const char *d,const char *docFile,int docLine);
300 
301  /*! Sets the tag file id via which this definition was imported. */
302  void setReference(const char *r);
303 
304  /*! Add the list of anchors that mark the sections that are found in the
305  * documentation.
306  */
307  void addSectionsToDefinition(QList<SectionInfo> *anchorList);
308 
309  // source references
310  void setBodySegment(int bls,int ble);
311  void setBodyDef(FileDef *fd);
312  void addSourceReferencedBy(MemberDef *d);
314 
315  void setRefItems(const QList<ListItemInfo> *sli);
316  void mergeRefItems(Definition *d);
317  virtual void addInnerCompound(Definition *d);
318  virtual void setOuterScope(Definition *d);
319 
320  virtual void setHidden(bool b);
321 
322  void setArtificial(bool b);
323  void setLanguage(SrcLangExt lang);
324 
325  //-----------------------------------------------------------------------------------
326  // --- actions ----
327  //-----------------------------------------------------------------------------------
328 
329  QCString convertNameToFile(const char *name,bool allowDots=FALSE) const;
330  void writeSourceDef(OutputList &ol,const char *scopeName);
331  void writeInlineCode(OutputList &ol,const char *scopeName);
332  void writeSourceRefs(OutputList &ol,const char *scopeName);
333  void writeSourceReffedBy(OutputList &ol,const char *scopeName);
334  void makePartOfGroup(GroupDef *gd);
335  //void writePathFragment(OutputList &ol) const;
336  void writeNavigationPath(OutputList &ol) const;
337  QCString navigationPathAsString() const;
338  virtual void writeQuickMemberLinks(OutputList &,MemberDef *) const {}
339  virtual void writeSummaryLinks(OutputList &) {}
340  QCString pathFragment() const;
341 
342  /*! Writes the documentation anchors of the definition to
343  * the Doxygen::tagFile stream.
344  */
345  void writeDocAnchorsToTagFile(FTextStream &);
346  void setLocalName(const QCString name);
347 
348  void addSectionsToIndex();
349  void writeToc(OutputList &ol);
350 
351  void setCookie(Cookie *cookie) { delete m_cookie; m_cookie = cookie; }
352  Cookie *cookie() const { return m_cookie; }
353 
354  protected:
355 
356  Definition(const Definition &d);
357 
358  private:
359  static void addToMap(const char *name,Definition *d);
360  static void removeFromMap(Definition *d);
361 
362  void _setSymbolName(const QCString &name);
363 
364  int _getXRefListId(const char *listName) const;
365  void _writeSourceRefList(OutputList &ol,const char *scopeName,
366  const QCString &text,MemberSDict *members,bool);
367  void _setBriefDescription(const char *b,const char *briefFile,int briefLine);
368  void _setDocumentation(const char *d,const char *docFile,int docLine,bool stripWhiteSpace,bool atTop);
369  void _setInbodyDocumentation(const char *d,const char *docFile,int docLine);
370  bool _docsAlreadyAdded(const QCString &doc,QCString &sigList);
371  DefinitionImpl *m_impl; // internal structure holding all private data
378 };
379 
380 /** A list of Definition objects. */
381 class DefinitionList : public QList<Definition>, public DefinitionIntf
382 {
383  public:
385  DefType definitionType() const { return TypeSymbolList; }
386  int compareValues(const Definition *item1,const Definition *item2) const
387  {
388  return qstricmp(item1->name(),item2->name());
389  }
390 
391 };
392 
393 /** An iterator for Definition objects in a DefinitionList. */
394 class DefinitionListIterator : public QListIterator<Definition>
395 {
396  public:
400 };
401 
402 /** Reads a fragment from file \a fileName starting with line \a startLine
403  * and ending with line \a endLine. The result is returned as a string
404  * via \a result. The function returns TRUE if successful and FALSE
405  * in case of an error.
406  */
407 bool readCodeFragment(const char *fileName,
408  int &startLine,int &endLine,
409  QCString &result);
410 #endif
static QCString name
Definition: declinfo.cpp:673
Cookie * cookie() const
Definition: definition.h:352
static void addSourceReferences()
Definition: doxygen.cpp:7986
This file contains a number of basic enums and types.
QCString m_symbolName
Definition: definition.h:374
Cookie * m_cookie
Definition: definition.h:377
static QCString result
bool readCodeFragment(const char *fileName, int &startLine, int &endLine, QCString &result)
Definition: definition.cpp:728
QCString file
Definition: definition.h:44
int compareValues(const Definition *item1, const Definition *item2) const
Definition: definition.h:386
QCString tooltip
Definition: definition.h:51
const bool FALSE
Definition: qglobal.h:370
Simplified and optimized version of QTextStream.
Definition: ftextstream.h:11
SrcLangExt
Definition: types.h:41
static QStrList * l
Definition: config.cpp:1044
virtual ~DefinitionIntf()
Definition: definition.h:69
int getDefColumn() const
Definition: definition.h:191
int line
Definition: definition.h:43
DefType definitionType() const
Definition: definition.h:385
int line
Definition: definition.h:52
bool m_isSymbol
Definition: definition.h:373
const QCString & name() const
Definition: definition.h:114
int getDefLine() const
Definition: definition.h:188
int qstricmp(const char *str1, const char *str2)
Definition: qcstring.cpp:567
void setCookie(Cookie *cookie)
Definition: definition.h:351
fileName
Definition: dumpTree.py:9
int endLine
line number of the end of the definition
Definition: definition.h:60
QCString m_name
Definition: definition.h:372
virtual ~Cookie()
Definition: definition.h:97
QCString file
Definition: definition.h:53
QCString doc
Definition: definition.h:42
virtual void writeQuickMemberLinks(OutputList &, MemberDef *) const
Definition: definition.h:338
QCString convertNameToFile(const char *name, bool allowDots, bool allowUnderscore)
Definition: util.cpp:5354
static bool * b
Definition: config.cpp:1043
QCString abbreviate(const char *s, const char *name)
virtual void writeSummaryLinks(OutputList &)
Definition: definition.h:339
int m_defLine
Definition: definition.h:375
DefinitionImpl * m_impl
Definition: definition.h:371
QCString doc
Definition: definition.h:50
const bool TRUE
Definition: qglobal.h:371
FileDef * fileDef
file definition containing the function body
Definition: definition.h:61
int m_defColumn
Definition: definition.h:376
DefinitionListIterator(const DefinitionList &l)
Definition: definition.h:397
int startLine
line number of the start of the definition
Definition: definition.h:59