IT++ Logo
fix_factory.cpp
Go to the documentation of this file.
1 
30 #include <itpp/fixed/fix_factory.h>
31 #include <itpp/fixed/cfix.h>
32 
33 
34 namespace itpp
35 {
36 
37 void Fix_Factory::create(Fix* &ptr, const int n) const
38 {
39  void *p = ::operator new(sizeof(Fix) * n);
40  ptr = reinterpret_cast<Fix*>(p);
41  // Set fixed-point restrictions
42  for (int i = 0; i < n; ++i) {
43  new(ptr + i) Fix(0.0, 0, wordlen, emode, omode, qmode, stat_ptr);
44  }
45 }
46 
47 void Fix_Factory::create(CFix* &ptr, const int n) const
48 {
49  void *p = ::operator new(sizeof(CFix) * n);
50  ptr = reinterpret_cast<CFix*>(p);
51  // Set fixed-point restrictions
52  for (int i = 0; i < n; ++i) {
53  new(ptr + i) CFix(0.0, 0, wordlen, emode, omode, qmode, stat_ptr);
54  }
55 }
56 
57 template<>
58 void create_elements<Fix>(Fix* &ptr, const int n, const Factory &f)
59 {
60  if (const Fix_Factory *fix_factory_ptr = dynamic_cast<const Fix_Factory*>(&f)) {
61  // Yes, f seems to be a Fix_Factory. Now call the Fix_Factory::create method
62  fix_factory_ptr->create(ptr, n);
63  }
64  else {
65  // No, f does not seem to be a Fix_Factory. As a fallback solution,
66  // assume that f is DEFAULT_FACTORY and use the default constructor
67  void *p = ::operator new(sizeof(Fix) * n);
68  ptr = reinterpret_cast<Fix*>(p);
69  for (int i = 0; i < n; i++) {
70  new(ptr + i) Fix();
71  }
72  }
73 }
74 
75 template<>
76 void create_elements<CFix>(CFix* &ptr, const int n, const Factory &f)
77 {
78  if (const Fix_Factory *fix_factory_ptr = dynamic_cast<const Fix_Factory*>(&f)) {
79  // Yes, f seems to be a Fix_Factory. Now call the Fix_Factory::create method
80  fix_factory_ptr->create(ptr, n);
81  }
82  else {
83  // No, f does not seem to be a Fix_Factory. As a fallback solution,
84  // assume that f is DEFAULT_FACTORY and use the default constructor
85  void *p = ::operator new(sizeof(CFix) * n);
86  ptr = reinterpret_cast<CFix*>(p);
87  for (int i = 0; i < n; i++) {
88  new(ptr + i) CFix();
89  }
90  }
91 }
92 
93 } // namespace itpp
SourceForge Logo

Generated on Sat May 25 2013 16:32:22 for IT++ by Doxygen 1.8.2