Fix for UBSan build
[platform/upstream/doxygen.git] / src / reflist.cpp
1 /******************************************************************************
2  *
3  * $Id: reflist.cpp,v 1.2 2001/03/19 19:27:41 root Exp $
4  *
5  *
6  * Copyright (C) 1997-2012 by Dimitri van Heesch.
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation under the terms of the GNU General Public License is hereby 
10  * granted. No representations are made about the suitability of this software 
11  * for any purpose. It is provided "as is" without express or implied warranty.
12  * See the GNU General Public License for more details.
13  *
14  * Documents produced by Doxygen are derivative works derived from the
15  * input used in their production; they are not affected by this license.
16  *
17  */
18
19 #include <stdio.h>
20 #include "reflist.h"
21 #include "util.h"
22 #include "ftextstream.h"
23
24 /*! Create a list of items that are cross referenced with documentation blocks
25  *  @param listName String representing the name of the list.
26  *  @param pageTitle String representing the title of the list page.
27  *  @param secTitle String representing the title of the section.
28  */
29 RefList::RefList(const char *listName,
30                  const char *pageTitle,
31                  const char *secTitle
32                 )
33 {
34   m_itemList = 0;
35   m_dict = 0;
36   m_dictIterator = 0;
37   m_id = 0;
38   m_listName = listName;
39   m_pageTitle = pageTitle;
40   m_secTitle = secTitle;
41 }
42
43 /*! Destroy the todo list. Currently not called! */
44 RefList::~RefList()
45 {
46   delete m_dictIterator;
47   delete m_dict;
48   delete m_itemList;
49 }
50
51 /*! Adds a new item to the list.
52  *  \returns A unique id for this item.
53  */
54 int RefList::addRefItem()
55 {
56   if (m_dict==0)
57   {
58     m_dict = new QIntDict<RefItem>(1009);
59     m_dict->setAutoDelete(TRUE);
60     m_dictIterator = new QIntDictIterator<RefItem>(*m_dict);
61   }
62   RefItem *item = new RefItem;
63   m_id++;
64   m_dict->insert(m_id,item);
65   return m_id;
66 }
67
68 /*! Returns an item given it's id that is obtained with addRefItem()
69  *  \param itemId item's identifier.
70  *  \returns A pointer to the todo item's structure.
71  */
72 RefItem *RefList::getRefItem(int itemId)
73 {
74   return m_dict ? m_dict->find(itemId) : 0;
75 }
76
77 /*! Returns the first item in the dictionary or 0 if
78  *  non is available.
79  *  Items are not sorted.
80  */
81 RefItem *RefList::getFirstRefItem()
82 {
83   return m_dictIterator ? m_dictIterator->toFirst() : 0;
84 }
85
86 /*! Returns the next item in the dictionary or 0 if
87  *  we are at the end of the list.
88  *  Items are not sorted.
89  */
90 RefItem *RefList::getNextRefItem()
91 {
92   return m_dictIterator ? m_dictIterator->operator++() : 0;
93 }
94
95 /*! Returns the name of the list as set in the constructor. */
96 QCString RefList::listName() const
97 {
98   return m_listName;
99 }
100
101 QCString RefList::pageTitle() const
102 {
103   return m_pageTitle;
104 }
105
106 QCString RefList::sectionTitle() const
107 {
108   return m_secTitle;
109 }
110
111 void RefList::insertIntoList(const char *key,RefItem *item)
112 {
113   if (m_itemList==0)
114   {
115     m_itemList = new SortedRefItems(1009);
116   }
117   RefItem *ri = m_itemList->find(key);
118   if (ri==0)
119   {
120     m_itemList->append(key,item);
121   }
122   else // item already added to the list (i.e. multiple item for the same
123        // entity)
124   {
125     if (ri!=item)
126     {
127       ri->extraItems.append(item);
128     }
129   }
130 }
131
132
133 void RefList::generatePage()
134 {
135   if (m_itemList==0) return;
136   m_itemList->sort();
137   SDict<RefItem>::Iterator it(*m_itemList);
138   RefItem *item;
139   QCString doc;
140   doc += "<dl class=\"reflist\">";
141   for (it.toFirst();(item=it.current());++it)
142   {
143     doc += " <dt>";
144     doc +=  "\\anchor ";
145     doc += item->listAnchor;
146     doc += "\n";
147     doc += item->prefix;
148     doc += " \\_internalref ";
149     doc += item->name;
150     doc += " \"";
151     doc += item->title;
152     doc += "\" ";
153     // write declaration in case a function with arguments
154     if (!item->args.isEmpty()) 
155     {
156       doc += item->args;
157     }
158     doc += "</dt><dd> ";
159     doc += item->text;
160     QListIterator<RefItem> li(item->extraItems);
161     RefItem *extraItem;
162     for (li.toFirst();(extraItem=li.current());++li)
163     {
164       doc += "<p>" + extraItem->text;
165     }
166     doc += "</dd>";
167   }
168   doc += "</dl>\n";
169   addRelatedPage(m_listName,m_pageTitle,doc,0,m_listName,1,0,0,0);
170 }
171