home *** CD-ROM | disk | FTP | other *** search
- // This may look like C code, but it is really -*- C++ -*-
- /*
- Copyright (C) 1988 Free Software Foundation
- written by Doug Lea (dl@rocky.oswego.edu)
-
- This file is part of GNU CC.
-
- GNU CC is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY. No author or distributor
- accepts responsibility to anyone for the consequences of using it
- or for whether it serves any particular purpose or works at all,
- unless he says so in writing. Refer to the GNU CC General Public
- License for full details.
-
- Everyone is granted permission to copy, modify and redistribute
- GNU CC, but only under the conditions described in the
- GNU CC General Public License. A copy of this license is
- supposed to have been given to you along with GNU CC so you
- can know your rights and responsibilities. It should be in a
- file named COPYING. Among other things, the copyright notice
- and this notice must be preserved on all copies.
- */
-
-
- #ifndef _<T>OSet_h
- #define _<T>OSet_h 1
-
- #ifndef _<T>_typedefs
- #define _<T>_typedefs 1
- typedef void (*<T>Procedure)(<T&>);
- typedef <T> (*<T>Mapper)(<T&>);
- typedef <T> (*<T>Combiner)(<T&>, <T&>);
- typedef int (*<T>Predicate)(<T&>);
- typedef int (*<T>Comparator)(<T&>, <T&>);
- #endif
-
- #ifndef COMPARISON_FUNCTION
- #include <compare.h>
- #define COMPARISON_FUNCTION compare
- #endif
-
- #include "<T>SLListNode.h"
-
- class <T>OSetTrav;
-
- class <T>OSet
- {
- friend class <T>OSetTrav;
-
- <T>SLListNode* P;
-
- <T>OSet(<T>SLListNode* p);
- public:
- <T>OSet();
- <T>OSet(<T>OSet& a);
- <T>OSet(<T>OSetTrav& l);
- ~<T>OSet();
-
- <T>OSet& operator = (<T>OSet& a);
- <T>OSet& operator = (<T>OSetTrav& a);
-
- int null();
- int valid();
- const void* operator void* ();
- int operator ! ();
-
- int length();
-
- <T&> get();
-
- void add(<T&> item);
- void del(<T&> item);
- int contains(<T&> targ);
- void clear();
-
- void apply(<T>Procedure f);
- <T> reduce(<T>Combiner f, <T&> base);
- void destructive_union(<T>OSet& b);
-
- friend int operator == (<T>OSet& a, <T>OSet& b);
- friend int operator != (<T>OSet& a, <T>OSet& b);
- friend int operator < (<T>OSet& a, <T>OSet& b);
- friend int operator <= (<T>OSet& a, <T>OSet& b);
- friend int operator > (<T>OSet& a, <T>OSet& b);
- friend int operator >= (<T>OSet& a, <T>OSet& b);
-
- friend <T>OSet operator | (<T>OSet& a, <T>OSet& b);
- friend <T>OSet operator - (<T>OSet& a, <T>OSet& b);
- friend <T>OSet operator & (<T>OSet& a, <T>OSet& b);
- friend <T>OSet operator ^ (<T>OSet& a, <T>OSet& b);
-
- <T>OSet& operator |= (<T>OSet& b);
- <T>OSet& operator -= (<T>OSet& b);
- <T>OSet& operator &= (<T>OSet& b);
- <T>OSet& operator ^= (<T>OSet& b);
-
- void error(const char* msg);
- };
-
- class <T>OSetTrav
- {
- friend class <T>OSet;
-
- <T>SLListNode* P;
- public:
- <T>OSetTrav();
- <T>OSetTrav(<T>OSet& l);
- <T>OSetTrav(<T>OSetTrav& l);
- ~<T>OSetTrav();
-
- <T>OSetTrav& operator = (<T>OSet& l);
- <T>OSetTrav& operator = (<T>OSetTrav& l);
-
- int null();
- int valid();
- const void* operator void* ();
- int operator ! ();
-
- void advance_to(<T&> targ);
- void advance();
- <T&> get();
- };
-
- <T>SLListNode* copy<T>SLListNodes(<T>SLListNode*);
-
- inline <T>OSet::~<T>OSet()
- {
- clear();
- }
-
- inline <T>OSet::<T>OSet()
- {
- P = 0;
- }
-
- inline <T>OSet::<T>OSet(<T>SLListNode* p)
- {
- P = p;
- }
-
- inline <T>OSet::<T>OSet(<T>OSet& a)
- {
- P = copy<T>SLListNodes(a.P);
- }
-
- inline <T>OSet::<T>OSet(<T>OSetTrav& l)
- {
- P = copy<T>SLListNodes(l.P);
- }
-
- inline <T>OSet& <T>OSet::operator = (<T>OSet& a)
- {
- if (P != a.P)
- {
- clear();
- P = copy<T>SLListNodes(a.P);
- }
- return *this;
- }
-
- inline <T>OSet& <T>OSet::operator = (<T>OSetTrav& l)
- {
- if (P != l.P)
- {
- clear();
- P = copy<T>SLListNodes(l.P);
- }
- return *this;
- }
-
- inline <T&> <T>OSet::get()
- {
- return P->hd;
- }
-
- inline int <T>OSet::null()
- {
- return P == 0;
- }
-
- inline int <T>OSet::valid()
- {
- return P != 0;
- }
-
- inline const void* <T>OSet::operator void* ()
- {
- return (P == 0)? 0 : this;
- }
-
- inline int <T>OSet::operator ! ()
- {
- return (P == 0);
- }
-
- inline int <T>OSet::length()
- {
- int l = 0;
- for (<T>SLListNode* p = P; p != 0; p = p->tl) ++l;
- return l;
- }
-
-
- inline <T>OSetTrav::<T>OSetTrav()
- {
- P = 0;
- }
-
- inline <T>OSetTrav::<T>OSetTrav(<T>OSet& a)
- {
- P = a.P;
- }
-
- inline <T>OSetTrav::<T>OSetTrav(<T>OSetTrav& a)
- {
- P = a.P;
- }
-
- inline <T>OSetTrav& <T>OSetTrav::operator = (<T>OSet& a)
- {
- P = a.P;
- }
-
- inline <T>OSetTrav& <T>OSetTrav::operator = (<T>OSetTrav& a)
- {
- P = a.P;
- }
-
- inline <T>OSetTrav::~<T>OSetTrav() {}
-
- inline int <T>OSetTrav::null()
- {
- return P == 0;
- }
-
- inline int <T>OSetTrav::valid()
- {
- return P != 0;
- }
-
- inline const void* <T>OSetTrav::operator void* ()
- {
- return (P == 0)? 0 : this;
- }
-
- inline int <T>OSetTrav::operator ! ()
- {
- return (P == 0);
- }
-
- inline void <T>OSetTrav::advance()
- {
- if (P != 0) P = P->tl;
- }
-
- inline <T&> <T>OSetTrav::get()
- {
- if (P == 0)
- (*<T>OSet_error_handler)("get from null traverser");
- return P->hd;
- }
-
- inline int operator != (<T>OSet& a, <T>OSet& b)
- {
- return ! (a == b);
- }
-
- inline int operator > (<T>OSet& a, <T>OSet& b)
- {
- return b < a;
- }
-
- inline int operator >= (<T>OSet& a, <T>OSet& b)
- {
- return b <= a;
- }
-
- extern void default_<T>OSet_error_handler(char*);
- extern one_arg_error_handler_t <T>OSet_error_handler;
-
- extern one_arg_error_handler_t
- set_<T>OSet_error_handler(one_arg_error_handler_t f);
-
- #endif
-