sectionhandler.cpp 5.41 KB
Newer Older
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1 2 3 4 5
/******************************************************************************
 *
 * $Id$
 *
 *
6
 * Copyright (C) 1997-2013 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.
 *
 */

Dimitri van Heesch's avatar
Dimitri van Heesch committed
16
#include "mainhandler.h"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
17 18
#include "compoundhandler.h"
#include "sectionhandler.h"
19
#include "memberhandler.h"
20
#include "dochandler.h"
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#include "debug.h"

class SectionTypeMap
{
  public:
    SectionTypeMap() : m_map(37)
    {
      m_map.setAutoDelete(TRUE);
      m_map.insert("user-defined",new int(ISection::UserDefined));
      m_map.insert("public-type",new int(ISection::PubTypes));
      m_map.insert("public-func",new int(ISection::PubFuncs));
      m_map.insert("public-attrib",new int(ISection::PubAttribs));
      m_map.insert("public-slot",new int(ISection::PubSlots));
      m_map.insert("signal",new int(ISection::Signals));
      m_map.insert("dcop-func",new int(ISection::DCOPFuncs));
      m_map.insert("property",new int(ISection::Properties));
37
      m_map.insert("event",new int(ISection::Events));
38 39 40 41 42 43 44 45
      m_map.insert("public-static-func",new int(ISection::PubStatFuncs));
      m_map.insert("public-static-attrib",new int(ISection::PubStatAttribs));
      m_map.insert("protected-type",new int(ISection::ProTypes));
      m_map.insert("protected-func",new int(ISection::ProFuncs));
      m_map.insert("protected-attrib",new int(ISection::ProAttribs));
      m_map.insert("protected-slot",new int(ISection::ProSlots));
      m_map.insert("protected-static-func",new int(ISection::ProStatFuncs));
      m_map.insert("protected-static-attrib",new int(ISection::ProStatAttribs));
46 47 48 49 50
      m_map.insert("package-type",new int(ISection::PacTypes));
      m_map.insert("package-func",new int(ISection::PacFuncs));
      m_map.insert("package-attrib",new int(ISection::PacAttribs));
      m_map.insert("package-static-func",new int(ISection::PacStatFuncs));
      m_map.insert("package-static-attrib",new int(ISection::PacStatAttribs));
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
      m_map.insert("private-type",new int(ISection::PriTypes));
      m_map.insert("private-func",new int(ISection::PriFuncs));
      m_map.insert("private-attrib",new int(ISection::PriAttribs));
      m_map.insert("private-slot",new int(ISection::PriSlots));
      m_map.insert("private-static-func",new int(ISection::PriStatFuncs));
      m_map.insert("private-static-attrib",new int(ISection::PriStatAttribs));
      m_map.insert("friend",new int(ISection::Friend));
      m_map.insert("related",new int(ISection::Related));
      m_map.insert("define",new int(ISection::Defines));
      m_map.insert("prototype",new int(ISection::Prototypes));
      m_map.insert("typedef",new int(ISection::Typedefs));
      m_map.insert("enum",new int(ISection::Enums));
      m_map.insert("func",new int(ISection::Functions));
      m_map.insert("var",new int(ISection::Variables));
    }
    ISection::SectionKind map(const QString &s)
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
68
      int *val = m_map.find(s.utf8());
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
      if (val==0) 
      {
        debug(1,"Warning: `%s' is an invalid section type\n",s.data());
        return ISection::Invalid;
      }
      else return (ISection::SectionKind)*val;
    }
  private: 
    QDict<int> m_map;
};

static SectionTypeMap *s_typeMap;

void sectionhandler_init()
{
  s_typeMap = new SectionTypeMap;
}

void sectionhandler_exit()
{
  delete s_typeMap;
}
Dimitri van Heesch's avatar
Dimitri van Heesch committed
91 92 93

SectionHandler::SectionHandler(IBaseHandler *parent) : m_parent(parent)
{
94
  //printf("SectionHandler::SectionHandler()\n");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
95 96 97
  m_members.setAutoDelete(TRUE);
  addEndHandler("sectiondef",this,&SectionHandler::endSection);
  addStartHandler("memberdef",this,&SectionHandler::startMember);
98 99
  addStartHandler("header",this,&SectionHandler::startHeader);
  addEndHandler("header",this,&SectionHandler::endHeader);
100
  addStartHandler("description",this,&SectionHandler::startDescription);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
101 102 103 104
}

SectionHandler::~SectionHandler()
{
105
  debug(2,"SectionHandler::~SectionHandler()\n");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
106 107 108 109 110
}

void SectionHandler::startSection(const QXmlAttributes& attrib)
{
  m_parent->setDelegate(this);
111 112 113
  m_kindString = attrib.value("kind");
  m_kind = s_typeMap->map(m_kindString);
  debug(2,"section kind=`%s'\n",m_kindString.data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
114 115
}

116 117 118 119 120 121 122
void SectionHandler::startDescription(const QXmlAttributes& attrib)
{
  DocHandler *docHandler = new DocHandler(this);
  docHandler->startDoc(attrib);
  m_description = docHandler;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
123 124 125 126 127 128 129 130 131 132 133 134
void SectionHandler::endSection()
{
  m_parent->setDelegate(0);
}

void SectionHandler::startMember(const QXmlAttributes& attrib)
{
  MemberHandler *memHandler = new MemberHandler(this);
  memHandler->startMember(attrib);
  m_members.append(memHandler);
}

135 136 137 138 139 140 141 142 143 144 145 146
void SectionHandler::startHeader(const QXmlAttributes&)
{
  m_header="";
  m_curString="";
}

void SectionHandler::endHeader()
{
  m_header = m_curString.stripWhiteSpace();
  debug(2,"member header=`%s'\n",m_header.data());
}

147
void SectionHandler::initialize(CompoundHandler *ch)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
148
{
149
  QListIterator<MemberHandler> mli(m_members);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
150
  MemberHandler *mh;
151
  for (;(mh=mli.current());++mli)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
152
  {
153 154 155
    mh->setCompoundHandler(ch);
    ch->insertMember(mh);
    mh->setSectionHandler(this);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
156 157 158
  }
}

159 160 161 162 163
IDocRoot *SectionHandler::description() const 
{ 
  return m_description; 
}

164 165 166 167
IMemberIterator *SectionHandler::members() const 
{ 
  return new MemberIterator(m_members); 
}
Dimitri van Heesch's avatar
Dimitri van Heesch committed
168