/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/


#ifndef DDITEMTREE_H
#define DDITEMTREE_H

#include <dditem.h>
#include <ddstringrow.h>
#include <ddioinfo.h>
#include <typeinfo>

using namespace std;


/// dditemtreebase:
/**

*/


class dditemset;


class dditemtree : public dditem
{

public:
	
	dditemtree();
	dditemtree( const ddstring& name );
	dditemtree( const ddstring& name, const ddstring& value, const ddstring& call="", size_t access=0 );
	virtual ~dditemtree();

	dditem* clone() const;
	
	dd_result flush_content ( ddwebpage& pagelet );
	dd_result flush_children( ddwebpage& pagelet, int from=0, int to=0 );
	dd_result flush_content ( ddwebpage& pagelet, ddstring& target ); 
	dd_result flush_children( ddwebpage& pagelet, ddstring& target, int from=0, int to=0 ); 

	// kind aspekt
  virtual dditem& clear_children();
	virtual ddstring to_string() const;
	virtual ddstring join() const;
	virtual void dump() const;
	
	virtual void add_child( const ddstring& name, const ddstring& value );
	virtual void add_child( dditem* item );

	virtual void sync( ddwebcgi& cgi );

	
	/**
		@return the number of child objects.
	*/
	
	inline size_t size()
	{
		return _data.size();
	}
	
	
	/**
		Access by key.
	*/
	
	inline dditem& operator[]( const ddstring& key )
	{
		return _data.get_entry( key );
	}
	
	
	/**
		Access by index.
	*/
			
	inline dditem& operator[]( size_t index )
	{
		return _data.get_entry( index );	
	}
	
	
	/**
		Access by key, const version.
	*/
	
	inline const dditem& operator[]( const ddstring& key ) const
	{
		return _data.get_entry( key );
	}
	
	
	/**
		Returns true, when "key" exists.
	*/
	
	inline bool contains_key( const ddstring& key ) const
	{
		return _data.contains_key( key );
	}
	
	
	/**
		Returns the internal index of "key" or -1.
	*/
	
	inline int index_of( const ddstring& key ) const
	{
		return _data.index_of( key );
	}
	
	
	/**
		Access by index, const version.
	*/
			
	inline const dditem& operator[]( size_t index ) const
	{
		return _data.get_entry( index );	
	}
	
	
	/**
		Returns the index.
	*/
	
	inline const ddmapindex& get_index() const
	{
		return _data.get_index();
	}	
  
protected:

	dditemptrmap _data;
	

};


#endif
