📄 method_properties.hpp
字号:
/// @{
private:
typedef V value_type;
typedef RG get_reference_type;
typedef RS set_reference_type;
typedef C container_type;
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
typedef method_property_getset<V, RG, RS, C, PFnOff, PFnGet, PFnSet> class_type;
#else /* ? STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
typedef method_property_getset<V, RG, RS, C, PFnOff> class_type;
typedef member_get_pointer<class_type, RG, C> get_member_pointer_type;
typedef member_set_pointer<class_type, RS, C> set_member_pointer_type;
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
/// @}
/// \name Construction
/// @{
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
# if defined(STLSOFT_COMPILER_IS_DMC)
public:
# else /* ? compiler */
private:
# endif /* compiler */
method_property_getset()
{}
private:
ss_explicit_k method_property_getset(set_reference_type value)
: m_value(value)
{}
#else
private:
typedef get_member_pointer_type PFnGet;
typedef set_member_pointer_type PFnSet;
private:
method_property_getset(get_reference_type (C::*pfnGet)() const, void (C::*pfnSet)(set_reference_type ))
{
PFnGet fg(pfnGet);
PFnSet fs(pfnSet);
}
method_property_getset(get_reference_type (C::*pfnGet)() const, void (C::*pfnSet)(set_reference_type ), set_reference_type value)
: m_value(value)
{
PFnGet fg(pfnGet);
PFnSet fs(pfnSet);
}
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
/// @}
STLSOFT_DECLARE_TEMPLATE_PARAM_AS_FRIEND(C);
/// \name Accessors
/// @{
public:
/// Provides read-only access to the property
operator get_reference_type () const
{
ss_ptrdiff_t offset = (*PFnOff)();
container_type *pC = (container_type*)((ss_byte_t*)this - offset);
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
return (pC->*PFnGet)();
#else /* ? STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
return PFnGet::get(pC);
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
}
/// Provides write-only access to the property
class_type& operator =(set_reference_type value)
{
ss_ptrdiff_t offset = (*PFnOff)();
container_type *pC = (container_type*)((ss_byte_t*)this - offset);
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
(pC->*PFnSet)(value);
#else /* ? STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
PFnSet::set(pC, &value);
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
return *this;
}
/// @}
/// \name Members
/// @{
private:
value_type m_value;
/// @}
};
/* /////////////////////////////////////////////////////////////////////////
* External method property classes
*/
/**\brief This class provides indirect method-based read-only property access
*
* \ingroup group__library__properties
*
* The containing class defines a get method. It also defines a static method
* that contains the offset of the given property from within the container.
* Then the template is parameterised with the the reference type, the
* container type, the member function and the offset function.
*/
template< ss_typename_param_k R /* The reference type */
, ss_typename_param_k C /* The enclosing class */
, ss_ptrdiff_t (*PFnOff)() /* Pointer to function providing offset of property within container */
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
, R (C::*PFnGet)() const /* Pointer to a const member function returning R */
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
>
class method_property_get_external
: public external_property<1, 0, 0>
{
/// \name Member Types
/// @{
public:
typedef R reference_type;
typedef C container_type;
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
typedef method_property_get_external<R, C, PFnOff, PFnGet> class_type;
#else /* ? STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
typedef method_property_get_external<R, C, PFnOff> class_type;
typedef member_get_pointer<class_type, R, C> member_pointer_type;
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
#ifndef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
/// @}
/// \name Construction
/// @{
private:
method_property_get_external(R (C::*pfn)() const)
{
PFnGet f(pfn);
}
STLSOFT_DECLARE_TEMPLATE_PARAM_AS_FRIEND(C);
private:
typedef member_pointer_type PFnGet;
#endif /* !STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
/// @}
/// \name Operators
/// @{
public:
/// Provides read-only access to the property
operator reference_type () const
{
ss_ptrdiff_t offset = (*PFnOff)();
container_type *pC = (container_type*)((ss_byte_t*)this - offset);
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
return (pC->*PFnGet)();
#else /* ? STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
return PFnGet::get(pC);
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
}
/// @}
/// \name Not to be implemented
/// @{
private:
/// This method is hidden in order to prevent users of this class from
/// becoming familiar with using operator = on the property instances
/// from within the containing class, since doing so with
/// method_property_getset<> would result in an infinite loop.
class_type& operator =(reference_type value);
/// @}
};
/** \brief This class provides indirect method-based write-only property access
*
* \ingroup group__library__properties
*
* The containing class defines a set method. It also defines a static method
* that contains the offset of the given property from within the container.
* Then the template is parameterised with the reference type, the container
* type, the member function and the offset function.
*/
template< ss_typename_param_k R /* The reference type */
, ss_typename_param_k C /* The enclosing class */
, ss_ptrdiff_t (*PFnOff)() /* Pointer to function providing offset of property within container */
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
, void (C::*PFnSet)(R ) /* Pointer to a member function taking R */
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
>
class method_property_set_external
: public external_property<0, 1, 0>
{
/// \name Member Types
/// @{
public:
typedef R reference_type;
typedef C container_type;
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
typedef method_property_set_external<R, C, PFnOff, PFnSet> class_type;
#else /* ? STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
typedef method_property_set_external<R, C, PFnOff> class_type;
typedef member_set_pointer<class_type, R, C> member_pointer_type;
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
#ifndef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
/// @}
/// \name Construction
/// @{
private:
method_property_set_external(void (C::*pfn)(R ))
{
PFnSet f(pfn);
}
STLSOFT_DECLARE_TEMPLATE_PARAM_AS_FRIEND(C);
private:
typedef member_pointer_type PFnSet;
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
/// @}
/// \name Operators
/// @{
public:
/// Provides read-only access to the property
method_property_set_external& operator =(reference_type value)
{
ss_ptrdiff_t offset = (*PFnOff)();
container_type *pC = (container_type*)((ss_byte_t*)this - offset);
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
(pC->*PFnSet)(value);
#else /* ? STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
PFnSet::set(pC, &value);
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
return *this;
}
/// @}
};
/** \brief This class provides indirect method-based read/write property access
*
* \ingroup group__library__properties
*
* The containing class defines get and set methods. It also defines a static
* method that contains the offset of the given property from within the container.
* Then the template is parameterised with the set reference type, the get
* reference type, the container type, the member functions and the offset function.
*/
template< ss_typename_param_k RG /* The reference type */
, ss_typename_param_k RS /* The reference type */
, ss_typename_param_k C /* The enclosing class */
, ss_ptrdiff_t (*PFnOff)() /* Pointer to function providing offset of property within container */
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
, RG (C::*PFnGet)() const /* Pointer to a const member function returning R */
, void (C::*PFnSet)(RS ) /* Pointer to a member function taking R */
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
>
class method_property_getset_external
: public external_property<1, 1, 0>
{
/// \name Member Types
/// @{
public:
typedef RG get_reference_type;
typedef RS set_reference_type;
typedef C container_type;
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
typedef method_property_getset_external<RG, RS, C, PFnOff, PFnGet, PFnSet> class_type;
#else /* ? STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
typedef method_property_getset_external<RG, RS, C, PFnOff> class_type;
typedef member_get_pointer<class_type, RG, C> get_member_pointer_type;
typedef member_set_pointer<class_type, RS, C> set_member_pointer_type;
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
#ifndef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
/// @}
/// \name Construction
/// @{
private:
method_property_getset_external(get_reference_type (C::*pfnGet)() const, void (C::*pfnSet)(set_reference_type ))
{
PFnGet fg(pfnGet);
PFnSet fs(pfnSet);
}
STLSOFT_DECLARE_TEMPLATE_PARAM_AS_FRIEND(C);
private:
typedef get_member_pointer_type PFnGet;
typedef set_member_pointer_type PFnSet;
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
/// @}
/// \name Operators
/// @{
public:
/// Provides read-only access to the property
operator get_reference_type () const
{
ss_ptrdiff_t offset = (*PFnOff)();
container_type *pC = (container_type*)((ss_byte_t*)this - offset);
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
return (pC->*PFnGet)();
#else /* ? STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
return PFnGet::get(pC);
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
}
/// Provides read-only access to the property
class_type& operator =(set_reference_type value)
{
ss_ptrdiff_t offset = (*PFnOff)();
container_type *pC = (container_type*)((ss_byte_t*)this - offset);
#ifdef STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT
(pC->*PFnSet)(value);
#else /* ? STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
PFnSet::set(pC, &value);
#endif /* STLSOFT_CF_MEM_FUNC_AS_TEMPLATE_PARAM_SUPPORT */
return *this;
}
/// @}
};
/* /////////////////////////////////////////////////////////////////////////
* Internal static method property classes
*/
/** \brief Implements static read-only Method Property
*
* \ingroup group__library__properties
*/
template< ss_typename_param_k V
, ss_typename_param_k R /* The reference type */
, ss_typename_param_k C
, R (*PFn)(void)
>
class static_method_property_get
: public internal_property<1, 0, 1>
{
/// \name Member Types
/// @{
public:
typedef V value_type;
typedef R reference_type;
typedef C container_type;
typedef static_method_property_get<V, R, C, PFn> class_type;
/// @}
/// \name Construction
/// @{
public:
static_method_property_get()
{}
ss_explicit_k static_method_property_get(reference_type value)
: m_value(value)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -