GNU Radio 3.6.5 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 <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 GRUEL_API 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_uint64()  const { return false; }
00051   virtual bool is_real()    const { return false; }
00052   virtual bool is_complex() const { return false; }
00053   virtual bool is_null()    const { return false; }
00054   virtual bool is_pair()    const { return false; }
00055   virtual bool is_tuple()   const { return false; }
00056   virtual bool is_vector()  const { return false; }
00057   virtual bool is_dict()    const { return false; }
00058   virtual bool is_any()     const { return false; }
00059 
00060   virtual bool is_uniform_vector() const { return false; }
00061   virtual bool is_u8vector()  const { return false; }
00062   virtual bool is_s8vector()  const { return false; }
00063   virtual bool is_u16vector() const { return false; }
00064   virtual bool is_s16vector() const { return false; }
00065   virtual bool is_u32vector() const { return false; }
00066   virtual bool is_s32vector() const { return false; }
00067   virtual bool is_u64vector() const { return false; }
00068   virtual bool is_s64vector() const { return false; }
00069   virtual bool is_f32vector() const { return false; }
00070   virtual bool is_f64vector() const { return false; }
00071   virtual bool is_c32vector() const { return false; }
00072   virtual bool is_c64vector() const { return false; }
00073 
00074   friend void intrusive_ptr_add_ref(pmt_base* p);
00075   friend void intrusive_ptr_release(pmt_base* p);
00076 
00077 # if (PMT_LOCAL_ALLOCATOR)
00078   void *operator new(size_t);
00079   void operator delete(void *, size_t);
00080 #endif
00081 };
00082 
00083 class pmt_bool : public pmt_base
00084 {
00085 public:
00086   pmt_bool();
00087   //~pmt_bool(){}
00088 
00089   bool is_bool() const { return true; }
00090 };
00091 
00092 
00093 class pmt_symbol : public pmt_base
00094 {
00095   std::string   d_name;
00096   pmt_t         d_next;
00097 
00098 public:
00099   pmt_symbol(const std::string &name);
00100   //~pmt_symbol(){}
00101 
00102   bool is_symbol() const { return true; }
00103   const std::string name() { return d_name; }
00104 
00105   pmt_t next() { return d_next; }               // symbol table link
00106   void set_next(pmt_t next) { d_next = next; }
00107 };
00108 
00109 class pmt_integer : public pmt_base
00110 {
00111 public:
00112   long          d_value;
00113 
00114   pmt_integer(long value);
00115   //~pmt_integer(){}
00116 
00117   bool is_number()  const { return true; }
00118   bool is_integer() const { return true; }
00119   long value() const { return d_value; }
00120 };
00121 
00122 class pmt_uint64 : public pmt_base
00123 {
00124 public:
00125   uint64_t              d_value;
00126 
00127   pmt_uint64(uint64_t value);
00128   //~pmt_uint64(){}
00129 
00130   bool is_number()  const { return true; }
00131   bool is_uint64() const { return true; }
00132   uint64_t value() const { return d_value; }
00133 };
00134 
00135 class pmt_real : public pmt_base
00136 {
00137 public:
00138   double        d_value;
00139 
00140   pmt_real(double value);
00141   //~pmt_real(){}
00142 
00143   bool is_number()  const { return true; }
00144   bool is_real() const { return true; }
00145   double value() const { return d_value; }
00146 };
00147 
00148 class pmt_complex : public pmt_base
00149 {
00150 public:
00151   std::complex<double>  d_value;
00152 
00153   pmt_complex(std::complex<double> value);
00154   //~pmt_complex(){}
00155 
00156   bool is_number()  const { return true; }
00157   bool is_complex() const { return true; }
00158   std::complex<double> value() const { return d_value; }
00159 };
00160 
00161 class pmt_null  : public pmt_base
00162 {
00163 public:
00164   pmt_null();
00165   //~pmt_null(){}
00166 
00167   bool is_null() const { return true; }
00168 };
00169 
00170 class pmt_pair : public pmt_base
00171 {
00172 public:
00173   pmt_t         d_car;
00174   pmt_t         d_cdr;
00175 
00176   pmt_pair(const pmt_t& car, const pmt_t& cdr);
00177   //~pmt_pair(){};
00178 
00179   bool is_pair() const { return true; }
00180   pmt_t car() const { return d_car; }
00181   pmt_t cdr() const { return d_cdr; }
00182 
00183   void set_car(pmt_t car) { d_car = car; }
00184   void set_cdr(pmt_t cdr) { d_cdr = cdr; }
00185 };
00186 
00187 class pmt_vector : public pmt_base
00188 {
00189   std::vector<pmt_t>    d_v;
00190 
00191 public:
00192   pmt_vector(size_t len, pmt_t fill);
00193   //~pmt_vector();
00194 
00195   bool is_vector() const { return true; }
00196   pmt_t ref(size_t k) const;
00197   void  set(size_t k, pmt_t obj);
00198   void  fill(pmt_t fill);
00199   size_t length() const { return d_v.size(); }
00200 
00201   pmt_t _ref(size_t k) const { return d_v[k]; }
00202 };
00203 
00204 class pmt_tuple : public pmt_base
00205 {
00206   std::vector<pmt_t>    d_v;
00207 
00208 public:
00209   pmt_tuple(size_t len);
00210   //~pmt_tuple();
00211 
00212   bool is_tuple() const { return true; }
00213   pmt_t ref(size_t k) const;
00214   size_t length() const { return d_v.size(); }
00215 
00216   pmt_t _ref(size_t k) const { return d_v[k]; }
00217   void _set(size_t k, pmt_t v) { d_v[k] = v; }
00218 };
00219 
00220 class pmt_any : public pmt_base
00221 {
00222   boost::any    d_any;
00223 
00224 public:
00225   pmt_any(const boost::any &any);
00226   //~pmt_any();
00227 
00228   bool is_any() const { return true; }
00229   const boost::any &ref() const { return d_any; }
00230   void  set(const boost::any &any) { d_any = any; }
00231 };
00232 
00233 
00234 class pmt_uniform_vector : public pmt_base
00235 {
00236 public:
00237   bool is_uniform_vector() const { return true; }
00238   virtual const void *uniform_elements(size_t &len) = 0;
00239   virtual void *uniform_writable_elements(size_t &len) = 0;
00240   virtual size_t length() const = 0;
00241 };
00242 
00243 #include "pmt_unv_int.h"
00244 
00245 } /* namespace pmt */
00246 
00247 #endif /* INCLUDED_PMT_INT_H */