Skip to content

Commit fa520f9

Browse files
committed
Restructure citation handling
1 parent 80bcbbb commit fa520f9

File tree

8 files changed

+214
-186
lines changed

8 files changed

+214
-186
lines changed

src/cite.cpp

Lines changed: 164 additions & 113 deletions
Large diffs are not rendered by default.

src/cite.h

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/******************************************************************************
22
*
3-
*
4-
*
5-
* Copyright (C) 2011 by Dimitri van Heesch
3+
* Copyright (C) 2020 by Dimitri van Heesch
64
* Based on a patch by David Munger
75
*
86
* Permission to use, copy, modify, and distribute this software and its
@@ -16,83 +14,64 @@
1614
*
1715
*/
1816

19-
#ifndef CITEDB_H
20-
#define CITEDB_H
17+
#ifndef CITE_H
18+
#define CITE_H
2119

22-
#include <qdict.h>
20+
#include <memory>
2321

24-
class FTextStream;
22+
#include <qcstring.h>
2523

26-
/// String constants for citations
27-
struct CiteConsts
28-
{
29-
static const QCString fileName;
30-
static const QCString anchorPrefix;
31-
};
24+
class FTextStream;
3225

3326
/// Citation-related data.
3427
struct CiteInfo
3528
{
36-
CiteInfo(const char *label_, const char *text_=0, const char *fullText_=0,
37-
const char *ref_=0) :
38-
label(label_), text(text_), fullText(fullText_), ref(ref_)
39-
{ }
40-
41-
CiteInfo(const CiteInfo &o)
42-
{ label=o.label.copy(); text=o.text.copy(); fullText=o.fullText.copy(); ref=o.ref.copy(); }
43-
44-
QCString label;
45-
QCString text;
46-
QCString fullText;
47-
QCString ref;
48-
29+
virtual ~CiteInfo() {}
30+
virtual QCString label() const = 0;
31+
virtual QCString text() const = 0;
4932
};
5033

5134
/**
52-
* @brief Cite database access class.
53-
* @details This class provides access do the database of bibliographic
35+
* @brief Citation manager class.
36+
* @details This class provides access do the database of bibliographic
5437
* references through the bibtex backend.
5538
*/
56-
class CiteDict
39+
class CitationManager
5740
{
5841
public:
59-
/** Create the database, with an expected maximum of \a size entries */
60-
CiteDict(int size);
61-
62-
// /** Resolve references to citations */
63-
// void resolve();
42+
static CitationManager &instance();
6443

6544
/** Insert a citation identified by \a label into the database */
6645
void insert(const char *label);
6746

68-
/** Return the citation info for a given \a label */
69-
CiteInfo *find(const char *label) const;
47+
/** Return the citation info for a given \a label.
48+
* Ownership of the info stays with the manager.
49+
*/
50+
const CiteInfo *find(const char *label) const;
7051

7152
/** Generate the citations page */
72-
void generatePage() const;
53+
void generatePage();
7354

7455
/** clears the database */
7556
void clear();
7657

77-
/** return TRUE if there are no citations.
78-
* Only valid after calling resolve()
58+
/** return TRUE if there are no citations.
7959
*/
8060
bool isEmpty() const;
8161

82-
/** writes the latex code for the standard bibliography
83-
* section to text stream \a t
62+
/** writes the latex code for the standard bibliography
63+
* section to text stream \a t
8464
*/
85-
void writeLatexBibliography(FTextStream &t);
65+
void writeLatexBibliography(FTextStream &t) const;
66+
67+
const char *fileName() const;
68+
const char *anchorPrefix() const;
8669

8770
private:
88-
// bool writeAux();
89-
// bool writeBst();
90-
// bool execute();
91-
// void parse();
92-
// void clean();
93-
QDict<CiteInfo> m_entries;
94-
// QList<QCString> m_ordering;
95-
QCString m_baseFileName;
71+
/** Create the database, with an expected maximum of \a size entries */
72+
CitationManager();
73+
struct Private;
74+
std::unique_ptr<Private> p;
9675
};
9776

98-
#endif
77+
#endif // CITE_H

src/commentscan.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2923,7 +2923,7 @@ static void addCite(yyscan_t yyscanner)
29232923
name=yytext+1;
29242924
name=name.left(yyleng-2);
29252925
}
2926-
Doxygen::citeDict->insert(name.data());
2926+
CitationManager::instance().insert(name.data());
29272927
}
29282928

29292929
//-----------------------------------------------------------------------------

src/docparser.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,12 +1919,14 @@ DocAnchor::DocAnchor(DocNode *parent,const QCString &id,bool newAnchor)
19191919
return;
19201920
}
19211921

