class Value
{
public:
+ class ComparisonHelper;
+
Value();
Value(const Value&);
Value(Value&&);
void swap(Value&);
//! @cond
- friend bool operator==(const Value&, const Value&);
-
- template< typename T >
- friend typename std::enable_if< ResourceAttributes::is_supported_type< T >::value,
- bool >::type operator==(const Value&, const T&);
-
- bool operator==(const char*) const;
-
friend class ResourceAttributes;
//! @endcond
//! @endcond
};
+ /**
+ * A helper class to avoid obscure comparisons of values which are supported
+ * by ResourceAttributes::Value caused by implicitly converting a value
+ * to a ResourceAttributes::Value.
+ *
+ * @see Value
+ * @see ResourceAttributes
+ * @see is_supported_type
+ */
+ class ResourceAttributes::Value::ComparisonHelper
+ {
+ public:
+ ComparisonHelper(const Value&);
+
+ template< typename T >
+ typename std::enable_if< is_supported_type< T >::value, bool >::type equals(
+ const T& v) const
+ {
+ return m_valueRef.equals< T >(v);
+ }
+
+ bool equals(const std::string& v) const
+ {
+ return m_valueRef.equals< std::string >(v);
+ }
+
+ bool operator==(const ComparisonHelper&) const;
+
+ private:
+ const Value& m_valueRef;
+ };
+
template< typename T >
struct ResourceAttributes::IsSupportedTypeHelper
{
*/
bool operator!=(const ResourceAttributes::Type&, const ResourceAttributes::Type&);
-
/**
* @relates ResourceAttributes::Value
*
*
* @return true if the contents are equal, false otherwise.
*/
- bool operator==(const ResourceAttributes::Value&, const ResourceAttributes::Value&);
+ bool operator==(const ResourceAttributes::Value::ComparisonHelper&,
+ const ResourceAttributes::Value::ComparisonHelper&);
/**
* @relates ResourceAttributes::Value
*
* @return true if the contents are not equal, false otherwise.
*/
- bool operator!=(const ResourceAttributes::Value&, const ResourceAttributes::Value&);
+ bool operator!=(const ResourceAttributes::Value::ComparisonHelper&,
+ const ResourceAttributes::Value::ComparisonHelper&);
//! @cond
template< typename T >
- typename std::enable_if< ResourceAttributes::is_supported_type< T >::value, bool >::type
- operator==(const ResourceAttributes::Value& lhs, const T& rhs)
+ typename std::enable_if< ResourceAttributes::is_supported_type< T >::value ||
+ std::is_constructible< std::string, T >::value, bool >::type
+ operator==(const ResourceAttributes::Value::ComparisonHelper& lhs, const T& rhs)
{
- return lhs.equals< T >(rhs);
+ return lhs.equals(rhs);
}
template< typename T >
- bool operator==(const T& lhs, const ResourceAttributes::Value& rhs)
+ typename std::enable_if< ResourceAttributes::is_supported_type< T >::value ||
+ std::is_constructible< std::string, T >::value, bool >::type
+ operator==(const T& lhs, const ResourceAttributes::Value::ComparisonHelper& rhs)
{
return rhs == lhs;
}
template< typename T >
- typename std::enable_if< ResourceAttributes::is_supported_type< T >::value, bool >::type
- operator!=(const T& lhs, const ResourceAttributes::Value& rhs)
+ typename std::enable_if< ResourceAttributes::is_supported_type< T >::value ||
+ std::is_constructible< std::string, T >::value, bool >::type
+ operator!=(const ResourceAttributes::Value::ComparisonHelper& lhs, const T& rhs)
{
- return !(rhs == lhs);
+ return !(lhs == rhs);
}
- bool operator!=(const char*, const ResourceAttributes::Value&);
-
- bool operator==(const char* lhs, const ResourceAttributes::Value& rhs);
+ template< typename T >
+ typename std::enable_if< ResourceAttributes::is_supported_type< T >::value ||
+ std::is_constructible< std::string, T >::value, bool >::type
+ operator!=(const T& lhs, const ResourceAttributes::Value::ComparisonHelper& rhs)
+ {
+ return !(rhs == lhs);
+ }
//! @endcond
/**
template< typename VARIANT, int POS >
static constexpr TypeInfo get()
{
- return TypeInfo(
- TypeInfoConverter<
- typename boost::mpl::deref<
- typename boost::mpl::advance<
- typename boost::mpl::begin< typename VARIANT::types >::type,
- boost::mpl::int_< POS > >::type >::type >{ });
+ return TypeInfo(TypeInfoConverter<
+ typename boost::mpl::deref<
+ typename boost::mpl::advance<
+ typename boost::mpl::begin< typename VARIANT::types>::type,
+ boost::mpl::int_< POS >
+ >::type
+ >::type >{ });
}
};
namespace Service
{
- bool operator==(const ResourceAttributes::Type& lhs, const ResourceAttributes::Type& rhs)
+ ResourceAttributes::Value::ComparisonHelper::ComparisonHelper(const Value& v) :
+ m_valueRef(v)
{
- return lhs.m_which == rhs.m_which;
}
- bool operator!=(const ResourceAttributes::Type& lhs, const ResourceAttributes::Type& rhs)
+ bool ResourceAttributes::Value::ComparisonHelper::operator==
+ (const Value::ComparisonHelper& rhs) const
{
- return !(lhs == rhs);
+ return *m_valueRef.m_data == *rhs.m_valueRef.m_data;
}
- bool operator!=(const ResourceAttributes::Value& lhs, const ResourceAttributes::Value& rhs)
+ bool operator==(const ResourceAttributes::Type& lhs, const ResourceAttributes::Type& rhs)
{
- return !(lhs == rhs);
+ return lhs.m_which == rhs.m_which;
}
- bool operator!=(const char* lhs, const ResourceAttributes::Value& rhs)
+ bool operator!=(const ResourceAttributes::Type& lhs, const ResourceAttributes::Type& rhs)
{
- return !(rhs == lhs);
+ return !(lhs == rhs);
}
- bool operator==(const char* lhs, const ResourceAttributes::Value& rhs)
+ bool operator==(const ResourceAttributes::Value::ComparisonHelper& lhs,
+ const ResourceAttributes::Value::ComparisonHelper& rhs)
{
- return rhs == lhs;
+ return lhs.operator==(rhs);
}
- bool operator==(const ResourceAttributes::Value& lhs, const ResourceAttributes::Value& rhs)
+ bool operator!=(const ResourceAttributes::Value::ComparisonHelper& lhs,
+ const ResourceAttributes::Value::ComparisonHelper& rhs)
{
- return *lhs.m_data == *rhs.m_data;
+ return !lhs.operator==(rhs);
}
bool operator==(const ResourceAttributes& lhs, const ResourceAttributes& rhs)
return *this;
}
- bool ResourceAttributes::Value::operator==(const char* rhs) const
- {
- return equals< std::string >(rhs);
- }
-
auto ResourceAttributes::Value::getType() const -> Type
{
return boost::apply_visitor(TypeVisitor(), *m_data);
{
createResource();
ResourceAttributes result = object->getCachedAttributes();
- EXPECT_TRUE(result != NULL);
+ EXPECT_TRUE(result.empty());
destroyResource();
}
{
createResource();
ResourceAttributes::Value result = object->getCachedAttribute("");
- std::nullptr_t null;
- EXPECT_TRUE(result == null);
+ EXPECT_TRUE(result == nullptr);
destroyResource();
}
{
createResource();
std::string result = object->getUri();
- EXPECT_TRUE(result != NULL);
+ EXPECT_TRUE(!result.empty());
destroyResource();
}
{
createResource();
std::string result = object->getAddress();
- EXPECT_TRUE(result != NULL);
+ EXPECT_TRUE(!result.empty());
destroyResource();
}
{
createResource();
ResourceAttributes::Value result = object->getCachedAttribute("Temperature");
- EXPECT_TRUE(result != NULL);
+ EXPECT_TRUE(result != nullptr);
destroyResource();
}