core/vnl/vnl_T_n.h
Go to the documentation of this file.
00001 // This is core/vnl/vnl_T_n.h
00002 #ifndef vnl_T_n_h_
00003 #define vnl_T_n_h_
00004 //:
00005 // \file
00006 // \author fsm
00007 //
00008 // Purpose: the vnl_vector_fixed<T,n> template class provides
00009 // non-mallocing vectors of given size, but it has no constructor
00010 // from n Ts. This macro declares a class vnl_T_n which is derived
00011 // directly from vnl_vector_fixed<T,n> and has such a constructor.
00012 //
00013 // Inspired by the numerous double-3, int-2 things lying around.
00014 
00015 #include <vnl/vnl_vector_fixed.h>
00016 
00017 //: cpp traits!
00018 #define vnl_T_n_aux_1(T) (T x) { data_[0] = x; }
00019 #define vnl_T_n_aux_2(T) (T x, T y) { data_[0] = x; data_[1] = y; }
00020 #define vnl_T_n_aux_3(T) (T x, T y, T z) { data_[0] = x; data_[1] = y; data_[2] = z; }
00021 #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; }
00022 #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; }
00023 
00024 //: this macro defines the class.
00025 // e.g. use vnl_T_n_impl(int,2) to implement class vnl_int_2.
00026 #define vnl_T_n_class_impl(T,n) \
00027 class vnl_##T##_##n : public vnl_vector_fixed<T ,n> \
00028 { \
00029  public: \
00030   vnl_##T##_##n() { } \
00031   vnl_##T##_##n(vnl_vector<T > const & rhs) : vnl_vector_fixed<T ,n>(rhs) { } \
00032   vnl_##T##_##n(vnl_vector_fixed<T ,n> const & rhs) : vnl_vector_fixed<T ,n>(rhs) { } \
00033   vnl_##T##_##n vnl_T_n_aux_##n(T) \
00034 };
00035 
00036 // some compilers need a bit of help with the overload resolution.
00037 #define vnl_T_n_funcs_impl(T,n) /* no need */
00038 
00039 //: clients use this.
00040 #define vnl_T_n_impl(T,n) \
00041 vnl_T_n_class_impl(T,n) \
00042 vnl_T_n_funcs_impl(T,n)
00043 
00044 #endif // vnl_T_n_h_