Applied patch c1258.diff from Stephan Bruns (ticket:359)
[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 #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 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_real()    const { return false; }
51   virtual bool is_complex() const { return false; }
52   virtual bool is_null()    const { return false; }
53   virtual bool is_pair()    const { return false; }
54   virtual bool is_vector()  const { return false; }
55   virtual bool is_dict()    const { return false; }
56   virtual bool is_any()     const { return false; }
57
58   virtual bool is_uniform_vector() const { return false; }
59   virtual bool is_u8vector()  const { return false; }
60   virtual bool is_s8vector()  const { return false; }
61   virtual bool is_u16vector() const { return false; }
62   virtual bool is_s16vector() const { return false; }
63   virtual bool is_u32vector() const { return false; }
64   virtual bool is_s32vector() const { return false; }
65   virtual bool is_u64vector() const { return false; }
66   virtual bool is_s64vector() const { return false; }
67   virtual bool is_f32vector() const { return false; }
68   virtual bool is_f64vector() const { return false; }
69   virtual bool is_c32vector() const { return false; }
70   virtual bool is_c64vector() const { return false; }
71
72   friend void intrusive_ptr_add_ref(pmt_base* p);
73   friend void intrusive_ptr_release(pmt_base* p);
74
75 # if (PMT_LOCAL_ALLOCATOR)
76   void *operator new(size_t);
77   void operator delete(void *, size_t);
78 #endif
79 };
80
81 class pmt_bool : public pmt_base
82 {
83 public:
84   pmt_bool();
85   //~pmt_bool(){}
86
87   bool is_bool() const { return true; }
88 };
89
90
91 class pmt_symbol : public pmt_base
92 {
93   std::string   d_name;
94   pmt_t         d_next;
95   
96 public:
97   pmt_symbol(const std::string &name);
98   //~pmt_symbol(){}
99
100   bool is_symbol() const { return true; }
101   const std::string name() { return d_name; }
102
103   pmt_t next() { return d_next; }               // symbol table link
104   void set_next(pmt_t next) { d_next = next; }
105 };
106
107 class pmt_integer : public pmt_base
108 {
109   long          d_value;
110
111 public:
112   pmt_integer(long value);
113   //~pmt_integer(){}
114
115   bool is_number()  const { return true; }
116   bool is_integer() const { return true; }
117   long value() const { return d_value; }
118 };
119
120 class pmt_real : public pmt_base
121 {
122   double        d_value;
123
124 public:
125   pmt_real(double value);
126   //~pmt_real(){}
127
128   bool is_number()  const { return true; }
129   bool is_real() const { return true; }
130   double value() const { return d_value; }
131 };
132
133 class pmt_complex : public pmt_base
134 {
135   std::complex<double>  d_value;
136
137 public:
138   pmt_complex(std::complex<double> value);
139   //~pmt_complex(){}
140
141   bool is_number()  const { return true; }
142   bool is_complex() const { return true; }
143   std::complex<double> value() const { return d_value; }
144 };
145
146 class pmt_null  : public pmt_base
147 {
148 public:
149   pmt_null();
150   //~pmt_null(){}
151
152   bool is_null() const { return true; }
153 };
154
155 class pmt_pair : public pmt_base
156 {
157   pmt_t         d_car;
158   pmt_t         d_cdr;
159
160 public:
161   pmt_pair(const pmt_t& car, const pmt_t& cdr);
162   //~pmt_pair(){};
163
164   bool is_pair() const { return true; }
165   pmt_t car() const { return d_car; }
166   pmt_t cdr() const { return d_cdr; }
167
168   void set_car(pmt_t car) { d_car = car; }
169   void set_cdr(pmt_t cdr) { d_cdr = cdr; }
170 };
171
172 class pmt_vector : public pmt_base
173 {
174   std::vector<pmt_t>    d_v;
175
176 public:
177   pmt_vector(size_t len, pmt_t fill);
178   //~pmt_vector();
179
180   bool is_vector() const { return true; }
181   pmt_t ref(size_t k) const;
182   void  set(size_t k, pmt_t obj);
183   void  fill(pmt_t fill);
184   size_t length() const { return d_v.size(); }
185
186   pmt_t _ref(size_t k) const { return d_v[k]; }
187 };
188
189 class pmt_dict : public pmt_base
190 {
191   pmt_t         d_alist;        // list of (key . value) pairs
192
193 public:
194   pmt_dict();
195   //~pmt_dict();
196
197   bool  is_dict() const { return true; }
198   void  set(pmt_t key, pmt_t value);
199   pmt_t ref(pmt_t key, pmt_t default_value) const;
200   bool  has_key(pmt_t key) const;
201   pmt_t items() const;
202   pmt_t keys() const;
203   pmt_t values() const;
204 };
205
206 class pmt_any : public pmt_base
207 {
208   boost::any    d_any;
209
210 public:
211   pmt_any(const boost::any &any);
212   //~pmt_any();
213
214   bool is_any() const { return true; }
215   const boost::any &ref() const { return d_any; }
216   void  set(const boost::any &any) { d_any = any; }
217 };
218
219
220 class pmt_uniform_vector : public pmt_base
221 {
222 public:
223   bool is_uniform_vector() const { return true; }
224   virtual const void *uniform_elements(size_t &len) = 0;
225   virtual void *uniform_writable_elements(size_t &len) = 0;
226   virtual size_t length() const = 0;
227 };
228
229 #include "pmt_unv_int.h"
230
231 } /* namespace pmt */
232
233 #endif /* INCLUDED_PMT_INT_H */