⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 int_to_string.hpp

📁 新版本TR1的stl
💻 HPP
📖 第 1 页 / 共 2 页
字号:
// But we're not in an ideal world, so it is like this
    ws_dword_t      m_index;
    Slot            *m_top;
    struct
    {
        ws_byte_t   _mx[sizeof(thread_mutex)];
    }               m__mx;
    ws_sint32_t     m_init; // Construction count
    ws_sint32_t     m_ctor; // Ctor entry count
#endif /* 0 */
};

#ifdef STLSOFT_CF_NAMESPACE_SUPPORT
} /* namespace int_to_string_tls */
#endif /* STLSOFT_CF_NAMESPACE_SUPPORT */


template< ss_typename_param_k C
        , ws_size_t           CCH
        >
inline C *i2str_get_tss_buffer()
{
#if defined(_WINSTL_INT_TO_STRING_USE_DECLSPECTHREAD_FOR_EXES)
    __declspec(thread) static C s_buffer[CCH];

    return s_buffer;
#else

#ifdef STLSOFT_CF_NAMESPACE_SUPPORT
    typedef int_to_string_tls::Key<C, CCH>      Key;
    typedef int_to_string_tls::Slot<C, CCH>     Slot;
#else
    typedef Key<C, CCH>                         Key;
    typedef Slot<C, CCH>                        Slot;
#endif /* STLSOFT_CF_NAMESPACE_SUPPORT */

    static Key      s_index;
    Slot            *slot   =   s_index.GetSlot();

    if(NULL == slot)
    {
        slot = s_index.AllocSlot();
    }

    return slot->buff;
#endif /* dll */
}

#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/** Converts a signed 8-bit integer to a character string
 *
 * For example:
\code
signed char   v = 13;
  
assert(0 == ::strcmp(winstl::int_to_string<char>(v), "13"));
assert(0 == ::wcscmp(winstl::int_to_string<wchar_t>(v), L"13"));
\endcode
 *
 * \ingroup group__library__conversion
 *
 * \warning This function is *not* re-entrant. You must ensure that
 *   it is only invoked once in a statement. This includes possible
 *   invocations by other functions in the same statement.
 */
template<ss_typename_param_k C>
inline C const* int_to_string(ws_sint8_t value)
{
    const ws_size_t CCH     = 21; // 5 fits 8-bit + sign
    C               *buffer = i2str_get_tss_buffer<C, CCH>();

    return stlsoft::integer_to_string(buffer, CCH, value);
}

/** Converts a unsigned 8-bit integer to a character string
 *
 * For example:
\code
unsigned char   v = 14;
  
assert(0 == ::strcmp(winstl::int_to_string<char>(v), "14"));
assert(0 == ::wcscmp(winstl::int_to_string<wchar_t>(v), L"14"));
\endcode
 *
 * \ingroup group__library__conversion
 *
 * \warning This function is *not* re-entrant. You must ensure that
 *   it is only invoked once in a statement. This includes possible
 *   invocations by other functions in the same statement.
 */
template<ss_typename_param_k C>
inline C const* int_to_string(ws_uint8_t value)
{
    const ws_size_t CCH     = 21; // 4 fits 8-bit
    C               *buffer = i2str_get_tss_buffer<C, CCH>();

    return stlsoft::integer_to_string(buffer, CCH, value);
}

/** Converts a signed 16-bit integer to a character string
 *
 * For example:
\code
signed char   v = 15;
  
assert(0 == ::strcmp(winstl::int_to_string<char>(v), "15"));
assert(0 == ::wcscmp(winstl::int_to_string<wchar_t>(v), L"15"));
\endcode
 *
 * \ingroup group__library__conversion
 *
 * \warning This function is *not* re-entrant. You must ensure that
 *   it is only invoked once in a statement. This includes possible
 *   invocations by other functions in the same statement.
 */
template<ss_typename_param_k C>
inline C const* int_to_string(ws_sint16_t value)
{
    const ws_size_t CCH     = 21; // 7 fits 16-bit + sign
    C               *buffer = i2str_get_tss_buffer<C, CCH>();

    return stlsoft::integer_to_string(buffer, CCH, value);
}

/** Converts a unsigned 16-bit integer to a character string
 *
 * For example:
\code
unsigned char   v = 16;
  
assert(0 == ::strcmp(winstl::int_to_string<char>(v), "16"));
assert(0 == ::wcscmp(winstl::int_to_string<wchar_t>(v), L"16"));
\endcode
 *
 * \ingroup group__library__conversion
 *
 * \warning This function is *not* re-entrant. You must ensure that
 *   it is only invoked once in a statement. This includes possible
 *   invocations by other functions in the same statement.
 */
template<ss_typename_param_k C>
inline C const* int_to_string(ws_uint16_t value)
{
    const ws_size_t CCH     = 21; // 6 fits 16-bit
    C               *buffer = i2str_get_tss_buffer<C, CCH>();

    return stlsoft::integer_to_string(buffer, CCH, value);
}

/** Converts a signed 32-bit integer to a character string
 *
 * For example:
\code
signed char   v = 17;
  
assert(0 == ::strcmp(winstl::int_to_string<char>(v), "17"));
assert(0 == ::wcscmp(winstl::int_to_string<wchar_t>(v), L"17"));
\endcode
 *
 * \ingroup group__library__conversion
 *
 * \warning This function is *not* re-entrant. You must ensure that
 *   it is only invoked once in a statement. This includes possible
 *   invocations by other functions in the same statement.
 */
