File: unv_template.cc.t

package info (click to toggle)
gnuradio 3.7.13.4-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 45,992 kB
  • sloc: cpp: 155,723; python: 88,934; xml: 42,165; ansic: 41,036; fortran: 927; asm: 803; sh: 224; lisp: 31; makefile: 17
file content (149 lines) | stat: -rw-r--r-- 3,112 bytes parent folder | download
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
////////////////////////////////////////////////////////////////////////////
//                           pmt_@TAG@vector
////////////////////////////////////////////////////////////////////////////

namespace pmt {

static pmt_@TAG@vector *
_@TAG@vector(pmt_t x)
{
  return dynamic_cast<pmt_@TAG@vector*>(x.get());
}


pmt_@TAG@vector::pmt_@TAG@vector(size_t k, @TYPE@ fill)
  : d_v(k)
{
  for (size_t i = 0; i < k; i++)
    d_v[i] = fill;
}

pmt_@TAG@vector::pmt_@TAG@vector(size_t k, const @TYPE@ *data)
  : d_v(k)
{
  if(k)
    memcpy( &d_v[0], data, k * sizeof(@TYPE@) );
}

@TYPE@
pmt_@TAG@vector::ref(size_t k) const
{
  if (k >= length())
    throw out_of_range("pmt_@TAG@vector_ref", from_long(k));
  return d_v[k];
}

void
pmt_@TAG@vector::set(size_t k, @TYPE@ x)
{
  if (k >= length())
    throw out_of_range("pmt_@TAG@vector_set", from_long(k));
  d_v[k] = x;
}

const @TYPE@ *
pmt_@TAG@vector::elements(size_t &len)
{
  len = length();
  return len ?  &d_v[0] : NULL;
}

@TYPE@ *
pmt_@TAG@vector::writable_elements(size_t &len)
{
  len = length();
  return len ? &d_v[0] : NULL;
}

const void*
pmt_@TAG@vector::uniform_elements(size_t &len)
{
  len = length() * sizeof(@TYPE@);
  return len ? &d_v[0] : NULL;
}

void*
pmt_@TAG@vector::uniform_writable_elements(size_t &len)
{
  len = length() * sizeof(@TYPE@);
  return len ? (&d_v[0]) : NULL;
}

bool
is_@TAG@vector(pmt_t obj)
{
  return obj->is_@TAG@vector();
}

pmt_t
make_@TAG@vector(size_t k, @TYPE@ fill)
{
  return pmt_t(new pmt_@TAG@vector(k, fill));
}

pmt_t
init_@TAG@vector(size_t k, const @TYPE@ *data)
{
  return pmt_t(new pmt_@TAG@vector(k, data));
}

pmt_t
init_@TAG@vector(size_t k, const std::vector< @TYPE@ > &data)
{
  if(k) {
    return pmt_t(new pmt_@TAG@vector(k, &data[0]));
  }
  return pmt_t(new pmt_@TAG@vector(k, static_cast< @TYPE@ >(0))); // fills an empty vector with 0
}

@TYPE@
@TAG@vector_ref(pmt_t vector, size_t k)
{
  if (!vector->is_@TAG@vector())
    throw wrong_type("pmt_@TAG@vector_ref", vector);
  return _@TAG@vector(vector)->ref(k);
}

void
@TAG@vector_set(pmt_t vector, size_t k, @TYPE@ obj)
{
  if (!vector->is_@TAG@vector())
    throw wrong_type("pmt_@TAG@vector_set", vector);
  _@TAG@vector(vector)->set(k, obj);
}

const @TYPE@ *
@TAG@vector_elements(pmt_t vector, size_t &len)
{
  if (!vector->is_@TAG@vector())
    throw wrong_type("pmt_@TAG@vector_elements", vector);
  return _@TAG@vector(vector)->elements(len);
}

const std::vector< @TYPE@ >
@TAG@vector_elements(pmt_t vector)
{
  if (!vector->is_@TAG@vector())
    throw wrong_type("pmt_@TAG@vector_elements", vector);
  size_t len;
  const @TYPE@ *array = _@TAG@vector(vector)->elements(len);
  const std::vector< @TYPE@ > vec(array, array+len);
  return vec;
}


@TYPE@ *
@TAG@vector_writable_elements(pmt_t vector, size_t &len)
{
  if (!vector->is_@TAG@vector())
    throw wrong_type("pmt_@TAG@vector_writable_elements", vector);
  return _@TAG@vector(vector)->writable_elements(len);
}

const std::string
pmt_@TAG@vector::string_ref(size_t k) const
{
  return boost::lexical_cast< std::string, @TYPE@ > (ref(k));
}

} /* namespace pmt */