reflist.cpp 3.98 KB
Newer Older
1 2
/******************************************************************************
 *
3
 * 
4 5
 *
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6
 * Copyright (C) 1997-2013 by Dimitri van Heesch.
7 8 9 10 11 12 13 14 15 16 17 18
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
 *
 */

Dimitri van Heesch's avatar
Dimitri van Heesch committed
19
#include <stdio.h>
20
#include "reflist.h"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
21
#include "util.h"
22
#include "ftextstream.h"
23

24 25 26 27 28
/*! Create a list of items that are cross referenced with documentation blocks
 *  @param listName String representing the name of the list.
 *  @param pageTitle String representing the title of the list page.
 *  @param secTitle String representing the title of the section.
 */
29 30 31 32
RefList::RefList(const char *listName,
                 const char *pageTitle,
                 const char *secTitle
                )
Dimitri van Heesch's avatar
Dimitri van Heesch committed
33 34
{
  m_itemList = 0;
35 36 37
  m_dict = 0;
  m_dictIterator = 0;
  m_id = 0;
38 39 40
  m_listName = listName;
  m_pageTitle = pageTitle;
  m_secTitle = secTitle;
41 42 43
}

/*! Destroy the todo list. Currently not called! */
Dimitri van Heesch's avatar
Dimitri van Heesch committed
44 45 46 47
RefList::~RefList()
{
  delete m_dictIterator;
  delete m_dict;
48
  delete m_itemList;
49 50 51 52 53 54 55 56 57
}

/*! Adds a new item to the list.
 *  \returns A unique id for this item.
 */
int RefList::addRefItem()
{
  if (m_dict==0)
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
58
    m_dict = new QIntDict<RefItem>(1009);
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    m_dict->setAutoDelete(TRUE);
    m_dictIterator = new QIntDictIterator<RefItem>(*m_dict);
  }
  RefItem *item = new RefItem;
  m_id++;
  m_dict->insert(m_id,item);
  return m_id;
}

/*! Returns an item given it's id that is obtained with addRefItem()
 *  \param itemId item's identifier.
 *  \returns A pointer to the todo item's structure.
 */
RefItem *RefList::getRefItem(int itemId)
{
74
  return m_dict ? m_dict->find(itemId) : 0;
75 76
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
77
/*! Returns the first item in the dictionary or 0 if
78 79 80 81 82
 *  non is available.
 *  Items are not sorted.
 */
RefItem *RefList::getFirstRefItem()
{
83
  return m_dictIterator ? m_dictIterator->toFirst() : 0;
84 85 86 87 88 89 90 91
}

/*! Returns the next item in the dictionary or 0 if
 *  we are at the end of the list.
 *  Items are not sorted.
 */
RefItem *RefList::getNextRefItem()
{
92
  return m_dictIterator ? m_dictIterator->operator++() : 0;
93 94
}

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
/*! Returns the name of the list as set in the constructor. */
QCString RefList::listName() const
{
  return m_listName;
}

QCString RefList::pageTitle() const
{
  return m_pageTitle;
}

QCString RefList::sectionTitle() const
{
  return m_secTitle;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
void RefList::insertIntoList(const char *key,RefItem *item)
{
  if (m_itemList==0)
  {
    m_itemList = new SortedRefItems(1009);
  }
  RefItem *ri = m_itemList->find(key);
  if (ri==0)
  {
    m_itemList->append(key,item);
  }
  else // item already added to the list (i.e. multiple item for the same
       // entity)
  {
    if (ri!=item)
    {
      ri->extraItems.append(item);
    }
  }
}

132

Dimitri van Heesch's avatar
Dimitri van Heesch committed
133 134 135 136 137 138
void RefList::generatePage()
{
  if (m_itemList==0) return;
  m_itemList->sort();
  SDict<RefItem>::Iterator it(*m_itemList);
  RefItem *item;
139 140
  QCString doc;
  doc += "<dl class=\"reflist\">";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
141 142
  for (it.toFirst();(item=it.current());++it)
  {
143 144
    doc += " <dt>";
    doc +=  "\\anchor ";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
145
    doc += item->listAnchor;
146
    doc += "\n";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
147 148 149 150 151
    doc += item->prefix;
    doc += " \\_internalref ";
    doc += item->name;
    doc += " \"";
    doc += item->title;
152 153 154 155 156 157 158
    doc += "\" ";
    // write declaration in case a function with arguments
    if (!item->args.isEmpty()) 
    {
      doc += item->args;
    }
    doc += "</dt><dd> ";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
159 160 161 162 163 164 165
    doc += item->text;
    QListIterator<RefItem> li(item->extraItems);
    RefItem *extraItem;
    for (li.toFirst();(extraItem=li.current());++li)
    {
      doc += "<p>" + extraItem->text;
    }
166
    doc += "</dd>";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
167
  }
168 169
  doc += "</dl>\n";
  addRelatedPage(m_listName,m_pageTitle,doc,0,m_listName,1,0,0,0);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
170 171
}