- public: // queries
-
- virtual const std::type_info & type() const
- {
- return typeid(ValueType);
- }
-
- virtual placeholder * clone() const
- {
- return new holder(held);
- }
-
- public: // representation
-
- ValueType held;
-
- };
-
-#ifndef BBTK_NO_MEMBER_TEMPLATE_FRIENDS
-
- private: // representation
-
- // template<typename ValueType>
- // friend ValueType * Data_cast(Data *);
-
- template<typename ValueType>
- friend ValueType * unsafe_Data_cast(Data *);
-
- template<typename ValueType>
- friend ValueType unsafe_Data_cast(Data &);
-
-#else
-
- public: // representation (public so Data_cast can be non-friend)
-
-#endif
-
- placeholder * content;
-
- };
-
- class bad_Data_cast : public std::bad_cast
- {
- public:
- virtual const char * what() const throw()
- {
- return "bbtk::bad_Data_cast: "
- "failed conversion using bbtk::Data_cast";
- }
- };
- */
- /*
- template<typename ValueType>
- ValueType * Data_cast(Data * operand)
- {
- return operand && operand->type() == typeid(ValueType)
- ? &static_cast<Data::holder<ValueType> *>(operand->content)->held
- : 0;
- }
-
- template<typename ValueType>
- const ValueType * Data_cast(const Data * operand)
- {
- return Data_cast<ValueType>(const_cast<Data *>(operand));
- }
-
-// Removed Data_cast
- template<typename ValueType>
- ValueType Data_cast(const Data & operand)
- {
- typedef BBTK_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref;
-
-#ifdef BBTK_NO_TEMPLATE_PARTIAL_SPECIALIZATION
- // If 'nonref' is still reference type, it means the user has not
- // specialized 'remove_reference'.
-
- // Please use BBTK_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION macro
- // to generate specialization of remove_reference for your class
- // See type traits library documentation for details
- BBTK_STATIC_ASSERT(!is_reference<nonref>::value);
-#endif
-
- const nonref * result = Data_cast<nonref>(&operand);
- if(!result)
- bbtk::throw_exception(bad_Data_cast());
- return *result;
- }
-
- template<typename ValueType>
- ValueType Data_cast(Data & operand)
- {
- typedef BBTK_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref;
-
-#ifdef BBTK_NO_TEMPLATE_PARTIAL_SPECIALIZATION
- // The comment in the above version of 'Data_cast' explains when this
- // assert is fired and what to do.
- BBTK_STATIC_ASSERT(!is_reference<nonref>::value);
-#endif
-
- nonref * result = Data_cast<nonref>(&operand);
- if(!result)
- bbtk::throw_exception(bad_Data_cast());
- return *result;
- }
- */
- // Note: The "unsafe" versions of Data_cast are not part of the
- // public interface and may be removed at Data time. They are
- // required where we know what type is stored in the Data and can't
- // use typeid() comparison, e.g., when our types may travel across
- // different shared libraries.
- // LG : This is precisely our case !
- /*
- template<typename ValueType>
- inline ValueType * unsafe_Data_cast(Data * operand)
- {
- return &static_cast<Data::holder<ValueType> *>(operand->content)->held;
- }
-
- template<typename ValueType>
- inline const ValueType * unsafe_Data_cast(const Data * operand)
- {
- return unsafe_Data_cast<ValueType>(const_cast<Data *>(operand));
- }