// This may look like C code, but it is really -*- C++ -*-
//
//  Copyright (c) University of Aizu 1994
//

// Wrappers protect against including this file more than once

#ifndef Index_h
#define Index_h 1


#include <List.h>
#include <Key.h>

class Index;

//  Index element:
class Indexable: public Listable {
public:
  // constructors: Note how we use the initializing syntax.
  // The actual body of the constructor is empty. We will define
  // constructors (and destructors) with an empty body in the
  // header file, so that the initialization is visible.
  Indexable(void) : key_() {}
  Indexable(const Key& key) : key_(key) {}
  Indexable(const Indexable& indexable) : key_(indexable.key_) {}

  // destructor
  virtual ~Indexable(void) {}

  // access
  Key& key(void);

  Indexable *next(const Key& searchKey = 0) const;
  Indexable *prev(const Key& searchKey = 0) const;

  //  I/O. 
  virtual IOstatus readContents(void);
  virtual IOstatus writeContents(void) const;

private:
  friend class Index;
  Key key_;
};


class Index: public List {
public:
  // Once again, note the initialization. This time, we initialize 
  // the class from which we are deriving.
  Index(Indexable* sample = 0) : List(sample) {}
  Index(Index& index) : List(index) {}
  virtual ~Index(void) {}

  //  this is a real class, so make it's name known.
  virtual char *classname(void) const;

  // Note that since there is no data in this class,
  // we can simply re-use List's I/O functions.

  //  search index from the head ot from the last element.
  Indexable *head(const Key& searchKey = 0) const;
  Indexable *last(const Key& searchKey = 0) const;
};

// End of wrapper
#endif
// End of file
