mirror of
https://github.com/EttusResearch/uhd.git
synced 2026-10-25 17:36:10 +00:00
uhd: revert "Check property type at access..."
This change reverts cb9329a681.
The type checking is causing some conversion issues on clang/macos.
The type_index checking doesn't work correctly across shared
libraries and should not be relied on to verify type, since it can
vary from compiler to compiler.
Signed-off-by: Steven Koo <steven.koo@ni.com>
This commit is contained in:
parent
9f3ec1c5ab
commit
f22e3c2d47
@ -13,7 +13,6 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <typeindex>
|
||||
#include <vector>
|
||||
|
||||
namespace uhd {
|
||||
@ -253,15 +252,10 @@ private:
|
||||
|
||||
//! Internal create property with wild-card type
|
||||
virtual void _create(const fs_path& path,
|
||||
const std::shared_ptr<void>& prop,
|
||||
std::type_index prop_type) = 0;
|
||||
const std::shared_ptr<void>& prop) = 0;
|
||||
|
||||
//! Internal access property with wild-card type
|
||||
virtual std::shared_ptr<void>& _access(const fs_path& path) const = 0;
|
||||
|
||||
//! Internal access property with wild-card type but with type verification
|
||||
virtual std::shared_ptr<void>& _access_with_type_check(
|
||||
const fs_path& path, std::type_index expected_prop_type) const = 0;
|
||||
};
|
||||
|
||||
} // namespace uhd
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <uhd/exception.hpp>
|
||||
#include <typeindex>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
@ -181,8 +180,7 @@ template <typename T>
|
||||
property<T>& property_tree::create(const fs_path& path, coerce_mode_t coerce_mode)
|
||||
{
|
||||
this->_create(path,
|
||||
typename std::shared_ptr<property<T> >(new property_impl<T>(coerce_mode)),
|
||||
std::type_index(typeid(T)));
|
||||
typename std::shared_ptr<property<T> >(new property_impl<T>(coerce_mode)));
|
||||
return this->access<T>(path);
|
||||
}
|
||||
|
||||
@ -190,7 +188,7 @@ template <typename T>
|
||||
property<T>& property_tree::access(const fs_path& path)
|
||||
{
|
||||
return *std::static_pointer_cast<property<T> >(
|
||||
this->_access_with_type_check(path, std::type_index(typeid(T))));
|
||||
this->_access(path));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <typeindex>
|
||||
|
||||
using namespace uhd;
|
||||
|
||||
@ -158,8 +157,7 @@ public:
|
||||
}
|
||||
|
||||
void _create(const fs_path& path_,
|
||||
const std::shared_ptr<void>& prop,
|
||||
std::type_index prop_type)
|
||||
const std::shared_ptr<void>& prop)
|
||||
{
|
||||
const fs_path path = _root / path_;
|
||||
boost::mutex::scoped_lock lock(_guts->mutex);
|
||||
@ -174,7 +172,6 @@ public:
|
||||
throw uhd::runtime_error(
|
||||
"Cannot create! Property already exists at: " + path);
|
||||
node->prop = prop;
|
||||
node->prop_type_hash = prop_type.hash_code();
|
||||
}
|
||||
|
||||
std::shared_ptr<void>& _access(const fs_path& path_) const
|
||||
@ -193,26 +190,6 @@ public:
|
||||
return node->prop;
|
||||
}
|
||||
|
||||
std::shared_ptr<void>& _access_with_type_check(
|
||||
const fs_path& path_, std::type_index expected_prop_type) const
|
||||
{
|
||||
const fs_path path = _root / path_;
|
||||
boost::mutex::scoped_lock lock(_guts->mutex);
|
||||
|
||||
node_type* node = &_guts->root;
|
||||
for (const std::string& name : path_tokenizer(path)) {
|
||||
if (not node->has_key(name))
|
||||
throw_path_not_found(path);
|
||||
node = &(*node)[name];
|
||||
}
|
||||
if (node->prop.get() == NULL)
|
||||
throw uhd::runtime_error("Cannot access! Property uninitialized at: " + path);
|
||||
if (node->prop_type_hash != expected_prop_type.hash_code())
|
||||
throw uhd::runtime_error(
|
||||
"Cannot access! Property types do not match at: " + path);
|
||||
return node->prop;
|
||||
}
|
||||
|
||||
private:
|
||||
void throw_path_not_found(const fs_path& path) const
|
||||
{
|
||||
@ -223,7 +200,6 @@ private:
|
||||
struct node_type : uhd::dict<std::string, node_type>
|
||||
{
|
||||
std::shared_ptr<void> prop;
|
||||
std::size_t prop_type_hash;
|
||||
};
|
||||
|
||||
// tree guts which may be referenced in a subtree
|
||||
|
||||
@ -265,21 +265,3 @@ BOOST_AUTO_TEST_CASE(test_prop_operators)
|
||||
path4 = path4 / x;
|
||||
BOOST_CHECK_EQUAL(path4, "/root/2");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_mismatched_type_access)
|
||||
{
|
||||
uhd::property_tree::sptr tree = uhd::property_tree::make();
|
||||
|
||||
// accesses of the correct type should succeed
|
||||
tree->create<int>("/intprop");
|
||||
tree->create<double>("/doubleprop");
|
||||
tree->create<std::string>("/stringprop");
|
||||
BOOST_CHECK_NO_THROW(tree->access<int>("/intprop"));
|
||||
BOOST_CHECK_NO_THROW(tree->access<double>("/doubleprop"));
|
||||
BOOST_CHECK_NO_THROW(tree->access<std::string>("/stringprop"));
|
||||
|
||||
// accesses of the incorrect type should throw an exception
|
||||
BOOST_CHECK_THROW(tree->access<int>("/doubleprop"), uhd::runtime_error);
|
||||
BOOST_CHECK_THROW(tree->access<double>("/stringprop"), uhd::runtime_error);
|
||||
BOOST_CHECK_THROW(tree->access<std::string>("/intprop"), uhd::runtime_error);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user