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

📄 system_traits.hpp

📁 新版本TR1的stl
💻 HPP
📖 第 1 页 / 共 2 页
字号:
        return ::strcat(dest, src);
    }

    static char_type *str_n_cat(char_type *dest, char_type const* src, size_type cch)
    {
        return ::strncat(dest, src, cch);
    }

    static int_type str_compare(char_type const* s1, char_type const* s2)
    {
        return ::strcmp(s1, s2);
    }

    static int_type str_compare_no_case(char_type const* s1, char_type const* s2);

    static int_type str_n_compare(char_type const* s1, char_type const* s2, size_type cch)
    {
        return ::strncmp(s1, s2, cch);
    }

    static size_type str_len(char_type const* src)
    {
        return static_cast<size_type>(::strlen(src));
    }

    static char_type *str_chr(char_type const* s, char_type ch)
    {
        return const_cast<char_type*>(::strchr(s, ch));
    }

    static char_type *str_rchr(char_type const* s, char_type ch)
    {
        return const_cast<char_type*>(::strrchr(s, ch));
    }

    static char_type *str_str(char_type const* s, char_type const* sub)
    {
        return const_cast<char_type*>(::strstr(s, sub));
    }

    static char_type *str_pbrk(char_type const* s, char_type const* charSet)
    {
        return const_cast<char_type*>(::strpbrk(s, charSet));
    }

    static char_type *str_end(char_type const* s)
    {
        UNIXSTL_ASSERT(NULL != s);

        for(; *s != '\0'; ++s)
        {}

        return const_cast<char_type*>(s);
    }

public:
    static module_type load_library(char_type const* name)
    {
        return ::dlopen(name, RTLD_NOW);
    }

    static bool_type free_library(module_type hModule)
    {
        return 0 == ::dlclose(hModule);
    }

    static void *find_symbol(module_type hModule, char const* symbolName)
    {
        return ::dlsym(hModule, symbolName);
    }

public:
    static bool_type close_handle(handle_type h)
    {
        return 0 == ::close(h);     
    }       

public:
    static error_type get_last_error()
    {
        return errno;
    }

    static void set_last_error(error_type er = error_type())
    {
        errno = er;
    }

public:
    static size_type get_environment_variable(char_type const* name, char_type* buffer, size_type cchBuffer)
    {
        char const  *var = ::getenv(name);

        if(NULL == var)
        {
            return 0;
        }
        else
        {
            us_size_t   var_len = ::strlen(var);

            if(NULL == buffer)
            {
                return var_len;
            }
            else
            {
                ::strncpy(buffer, var, cchBuffer);

                return (var_len < cchBuffer) ? var_len : cchBuffer;
            }
        }
    }

    static size_type expand_environment_strings(char_type const* src, char_type* buffer, size_type cchBuffer);
};

STLSOFT_TEMPLATE_SPECIALISATION
struct system_traits<us_char_w_t>
{
public:
    typedef us_char_w_t                 char_type;
    typedef us_size_t                   size_type;
    typedef us_ptrdiff_t                difference_type;
    typedef system_traits<us_char_a_t>  class_type;
    typedef us_int_t                    int_type;
    typedef us_bool_t                   bool_type;
    typedef void                        *module_type;
    typedef int                         handle_type;
    typedef int                         error_type;

public:
    static char_type *str_copy(char_type *dest, char_type const* src)
    {
        return ::wcscpy(dest, src);
    }

    static char_type *str_n_copy(char_type *dest, char_type const* src, size_type cch)
    {
        return ::wcsncpy(dest, src, cch);
    }

    static char_type *str_cat(char_type *dest, char_type const* src)
    {
        return ::wcscat(dest, src);
    }

    static char_type *str_n_cat(char_type *dest, char_type const* src, size_type cch)
    {
        return ::wcsncat(dest, src, cch);
    }

    static int_type str_compare(char_type const* s1, char_type const* s2)
    {
        return ::wcscmp(s1, s2);
    }

    static int_type str_compare_no_case(char_type const* s1, char_type const* s2);

    static int_type str_n_compare(char_type const* s1, char_type const* s2, size_type cch)
    {
        return ::wcsncmp(s1, s2, cch);
    }

    static size_type str_len(char_type const* src)
    {
        return static_cast<size_type>(::wcslen(src));
    }

    static char_type *str_chr(char_type const* s, char_type ch)
    {
        return const_cast<char_type*>(::wcschr(s, ch));
    }

    static char_type *str_rchr(char_type const* s, char_type ch)
    {
        return const_cast<char_type*>(::wcsrchr(s, ch));
    }

    static char_type *str_str(char_type const* s, char_type const* sub)
    {
        return const_cast<char_type*>(::wcsstr(s, sub));
    }

    static char_type *str_pbrk(char_type const* s, char_type const* charSet)
    {
        return const_cast<char_type*>(::wcspbrk(s, charSet));
    }

    static char_type *str_end(char_type const* s)
    {
        UNIXSTL_ASSERT(NULL != s);

        for(; *s != L'\0'; ++s)
        {}

        return const_cast<char_type*>(s);
    }

public:
    static module_type load_library(char_type const* name);
    static bool_type free_library(module_type hModule);
    static void *find_symbol(module_type hModule, char const* symbolName);

public:
    static bool_type close_handle(handle_type h)
    {
        return 0 == ::close(h);     
    }       

public:
    static error_type get_last_error()
    {
        return errno;
    }

    static void set_last_error(error_type er = error_type())
    {
        errno = er;
    }

public:
    static size_type get_environment_variable(char_type const* name, char_type* buffer, size_type cchBuffer);
    static size_type expand_environment_strings(char_type const* src, char_type* buffer, size_type cchBuffer);
};

#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

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

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

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

#ifndef _UNIXSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
     defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace unixstl
# else
} // namespace unixstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_UNIXSTL_NO_NAMESPACE */

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

#endif /* UNIXSTL_INCL_UNIXSTL_SYSTEM_HPP_SYSTEM_TRAITS */

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

⌨️ 快捷键说明

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