template<ss_typename_param_k C>
inline C const* int_to_string(ws_sint32_t value)
{
    const ws_size_t CCH     = 21; // 12 fits 32-bit + sign
    C               *buffer = i2str_get_tss_buffer<C, CCH>();

    return stlsoft::integer_to_string(buffer, CCH, value);
}

/** Converts a unsigned 32-bit integer to a character string
 *
 * For example:
\code
unsigned char   v = 18;
  
assert(0 == ::strcmp(winstl::int_to_string<char>(v), "18"));
assert(0 == ::wcscmp(winstl::int_to_string<wchar_t>(v), L"18"));
\endcode
 *
 * \ingroup group__library__conversion
 *
 * \warning This function is *not* re-entrant. You must ensure that
 *   it is only invoked once in a statement. This includes possible
 *   invocations by other functions in the same statement.
 */
template<ss_typename_param_k C>
inline C const* int_to_string(ws_uint32_t value)
{
    const ws_size_t CCH     = 21; // 11 fits 32-bit
    C               *buffer = i2str_get_tss_buffer<C, CCH>();

    return stlsoft::integer_to_string(buffer, CCH, value);
}

/** Converts a signed 64-bit integer to a character string
 *
 * For example:
\code
signed char   v = 19;
  
assert(0 == ::strcmp(winstl::int_to_string<char>(v), "19"));
assert(0 == ::wcscmp(winstl::int_to_string<wchar_t>(v), L"19"));
\endcode
 *
 * \ingroup group__library__conversion
 *
 * \warning This function is *not* re-entrant. You must ensure that
 *   it is only invoked once in a statement. This includes possible
 *   invocations by other functions in the same statement.
 */
template<ss_typename_param_k C>
inline C const* int_to_string(ws_sint64_t const& value)
{
    const ws_size_t CCH     = 21; // fits 64-bit + sign
    C               *buffer = i2str_get_tss_buffer<C, CCH>();

    return stlsoft::integer_to_string(buffer, CCH, value);
}

/** Converts a unsigned 64-bit integer to a character string
 *
 * For example:
\code
unsigned char   v = 20;
  
assert(0 == ::strcmp(winstl::int_to_string<char>(v), "20"));
assert(0 == ::wcscmp(winstl::int_to_string<wchar_t>(v), L"20"));
\endcode
 *
 * \ingroup group__library__conversion
 *
 * \warning This function is *not* re-entrant. You must ensure that
 *   it is only invoked once in a statement. This includes possible
 *   invocations by other functions in the same statement.
 */
template<ss_typename_param_k C>
inline C const* int_to_string(ws_uint64_t const& value)
{
    const ws_size_t CCH     = 21; // fits 64-bit
    C               *buffer = i2str_get_tss_buffer<C, CCH>();

    return stlsoft::integer_to_string(buffer, CCH, value);
}


#ifdef STLSOFT_CF_INT_DISTINCT_INT_TYPE

template<ss_typename_param_k C>
inline C const* int_to_string(int const& value)
{
    const ws_size_t CCH     = 21; // fits 64-bit
    C               *buffer = i2str_get_tss_buffer<C, CCH>();

    return stlsoft::integer_to_string(buffer, CCH, value);
}

template<ss_typename_param_k C>
inline C const* int_to_string(unsigned int const& value)
{
    const ws_size_t CCH     = 21; // fits 64-bit
    C               *buffer = i2str_get_tss_buffer<C, CCH>();

    return stlsoft::integer_to_string(buffer, CCH, value);
}

#endif /* !STLSOFT_CF_INT_DISTINCT_INT_TYPE */

#ifdef STLSOFT_CF_LONG_DISTINCT_INT_TYPE

template<ss_typename_param_k C>
inline C const* int_to_string(long const& value)
{
    const ws_size_t CCH     = 21; // fits 64-bit
    C               *buffer = i2str_get_tss_buffer<C, CCH>();

    return stlsoft::integer_to_string(buffer, CCH, value);
}

template<ss_typename_param_k C>
inline C const* int_to_string(unsigned long const& value)
{
    const ws_size_t CCH     = 21; // fits 64-bit
    C               *buffer = i2str_get_tss_buffer<C, CCH>();

    return stlsoft::integer_to_string(buffer, CCH, value);
}

#endif /* !STLSOFT_CF_LONG_DISTINCT_INT_TYPE */

////////////////////////////////////////////////////////////////////////////
// Unit-testing

#ifdef STLSOFT_UNITTEST
# include "./unittest/int_to_string_unittest_.h"
#endif /* STLSOFT_UNITTEST */

/* ////////////////////////////////////////////////////////////////////// */

#ifndef _WINSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
     defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} /* namespace winstl */
# else
} /* namespace winstl_project */
} /* namespace stlsoft */
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */

/* ////////////////////////////////////////////////////////////////////// */

#endif /* !WINSTL_INCL_WINSTL_CONVERSION_HPP_INT_TO_STRING */

/* ////////////////////////////////////////////////////////////////////// */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -