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

// Wrappers protect against including this file more than once

#ifndef Deed_h
#define Deed_h 1

#include <Index.h>
#include <Game.h>
#include <SpacePtr.h>

class Deed;
class DeedPtrList;

class DeedPtr : public Pointer {
public:
  // Note how we use the initializer syntax
  DeedPtr(char* key = 0) : Pointer(theGame->deeds, key) {}

  // Assignment and Comparison. Note the C++ bureaucracy required to "upgrade"
  // Pointer to DeedPtr.... I exceptionally put the code here so that you can see it.
  int operator==(const DeedPtr& deedp) const 
  {return Pointer::operator==((Pointer&)deedp); }
  DeedPtr& operator=(const DeedPtr& deedp)
  {return (DeedPtr&)Pointer::operator=((Pointer&)deedp); }

  // wrapper for "(Deed*)lookup()"
  Deed* operator->() const;

  // wrappers for "(DeedPtr*)next()" and "(DeedPtr*)prev()"
  DeedPtr* next();
  DeedPtr* prev();

  virtual char* classname() const;
  virtual Listable* duplicate() const;
};

class DeedPtrList : public List {
public:
  // Note how we use the initializer syntax
  DeedPtrList() : List(new DeedPtr) {}

  // wrapper for "(DeedPtr*)list.head()"
  DeedPtr* operator*() const;

  // We don't need a classname, as "List" suits us fine...
};

class Deed : public Indexable {
public:
  // IO
  virtual Listable* duplicate(void) const;
  virtual char* classname(void) const;
  virtual IOstatus readContents(void);
  virtual IOstatus writeContents(void) const;

  // Query
  virtual int rent() const {}

  GroupSize monopoly() const;
  Bool mortgaged() const;
  int price() const;

  // Set -- note that when functions return a *reference*, you can
  // use the result on the left side of an assignment. A non-const
  // reference is a so-called "lvalue".
  Key& owner();
  SpacePtr& location();

  void mortgage();
  void payback();

private:
  DeedPtrList group_;
  Key  owner_;
  SpacePtr  location_;
  int  price_;
  int  mortgage_;
  Bool mortgaged_;
};

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