source: trunk/src/emx/include/Attic/cpp/gen/Vec.hP@ 18

Last change on this file since 18 was 18, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.4 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2/*
3Copyright (C) 1988 Free Software Foundation
4 written by Doug Lea ([email protected])
5
6This file is part of the GNU C++ Library. This library is free
7software; you can redistribute it and/or modify it under the terms of
8the GNU Library General Public License as published by the Free
9Software Foundation; either version 2 of the License, or (at your
10option) any later version. This library is distributed in the hope
11that it will be useful, but WITHOUT ANY WARRANTY; without even the
12implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13PURPOSE. See the GNU Library General Public License for more details.
14You should have received a copy of the GNU Library General Public
15License along with this library; if not, write to the Free Software
16Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19
20#ifndef _<T>Vec_h
21#ifdef __GNUG__
22#pragma interface
23#endif
24#define _<T>Vec_h 1
25
26#include <builtin.h>
27#include "<T>.defs.h"
28
29#ifndef _<T>_typedefs
30#define _<T>_typedefs 1
31typedef void (*<T>Procedure)(<T&>);
32typedef <T> (*<T>Mapper)(<T&>);
33typedef <T> (*<T>Combiner)(<T&>, <T&>);
34typedef int (*<T>Predicate)(<T&>);
35typedef int (*<T>Comparator)(<T&>, <T&>);
36#endif
37
38
39class <T>Vec
40{
41protected:
42 int len;
43 <T> *s;
44
45 <T>Vec(int l, <T>* d);
46public:
47 <T>Vec ();
48 <T>Vec (int l);
49 <T>Vec (int l, <T&> fill_value);
50 <T>Vec (const <T>Vec&);
51 ~<T>Vec ();
52
53 <T>Vec & operator = (const <T>Vec & a);
54 <T>Vec at(int from = 0, int n = -1);
55
56 int capacity() const;
57 void resize(int newlen);
58
59 <T>& operator [] (int n);
60 <T>& elem(int n);
61
62 friend <T>Vec concat(<T>Vec & a, <T>Vec & b);
63 friend <T>Vec map(<T>Mapper f, <T>Vec & a);
64 friend <T>Vec merge(<T>Vec & a, <T>Vec & b, <T>Comparator f);
65 friend <T>Vec combine(<T>Combiner f, <T>Vec & a, <T>Vec & b);
66 friend <T>Vec reverse(<T>Vec & a);
67
68 void reverse();
69 void sort(<T>Comparator f);
70 void fill(<T&> val, int from = 0, int n = -1);
71
72 void apply(<T>Procedure f);
73 <T> reduce(<T>Combiner f, <T&> base);
74 int index(<T&> targ);
75
76 friend int operator == (<T>Vec& a, <T>Vec& b);
77 friend int operator != (<T>Vec& a, <T>Vec& b);
78
79 void error(const char* msg);
80 void range_error();
81};
82
83extern void default_<T>Vec_error_handler(const char*);
84extern one_arg_error_handler_t <T>Vec_error_handler;
85
86extern one_arg_error_handler_t
87 set_<T>Vec_error_handler(one_arg_error_handler_t f);
88
89
90inline <T>Vec::<T>Vec()
91{
92 len = 0; s = 0;
93}
94
95inline <T>Vec::<T>Vec(int l)
96{
97 s = new <T> [len = l];
98}
99
100
101inline <T>Vec::<T>Vec(int l, <T>* d) :len(l), s(d) {}
102
103
104inline <T>Vec::~<T>Vec()
105{
106 delete [] s;
107}
108
109
110inline <T>& <T>Vec::operator [] (int n)
111{
112 if ((unsigned)n >= (unsigned)len)
113 range_error();
114 return s[n];
115}
116
117inline <T>& <T>Vec::elem(int n)
118{
119 return s[n];
120}
121
122
123inline int <T>Vec::capacity() const
124{
125 return len;
126}
127
128
129
130inline int operator != (<T>Vec& a, <T>Vec& b)
131{
132 return !(a == b);
133}
134
135#endif
Note: See TracBrowser for help on using the repository browser.