Initialize assignments of reals
[iverilog.git] / svector.h
blob09181966de83e412dc78900091170a7145f493ce
1 #ifndef __svector_H
2 #define __svector_H
3 /*
4 * Copyright (c) 1999 Stephen Williams (steve@icarus.com)
6 * This source code is free software; you can redistribute it
7 * and/or modify it in source code form under the terms of the GNU
8 * General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
10 * any later version. In order to redistribute the software in
11 * binary form, you will need a Picture Elements Binary Software
12 * License.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
23 #ifdef HAVE_CVS_IDENT
24 #ident "$Id: svector.h,v 1.11 2007/03/22 16:08:17 steve Exp $"
25 #endif
27 # include "config.h"
28 # include <string>
29 # include <assert.h>
32 * This is a way simplified vector class that cannot grow or shrink,
33 * and is really only able to handle values. It is intended to be
34 * lighter weight than the STL list class.
37 template <class TYPE> class svector {
39 public:
40 explicit svector() : nitems_(0), items_(0) { }
42 explicit svector(unsigned size) : nitems_(size), items_(new TYPE[size])
43 { for (unsigned idx = 0 ; idx < size ; idx += 1)
44 items_[idx] = 0;
47 svector(const svector<TYPE>&that)
48 : nitems_(that.nitems_), items_(new TYPE[nitems_])
49 { for (unsigned idx = 0 ; idx < that.nitems_ ; idx += 1)
50 items_[idx] = that[idx];
53 svector(const svector<TYPE>&l, const svector<TYPE>&r)
54 : nitems_(l.nitems_ + r.nitems_), items_(new TYPE[nitems_])
55 { for (unsigned idx = 0 ; idx < l.nitems_ ; idx += 1)
56 items_[idx] = l[idx];
58 for (unsigned idx = 0 ; idx < r.nitems_ ; idx += 1)
59 items_[l.nitems_+idx] = r[idx];
62 svector(const svector<TYPE>&l, TYPE r)
63 : nitems_(l.nitems_ + 1), items_(new TYPE[nitems_])
64 { for (unsigned idx = 0 ; idx < l.nitems_ ; idx += 1)
65 items_[idx] = l[idx];
66 items_[nitems_-1] = r;
69 ~svector() { delete[]items_; }
71 svector<TYPE>& operator= (const svector<TYPE>&that)
72 { if (&that == this) return *this;
73 delete[]items_;
74 nitems_ = that.nitems_;
75 items_ = new TYPE[nitems_];
76 for (unsigned idx = 0 ; idx < nitems_ ; idx += 1) {
77 items_[idx] = that.items_[idx];
79 return *this;
82 unsigned count() const { return nitems_; }
84 TYPE&operator[] (unsigned idx)
85 { assert(idx < nitems_);
86 return items_[idx];
89 TYPE operator[] (unsigned idx) const
90 { assert(idx < nitems_);
91 return items_[idx];
94 private:
95 unsigned nitems_;
96 TYPE* items_;
101 * Override the implementation of the above template for the string
102 * type parameter. The initialization to nil works different here.
104 template <> inline svector<std::string>::svector(unsigned size)
105 : nitems_(size), items_(new std::string[size])
111 * $Log: svector.h,v $
112 * Revision 1.11 2007/03/22 16:08:17 steve
113 * Spelling fixes from Larry
115 * Revision 1.10 2005/06/14 19:13:43 steve
116 * gcc3/4 compile errors.
118 * Revision 1.9 2003/07/23 02:35:44 steve
119 * Inline the svector<string> constructor.
121 * Revision 1.8 2003/07/16 00:54:07 steve
122 * Needs the config.h header.
124 * Revision 1.7 2003/07/15 05:07:13 steve
125 * Move PUdp constructor into compiled file.
127 * Revision 1.6 2002/08/12 01:35:00 steve
128 * conditional ident string using autoconfig.
130 * Revision 1.5 2000/02/23 02:56:55 steve
131 * Macintosh compilers do not support ident.
133 * Revision 1.4 1999/06/15 03:44:53 steve
134 * Get rid of the STL vector template.
136 * Revision 1.3 1999/05/06 04:37:17 steve
137 * Get rid of list<lgate> types.
139 * Revision 1.2 1999/05/01 02:57:53 steve
140 * Handle much more complex event expressions.
142 * Revision 1.1 1999/04/29 02:16:26 steve
143 * Parse OR of event expressions.
146 #endif