fix_factory.cpp
Go to the documentation of this file.
#include <itpp/fixed/fix_factory.h>
#include <itpp/fixed/cfix.h>
namespace itpp
{
void Fix_Factory::create(Fix* &ptr, const int n) const
{
void *p = ::operator new(sizeof(Fix) * n);
ptr = reinterpret_cast< Fix*>(p);
// Set fixed-point restrictions
for (int i = 0; i < n; ++i) {
new(ptr + i) Fix(0.0, 0, wordlen, emode, omode, qmode, stat_ptr);
}
}
void Fix_Factory::create(CFix* &ptr, const int n) const
{
void *p = ::operator new(sizeof(CFix) * n);
ptr = reinterpret_cast< CFix*>(p);
// Set fixed-point restrictions
for (int i = 0; i < n; ++i) {
new(ptr + i) CFix(0.0, 0, wordlen, emode, omode, qmode, stat_ptr);
}
}
template<>
void create_elements<Fix>(Fix* &ptr, const int n, const Factory &f)
{
if (const Fix_Factory *fix_factory_ptr = dynamic_cast<const Fix_Factory*>(&f)) {
// Yes, f seems to be a Fix_Factory. Now call the Fix_Factory::create method
fix_factory_ptr->create(ptr, n);
}
else {
// No, f does not seem to be a Fix_Factory. As a fallback solution,
// assume that f is DEFAULT_FACTORY and use the default constructor
void *p = ::operator new(sizeof(Fix) * n);
ptr = reinterpret_cast< Fix*>(p);
for (int i = 0; i < n; i++) {
new(ptr + i) Fix();
}
}
}
template<>
void create_elements<CFix>(CFix* &ptr, const int n, const Factory &f)
{
if (const Fix_Factory *fix_factory_ptr = dynamic_cast<const Fix_Factory*>(&f)) {
// Yes, f seems to be a Fix_Factory. Now call the Fix_Factory::create method
fix_factory_ptr->create(ptr, n);
}
else {
// No, f does not seem to be a Fix_Factory. As a fallback solution,
// assume that f is DEFAULT_FACTORY and use the default constructor
void *p = ::operator new(sizeof(CFix) * n);
ptr = reinterpret_cast< CFix*>(p);
for (int i = 0; i < n; i++) {
new(ptr + i) CFix();
}
}
}
} // namespace itpp
cfix.h
Definitions of a complex fixed-point data type CFix.
itpp::Array
General array class.
Definition array.h:105
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 on Mon Jun 10 2024 11:49:23 for IT++ by Doxygen 1.9.8