GNU Radio 3.6.4.2 C++ API
pmt_int.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006,2009,2010 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 #ifndef INCLUDED_PMT_INT_H
23 #define INCLUDED_PMT_INT_H
24 
25 #include <gruel/pmt.h>
26 #include <boost/utility.hpp>
27 #include <boost/detail/atomic_count.hpp>
28 
29 /*
30  * EVERYTHING IN THIS FILE IS PRIVATE TO THE IMPLEMENTATION!
31  *
32  * See pmt.h for the public interface
33  */
34 
35 #define PMT_LOCAL_ALLOCATOR 0 // define to 0 or 1
36 namespace pmt {
37 
38 class GRUEL_API pmt_base : boost::noncopyable {
39  mutable boost::detail::atomic_count count_;
40 
41 protected:
42  pmt_base() : count_(0) {};
43  virtual ~pmt_base();
44 
45 public:
46  virtual bool is_bool() const { return false; }
47  virtual bool is_symbol() const { return false; }
48  virtual bool is_number() const { return false; }
49  virtual bool is_integer() const { return false; }
50  virtual bool is_uint64() const { return false; }
51  virtual bool is_real() const { return false; }
52  virtual bool is_complex() const { return false; }
53  virtual bool is_null() const { return false; }
54  virtual bool is_pair() const { return false; }
55  virtual bool is_tuple() const { return false; }
56  virtual bool is_vector() const { return false; }
57  virtual bool is_dict() const { return false; }
58  virtual bool is_any() const { return false; }
59 
60  virtual bool is_uniform_vector() const { return false; }
61  virtual bool is_u8vector() const { return false; }
62  virtual bool is_s8vector() const { return false; }
63  virtual bool is_u16vector() const { return false; }
64  virtual bool is_s16vector() const { return false; }
65  virtual bool is_u32vector() const { return false; }
66  virtual bool is_s32vector() const { return false; }
67  virtual bool is_u64vector() const { return false; }
68  virtual bool is_s64vector() const { return false; }
69  virtual bool is_f32vector() const { return false; }
70  virtual bool is_f64vector() const { return false; }
71  virtual bool is_c32vector() const { return false; }
72  virtual bool is_c64vector() const { return false; }
73 
74  friend void intrusive_ptr_add_ref(pmt_base* p);
75  friend void intrusive_ptr_release(pmt_base* p);
76 
77 # if (PMT_LOCAL_ALLOCATOR)
78  void *operator new(size_t);
79  void operator delete(void *, size_t);
80 #endif
81 };
82 
83 class pmt_bool : public pmt_base
84 {
85 public:
86  pmt_bool();
87  //~pmt_bool(){}
88 
89  bool is_bool() const { return true; }
90 };
91 
92 
93 class pmt_symbol : public pmt_base
94 {
95  std::string d_name;
96  pmt_t d_next;
97 
98 public:
99  pmt_symbol(const std::string &name);
100  //~pmt_symbol(){}
101 
102  bool is_symbol() const { return true; }
103  const std::string name() { return d_name; }
104 
105  pmt_t next() { return d_next; } // symbol table link
106  void set_next(pmt_t next) { d_next = next; }
107 };
108 
109 class pmt_integer : public pmt_base
110 {
111 public:
112  long d_value;
113 
114  pmt_integer(long value);
115  //~pmt_integer(){}
116 
117  bool is_number() const { return true; }
118  bool is_integer() const { return true; }
119  long value() const { return d_value; }
120 };
121 
122 class pmt_uint64 : public pmt_base
123 {
124 public:
126 
128  //~pmt_uint64(){}
129 
130  bool is_number() const { return true; }
131  bool is_uint64() const { return true; }
132  uint64_t value() const { return d_value; }
133 };
134 
135 class pmt_real : public pmt_base
136 {
137 public:
138  double d_value;
139 
140  pmt_real(double value);
141  //~pmt_real(){}
142 
143  bool is_number() const { return true; }
144  bool is_real() const { return true; }
145  double value() const { return d_value; }
146 };
147 
148 class pmt_complex : public pmt_base
149 {
150 public:
151  std::complex<double> d_value;
152 
153  pmt_complex(std::complex<double> value);
154  //~pmt_complex(){}
155 
156  bool is_number() const { return true; }
157  bool is_complex() const { return true; }
158  std::complex<double> value() const { return d_value; }
159 };
160 
161 class pmt_null : public pmt_base
162 {
163 public:
164  pmt_null();
165  //~pmt_null(){}
166 
167  bool is_null() const { return true; }
168 };
169 
170 class pmt_pair : public pmt_base
171 {
172 public:
175 
176  pmt_pair(const pmt_t& car, const pmt_t& cdr);
177  //~pmt_pair(){};
178 
179  bool is_pair() const { return true; }
180  pmt_t car() const { return d_car; }
181  pmt_t cdr() const { return d_cdr; }
182 
183  void set_car(pmt_t car) { d_car = car; }
184  void set_cdr(pmt_t cdr) { d_cdr = cdr; }
185 };
186 
187 class pmt_vector : public pmt_base
188 {
189  std::vector<pmt_t> d_v;
190 
191 public:
192  pmt_vector(size_t len, pmt_t fill);
193  //~pmt_vector();
194 
195  bool is_vector() const { return true; }
196  pmt_t ref(size_t k) const;
197  void set(size_t k, pmt_t obj);
198  void fill(pmt_t fill);
199  size_t length() const { return d_v.size(); }
200 
201  pmt_t _ref(size_t k) const { return d_v[k]; }
202 };
203 
204 class pmt_tuple : public pmt_base
205 {
206  std::vector<pmt_t> d_v;
207 
208 public:
209  pmt_tuple(size_t len);
210  //~pmt_tuple();
211 
212  bool is_tuple() const { return true; }
213  pmt_t ref(size_t k) const;
214  size_t length() const { return d_v.size(); }
215 
216  pmt_t _ref(size_t k) const { return d_v[k]; }
217  void _set(size_t k, pmt_t v) { d_v[k] = v; }
218 };
219 
220 class pmt_any : public pmt_base
221 {
222  boost::any d_any;
223 
224 public:
225  pmt_any(const boost::any &any);
226  //~pmt_any();
227 
228  bool is_any() const { return true; }
229  const boost::any &ref() const { return d_any; }
230  void set(const boost::any &any) { d_any = any; }
231 };
232 
233 
235 {
236 public:
237  bool is_uniform_vector() const { return true; }
238  virtual const void *uniform_elements(size_t &len) = 0;
239  virtual void *uniform_writable_elements(size_t &len) = 0;
240  virtual size_t length() const = 0;
241 };
242 
243 #include "pmt_unv_int.h"
244 
245 } /* namespace pmt */
246 
247 #endif /* INCLUDED_PMT_INT_H */
#define GRUEL_API
Definition: gruel/src/include/gruel/api.h:30
virtual bool is_s64vector() const
Definition: pmt_int.h:68
pmt_t car() const
Definition: pmt_int.h:180
virtual bool is_u8vector() const
Definition: pmt_int.h:61
size_t length() const
Definition: pmt_int.h:199
bool is_uint64() const
Definition: pmt_int.h:131
pmt_t _ref(size_t k) const
Definition: pmt_int.h:216
virtual bool is_any() const
Definition: pmt_int.h:58
bool is_tuple() const
Definition: pmt_int.h:212
pmt_tuple(size_t len)
pmt_t d_cdr
Definition: pmt_int.h:174
pmt_vector(size_t len, pmt_t fill)
pmt_t d_car
Definition: pmt_int.h:173
bool is_complex() const
Definition: pmt_int.h:157
uint64_t value() const
Definition: pmt_int.h:132
virtual bool is_uniform_vector() const
Definition: pmt_int.h:60
virtual void * uniform_writable_elements(size_t &len)=0
pmt_pair(const pmt_t &car, const pmt_t &cdr)
bool is_real() const
Definition: pmt_int.h:144
Definition: pmt_int.h:93
virtual bool is_s16vector() const
Definition: pmt_int.h:64
std::complex< double > value() const
Definition: pmt_int.h:158
void set_cdr(pmt_t cdr)
Definition: pmt_int.h:184
pmt_uint64(uint64_t value)
Definition: pmt_int.h:122
pmt_t next()
Definition: pmt_int.h:105
pmt_base()
Definition: pmt_int.h:42
pmt_complex(std::complex< double > value)
virtual bool is_bool() const
Definition: pmt_int.h:46
virtual bool is_uint64() const
Definition: pmt_int.h:50
double value() const
Definition: pmt_int.h:145
bool is_number() const
Definition: pmt_int.h:130
virtual bool is_dict() const
Definition: pmt_int.h:57
virtual bool is_s8vector() const
Definition: pmt_int.h:62
Definition: pmt_int.h:170
virtual bool is_f64vector() const
Definition: pmt_int.h:70
bool is_number() const
Definition: pmt_int.h:156
virtual bool is_real() const
Definition: pmt_int.h:51
virtual bool is_null() const
Definition: pmt_int.h:53
uint64_t d_value
Definition: pmt_int.h:125
virtual bool is_complex() const
Definition: pmt_int.h:52
bool is_integer() const
Definition: pmt_int.h:118
virtual bool is_u16vector() const
Definition: pmt_int.h:63
const boost::any & ref() const
Definition: pmt_int.h:229
pmt_t _ref(size_t k) const
Definition: pmt_int.h:201
pmt_t ref(size_t k) const
virtual bool is_s32vector() const
Definition: pmt_int.h:66
void set(const boost::any &any)
Definition: pmt_int.h:230
double d_value
Definition: pmt_int.h:138
std::complex< double > d_value
Definition: pmt_int.h:151
virtual size_t length() const =0
unsigned __int64 uint64_t
Definition: stdint.h:90
bool is_uniform_vector() const
Definition: pmt_int.h:237
virtual const void * uniform_elements(size_t &len)=0
void set_next(pmt_t next)
Definition: pmt_int.h:106
Definition: pmt_int.h:161
Definition: pmt_int.h:234
bool is_symbol() const
Definition: pmt_int.h:102
bool is_number() const
Definition: pmt_int.h:117
bool is_null() const
Definition: pmt_int.h:167
pmt_any(const boost::any &any)
virtual bool is_c64vector() const
Definition: pmt_int.h:72
void set(size_t k, pmt_t obj)
void fill(pmt_t fill)
virtual bool is_vector() const
Definition: pmt_int.h:56
virtual bool is_symbol() const
Definition: pmt_int.h:47
Definition: pmt_int.h:148
virtual bool is_u32vector() const
Definition: pmt_int.h:65
Definition: pmt_int.h:135
virtual bool is_f32vector() const
Definition: pmt_int.h:69
Definition: pmt_int.h:38
pmt_t ref(size_t k) const
Definition: pmt_int.h:83
virtual bool is_tuple() const
Definition: pmt_int.h:55
long value() const
Definition: pmt_int.h:119
Definition: pmt_int.h:109
pmt_t cdr() const
Definition: pmt_int.h:181
size_t length() const
Definition: pmt_int.h:214
bool is_bool() const
Definition: pmt_int.h:89
virtual bool is_u64vector() const
Definition: pmt_int.h:67
GRUEL_API void intrusive_ptr_release(pmt_base *)
bool is_vector() const
Definition: pmt_int.h:195
GRUEL_API void intrusive_ptr_add_ref(pmt_base *)
bool is_any() const
Definition: pmt_int.h:228
virtual bool is_pair() const
Definition: pmt_int.h:54
Definition: pmt_int.h:204
boost::intrusive_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
Definition: pmt.h:54
bool is_number() const
Definition: pmt_int.h:143
virtual bool is_number() const
Definition: pmt_int.h:48
Definition: pmt_int.h:220
pmt_symbol(const std::string &name)
pmt_integer(long value)
bool is_pair() const
Definition: pmt_int.h:179
virtual bool is_integer() const
Definition: pmt_int.h:49
void _set(size_t k, pmt_t v)
Definition: pmt_int.h:217
virtual bool is_c32vector() const
Definition: pmt_int.h:71
long d_value
Definition: pmt_int.h:112
const std::string name()
Definition: pmt_int.h:103
Definition: pmt_int.h:187
void set_car(pmt_t car)
Definition: pmt_int.h:183
pmt_real(double value)