xref: /386bsd/usr/include/nonstd/gnu/g++/gen/SLBag.hP (revision a2142627)
1// This may look like C code, but it is really -*- C++ -*-
2/*
3Copyright (C) 1988 Free Software Foundation
4    written by Doug Lea (dl@rocky.oswego.edu)
5
6This file is part of GNU CC.
7
8GNU CC is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY.  No author or distributor
10accepts responsibility to anyone for the consequences of using it
11or for whether it serves any particular purpose or works at all,
12unless he says so in writing.  Refer to the GNU CC General Public
13License for full details.
14
15Everyone is granted permission to copy, modify and redistribute
16GNU CC, but only under the conditions described in the
17GNU CC General Public License.   A copy of this license is
18supposed to have been given to you along with GNU CC so you
19can know your rights and responsibilities.  It should be in a
20file named COPYING.  Among other things, the copyright notice
21and this notice must be preserved on all copies.
22*/
23
24
25#ifndef _<T>SLBag_h
26#ifdef __GNUG__
27#pragma once
28#pragma interface
29#endif
30#define _<T>SLBag_h 1
31
32#include "<T>.Bag.h"
33#include "<T>.SLList.h"
34
35class <T>SLBag : public <T>Bag
36{
37protected:
38  <T>SLList     p;
39
40public:
41                <T>SLBag();
42                <T>SLBag(const <T>SLBag&);
43
44  Pix           add(<T&> item);
45  void          del(<T&> item);
46  void          remove(<T&>item);
47  int           contains(<T&> item);
48  int           nof(<T&> item);
49
50  void          clear();
51
52  Pix           first();
53  void          next(Pix& i);
54  <T>&          operator () (Pix i);
55  int           owns(Pix i);
56  Pix           seek(<T&> item, Pix from = 0);
57
58  int           OK();
59};
60
61#if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
62
63inline <T>SLBag::<T>SLBag() : p() { count = 0; }
64
65inline <T>SLBag::<T>SLBag(const <T>SLBag& s) : p(s.p) { count = s.count; }
66
67inline Pix <T>SLBag::first()
68{
69  return p.first();
70}
71
72inline void <T>SLBag::next(Pix  & idx)
73{
74  p.next(idx);
75}
76
77inline <T>& <T>SLBag::operator ()(Pix   idx)
78{
79  return p(idx);
80}
81
82inline void <T>SLBag::clear()
83{
84  count = 0;  p.clear();
85}
86
87inline int <T>SLBag::owns (Pix   idx)
88{
89  return p.owns(idx);
90}
91
92inline Pix <T>SLBag::add(<T&> item)
93{
94  ++count;
95  return p.append(item);
96}
97
98inline int <T>SLBag::contains(<T&> item)
99{
100  return seek(item) != 0;
101}
102
103#endif
104#endif
105