Added most of the support for a new PMT type: tuple.
[debian/gnuradio] / gruel / src / lib / pmt / pmt_int.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006,2009 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
28 /*
29  * EVERYTHING IN THIS FILE IS PRIVATE TO THE IMPLEMENTATION!
30  *
31  * See pmt.h for the public interface
32  */
33
34 #define PMT_LOCAL_ALLOCATOR 0           // define to 0 or 1
35 namespace pmt {
36
37 class pmt_base : boost::noncopyable {
38 protected:
39   pmt_base(){};
40   virtual ~pmt_base();
41
42 public:
43   virtual bool is_bool()    const { return false; }
44   virtual bool is_symbol()  const { return false; }
45   virtual bool is_number()  const { return false; }
46   virtual bool is_integer() const { return false; }
47   virtual bool is_real()    const { return false; }
48   virtual bool is_complex() const { return false; }
49   virtual bool is_null()    const { return false; }
50   virtual bool is_pair()    const { return false; }
51   virtual bool is_tuple()   const { return false; }
52   virtual bool is_vector()  const { return false; }
53   virtual bool is_dict()    const { return false; }
54   virtual bool is_any()     const { return false; }
55
56   virtual bool is_uniform_vector() const { return false; }
57   virtual bool is_u8vector()  const { return false; }
58   virtual bool is_s8vector()  const { return false; }
59   virtual bool is_u16vector() const { return false; }
60   virtual bool is_s16vector() const { return false; }
61   virtual bool is_u32vector() const { return false; }
62   virtual bool is_s32vector() const { return false; }
63   virtual bool is_u64vector() const { return false; }
64   virtual bool is_s64vector() const { return false; }
65   virtual bool is_f32vector() const { return false; }
66   virtual bool is_f64vector() const { return false; }
67   virtual bool is_c32vector() const { return false; }
68   virtual bool is_c64vector() const { return false; }
69
70 # if (PMT_LOCAL_ALLOCATOR)
71   void *operator new(size_t);
72   void operator delete(void *, size_t);
73 #endif
74 };
75
76 class pmt_bool : public pmt_base
77 {
78 public:
79   pmt_bool();
80   //~pmt_bool(){}
81
82   bool is_bool() const { return true; }
83 };
84
85
86 class pmt_symbol : public pmt_base
87 {
88   std::string   d_name;
89   pmt_t         d_next;
90   
91 public:
92   pmt_symbol(const std::string &name);
93   //~pmt_symbol(){}
94
95   bool is_symbol() const { return true; }
96   const std::string name() { return d_name; }
97
98   pmt_t next() { return d_next; }               // symbol table link
99   void set_next(pmt_t next) { d_next = next; }
100 };
101
102 class pmt_integer : public pmt_base
103 {
104   long          d_value;
105
106 public:
107   pmt_integer(long value);
108   //~pmt_integer(){}
109
110   bool is_number()  const { return true; }
111   bool is_integer() const { return true; }
112   long value() const { return d_value; }
113 };
114
115 class pmt_real : public pmt_base
116 {
117   double        d_value;
118
119 public:
120   pmt_real(double value);
121   //~pmt_real(){}
122
123   bool is_number()  const { return true; }
124   bool is_real() const { return true; }
125   double value() const { return d_value; }
126 };
127
128 class pmt_complex : public pmt_base
129 {
130   std::complex<double>  d_value;
131
132 public:
133   pmt_complex(std::complex<double> value);
134   //~pmt_complex(){}
135
136   bool is_number()  const { return true; }
137   bool is_complex() const { return true; }
138   std::complex<double> value() const { return d_value; }
139 };
140
141 class pmt_null  : public pmt_base
142 {
143 public:
144   pmt_null();
145   //~pmt_null(){}
146
147   bool is_null() const { return true; }
148 };
149
150 class pmt_pair : public pmt_base
151 {
152   pmt_t         d_car;
153   pmt_t         d_cdr;
154
155 public:
156   pmt_pair(const pmt_t& car, const pmt_t& cdr);
157   //~pmt_pair(){};
158
159   bool is_pair() const { return true; }
160   pmt_t car() const { return d_car; }
161   pmt_t cdr() const { return d_cdr; }
162
163   void set_car(pmt_t car) { d_car = car; }
164   void set_cdr(pmt_t cdr) { d_cdr = cdr; }
165 };
166
167 class pmt_vector : public pmt_base
168 {
169   std::vector<pmt_t>    d_v;
170
171 public:
172   pmt_vector(size_t len, pmt_t fill);
173   //~pmt_vector();
174
175   bool is_vector() const { return true; }
176   pmt_t ref(size_t k) const;
177   void  set(size_t k, pmt_t obj);
178   void  fill(pmt_t fill);
179   size_t length() const { return d_v.size(); }
180
181   pmt_t _ref(size_t k) const { return d_v[k]; }
182 };
183
184 class pmt_tuple : public pmt_base
185 {
186   std::vector<pmt_t>    d_v;
187
188 public:
189   pmt_tuple(size_t len);
190   //~pmt_tuple();
191
192   bool is_tuple() const { return true; }
193   pmt_t ref(size_t k) const;
194   size_t length() const { return d_v.size(); }
195
196   pmt_t _ref(size_t k) const { return d_v[k]; }
197   void _set(size_t k, pmt_t v) { d_v[k] = v; }
198 };
199
200 class pmt_dict : public pmt_base
201 {
202   pmt_t         d_alist;        // list of (key . value) pairs
203
204 public:
205   pmt_dict();
206   //~pmt_dict();
207
208   bool  is_dict() const { return true; }
209   void  set(pmt_t key, pmt_t value);
210   pmt_t ref(pmt_t key, pmt_t default_value) const;
211   bool  has_key(pmt_t key) const;
212   pmt_t items() const;
213   pmt_t keys() const;
214   pmt_t values() const;
215 };
216
217 class pmt_any : public pmt_base
218 {
219   boost::any    d_any;
220
221 public:
222   pmt_any(const boost::any &any);
223   //~pmt_any();
224
225   bool is_any() const { return true; }
226   const boost::any &ref() const { return d_any; }
227   void  set(const boost::any &any) { d_any = any; }
228 };
229
230
231 class pmt_uniform_vector : public pmt_base
232 {
233 public:
234   bool is_uniform_vector() const { return true; }
235   virtual const void *uniform_elements(size_t &len) = 0;
236   virtual void *uniform_writable_elements(size_t &len) = 0;
237   virtual size_t length() const = 0;
238 };
239
240 #include "pmt_unv_int.h"
241
242 } /* namespace pmt */
243
244 #endif /* INCLUDED_PMT_INT_H */