htmlattrib.h 2.04 KB
Newer Older
1 2
/******************************************************************************
 *
3
 * 
4
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5
 * Copyright (C) 1997-2014 by Dimitri van Heesch.
6 7 8 9 10 11 12 13 14 15 16 17
 *
 * 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.
 *
 */

#ifndef _HTMLATTRIB_H
#define _HTMLATTRIB_H

18 19 20
#include <qcstring.h>
#include <qlist.h>

21 22 23
/*! A Html option. A name, value pair */
struct HtmlAttrib
{
24 25
  QCString name;
  QCString value;
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
};

/*! @brief A list of Html attributes. 
 *
 * The Html attributes are deeply copied into the list.
 */
class HtmlAttribList : public QList<HtmlAttrib>
{
  public:
    HtmlAttribList() : QList<HtmlAttrib>() { setAutoDelete(TRUE); }
   ~HtmlAttribList() { clear(); }
    HtmlAttribList(const HtmlAttribList &l) : QList<HtmlAttrib>() 
    { operator=(l); }
    HtmlAttribList &operator=(const HtmlAttribList &l)
    { clear(); QList<HtmlAttrib>::operator=(l); return *this; }
41 42
    QCString find(const QCString name) const
    {
43
      QListIterator<HtmlAttrib> it(*this);
44
      QCString result;
45 46
      HtmlAttrib *attr;
      for (;(attr=it.current());++it)
47 48 49 50 51
      {
        if (attr->name==name) return attr->value;
      }
      return result;
    }
52
    QCString toString() const
53
    {
54
      QListIterator<HtmlAttrib> it(*this);
55
      QCString result;
56 57
      HtmlAttrib *attr;
      for (;(attr=it.current());++it)
58 59 60 61 62
      {
        result+=" "+attr->name+"=\""+attr->value+"\"";
      }
      return result;
    }
63
  private:
64 65 66 67
    HtmlAttrib *newValue( HtmlAttrib *v ) const
    { return new HtmlAttrib(*v); }
    void deleteValue(HtmlAttrib *v) const
    { delete v;  }
68 69 70 71 72 73 74 75 76 77 78
};

/*! @brief Html attribute list iterator */
class HtmlAttribListIterator : public QListIterator<HtmlAttrib>
{
  public:
    HtmlAttribListIterator(const HtmlAttribList &l) : QListIterator<HtmlAttrib>(l) {}
};

#endif