IT++ Logo

fix_factory.cpp

Go to the documentation of this file.
00001 
00031 #include <itpp/fixed/fix_factory.h>
00032 #include <itpp/fixed/cfix.h>
00033 
00034 
00035 namespace itpp {
00036 
00037   void Fix_Factory::create(Fix* &ptr, const int n) const
00038   {
00039     void *p = ::operator new(sizeof(Fix) * n);
00040     ptr = reinterpret_cast<Fix*>(p);
00041     // Set fixed-point restrictions
00042     for (int i = 0; i < n; ++i) {
00043       new (ptr + i) Fix(0.0, 0, wordlen, emode, omode, qmode, stat_ptr);
00044     }
00045   }
00046 
00047   void Fix_Factory::create(CFix* &ptr, const int n) const
00048   {
00049     void *p = ::operator new(sizeof(CFix) * n);
00050     ptr = reinterpret_cast<CFix*>(p);
00051     // Set fixed-point restrictions
00052     for (int i = 0; i < n; ++i) {
00053       new (ptr + i) CFix(0.0, 0, wordlen, emode, omode, qmode, stat_ptr);
00054     }
00055   }
00056 
00057   template<>
00058   void create_elements<Fix>(Fix* &ptr, const int n, const Factory &f)
00059   {
00060     if (const Fix_Factory *fix_factory_ptr = dynamic_cast<const Fix_Factory*>(&f)) {
00061       // Yes, f seems to be a Fix_Factory. Now call the Fix_Factory::create method
00062       fix_factory_ptr->create(ptr, n);
00063     }
00064     else {
00065       // No, f does not seem to be a Fix_Factory. As a fallback solution,
00066       // assume that f is DEFAULT_FACTORY and use the default constructor
00067       void *p = ::operator new(sizeof(Fix) * n);
00068       ptr = reinterpret_cast<Fix*>(p);
00069       for (int i = 0; i < n; i++) {
00070         new (ptr + i) Fix();
00071       }
00072     }
00073   }
00074 
00075   template<>
00076   void create_elements<CFix>(CFix* &ptr, const int n, const Factory &f)
00077   {
00078     if (const Fix_Factory *fix_factory_ptr = dynamic_cast<const Fix_Factory*>(&f)) {
00079       // Yes, f seems to be a Fix_Factory. Now call the Fix_Factory::create method
00080       fix_factory_ptr->create(ptr, n);
00081     }
00082     else {
00083       // No, f does not seem to be a Fix_Factory. As a fallback solution,
00084       // assume that f is DEFAULT_FACTORY and use the default constructor
00085       void *p = ::operator new(sizeof(CFix) * n);
00086       ptr = reinterpret_cast<CFix*>(p);
00087       for (int i = 0; i < n; i++) {
00088         new (ptr + i) CFix();
00089       }
00090     }
00091   }
00092 
00093 } // namespace itpp
SourceForge Logo

Generated on Sat Apr 19 10:57:52 2008 for IT++ by Doxygen 1.5.5