linkedtexthandler.cpp 3.71 KB
Newer Older
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1 2 3 4 5
/******************************************************************************
 *
 * $Id$
 *
 *
6
 * Copyright (C) 1997-2006 by Dimitri van Heesch.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
7 8 9 10 11 12 13 14 15
 *
 * 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.
 *
 */
#include "linkedtexthandler.h"
16
#include "debug.h"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
17
#include <doxmlintf.h>
18
#include "stringimpl.h"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
19

Dimitri van Heesch's avatar
Dimitri van Heesch committed
20
class LT_Text : public LinkedTextImpl, public ILT_Text
Dimitri van Heesch's avatar
Dimitri van Heesch committed
21 22 23 24 25 26
{
  public:
    LT_Text(const QString &text) : m_text(text) {}
    virtual ~LT_Text() {}

    // ILT_Text
27 28
    virtual const IString *text() const { return &m_text; }
    virtual Kind kind() const     { return LinkedTextImpl::Kind_Text; }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
29
  private:
30
    StringImpl m_text;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
31 32
};

Dimitri van Heesch's avatar
Dimitri van Heesch committed
33
class LT_Ref : public LinkedTextImpl, public ILT_Ref
Dimitri van Heesch's avatar
Dimitri van Heesch committed
34 35 36 37 38 39 40
{
  public:
    LT_Ref() {}
    virtual ~LT_Ref() {}
    void setRefId(const QString &refId) { m_refId=refId; }
    void setText(const QString &text) { m_text=text; }
    void setExtId(const QString &extId) { m_extId=extId; }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
41
    void setTargetKind(TargetKind k) { m_targetKind=k; }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
42 43

    // ILT_Ref
44 45
    virtual const IString *text() const { return &m_text; }
    virtual const IString * id() const { return &m_refId; }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
46
    virtual TargetKind targetKind() const { return m_targetKind; }
47
    virtual const IString *external() const { return &m_extId; }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
48
    virtual Kind kind() const { return LinkedTextImpl::Kind_Ref; }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
49 50
    
  private:
51 52 53
    StringImpl    m_refId;
    StringImpl    m_extId;
    StringImpl    m_text;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
54
    TargetKind m_targetKind;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
55 56 57
};

LinkedTextHandler::LinkedTextHandler(IBaseHandler *parent,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
58
                                     QList<LinkedTextImpl> &children
Dimitri van Heesch's avatar
Dimitri van Heesch committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
                                    ) 
 : m_parent(parent), m_children(children)
{
  addStartHandler("ref",this,&LinkedTextHandler::startRef);
  addEndHandler("ref",this,&LinkedTextHandler::endRef);
  m_children.setAutoDelete(TRUE);
  m_ref=0;
}

LinkedTextHandler::~LinkedTextHandler()
{
}

void LinkedTextHandler::start(const char *endTag)
{
  addEndHandler(endTag,this,&LinkedTextHandler::end);
  m_parent->setDelegate(this);
  m_curString="";
}

void LinkedTextHandler::end()
{
  if (!m_curString.isEmpty())
  {
    m_children.append(new LT_Text(m_curString));
84
    debug(2,"LinkedTextHandler: add text `%s'\n",m_curString.data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
85 86 87 88 89 90 91 92 93 94
    m_curString="";
  }
  m_parent->setDelegate(0);
}

void LinkedTextHandler::startRef(const QXmlAttributes& attrib)
{
  if (!m_curString.isEmpty())
  {
    m_children.append(new LT_Text(m_curString));
95
    debug(2,"LinkedTextHandler: add text `%s'\n",m_curString.data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
96 97 98 99
    m_curString="";
  }
  ASSERT(m_ref==0);
  m_ref = new LT_Ref;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
100
  m_ref->setRefId(attrib.value("refid"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
101
  m_ref->setExtId(attrib.value("external"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
102
  ASSERT(attrib.value("kindref")=="compound" || attrib.value("kindref")=="member");
103
  m_ref->setTargetKind(attrib.value("kindref")=="compound" ? ILT_Ref::Compound : ILT_Ref::Member);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
104 105 106 107 108 109
}

void LinkedTextHandler::endRef()
{
  m_ref->setText(m_curString);
  m_children.append(m_ref);
110
  debug(2,"LinkedTextHandler: add ref `%s'\n",m_ref->text()->latin1());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
111 112 113
  m_ref=0;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
114
QString LinkedTextHandler::toString(const QList<LinkedTextImpl> &list) 
115
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
116
  QListIterator<LinkedTextImpl> li(list);
117
  QString result;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
118
  LinkedTextImpl *lt;
119 120 121 122 123
  for (li.toFirst();(lt=li.current());++li)
  {
    switch(lt->kind())
    {
      case ILinkedText::Kind_Text:
124
        result+=dynamic_cast<ILT_Text*>(lt)->text()->latin1();
125 126
        break;
      case ILinkedText::Kind_Ref:
127
        result+=dynamic_cast<ILT_Ref *>(lt)->text()->latin1();
128 129 130 131 132
        break;
    }
  }
  return result;
}
Dimitri van Heesch's avatar
Dimitri van Heesch committed
133