mirror of
https://github.com/EttusResearch/uhd.git
synced 2026-10-25 17:36:10 +00:00
uhd: removed wax and props utils
This commit is contained in:
parent
9d4350d74e
commit
902818f50b
@ -32,7 +32,6 @@ INSTALL(FILES
|
||||
property_tree.hpp
|
||||
stream.hpp
|
||||
version.hpp
|
||||
wax.hpp
|
||||
DESTINATION ${INCLUDE_DIR}/uhd
|
||||
COMPONENT headers
|
||||
)
|
||||
|
||||
@ -2,176 +2,6 @@
|
||||
//-- deprecated interfaces below, to be removed when the API is changed
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
//
|
||||
// Copyright 2010-2011 Ettus Research LLC
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef INCLUDED_WAX_HPP
|
||||
#define INCLUDED_WAX_HPP
|
||||
|
||||
#include <uhd/config.hpp>
|
||||
#include <uhd/exception.hpp>
|
||||
#include <boost/any.hpp>
|
||||
#include <typeinfo>
|
||||
#include <string>
|
||||
|
||||
/*!
|
||||
* WAX - it's a metaphor!
|
||||
*
|
||||
* The WAX framework allows an object to have generic/anyobj properties.
|
||||
* These properties can be addressed through generic/anyobj identifiers.
|
||||
*
|
||||
* The WAX object itself is an anytype container much like boost::any.
|
||||
* To retrieve the value of the appropriate type, use my_obj.as<type>().
|
||||
*
|
||||
* Proprties may be referenced though the [] overloaded operator.
|
||||
* The [] operator returns a special proxy that allows for assigment.
|
||||
* Also, the [] operators may be chained as in the folowing examples:
|
||||
* my_obj[prop1][prop2][prop3] = value;
|
||||
* value = my_obj[prop1][prop2][prop3].as<type>();
|
||||
*
|
||||
* Property nesting occurs when a WAX object gets another object's link.
|
||||
* This special link is obtained through a call to my_obj.get_link().
|
||||
*
|
||||
* Note: Do not put a class derived from wax::obj into an stl container.
|
||||
* MSVC will compile the code, but the binaries will crash at runtime.
|
||||
* Rather, use pointers or smart pointers to instances of the derived class.
|
||||
*/
|
||||
|
||||
namespace wax{
|
||||
|
||||
/*!
|
||||
* WAX object base class:
|
||||
*
|
||||
* A wax obj has two major purposes:
|
||||
* 1) to act as a polymorphic container, just like boost any
|
||||
* 2) to provide a nested set/get properties interface
|
||||
*
|
||||
* Internally, the polymorphic container is handled by a boost any.
|
||||
* For properties, a subclass should override the set and get methods.
|
||||
* For property nesting, wax obj subclasses return special links
|
||||
* to other wax obj subclasses, and the api handles the magic.
|
||||
*/
|
||||
class UHD_API obj{
|
||||
public:
|
||||
|
||||
/*!
|
||||
* Default constructor:
|
||||
* The contents will be empty.
|
||||
*/
|
||||
obj(void);
|
||||
|
||||
/*!
|
||||
* Copy constructor:
|
||||
* The contents will be cloned.
|
||||
* \param o another wax::obj
|
||||
*/
|
||||
obj(const obj &o);
|
||||
|
||||
/*!
|
||||
* Templated any type constructor:
|
||||
* The contents can be anything.
|
||||
* Uses the boost::any to handle the magic.
|
||||
* \param o an object of any type
|
||||
*/
|
||||
template<class T> obj(const T &o){
|
||||
_contents = o;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~obj(void);
|
||||
|
||||
/*!
|
||||
* The chaining operator:
|
||||
* This operator allows access objs with properties.
|
||||
* A call to the [] operator will return a new proxy obj.
|
||||
* The proxy object is an obj with special proxy contents.
|
||||
* Assignment and casting can be used on this special object
|
||||
* to access the property referenced by the obj key.
|
||||
* \param key a key to identify a property within this obj
|
||||
* \return a special wax obj that proxies the obj and key
|
||||
*/
|
||||
obj operator[](const obj &key);
|
||||
|
||||
/*!
|
||||
* The assignment operator:
|
||||
* This operator allows for assignment of new contents.
|
||||
* In the special case where this obj contains a proxy,
|
||||
* the value will be set to the proxy's property reference.
|
||||
* \param val the new value to assign to the wax obj
|
||||
* \return a reference to this obj (*this)
|
||||
*/
|
||||
obj & operator=(const obj &val);
|
||||
|
||||
/*!
|
||||
* Get a link in the chain:
|
||||
* When a wax obj returns another wax obj as part of a get call,
|
||||
* the return value should be set to the result of this method.
|
||||
* Doing so will ensure chain-ability of the returned object.
|
||||
* \return an obj containing a valid link to a wax obj
|
||||
*/
|
||||
obj get_link(void) const;
|
||||
|
||||
/*!
|
||||
* Get the type of the contents of this obj.
|
||||
* \return a reference to the type_info
|
||||
*/
|
||||
const std::type_info & type(void) const;
|
||||
|
||||
/*!
|
||||
* Cast this obj into the desired type.
|
||||
* Usage: myobj.as<type>()
|
||||
*
|
||||
* \return an object of the desired type
|
||||
* \throw wax::bad_cast when the cast fails
|
||||
*/
|
||||
template<class T> T as(void) const{
|
||||
try{
|
||||
return boost::any_cast<T>(resolve());
|
||||
}
|
||||
catch(const boost::bad_any_cast &e){
|
||||
throw uhd::type_error(std::string("") + "Cannot wax cast " + type().name() + " to " + typeid(T).name() + " " + e.what());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
//private interface (override in subclasses)
|
||||
virtual void get(const obj &, obj &);
|
||||
virtual void set(const obj &, const obj &);
|
||||
|
||||
/*!
|
||||
* Resolve the contents of this obj.
|
||||
* In the case where this obj is a proxy,
|
||||
* the referenced property will be resolved.
|
||||
* Otherwise, just get the private contents.
|
||||
* \return a boost any type with contents
|
||||
*/
|
||||
boost::any resolve(void) const;
|
||||
|
||||
//private contents of this obj
|
||||
boost::any _contents;
|
||||
|
||||
};
|
||||
|
||||
} //namespace wax
|
||||
|
||||
#endif /* INCLUDED_WAX_HPP */
|
||||
|
||||
//
|
||||
// Copyright 2010 Ettus Research LLC
|
||||
//
|
||||
|
||||
@ -26,7 +26,6 @@ INSTALL(FILES
|
||||
log.hpp
|
||||
msg.hpp
|
||||
pimpl.hpp
|
||||
props.hpp
|
||||
safe_call.hpp
|
||||
safe_main.hpp
|
||||
static.hpp
|
||||
|
||||
@ -1,81 +0,0 @@
|
||||
//
|
||||
// Copyright 2010-2011 Ettus Research LLC
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef INCLUDED_UHD_UTILS_PROPS_HPP
|
||||
#define INCLUDED_UHD_UTILS_PROPS_HPP
|
||||
|
||||
#include <uhd/config.hpp>
|
||||
#include <uhd/wax.hpp>
|
||||
#include <uhd/exception.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace uhd{
|
||||
|
||||
//! The type for a vector of property names
|
||||
typedef std::vector<std::string> prop_names_t;
|
||||
|
||||
/*!
|
||||
* A named prop struct holds a key and a name.
|
||||
* Allows properties to be sub-sectioned by name.
|
||||
*/
|
||||
struct UHD_API named_prop_t{
|
||||
const wax::obj key;
|
||||
const std::string name;
|
||||
|
||||
//! Convert the key to the specified type
|
||||
template<typename T> inline T as(void){
|
||||
return key.as<T>();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Utility function to convert generic key into a named prop.
|
||||
* If the key was already a named prop, the prop will be split.
|
||||
* Otherwise, the key will be the key, and the name will be used.
|
||||
* \param key a reference to the prop object
|
||||
* \param name a reference to the name object
|
||||
* \return a named property struct with key and name
|
||||
*/
|
||||
static named_prop_t extract(
|
||||
const wax::obj &key, const std::string &name = ""
|
||||
);
|
||||
|
||||
/*!
|
||||
* Create a new named prop from key and name.
|
||||
* \param key the property key
|
||||
* \param name the string name
|
||||
*/
|
||||
named_prop_t(const wax::obj &key, const std::string &name);
|
||||
};
|
||||
|
||||
/*!
|
||||
* Throw when getting a not-implemented or write-only property.
|
||||
* Throw-site information will be included with this error.
|
||||
*/
|
||||
#define UHD_THROW_PROP_GET_ERROR() \
|
||||
throw uhd::key_error(UHD_THROW_SITE_INFO("cannot get this property"))
|
||||
|
||||
/*!
|
||||
* Throw when setting a not-implemented or read-only property.
|
||||
* Throw-site information will be included with this error.
|
||||
*/
|
||||
#define UHD_THROW_PROP_SET_ERROR() \
|
||||
throw uhd::key_error(UHD_THROW_SITE_INFO("cannot set this property"))
|
||||
|
||||
} //namespace uhd
|
||||
|
||||
#endif /* INCLUDED_UHD_UTILS_PROPS_HPP */
|
||||
@ -1,2 +0,0 @@
|
||||
//The wax API has been deprecated in favor of the properties interface
|
||||
#include <uhd/deprecated.hpp>
|
||||
@ -2,158 +2,6 @@
|
||||
//-- deprecated interfaces below, to be removed when the API is changed
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
//
|
||||
// Copyright 2010-2011 Ettus Research LLC
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include <uhd/wax.hpp>
|
||||
#include <uhd/exception.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
/*!
|
||||
* The link args for internal use within this cpp file:
|
||||
*
|
||||
* It contains a link (in this case a pointer) to a wax object.
|
||||
* Only the methods in this file may create or parse link args.
|
||||
* The get_link method is the creator of a link args object.
|
||||
* The [] operator will resolve the link and make the [] call.
|
||||
*
|
||||
* TODO: register the link args with the wax obj that it links to.
|
||||
* That way, if the obj destructs, the link can be invalidated.
|
||||
* The operator() will throw, rather than dereferencing bad memory.
|
||||
*/
|
||||
class link_args_t{
|
||||
public:
|
||||
link_args_t(const wax::obj *obj_ptr) : _obj_ptr(obj_ptr){
|
||||
/* NOP */
|
||||
}
|
||||
wax::obj & operator()(void) const{
|
||||
//recursively resolve link args to get at original pointer
|
||||
if (_obj_ptr->type() == typeid(link_args_t)){
|
||||
return _obj_ptr->as<link_args_t>()();
|
||||
}
|
||||
return *const_cast<wax::obj *>(_obj_ptr);
|
||||
}
|
||||
private:
|
||||
const wax::obj *_obj_ptr;
|
||||
};
|
||||
|
||||
/*!
|
||||
* The proxy args for internal use within this cpp file:
|
||||
*
|
||||
* It contains a link and a key for setting/getting a property.
|
||||
* Only the methods in this file may create or parse proxy args.
|
||||
* Class methods have special handling for the case when the
|
||||
* wax obj contains an instance of the proxy args.
|
||||
*/
|
||||
class proxy_args_t{
|
||||
public:
|
||||
proxy_args_t(const wax::obj *obj_ptr, const wax::obj &key) : _key(key){
|
||||
_obj_link = obj_ptr->get_link();
|
||||
}
|
||||
wax::obj & operator()(void) const{
|
||||
return _obj_link.as<link_args_t>()();
|
||||
}
|
||||
const wax::obj & key(void) const{
|
||||
return _key;
|
||||
}
|
||||
private:
|
||||
wax::obj _obj_link;
|
||||
const wax::obj _key;
|
||||
};
|
||||
|
||||
/***********************************************************************
|
||||
* Structors
|
||||
**********************************************************************/
|
||||
wax::obj::obj(void){
|
||||
/* NOP */
|
||||
}
|
||||
|
||||
wax::obj::obj(const obj &o){
|
||||
_contents = o._contents;
|
||||
}
|
||||
|
||||
wax::obj::~obj(void){
|
||||
/* NOP */
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Special Operators
|
||||
**********************************************************************/
|
||||
wax::obj wax::obj::operator[](const obj &key){
|
||||
if (_contents.type() == typeid(proxy_args_t)){
|
||||
obj val = resolve();
|
||||
//check if its a special link and call
|
||||
if (val.type() == typeid(link_args_t)){
|
||||
return val.as<link_args_t>()()[key];
|
||||
}
|
||||
//unknown obj
|
||||
throw uhd::type_error("cannot use [] on non wax::obj link");
|
||||
}
|
||||
else{
|
||||
return proxy_args_t(this, key);
|
||||
}
|
||||
}
|
||||
|
||||
wax::obj & wax::obj::operator=(const obj &val){
|
||||
if (_contents.type() == typeid(proxy_args_t)){
|
||||
proxy_args_t proxy_args = boost::any_cast<proxy_args_t>(_contents);
|
||||
proxy_args().set(proxy_args.key(), val);
|
||||
}
|
||||
else{
|
||||
_contents = val._contents;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Public Methods
|
||||
**********************************************************************/
|
||||
wax::obj wax::obj::get_link(void) const{
|
||||
return link_args_t(this);
|
||||
}
|
||||
|
||||
const std::type_info & wax::obj::type(void) const{
|
||||
return resolve().type();
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Private Methods
|
||||
**********************************************************************/
|
||||
boost::any wax::obj::resolve(void) const{
|
||||
if (_contents.type() == typeid(proxy_args_t)){
|
||||
obj val;
|
||||
proxy_args_t proxy_args = boost::any_cast<proxy_args_t>(_contents);
|
||||
proxy_args().get(proxy_args.key(), val);
|
||||
return val.resolve();
|
||||
}
|
||||
else{
|
||||
return _contents;
|
||||
}
|
||||
}
|
||||
|
||||
void wax::obj::get(const obj &, obj &){
|
||||
throw uhd::type_error("Cannot call get on wax obj base class");
|
||||
}
|
||||
|
||||
void wax::obj::set(const obj &, const obj &){
|
||||
throw uhd::type_error("Cannot call set on wax obj base class");
|
||||
}
|
||||
|
||||
#include <uhd/types/otw_type.hpp>
|
||||
#include <uhd/types/io_type.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
@ -69,7 +69,6 @@
|
||||
#include <uhd/types/ranges.hpp>
|
||||
#include <uhd/types/sensors.hpp>
|
||||
#include <uhd/utils/log.hpp>
|
||||
#include <uhd/utils/props.hpp>
|
||||
#include <uhd/utils/static.hpp>
|
||||
#include <uhd/usrp/dboard_base.hpp>
|
||||
#include <boost/assign/list_of.hpp>
|
||||
|
||||
@ -36,9 +36,9 @@ using namespace boost::assign;
|
||||
/***********************************************************************
|
||||
* The WBX Simple dboard constants
|
||||
**********************************************************************/
|
||||
static const prop_names_t wbx_tx_antennas = list_of("TX/RX");
|
||||
static const std::vector<std::string> wbx_tx_antennas = list_of("TX/RX");
|
||||
|
||||
static const prop_names_t wbx_rx_antennas = list_of("TX/RX")("RX2");
|
||||
static const std::vector<std::string> wbx_rx_antennas = list_of("TX/RX")("RX2");
|
||||
|
||||
/***********************************************************************
|
||||
* The WBX simple implementation
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
|
||||
#include <uhd/usrp/gps_ctrl.hpp>
|
||||
#include <uhd/utils/msg.hpp>
|
||||
#include <uhd/utils/props.hpp>
|
||||
#include <uhd/exception.hpp>
|
||||
#include <uhd/types/sensors.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
@ -121,7 +120,7 @@ public:
|
||||
return sensor_value_t("GPS lock status", locked(), "locked", "unlocked");
|
||||
}
|
||||
else {
|
||||
UHD_THROW_PROP_GET_ERROR();
|
||||
throw uhd::value_error("gps ctrl get_sensor unknown key: " + key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -134,7 +134,6 @@ LIBUHD_APPEND_SOURCES(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/log.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/msg.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/props.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/static.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tasks.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/thread_priority.cpp
|
||||
|
||||
@ -1,40 +0,0 @@
|
||||
//
|
||||
// Copyright 2010 Ettus Research LLC
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include <uhd/utils/props.hpp>
|
||||
|
||||
using namespace uhd;
|
||||
|
||||
named_prop_t::named_prop_t(
|
||||
const wax::obj &key,
|
||||
const std::string &name
|
||||
):
|
||||
key(key),
|
||||
name(name)
|
||||
{
|
||||
/* NOP */
|
||||
}
|
||||
|
||||
named_prop_t named_prop_t::extract(
|
||||
const wax::obj &key,
|
||||
const std::string &name
|
||||
){
|
||||
if (key.type() == typeid(named_prop_t)){
|
||||
return key.as<named_prop_t>();
|
||||
}
|
||||
return named_prop_t(key, name);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user