comparison liboctave/dim-vector.h @ 10419:afe44ee90cbd

implement generic macro magic for repeated decls
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 17 Mar 2010 10:30:36 +0100
parents 6c19d6fcd7e5
children 3373fdc0b14a
comparison
equal deleted inserted replaced
10418:6c19d6fcd7e5 10419:afe44ee90cbd
29 29
30 #include <sstream> 30 #include <sstream>
31 #include <string> 31 #include <string>
32 32
33 #include "lo-error.h" 33 #include "lo-error.h"
34 #include "lo-macros.h"
34 35
35 // Rationale: This implementation is more tricky than Array, but the 36 // Rationale: This implementation is more tricky than Array, but the
36 // big plus is that dim_vector requires only one allocation instead of 37 // big plus is that dim_vector requires only one allocation instead of
37 // two. It is (slightly) patterned after GCC's basic_string 38 // two. It is (slightly) patterned after GCC's basic_string
38 // implementation. rep is a pointer to an array of memory, comprising 39 // implementation. rep is a pointer to an array of memory, comprising
152 { 153 {
153 rep[0] = r; 154 rep[0] = r;
154 rep[1] = c; 155 rep[1] = c;
155 rep[2] = p; 156 rep[2] = p;
156 } 157 }
157 158
158 dim_vector (octave_idx_type r, octave_idx_type c, octave_idx_type p, 159 #define ASSIGN_REP(i) rep[i] = d ## i;
159 octave_idx_type q) 160 #define DIM_VECTOR_CTOR(N) \
160 : rep (newrep (4)) 161 dim_vector (OCT_MAKE_DECL_LIST(octave_idx_type, d, N)) \
161 { 162 : rep (newrep (N)) \
162 rep[0] = r; 163 { \
163 rep[1] = c; 164 OCT_ITERATE_MACRO(ASSIGN_REP, N) \
164 rep[2] = p; 165 }
165 rep[3] = q; 166
166 } 167 // Add more if needed.
167 168 DIM_VECTOR_CTOR(4)
168 dim_vector (octave_idx_type r, octave_idx_type c, octave_idx_type p, 169 DIM_VECTOR_CTOR(5)
169 octave_idx_type q, octave_idx_type s) 170 DIM_VECTOR_CTOR(6)
170 : rep (newrep (5)) 171 DIM_VECTOR_CTOR(7)
171 { 172
172 rep[0] = r; 173 #undef ASSIGN_REP
173 rep[1] = c; 174 #undef DIM_VECTOR_CTOR
174 rep[2] = p; 175
175 rep[3] = q;
176 rep[4] = s;
177 }
178
179 dim_vector (octave_idx_type r, octave_idx_type c, octave_idx_type p,
180 octave_idx_type q, octave_idx_type s, octave_idx_type t)
181 : rep (newrep (6))
182 {
183 rep[0] = r;
184 rep[1] = c;
185 rep[2] = p;
186 rep[3] = q;
187 rep[4] = s;
188 rep[5] = t;
189 }
190
191 dim_vector (octave_idx_type r, octave_idx_type c, octave_idx_type p,
192 octave_idx_type q, octave_idx_type s, octave_idx_type t,
193 octave_idx_type u)
194 : rep (newrep (7))
195 {
196 rep[0] = r;
197 rep[1] = c;
198 rep[2] = p;
199 rep[3] = q;
200 rep[4] = s;
201 rep[5] = t;
202 rep[6] = u;
203 }
204
205 dim_vector (const octave_idx_type *vec, size_t vec_size) 176 dim_vector (const octave_idx_type *vec, size_t vec_size)
206 : rep (newrep (vec_size)) 177 : rep (newrep (vec_size))
207 { 178 {
208 for (size_t k = 0; k < vec_size; k++) 179 for (size_t k = 0; k < vec_size; k++)
209 rep[k] = vec[k]; 180 rep[k] = vec[k];