IT++ Logo
fix_factory.cpp
Go to the documentation of this file.
1
31#include <itpp/fixed/cfix.h>
32
33
34namespace itpp
35{
36
37void 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
47void 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
57template<>
58void 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
75template<>
76void 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
Definitions of a complex fixed-point data type CFix.
Complex fixed-point data type.
Definition: cfix.h:52
Base class for class factories.
Definition: factory.h:130
Class factory for fixed-point data types Fix and CFix.
Definition: fix_factory.h:121
Stat * stat_ptr
Pointer to statistics object.
Definition: fix_factory.h:146
q_mode qmode
Quantization mode.
Definition: fix_factory.h:144
virtual void create(Fix *&ptr, const int n) const
Create an n-length array of Fix.
Definition: fix_factory.cpp:37
e_mode emode
Sign encoding mode.
Definition: fix_factory.h:140
int wordlen
Word length.
Definition: fix_factory.h:138
o_mode omode
Overflow mode.
Definition: fix_factory.h:142
Fixed-point data type.
Definition: fix.h:52
Definitions of a class factory for fixed-point data types Fix and CFix.
void create_elements< Fix >(Fix *&ptr, const int n, const Factory &f)
Create an n-length array of Fix using Fix_Factory f.
Definition: fix_factory.cpp:58
void create_elements< CFix >(CFix *&ptr, const int n, const Factory &f)
Create an n-length array of CFix using Fix_Factory f.
Definition: fix_factory.cpp:76
itpp namespace
Definition: itmex.h:37
SourceForge Logo

Generated on Tue Jan 24 2023 00:00:00 for IT++ by Doxygen 1.9.6