/* This file is part of cardwords
   (c) 1998 1999 2000 Tobias Peters
   see file COPYING for the copyright terms.
   
   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.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// cardwords_myslist.hh

/* This file defines a very simple singly linked list, as I have problems with
   the one provided by the stl. This is either a replacement for the stl-slist
   or a debugging tool for my CardWords_HashTable code.
*/

#ifndef CARDWORDS_MYSLIST_HH
#define CARDWORDS_MYSLIST_HH
namespace CardWords {

template <class data_type>
struct MySlistNode
{
public:
  MySlistNode<data_type> * next_node;

  data_type data;

  template<class data_type_initialisator>
  MySlistNode (data_type_initialisator d);

  template<class data_type_initialisator>
  MySlistNode (data_type_initialisator d,
                         MySlistNode<data_type> * next_node_ptr);

  MySlistNode();
};

template <class data_type>
struct MySlistIterator {
  MySlistNode<data_type> * pointer;

  MySlistIterator();
  MySlistIterator(MySlistNode<data_type> * p);
  MySlistIterator(MySlistNode<data_type> & p);

  data_type &
  operator*() const;

  MySlistIterator<data_type> & operator ++();

  MySlistIterator<data_type> operator ++(int);

  bool operator != (const MySlistIterator<data_type>& other);

  bool operator == (const MySlistIterator<data_type>& other);
};

template <class data_type>
class MySlist {
public:
  typedef MySlistIterator<data_type> iterator;
  
  MySlist();

  size_t
  size(void) const;

  iterator
  end(void) const;

  iterator
  begin(void) const;

  template <class data_type_initialisator>
  void
  push_front(const data_type_initialisator & d);

  void
  pop_front (void);

  void
  erase_after( iterator i );

  ~MySlist();

private:
  size_t list_size;

  typedef MySlistNode<data_type> list_node;

  list_node head;
};
}
#include "cardwords_myslist.icc"
#endif

