vnl_T_n.h
Go to the documentation of this file.
1 // This is core/vnl/vnl_T_n.h
2 #ifndef vnl_T_n_h_
3 #define vnl_T_n_h_
4 //:
5 // \file
6 // \author fsm
7 //
8 // Purpose: the vnl_vector_fixed<T,n> template class provides
9 // non-mallocing vectors of given size, but it has no constructor
10 // from n Ts. This macro declares a class vnl_T_n which is derived
11 // directly from vnl_vector_fixed<T,n> and has such a constructor.
12 //
13 // Inspired by the numerous double-3, int-2 things lying around.
14 
15 #include <vnl/vnl_vector_fixed.h>
16 #include "vnl/vnl_export.h"
17 
18 //: cpp traits!
19 #define vnl_T_n_aux_1(T) (T x) { data_[0] = x; }
20 #define vnl_T_n_aux_2(T) (T x, T y) { data_[0] = x; data_[1] = y; }
21 #define vnl_T_n_aux_3(T) (T x, T y, T z) { data_[0] = x; data_[1] = y; data_[2] = z; }
22 #define vnl_T_n_aux_4(T) (T x, T y, T z, T w) { data_[0] = x; data_[1] = y; data_[2] = z; data_[3] = w; }
23 #define vnl_T_n_aux_5(T) (T x, T y, T z, T w, T u) { data_[0] = x; data_[1] = y; data_[2] = z; data_[3] = w; data_[4]= u; }
24 
25 //: this macro defines the class.
26 // e.g. use vnl_T_n_impl(int,2) to implement class vnl_int_2.
27 #define vnl_T_n_class_impl(T,n) \
28 class vnl_##T##_##n : public vnl_vector_fixed<T ,n> \
29 { \
30  public: \
31  vnl_##T##_##n() { } \
32  vnl_##T##_##n(vnl_vector<T > const & rhs) : vnl_vector_fixed<T ,n>(rhs) { } \
33  vnl_##T##_##n(vnl_vector_fixed<T ,n> const & rhs) : vnl_vector_fixed<T ,n>(rhs) { } \
34  vnl_##T##_##n vnl_T_n_aux_##n(T) \
35 };
36 
37 // some compilers need a bit of help with the overload resolution.
38 #define vnl_T_n_funcs_impl(T,n) /* no need */
39 
40 //: clients use this.
41 #define vnl_T_n_impl(T,n) \
42 vnl_T_n_class_impl(T,n) \
43 vnl_T_n_funcs_impl(T,n)
44 
45 #endif // vnl_T_n_h_
Fixed length stack-stored vector.