// ---------------------------------------------------------------------------
// - HtmlElement.hpp                                                         -
// - afnix:www library - html element class definition                       -
// ---------------------------------------------------------------------------
// - This program is free software;  you can redistribute it  and/or  modify -
// - it provided that this copyright notice is kept intact.                  -
// -                                                                         -
// - This program  is  distributed in  the hope  that it will be useful, but -
// - without  any  warranty;  without  even   the   implied    warranty   of -
// - merchantability or fitness for a particular purpose.  In no event shall -
// - the copyright holder be liable for any  direct, indirect, incidental or -
// - special damages arising in any way out of the use of this software.     -
// ---------------------------------------------------------------------------
// - copyright (c) 1999-2005 amaury darsch                                   -
// ---------------------------------------------------------------------------

#ifndef  AFNIX_HTMLELEMENT_HPP
#define  AFNIX_HTMLELEMENT_HPP

#ifndef  AFNIX_VECTOR_HPP
#include "Vector.hpp"
#endif

#ifndef  AFNIX_BUFFER_HPP
#include "Buffer.hpp"
#endif

#ifndef  AFNIX_HTMLTAG_HPP
#include "HtmlTag.hpp"
#endif

namespace afnix {

  /// The HtmlElement class is a generic class that manages HTML element.
  /// An element is any valid HTML construct that can accept 0 or more
  /// tags. An element is defined by its name and a vector of tags.
  /// @author amaury darsch

  class HtmlElement : public Object {
  protected:
    /// the element name
    String d_name;
    /// the tag vector
    Vector d_tags;

  public:
    /// create an element by name
    HtmlElement (const String& name);

    /// @return the class name
    String repr (void) const;

    /// reset this html element
    virtual void reset (void);

    /// @return the element name
    virtual String getname (void) const;

    /// add a tag to this element
    /// @param tag the tag to add
    virtual void addtag (HtmlTag* tag);

    /// add a tag to this element by name and value
    /// @param name  the tag name to add
    /// @param value the tag value to add
    virtual void addtag (const String& name, const Literal& value);

    /// @return a opening string of the element
    virtual String opening (void) const;

    /// @return a closing string of the element
    virtual String closing (void) const;

    /// emit the element into a buffer
    virtual void emit (Buffer& buf) const;

    /// generate a new html element object
    /// @param argv the argument vector
    static Object* mknew (Vector* argv);

    /// apply this html element with a set of arguments and a quark
    /// @param robj  robj the current runnable
    /// @param nset  the current nameset    
    /// @param quark the quark to apply these arguments
    /// @param argv  the arguments to apply
    Object* apply (Runnable* robj, Nameset* nset, const long quark,
                   Vector* argv);
    
  private:
    // make the copy constructor private
    HtmlElement (const HtmlElement&);
    // make the assignment operator private
    HtmlElement& operator = (const HtmlElement&);
  };
}

#endif
