GNU Radio v3.5.2.1-32-g7e3f4b84 C++ API
pmt_int.h
Go to the documentation of this file.
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 <gruel/thread.h>
00027 #include <boost/utility.hpp>
00028 #include <boost/shared_array.hpp>
00029 #include <boost/detail/atomic_count.hpp>
00030 #include <boost/function.hpp>
00031 #include <queue>
00032 
00033 /*
00034  * EVERYTHING IN THIS FILE IS PRIVATE TO THE IMPLEMENTATION!
00035  *
00036  * See pmt.h for the public interface
00037  */
00038 
00039 #define PMT_LOCAL_ALLOCATOR 0           // define to 0 or 1
00040 namespace pmt {
00041 
00042 class GRUEL_API pmt_base : boost::noncopyable {
00043 public:
00044   mutable boost::detail::atomic_count count_;
00045 
00046   static void default_deleter(pmt_base *p){
00047     delete p;
00048   }
00049 
00050   boost::function<void(pmt_base *)> deleter_;
00051 
00052 protected:
00053   pmt_base() : count_(0), deleter_(&pmt::pmt_base::default_deleter) {};
00054   virtual ~pmt_base();
00055 
00056 public:
00057   virtual bool is_bool()    const { return false; }
00058   virtual bool is_symbol()  const { return false; }
00059   virtual bool is_number()  const { return false; }
00060   virtual bool is_integer() const { return false; }
00061   virtual bool is_uint64()  const { return false; }
00062   virtual bool is_real()    const { return false; }
00063   virtual bool is_complex() const { return false; }
00064   virtual bool is_null()    const { return false; }
00065   virtual bool is_pair()    const { return false; }
00066   virtual bool is_tuple()   const { return false; }
00067   virtual bool is_vector()  const { return false; }
00068   virtual bool is_dict()    const { return false; }
00069   virtual bool is_any()     const { return false; }
00070   virtual bool is_blob()    const { return false; }
00071   virtual bool is_mgr()     const { return false; }
00072 
00073   virtual bool is_uniform_vector() const { return false; }
00074   virtual bool is_u8vector()  const { return false; }
00075   virtual bool is_s8vector()  const { return false; }
00076   virtual bool is_u16vector() const { return false; }
00077   virtual bool is_s16vector() const { return false; }
00078   virtual bool is_u32vector() const { return false; }
00079   virtual bool is_s32vector() const { return false; }
00080   virtual bool is_u64vector() const { return false; }
00081   virtual bool is_s64vector() const { return false; }
00082   virtual bool is_f32vector() const { return false; }
00083   virtual bool is_f64vector() const { return false; }
00084   virtual bool is_c32vector() const { return false; }
00085   virtual bool is_c64vector() const { return false; }
00086 
00087   friend void intrusive_ptr_add_ref(pmt_base* p);
00088   friend void intrusive_ptr_release(pmt_base* p);
00089 
00090 # if (PMT_LOCAL_ALLOCATOR)
00091   void *operator new(size_t);
00092   void operator delete(void *, size_t);
00093 #endif
00094 };
00095 
00096 class pmt_bool : public pmt_base
00097 {
00098 public:
00099   pmt_bool();
00100   //~pmt_bool(){}
00101 
00102   bool is_bool() const { return true; }
00103 };
00104 
00105 
00106 class pmt_symbol : public pmt_base
00107 {
00108   std::string   d_name;
00109   pmt_t         d_next;
00110   
00111 public:
00112   pmt_symbol(const std::string &name);
00113   //~pmt_symbol(){}
00114 
00115   bool is_symbol() const { return true; }
00116   const std::string name() { return d_name; }
00117 
00118   pmt_t next() { return d_next; }               // symbol table link
00119   void set_next(pmt_t next) { d_next = next; }
00120 };
00121 
00122 class pmt_integer : public pmt_base
00123 {
00124 public:
00125   long          d_value;
00126 
00127   pmt_integer(long value);
00128   //~pmt_integer(){}
00129 
00130   bool is_number()  const { return true; }
00131   bool is_integer() const { return true; }
00132   long value() const { return d_value; }
00133 };
00134 
00135 class pmt_uint64 : public pmt_base
00136 {
00137 public:
00138   uint64_t              d_value;
00139 
00140   pmt_uint64(uint64_t value);
00141   //~pmt_uint64(){}
00142 
00143   bool is_number()  const { return true; }
00144   bool is_uint64() const { return true; }
00145   uint64_t value() const { return d_value; }
00146 };
00147 
00148 class pmt_real : public pmt_base
00149 {
00150 public:
00151   double        d_value;
00152 
00153   pmt_real(double value);
00154   //~pmt_real(){}
00155 
00156   bool is_number()  const { return true; }
00157   bool is_real() const { return true; }
00158   double value() const { return d_value; }
00159 };
00160 
00161 class pmt_complex : public pmt_base
00162 {
00163 public:
00164   std::complex<double>  d_value;
00165 
00166   pmt_complex(std::complex<double> value);
00167   //~pmt_complex(){}
00168 
00169   bool is_number()  const { return true; }
00170   bool is_complex() const { return true; }
00171   std::complex<double> value() const { return d_value; }
00172 };
00173 
00174 class pmt_null  : public pmt_base
00175 {
00176 public:
00177   pmt_null();
00178   //~pmt_null(){}
00179 
00180   bool is_null() const { return true; }
00181 };
00182 
00183 class pmt_pair : public pmt_base
00184 {
00185 public:
00186   pmt_t         d_car;
00187   pmt_t         d_cdr;
00188 
00189   pmt_pair(const pmt_t& car, const pmt_t& cdr);
00190   //~pmt_pair(){};
00191 
00192   bool is_pair() const { return true; }
00193   pmt_t car() const { return d_car; }
00194   pmt_t cdr() const { return d_cdr; }
00195 
00196   void set_car(pmt_t car) { d_car = car; }
00197   void set_cdr(pmt_t cdr) { d_cdr = cdr; }
00198 };
00199 
00200 class pmt_vector : public pmt_base
00201 {
00202   std::vector<pmt_t>    d_v;
00203 
00204 public:
00205   pmt_vector(size_t len, pmt_t fill);
00206   //~pmt_vector();
00207 
00208   bool is_vector() const { return true; }
00209   pmt_t ref(size_t k) const;
00210   void  set(size_t k, pmt_t obj);
00211   void  fill(pmt_t fill);
00212   size_t length() const { return d_v.size(); }
00213 
00214   pmt_t _ref(size_t k) const { return d_v[k]; }
00215 };
00216 
00217 class pmt_tuple : public pmt_base
00218 {
00219   std::vector<pmt_t>    d_v;
00220 
00221 public:
00222   pmt_tuple(size_t len);
00223   //~pmt_tuple();
00224 
00225   bool is_tuple() const { return true; }
00226   pmt_t ref(size_t k) const;
00227   size_t length() const { return d_v.size(); }
00228 
00229   pmt_t _ref(size_t k) const { return d_v[k]; }
00230   void _set(size_t k, pmt_t v) { d_v[k] = v; }
00231 };
00232 
00233 class pmt_any : public pmt_base
00234 {
00235   boost::any    d_any;
00236 
00237 public:
00238   pmt_any(const boost::any &any);
00239   //~pmt_any();
00240 
00241   bool is_any() const { return true; }
00242   const boost::any &ref() const { return d_any; }
00243   void  set(const boost::any &any) { d_any = any; }
00244 };
00245 
00246 class pmt_blob : public pmt_base
00247 {
00248 
00249 public:
00250   typedef boost::shared_array<char> shart;
00251   pmt_blob(const void *, void *, size_t, shart);
00252   //~pmt_blob();
00253 
00254   const void *romem;
00255   void *rwmem;
00256   size_t len;
00257   shart shar;
00258 
00259   bool is_blob() const { return true; }
00260 };
00261 
00262 class pmt_mgr : public pmt_base
00263 {
00264 
00265 public:
00266   pmt_mgr(void);
00267   ~pmt_mgr();
00268 
00269   class mgr_guts;
00270   typedef boost::shared_ptr<mgr_guts> guts_sptr;
00271   guts_sptr guts;
00272 
00273   bool is_mgr() const { return true; }
00274 };
00275 
00276 class pmt_uniform_vector : public pmt_base
00277 {
00278 public:
00279   bool is_uniform_vector() const { return true; }
00280   virtual const void *uniform_elements(size_t &len) = 0;
00281   virtual void *uniform_writable_elements(size_t &len) = 0;
00282   virtual size_t length() const = 0;
00283 };
00284 
00285 #include "pmt_unv_int.h"
00286 
00287 } /* namespace pmt */
00288 
00289 #endif /* INCLUDED_PMT_INT_H */