UHD 003.002.003
|
00001 // 00002 // Copyright 2010-2011 Ettus Research LLC 00003 // 00004 // This program is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #ifndef INCLUDED_WAX_HPP 00019 #define INCLUDED_WAX_HPP 00020 00021 #include <uhd/config.hpp> 00022 #include <uhd/exception.hpp> 00023 #include <boost/any.hpp> 00024 #include <typeinfo> 00025 #include <string> 00026 00050 namespace wax{ 00051 00064 class UHD_API obj{ 00065 public: 00066 00071 obj(void); 00072 00078 obj(const obj &o); 00079 00086 template<class T> obj(const T &o){ 00087 _contents = o; 00088 } 00089 00093 virtual ~obj(void); 00094 00105 obj operator[](const obj &key); 00106 00115 obj & operator=(const obj &val); 00116 00124 obj get_link(void) const; 00125 00130 const std::type_info & type(void) const; 00131 00139 template<class T> T as(void) const{ 00140 try{ 00141 return boost::any_cast<T>(resolve()); 00142 } 00143 catch(const boost::bad_any_cast &e){ 00144 throw uhd::type_error(std::string("") + "Cannot wax cast " + type().name() + " to " + typeid(T).name() + " " + e.what()); 00145 } 00146 } 00147 00148 private: 00149 //private interface (override in subclasses) 00150 virtual void get(const obj &, obj &); 00151 virtual void set(const obj &, const obj &); 00152 00160 boost::any resolve(void) const; 00161 00162 //private contents of this obj 00163 boost::any _contents; 00164 00165 }; 00166 00167 } //namespace wax 00168 00169 #endif /* INCLUDED_WAX_HPP */