IT++
4.3.1
Toggle main menu visibility
itpp
fixed
fix_factory.cpp
Go to the documentation of this file.
1
29
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
cfix.h
Definitions of a complex fixed-point data type CFix.
itpp::CFix
Complex fixed-point data type.
Definition
cfix.h:52
itpp::Factory
Base class for class factories.
Definition
factory.h:130
itpp::Fix_Factory
Class factory for fixed-point data types Fix and CFix.
Definition
fix_factory.h:121
itpp::Fix_Factory::stat_ptr
Stat * stat_ptr
Pointer to statistics object.
Definition
fix_factory.h:146
itpp::Fix_Factory::qmode
q_mode qmode
Quantization mode.
Definition
fix_factory.h:144
itpp::Fix_Factory::create
virtual void create(Fix *&ptr, const int n) const
Create an n-length array of Fix.
Definition
fix_factory.cpp:37
itpp::Fix_Factory::emode
e_mode emode
Sign encoding mode.
Definition
fix_factory.h:140
itpp::Fix_Factory::wordlen
int wordlen
Word length.
Definition
fix_factory.h:138
itpp::Fix_Factory::omode
o_mode omode
Overflow mode.
Definition
fix_factory.h:142
itpp::Fix
Fixed-point data type.
Definition
fix.h:52
fix_factory.h
Definitions of a class factory for fixed-point data types Fix and CFix.
itpp::create_elements< Fix >
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
itpp::create_elements< CFix >
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
itpp namespace
Definition
itmex.h:37
Generated by
1.17.0