#ifndef _DT_CONFIG_LIST
#define _DT_CONFIG_LIST

#include <StringAttribute.h>
#include <IntegerAttribute.h>
#include <FloatAttribute.h>
#include "ssdbg.hh"
#include "Item.h"
#include "ItemList.h"
#include "DecisionTool/DecisionTool.hh"

#define CFG_LIST_ID "dtinstance"

#define DEFAULT_MAXWAIT -1
#define DEFAULT_MINWAIT 0

/****************************************************************************
 *
 * In order to use the AttributeParser to read config files, we have
 * to deal with ItemLists etc.  I'd rather have my information in a
 * vector for various reasons, so this class is used only in the
 * SmartSampler constructor to load the config file.
 *
 ****************************************************************************/

class cfgItem : public Item{
public:
  ~cfgItem(){
    ssdbg(DBG_CLEAN)("destroying cfgItem %s", _name);
    free((void *)_dtconfig);
  };
  cfgItem(const char *name):Item(name){
    _attributes.add(new IntegerAttribute("model", "decision tool identifier", 
					 &_model) );
    _attributes.add(new StringAttribute("dtconfig", "decision tool configuration", 
					&_dtconfig, "none" ) );
    _attributes.add(new FloatAttribute("maxwait", "max time between consecutive gulps", 
				       &_maxwait, DEFAULT_MAXWAIT ) );
    _attributes.add(new FloatAttribute("minwait", "min time between consecutive gulps", 
				       &_minwait, DEFAULT_MINWAIT ) );
  };
  
  long model(){return(_model);};
  char *dtconfig(){return(_dtconfig);};
  double maxwait(){return(_maxwait);};
  double minwait(){return(_minwait);};
  // These identify an index in our DT info list with
  // a configuration item.
  void setid(short id){_dtiid=id;};
  int getid(){return(_dtiid);};

private:
  long _model;
  char *_dtconfig;
  double _maxwait,_minwait;
  short _dtiid;
};


class cfgItemList : public ItemList {
public:
  cfgItemList():ItemList( CFG_LIST_ID ){};
  ~cfgItemList(){
    cfgItem *current;
    ssdbg(DBG_CLEAN)("destroying cfgItemList");
    for( int i = 0; i < _itemList.size(); i++ ) {
      _itemList.get( i, (Item * *)&current);
      delete(current);
    }
    ItemList::~ItemList();
  };

  void dump(){
    cfgItem *current;
    Syslog::write("cfgItemList::dump -- List size = %d",_itemList.size());
    for( int i = 0; i < _itemList.size(); i++ ) {
      _itemList.get( i, (Item * *)&current);
      Syslog::write("%d:\t%s\tid=%d\tminwait=%f s\tmaxwait=%f s\tconfig=%s",
		    i, current->name(),
		    (int)current->model(),
		    current->minwait(),
		    current->maxwait(),
		    current->dtconfig());
    }
  }

private:
  Item *addItem( const char *name ){
     cfgItem *newTrans = new cfgItem( name );
     _itemList.add( (Item * * )&newTrans );
     return newTrans;
  }
};

#endif // _DT_CONFIG_LIST
