IT++ Logo Newcom Logo

factory.h

Go to the documentation of this file.
00001 
00033 #ifndef FACTORY_H
00034 #define FACTORY_H
00035 
00036 
00037 namespace itpp {
00038 
00039   // Forward declarations
00040   template<class T> class Array;
00041   template<class Num_T> class Mat;
00042   template<class Num_T> class Vec;
00043 
00129   class Factory {
00130   public:
00132     virtual ~Factory() {}
00133   };
00134 
00136   const Factory DEFAULT_FACTORY;
00137 
00139   template<class T>
00140   void create_elements(T* &ptr, const int n, const Factory &)
00141   {
00142     ptr = new T[n];
00143   }
00144 
00146   template<class T>
00147   void create_elements(Array<T>* &ptr, const int n, const Factory &f)
00148   {
00149     ptr = new Array<T>[n];
00150     if (ptr) {
00151       // Set factory
00152       for (int i=0; i<n; i++) {
00153         // Note: explicit destructor call intentionally omitted (to save time)
00154         new (ptr + i) Array<T>(f);
00155       }
00156     }
00157   }
00158 
00160   template<class T>
00161   void create_elements(Mat<T>* &ptr, const int n, const Factory &f)
00162   {
00163     ptr = new Mat<T>[n];
00164     if (ptr) {
00165       // Set factory
00166       for (int i=0; i<n; i++) {
00167         // Note: explicit destructor call intentionally omitted (to save time)
00168         new (ptr + i) Mat<T>(f);
00169       }
00170     }
00171   }
00172 
00174   template<class T>
00175   void create_elements(Vec<T>* &ptr, const int n, const Factory &f)
00176   {
00177     ptr = new Vec<T>[n];
00178     if (ptr) {
00179       // Set factory
00180       for (int i=0; i<n; i++) {
00181         // Note: explicit destructor call intentionally omitted (to save time)
00182         new (ptr + i) Vec<T>(f);
00183       }
00184     }
00185   }
00186 
00187 } // namespace itpp
00188 
00189 #endif // #ifndef FACTORY_H
SourceForge Logo

Generated on Fri Jan 11 08:51:36 2008 for IT++ by Doxygen 1.3.9.1