/
multiply_const.cpp
55 lines (45 loc) · 1.67 KB
/
multiply_const.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.
#include <grextras/multiply_const.hpp>
#include <boost/make_shared.hpp>
#include <stdexcept>
using namespace grextras;
//! This class is nothing more than a wrapper for the vlen=1 case of MultiplyConstV
class MultiplyConstImpl : public MultiplyConst
{
public:
MultiplyConstImpl(const size_t size, MultiplyConstV::sptr ub):
gras::HierBlock("GrExtras Multiply Const"),
underlying_block(ub)
{
this->connect(*this, 0, ub, 0);
this->connect(ub, 0, *this, 0);
}
void set_const(const std::complex<double> &val)
{
underlying_block->set_const(
std::vector<std::complex<double> >(1, val));
}
std::complex<double> get_const(void)
{
return underlying_block->get_const().front();
}
private:
MultiplyConstV::sptr underlying_block;
};
#define make_factory_function(suffix, type, op) \
MultiplyConst::sptr MultiplyConst::make_ ## suffix( \
const std::complex<double> &val \
){ \
return boost::make_shared<MultiplyConstImpl>( \
sizeof(type), \
MultiplyConstV::make_ ## suffix( \
std::vector<type>(1, type(val op)))); \
}
make_factory_function(fc32_fc32, std::complex<float>, )
make_factory_function(sc32_sc32, std::complex<boost::int32_t>, )
make_factory_function(sc16_sc16, std::complex<boost::int16_t>, )
make_factory_function(sc8_sc8, std::complex<boost::int8_t>, )
make_factory_function(f32_f32, float, .real())
make_factory_function(s32_s32, boost::int32_t, .real())
make_factory_function(s16_s16, boost::int16_t, .real())
make_factory_function(s8_s8, boost::int8_t, .real())