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