UHD  003.001.002
wax.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2010-2011 Ettus Research LLC
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef INCLUDED_WAX_HPP
19 #define INCLUDED_WAX_HPP
20 
21 #include <uhd/config.hpp>
22 #include <uhd/exception.hpp>
23 #include <boost/any.hpp>
24 #include <typeinfo>
25 #include <string>
26 
50 namespace wax{
51 
64  class UHD_API obj{
65  public:
66 
71  obj(void);
72 
78  obj(const obj &o);
79 
86  template<class T> obj(const T &o){
87  _contents = o;
88  }
89 
93  virtual ~obj(void);
94 
105  obj operator[](const obj &key);
106 
115  obj & operator=(const obj &val);
116 
124  obj get_link(void) const;
125 
130  const std::type_info & type(void) const;
131 
139  template<class T> T as(void) const{
140  try{
141  return boost::any_cast<T>(resolve());
142  }
143  catch(const boost::bad_any_cast &e){
144  throw uhd::type_error(std::string("") + "Cannot wax cast " + type().name() + " to " + typeid(T).name() + " " + e.what());
145  }
146  }
147 
148  private:
149  //private interface (override in subclasses)
150  virtual void get(const obj &, obj &);
151  virtual void set(const obj &, const obj &);
152 
160  boost::any resolve(void) const;
161 
162  //private contents of this obj
163  boost::any _contents;
164 
165  };
166 
167 } //namespace wax
168 
169 #endif /* INCLUDED_WAX_HPP */
T as(void) const
Definition: wax.hpp:139
#define UHD_API
Definition: config.hpp:76
Definition: wax.hpp:50
obj(const T &o)
Definition: wax.hpp:86
Definition: wax.hpp:64
Definition: exception.hpp:63