📄 special_string_instance.hpp
字号:
private:
static ssi_buffer_type &get_buffer(size_type (*pfn)(char_type *, size_type))
{
static ss_sint32_t s_count = 0;
static bool s_bInit = false;
spin_mutex_type mx(&s_count);
stlsoft::lock_scope<spin_mutex_type> lock(mx);
static ssi_buffer_type s_buffer;
if(!s_bInit)
{
s_buffer.init(pfn);
s_bInit = true;
}
return s_buffer;
}
static ssi_buffer_type &get_buffer(A0 a0, size_type (*pfn)(A0, char_type *, size_type))
{
static ss_sint32_t s_count = 0;
static bool s_bInit = false;
spin_mutex_type mx(&s_count);
stlsoft::lock_scope<spin_mutex_type> lock(mx);
static ssi_buffer_type s_buffer;
if(!s_bInit)
{
s_buffer.init(a0, pfn);
s_bInit = true;
}
return s_buffer;
}
/// @}
/// \name Members
/// @{
private:
ssi_buffer_type &m_buffer;
/// @}
/// \name Not to be implemented
/// @{
private:
ssi_buffer_static(class_type const&);
class_type& operator =(class_type const&);
/// @}
};
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/** \brief Special string instance class template.
*
* \ingroup group__library__string
*
* \param P The SSI policy type.
*
* The policy type provides the following:
*
* - A member constant <code>internalBufferSize</code> that determines the
* size of the SSI's internal
* \link stlsoft::auto_buffer auto_buffer\endlink's internal buffer size.
* - A static method <code>get_value(char_type *buffer, size_type cchBuffer)</code>
* that has the
* - A member constant <code>allowImplicitConversion</code> that determines
* whether an implicit conversion operator (to
* <code>char_type const*</code>) is to be provided.
*/
template <ss_typename_param_k P>
class special_string_instance_0
{
/// \name Member Types
/// @{
public:
/// \brief The policy type
typedef P policy_type;
/// \brief The current instantiation of the template.
typedef special_string_instance_0<P> class_type;
/// \brief The character type
typedef ss_typename_type_k policy_type::char_type char_type;
/// \brief The size type
typedef ss_typename_type_k policy_type::size_type size_type;
/// \brief The character type for ANSI specialisations
///
/// \note This is used in the specification of the string access shim
/// functions.
private:
enum { charTypeIsAnsi = is_same_type<ss_char_a_t, char_type>::value };
public:
typedef ss_typename_type_k select_first_type_if<ss_char_a_t const*
, void
, charTypeIsAnsi
>::type cstring_a_type;
/// \brief The character type for Unicode specialisations
///
/// \note This is used in the specification of the string access shim
/// functions.
private:
enum { charTypeIsWide = is_same_type<ss_char_w_t, char_type>::value };
public:
typedef ss_typename_type_k select_first_type_if<ss_char_w_t const*
, void
, charTypeIsWide
>::type cstring_w_type;
private:
typedef ss_typename_type_k policy_type::pfn_type pfn_type;
private:
// This section allows for the case where the policy does not define an
// allocator, which it indicates by defining its member type
// allocator_type to be void.
typedef ss_typename_type_k policy_type::allocator_type putative_allocator_type;
enum
{
policy_has_allocator_type = (0 != size_of<putative_allocator_type>::value)
};
typedef ss_typename_type_k allocator_selector<char_type>::allocator_type backup_allocator_type;
public:
/// \brief The allocator type
typedef ss_typename_type_k select_first_type_if<putative_allocator_type
, backup_allocator_type
, policy_has_allocator_type
>::type allocator_type;
private:
enum { allowImplicitConversion = policy_type::allowImplicitConversion };
public:
/// \brief The implicit conversion operator type
typedef ss_typename_type_k select_first_type_if<char_type const*
, void
, allowImplicitConversion
>::type implicit_conversion_type;
private:
// This section accounts for whether the policy indicates shared state.
// If so, then the buffer type resolves to the appropriate
// specialisation of ssi_buffer_static, which stores a threadsafe buffer
// shared by all instances. If not, then the buffer type resolves to
// ssi_buffer_non_static, which stores a buffer per instance.
enum
{
policy_indicates_shared_state = (0 != policy_type::sharedState)
};
struct null_argument
{};
enum { internalBufferSize = policy_type::internalBufferSize };
typedef ssi_buffer_static< char_type
, internalBufferSize
, allocator_type
, null_argument
, policy_type // Passes policy type, from which spin_mutex_type is elicited, so non-statics do not need to specify it
> ssi_buffer_static_type;
typedef ssi_buffer_non_static< char_type
, internalBufferSize
, allocator_type
, null_argument
> ssi_buffer_non_static_type;
typedef ss_typename_type_k select_first_type_if<ssi_buffer_static_type
, ssi_buffer_non_static_type
, policy_indicates_shared_state
>::type buffer_type;
/// @}
/// \name Construction
/// @{
public:
special_string_instance_0()
: m_buffer(policy_type::get_fn())
{}
/// @}
/// \name Accessors
/// @{
public:
size_type length() const
{
return m_buffer.length();
}
size_type size() const
{
return length();
}
char_type const* data() const
{
return m_buffer.data();
}
char_type const* c_str() const
{
return data();
}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
cstring_a_type c_str_a() const
{
return c_str();
}
cstring_w_type c_str_w() const
{
return c_str();
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/// @}
/// \name Operators
/// @{
public:
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
operator implicit_conversion_type () const
{
return this->c_str();
}
#endif /* compiler */
/// @}
/// \name Operations
/// @{
public:
static size_type get(char_type *buffer, size_type cchBuffer)
{
return (policy_type::get_fn())(buffer, cchBuffer);
}
/// @}
/// \name Members
/// @{
private:
buffer_type m_buffer;
/// @}
};
/** \brief Special string instance class template.
*
* \ingroup group__library__string
*
* \param P The SSI policy type.
*
* The policy type provides the following:
*
* - A member constant <code>internalBufferSize</code> that determines the
* size of the SSI's internal
* \link stlsoft::auto_buffer auto_buffer\endlink's internal buffer size.
* - A static method <code>get_value(char_type *buffer, size_type cchBuffer)</code>
* that has the
* - A member constant <code>allowImplicitConversion</code> that determines
* whether an implicit conversion operator (to
* <code>char_type const*</code>) is to be provided.
*/
template <ss_typename_param_k P>
class special_string_instance_1
{
/// \name Member Types
/// @{
public:
/// \brief The policy type.
typedef P policy_type;
/// \brief The current instantiation of the template.
typedef special_string_instance_1<P> class_type;
/// \brief The character type
typedef ss_typename_type_k policy_type::char_type char_type;
/// \brief The size type
typedef ss_typename_type_k policy_type::size_type size_type;
/// \brief The argument type
typedef ss_typename_type_k policy_type::argument_0_type argument_0_type;
/// \brief The character type for ANSI specialisations
///
/// \note This is used in the specification of the string access shim
/// functions.
private:
enum { charTypeIsAnsi = is_same_type<ss_char_a_t, char_type>::value };
public:
typedef ss_typename_type_k select_first_type_if<ss_char_a_t const*
, void
, charTypeIsAnsi
>::type cstring_a_type;
/// \brief The character type for Unicode specialisations
///
/// \note This is used in the specification of the string access shim
/// functions.
private:
enum { charTypeIsWide = is_same_type<ss_char_w_t, char_type>::value };
public:
typedef ss_typename_type_k select_first_type_if<ss_char_w_t const*
, void
, charTypeIsWide
>::type cstring_w_type;
private:
typedef ss_typename_type_k policy_type::pfn_type pfn_type;
private:
// This section allows for the case where the policy does not define an
// allocator, which it indicates by defining its member type
// allocator_type to be void.
typedef ss_typename_type_k policy_type::allocator_type putative_allocator_type;
enum
{
policy_has_allocator_type = (0 != size_of<putative_allocator_type>::value)
};
typedef ss_typename_type_k allocator_selector<char_type>::allocator_type backup_allocator_type;
public:
/// \brief The allocator type
typedef ss_typename_type_k select_first_type_if<putative_allocator_type
, backup_allocator_type
, policy_has_allocator_type
>::type allocator_type;
/// \brief The implicit conversion operator type
private:
enum { allowImplicitConversion = policy_type::allowImplicitConversion };
public:
typedef ss_typename_type_k select_first_type_if<char_type const*
, void
, allowImplicitConversion
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -