00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2006,2009,2010 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 #ifndef INCLUDED_PMT_INT_H 00023 #define INCLUDED_PMT_INT_H 00024 00025 #include <gruel/pmt.h> 00026 #include <boost/utility.hpp> 00027 #include <boost/detail/atomic_count.hpp> 00028 00029 /* 00030 * EVERYTHING IN THIS FILE IS PRIVATE TO THE IMPLEMENTATION! 00031 * 00032 * See pmt.h for the public interface 00033 */ 00034 00035 #define PMT_LOCAL_ALLOCATOR 0 // define to 0 or 1 00036 namespace pmt { 00037 00038 class pmt_base : boost::noncopyable { 00039 mutable boost::detail::atomic_count count_; 00040 00041 protected: 00042 pmt_base() : count_(0) {}; 00043 virtual ~pmt_base(); 00044 00045 public: 00046 virtual bool is_bool() const { return false; } 00047 virtual bool is_symbol() const { return false; } 00048 virtual bool is_number() const { return false; } 00049 virtual bool is_integer() const { return false; } 00050 virtual bool is_real() const { return false; } 00051 virtual bool is_complex() const { return false; } 00052 virtual bool is_null() const { return false; } 00053 virtual bool is_pair() const { return false; } 00054 virtual bool is_tuple() const { return false; } 00055 virtual bool is_vector() const { return false; } 00056 virtual bool is_dict() const { return false; } 00057 virtual bool is_any() const { return false; } 00058 00059 virtual bool is_uniform_vector() const { return false; } 00060 virtual bool is_u8vector() const { return false; } 00061 virtual bool is_s8vector() const { return false; } 00062 virtual bool is_u16vector() const { return false; } 00063 virtual bool is_s16vector() const { return false; } 00064 virtual bool is_u32vector() const { return false; } 00065 virtual bool is_s32vector() const { return false; } 00066 virtual bool is_u64vector() const { return false; } 00067 virtual bool is_s64vector() const { return false; } 00068 virtual bool is_f32vector() const { return false; } 00069 virtual bool is_f64vector() const { return false; } 00070 virtual bool is_c32vector() const { return false; } 00071 virtual bool is_c64vector() const { return false; } 00072 00073 friend void intrusive_ptr_add_ref(pmt_base* p); 00074 friend void intrusive_ptr_release(pmt_base* p); 00075 00076 # if (PMT_LOCAL_ALLOCATOR) 00077 void *operator new(size_t); 00078 void operator delete(void *, size_t); 00079 #endif 00080 }; 00081 00082 class pmt_bool : public pmt_base 00083 { 00084 public: 00085 pmt_bool(); 00086 //~pmt_bool(){} 00087 00088 bool is_bool() const { return true; } 00089 }; 00090 00091 00092 class pmt_symbol : public pmt_base 00093 { 00094 std::string d_name; 00095 pmt_t d_next; 00096 00097 public: 00098 pmt_symbol(const std::string &name); 00099 //~pmt_symbol(){} 00100 00101 bool is_symbol() const { return true; } 00102 const std::string name() { return d_name; } 00103 00104 pmt_t next() { return d_next; } // symbol table link 00105 void set_next(pmt_t next) { d_next = next; } 00106 }; 00107 00108 class pmt_integer : public pmt_base 00109 { 00110 public: 00111 long d_value; 00112 00113 pmt_integer(long value); 00114 //~pmt_integer(){} 00115 00116 bool is_number() const { return true; } 00117 bool is_integer() const { return true; } 00118 long value() const { return d_value; } 00119 }; 00120 00121 class pmt_real : public pmt_base 00122 { 00123 public: 00124 double d_value; 00125 00126 pmt_real(double value); 00127 //~pmt_real(){} 00128 00129 bool is_number() const { return true; } 00130 bool is_real() const { return true; } 00131 double value() const { return d_value; } 00132 }; 00133 00134 class pmt_complex : public pmt_base 00135 { 00136 public: 00137 std::complex<double> d_value; 00138 00139 pmt_complex(std::complex<double> value); 00140 //~pmt_complex(){} 00141 00142 bool is_number() const { return true; } 00143 bool is_complex() const { return true; } 00144 std::complex<double> value() const { return d_value; } 00145 }; 00146 00147 class pmt_null : public pmt_base 00148 { 00149 public: 00150 pmt_null(); 00151 //~pmt_null(){} 00152 00153 bool is_null() const { return true; } 00154 }; 00155 00156 class pmt_pair : public pmt_base 00157 { 00158 public: 00159 pmt_t d_car; 00160 pmt_t d_cdr; 00161 00162 pmt_pair(const pmt_t& car, const pmt_t& cdr); 00163 //~pmt_pair(){}; 00164 00165 bool is_pair() const { return true; } 00166 pmt_t car() const { return d_car; } 00167 pmt_t cdr() const { return d_cdr; } 00168 00169 void set_car(pmt_t car) { d_car = car; } 00170 void set_cdr(pmt_t cdr) { d_cdr = cdr; } 00171 }; 00172 00173 class pmt_vector : public pmt_base 00174 { 00175 std::vector<pmt_t> d_v; 00176 00177 public: 00178 pmt_vector(size_t len, pmt_t fill); 00179 //~pmt_vector(); 00180 00181 bool is_vector() const { return true; } 00182 pmt_t ref(size_t k) const; 00183 void set(size_t k, pmt_t obj); 00184 void fill(pmt_t fill); 00185 size_t length() const { return d_v.size(); } 00186 00187 pmt_t _ref(size_t k) const { return d_v[k]; } 00188 }; 00189 00190 class pmt_tuple : public pmt_base 00191 { 00192 std::vector<pmt_t> d_v; 00193 00194 public: 00195 pmt_tuple(size_t len); 00196 //~pmt_tuple(); 00197 00198 bool is_tuple() const { return true; } 00199 pmt_t ref(size_t k) const; 00200 size_t length() const { return d_v.size(); } 00201 00202 pmt_t _ref(size_t k) const { return d_v[k]; } 00203 void _set(size_t k, pmt_t v) { d_v[k] = v; } 00204 }; 00205 00206 class pmt_any : public pmt_base 00207 { 00208 boost::any d_any; 00209 00210 public: 00211 pmt_any(const boost::any &any); 00212 //~pmt_any(); 00213 00214 bool is_any() const { return true; } 00215 const boost::any &ref() const { return d_any; } 00216 void set(const boost::any &any) { d_any = any; } 00217 }; 00218 00219 00220 class pmt_uniform_vector : public pmt_base 00221 { 00222 public: 00223 bool is_uniform_vector() const { return true; } 00224 virtual const void *uniform_elements(size_t &len) = 0; 00225 virtual void *uniform_writable_elements(size_t &len) = 0; 00226 virtual size_t length() const = 0; 00227 }; 00228 00229 #include "pmt_unv_int.h" 00230 00231 } /* namespace pmt */ 00232 00233 #endif /* INCLUDED_PMT_INT_H */