458443eafa78b4304910e291dac62feb9b7a66d1
[debian/gnuradio] / pmt / src / lib / pmt_int.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 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 2, 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 <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 class pmt_base : boost::noncopyable {
35 protected:
36   pmt_base(){};
37   virtual ~pmt_base();
38
39 public:
40   virtual bool is_bool()    const { return false; }
41   virtual bool is_symbol()  const { return false; }
42   virtual bool is_number()  const { return false; }
43   virtual bool is_integer() const { return false; }
44   virtual bool is_real()    const { return false; }
45   virtual bool is_complex() const { return false; }
46   virtual bool is_null()    const { return false; }
47   virtual bool is_pair()    const { return false; }
48   virtual bool is_vector()  const { return false; }
49   virtual bool is_dict()    const { return false; }
50
51   virtual bool is_uniform_vector() const { return false; }
52   virtual bool is_u8vector()  const { return false; }
53   virtual bool is_s8vector()  const { return false; }
54   virtual bool is_u16vector() const { return false; }
55   virtual bool is_s16vector() const { return false; }
56   virtual bool is_u32vector() const { return false; }
57   virtual bool is_s32vector() const { return false; }
58   virtual bool is_u64vector() const { return false; }
59   virtual bool is_s64vector() const { return false; }
60   virtual bool is_f32vector() const { return false; }
61   virtual bool is_f64vector() const { return false; }
62   virtual bool is_c32vector() const { return false; }
63   virtual bool is_c64vector() const { return false; }
64
65 };
66
67 class pmt_bool : public pmt_base
68 {
69 public:
70   pmt_bool();
71   //~pmt_bool(){}
72
73   bool is_bool() const { return true; }
74 };
75
76
77 class pmt_symbol : public pmt_base
78 {
79   std::string   d_name;
80   pmt_t         d_next;
81   
82 public:
83   pmt_symbol(const std::string &name);
84   //~pmt_symbol(){}
85
86   bool is_symbol() const { return true; }
87   const std::string name() { return d_name; }
88
89   pmt_t next() { return d_next; }               // symbol table link
90   void set_next(pmt_t next) { d_next = next; }
91 };
92
93 class pmt_integer : public pmt_base
94 {
95   long          d_value;
96
97 public:
98   pmt_integer(long value);
99   //~pmt_integer(){}
100
101   bool is_number()  const { return true; }
102   bool is_integer() const { return true; }
103   long value() const { return d_value; }
104 };
105
106 class pmt_real : public pmt_base
107 {
108   double        d_value;
109
110 public:
111   pmt_real(double value);
112   //~pmt_real(){}
113
114   bool is_number()  const { return true; }
115   bool is_real() const { return true; }
116   double value() const { return d_value; }
117 };
118
119 class pmt_complex : public pmt_base
120 {
121   std::complex<double>  d_value;
122
123 public:
124   pmt_complex(std::complex<double> value);
125   //~pmt_complex(){}
126
127   bool is_number()  const { return true; }
128   bool is_complex() const { return true; }
129   std::complex<double> value() const { return d_value; }
130 };
131
132 class pmt_null  : public pmt_base
133 {
134 public:
135   pmt_null();
136   //~pmt_null(){}
137
138   bool is_null() const { return true; }
139 };
140
141 class pmt_pair : public pmt_base
142 {
143   pmt_t         d_car;
144   pmt_t         d_cdr;
145
146 public:
147   pmt_pair(pmt_t car, pmt_t cdr);
148   //~pmt_pair(){};
149
150   bool is_pair() const { return true; }
151   pmt_t car() const { return d_car; }
152   pmt_t cdr() const { return d_cdr; }
153
154   void set_car(pmt_t car) { d_car = car; }
155   void set_cdr(pmt_t cdr) { d_cdr = cdr; }
156 };
157
158 class pmt_vector : public pmt_base
159 {
160   std::vector<pmt_t>    d_v;
161
162 public:
163   pmt_vector(size_t len, pmt_t fill);
164   //~pmt_vector();
165
166   bool is_vector() const { return true; }
167   pmt_t ref(size_t k) const;
168   void  set(size_t k, pmt_t obj);
169   void  fill(pmt_t fill);
170   size_t length() const { return d_v.size(); }
171
172   pmt_t _ref(size_t k) const { return d_v[k]; }
173 };
174
175 class pmt_dict : public pmt_base
176 {
177   pmt_t         d_alist;        // list of (key . value) pairs
178
179 public:
180   pmt_dict();
181   //~pmt_dict();
182
183   bool  is_dict() const { return true; }
184   void  set(pmt_t key, pmt_t value);
185   pmt_t ref(pmt_t key, pmt_t default_value) const;
186   bool  has_key(pmt_t key) const;
187   pmt_t items() const;
188   pmt_t keys() const;
189   pmt_t values() const;
190 };
191
192 class pmt_uniform_vector : public pmt_base
193 {
194 public:
195   bool is_uniform_vector() const { return true; }
196   virtual const void *uniform_elements(size_t &len) = 0;
197   virtual void *uniform_writeable_elements(size_t &len) = 0;
198   virtual size_t length() const = 0;
199 };
200
201 #include "pmt_unv_int.h"
202
203 #endif /* INCLUDED_PMT_INT_H */