1922-
if (id.left(CiteConsts::anchorPrefix.length()) == CiteConsts::anchorPrefix)
1922+
const CitationManager &ct = CitationManager::instance();
1923+
QCString anchorPrefix = ct.anchorPrefix();
1924+
if (id.left(anchorPrefix.length()) == anchorPrefix)
19231925
{
1924-
CiteInfo *cite = Doxygen::citeDict->find(id.mid(CiteConsts::anchorPrefix.length()));
1925-
if (cite)
1926+
const CiteInfo *cite = ct.find(id.mid(anchorPrefix.length()));
1927+
if (cite)
19261928
{
1927-
m_file = convertNameToFile(CiteConsts::fileName,FALSE,TRUE);
1929+
m_file = convertNameToFile(ct.fileName(),FALSE,TRUE);
19281930
m_anchor = id;
19291931
}
19301932
else
@@ -2585,14 +2587,15 @@ DocCite::DocCite(DocNode *parent,const QCString &target,const QCString &) //cont
25852587
//printf("DocCite::DocCite(target=%s)\n",target.data());
25862588
ASSERT(!target.isEmpty());
25872589
m_relPath = g_relPath;
2588-
CiteInfo *cite = Doxygen::citeDict->find(target);
2590+
const CitationManager &ct = CitationManager::instance();
2591+
const CiteInfo *cite = ct.find(target);
25892592
//printf("cite=%p text='%s' numBibFiles=%d\n",cite,cite?cite->text.data():"<null>",numBibFiles);
2590-
if (numBibFiles>0 && cite && !cite->text.isEmpty()) // ref to citation
2593+
if (numBibFiles>0 && cite && !cite->text().isEmpty()) // ref to citation
25912594
{
2592-
m_text = cite->text;
2593-
m_ref = cite->ref;
2594-
m_anchor = CiteConsts::anchorPrefix+cite->label;
2595-
m_file = convertNameToFile(CiteConsts::fileName,FALSE,TRUE);
2595+
m_text = cite->text();
2596+
m_ref = "";
2597+
m_anchor = ct.anchorPrefix()+cite->label();
2598+
m_file = convertNameToFile(ct.fileName(),FALSE,TRUE);
25962599
//printf("CITE ==> m_text=%s,m_ref=%s,m_file=%s,m_anchor=%s\n",
25972600
// m_text.data(),m_ref.data(),m_file.data(),m_anchor.data());
25982601
return;

src/doxygen.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ GroupSDict *Doxygen::groupSDict = 0;
129129
PageSDict *Doxygen::pageSDict = 0;
130130
PageSDict *Doxygen::exampleSDict = 0;
131131
SectionDict *Doxygen::sectionDict = 0; // all page sections
132-
CiteDict *Doxygen::citeDict=0; // database of bibliographic references
133132
StringDict Doxygen::aliasDict(257); // aliases
134133
QDict<void> Doxygen::inputPaths(1009);
135134
FileNameDict *Doxygen::includeNameDict = 0; // include names
@@ -202,7 +201,7 @@ void clearAll()
202201
Doxygen::mscFileNameDict->clear();
203202
Doxygen::diaFileNameDict->clear();
204203
Doxygen::tagDestinationDict.clear();
205-
delete Doxygen::citeDict;
204+
CitationManager::instance().clear();
206205
delete Doxygen::mainPage; Doxygen::mainPage=0;
207206
FormulaManager::instance().clear();
208207
}
@@ -9862,7 +9861,6 @@ void initDoxygen()
98629861
Doxygen::memGrpInfoDict.setAutoDelete(TRUE);
98639862
Doxygen::tagDestinationDict.setAutoDelete(TRUE);
98649863
Doxygen::dirRelations.setAutoDelete(TRUE);
9865-
Doxygen::citeDict = new CiteDict(257);
98669864
Doxygen::genericsDict = new GenericsSDict;
98679865
Doxygen::indexList = new IndexList;
98689866
Doxygen::sectionDict = new SectionDict(257);
@@ -11252,11 +11250,8 @@ void parseInput()
1125211250
g_s.end();
1125311251
}
1125411252

11255-
//g_s.begin("Resolving citations...\n");
11256-
//Doxygen::citeDict->resolve();
11257-
1125811253
g_s.begin("Generating citations page...\n");
11259-
Doxygen::citeDict->generatePage();
11254+
CitationManager::instance().generatePage();
1126011255
g_s.end();
1126111256

1126211257
g_s.begin("Counting members...\n");

src/doxygen.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ class Doxygen
139139
static QCString objDBFileName;
140140
static QCString entryDBFileName;
141141
static QCString filterDBFileName;
142-
static CiteDict *citeDict;
143142
static bool userComments;
144143
static IndexList *indexList;
145144
static int subpageNestingLevel;

src/latexdocvisitor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,8 @@ void LatexDocVisitor::visit(DocCite *cite)
657657
{
658658
//startLink(cite->ref(),cite->file(),cite->anchor());
659659
QCString anchor = cite->anchor();
660-
anchor = anchor.mid(CiteConsts::anchorPrefix.length()); // strip prefix
660+
QCString anchorPrefix = CitationManager::instance().anchorPrefix();
661+
anchor = anchor.mid(anchorPrefix.length()); // strip prefix
661662
m_t << "\\cite{" << anchor << "}";
662663
}
663664
else

src/latexgen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ LatexGenerator::~LatexGenerator()
283283

284284
static void writeLatexMakefile()
285285
{
286-
bool generateBib = !Doxygen::citeDict->isEmpty();
286+
bool generateBib = !CitationManager::instance().isEmpty();
287287
QCString dir=Config_getString(LATEX_OUTPUT);
288288
QCString fileName=dir+"/Makefile";
289289
QFile file(fileName);
@@ -829,7 +829,7 @@ static void writeDefaultFooter(FTextStream &t)
829829
"\n";
830830

831831
// Bibliography
832-
Doxygen::citeDict->writeLatexBibliography(t);
832+
CitationManager::instance().writeLatexBibliography(t);
833833

834834
// Index
835835
t << "% Index\n";

0 commit comments

Comments
 (0)