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