// Change History
// 11/20/03 AV Development: BC6 conversion. Cons/none const

#ifndef _DRS_IDXLIST_H
#define _DRS_IDXLIST_H

////////////////////////////////////////////////////////
// DRS_IndexList
// DRS_IndexListEnumerated
// DRS_IndexListMapped
////////////////////////////////////////////////////////

// #include "drs/drs_fieldmap.h"

#include "base/at_defs.h"
#include "xdart/x_at_index.h"
#include "drs/drs_setting.h"
#include "drs/drs_idx.h"

enum DRS_IndexListType { INDEXLISTTYPE_ENUMERATED, INDEXLISTTYPE_MAPPED, INDEXLISTTYPE_COUNT};

class DRS_IndexList
{
  protected:
  explicit DRS_IndexList( DRS_Database const &rDB, AT_String sFile, AT_String sSection, DRS_Setting Key);

  public:
  virtual ~DRS_IndexList () {};
  
  //virtual AT_Record_List Search( byte *sSearch, uint iIndex) const = 0;

  virtual uint                 IndexCount() const = 0;
  virtual DRS_Index *          IndexOpen( uint iIndex) const = 0;
  virtual DRS_IndexDef const & IndexInfo( uint iIndex) const = 0;

  protected:
  DRS_Database const & rDatabase;
  int                  iIndexFileID; // -1 for no file enum
  int                  iIndexIDBase; // neg for -1 based link to other search field

  friend DRS_IndexList; //Linked index lists may access prior index lists.
                       //IndexIDBase is neg. -1 based link to other IndexList.
                       //BEWARE of creating endless loop in definitions of IndexLists!
  int                  IndexIDBase() const;
};

class DRS_IndexListEnumerated : public DRS_IndexList
{
  public:
  explicit DRS_IndexListEnumerated( DRS_Database const &rDB, AT_String sFile, AT_String sSection, DRS_Setting BaseKey);
  virtual ~DRS_IndexListEnumerated () {};

  //AT_Record_List Search( byte *sSearch, uint iIndex = MAX_UINT) const; //iIndex = MAXUINT for Intelli-Search

  inline uint                 IndexCount() const { return iIndexCount;};
  DRS_Index *                 IndexOpen( uint iIndex) const;

  inline DRS_IndexDef const & IndexInfo( uint iIndex) const
                                 { AT_Assert( (iIndex < iIndexCount), *this, "IndexInfo");
                                   return *aaIndexDefs[iIndex].get();
                                 };
  private:
  uint iIndexCount;
  auto_array< auto_ptr< DRS_IndexDef> > aaIndexDefs;
};

/*
class DRS_IndexListMapped : public DRS_IndexList
{
  public:
  DRS_IndexListMapped( DRS_Database const &rDB, AT_String sFile, AT_String sSection, DRS_Setting Key);
  virtual ~DRS_IndexListMapped() {};

  //AT_Record_List Search( byte *sSearch, uint iIndex) const;

  inline uint                 IndexCount() const { return pFieldMap->Size();};
  DRS_Index *                 IndexOpen( uint iIndex) const;
  inline DRS_IndexDef const & IndexInfo( uint iIndex) const
                                 { AT_Assert( (iIndex < pFieldMap->Size()), *this, "IndexInfo");
                                   return *apIndexDef.get();
                                 };
  inline uint                 FieldMapID() const { return iFieldMapID;};

  private:
  auto_ptr< DRS_IndexDef> apIndexDef; //One index def for all indexes
  uint                    iFieldMapID;
  DRS_FieldMap const      *pFieldMap;
};
*/

#endif