S operator ()(S const& s)
    {
        ss_size_t   len =   stlsoft_ns_qual(c_str_len)(s);

        if( len > 0 &&
                '\r' == s[len])
        {
            return s;
        }

        return S(stlsoft_ns_qual(c_str_ptr)(s), len - 1);
    }
inline ss_typename_type_ret_k string_view_helper_traits<S>::view_type mid_view(S const& s, ss_size_t start, ss_size_t n)
{
    typedef string_view_helper_traits<S>            traits_t;
    typedef ss_typename_type_k traits_t::view_type  view_t;

    const ss_size_t len = stlsoft_ns_qual(c_str_len)(s);
    ss_size_t       off =   0;

    if(start > len)
    {
        // Want more than is available, so we start at the end
        off = len;
    }
    else
    {
        off = start;
    }

    if(off + n > len)
    {
        // Want more than is available starting at off, so we just get what is available
        n = len - off;
    }

    return view_t(s.data() + off, n);
}
void readlines_impl(CH const* p, ss_size_t len, C &container)
{
    typedef CH                                  char_t;
    typedef ss_typename_type_k C::value_type    value_t;

    char_t const*   p0  =   p;
    char_t const*   p1  =   p0;
    char_t const*   end =   p + len;

    while(end != stlsoft_ns_qual(find_next_token)(p0, p1, end, static_cast<char_t>('\n')))
    {
        if( p1 > p0 &&
                '\r' == p1[-1])
        {
            --p1;
        }

        container.push_back(value_t(p0, static_cast<us_size_t>(p1 - p0)));

        if('\r' == *p1)
        {
            ++p1;
        }
    }
}
inline basic_string_view<C> left_view_helper(C const* s, ss_size_t n)
{
    const ss_size_t len = stlsoft_ns_qual(c_str_len)(s);

    if(n > len)
    {
        // Want more than is available, so get all
        n = len;
    }

    return basic_string_view<C>(s, n);
}
inline ss_typename_type_ret_k string_view_helper_traits<S>::view_type left_view(S const& s, ss_size_t n)
{
    typedef string_view_helper_traits<S>            traits_t;
    typedef ss_typename_type_k traits_t::view_type  view_t;

    const ss_size_t len = stlsoft_ns_qual(c_str_len)(s);

    if(n > len)
    {
        // Want more than is available, so get all
        n = len;
    }

    return view_t(s.data(), n);
}
inline basic_string_view<C> right_view_helper(C const* s, ss_size_t n)
{
    const ss_size_t len = stlsoft_ns_qual(c_str_len)(s);

    if(n > len)
    {
        // Want more than is available, so get all, from start
        n = len;
    }
    else
    {
        // Want less than is available, so get n from end
        s += (len - n);
    }

    return basic_string_view<C>(s, n);
}
inline ss_typename_type_ret_k string_view_helper_traits<S>::view_type right_view(S const& s, ss_size_t n)
{
    typedef string_view_helper_traits<S>            traits_t;
    typedef ss_typename_type_k traits_t::view_type  view_t;

    const ss_size_t len = stlsoft_ns_qual(c_str_len)(s);
    ss_size_t       off =   0;

    if(n > len)
    {
        // Want more than is available, so get all, from start
        n = len;
    }
    else
    {
        off = len - n;
    }

    return view_t(s.data() + off, n);
}
inline basic_string_view<C> mid_view_helper(C const* s, ss_size_t start, ss_size_t n)
{
    const ss_size_t len = stlsoft_ns_qual(c_str_len)(s);
    ss_size_t       off =   0;

    if(start > len)
    {
        // Want more than is available, so we start at the end
        off = len;
    }
    else
    {
        off = start;
    }

    if(off + n > len)
    {
        // Want more than is available starting at off, so we just get what is available
        n = len - off;
    }

    return basic_string_view<C>(s + off, n);
}
inline ws_bool_t browse_for_folder(S0 const& title, C* displayName, UINT flags, HWND hwndOwner, LPCITEMIDLIST pidlRoot, S1 const& defaultFolder)
{
    return shell_browse_impl(stlsoft_ns_qual(c_str_ptr)(title), displayName, flags, hwndOwner, pidlRoot, stlsoft_ns_qual(c_str_ptr)(defaultFolder));
}
inline ws_bool_t browse_for_folder(S const& title, C* displayName, UINT flags, HWND hwndOwner, LPCITEMIDLIST pidlRoot)
{
    return shell_browse_impl(stlsoft_ns_qual(c_str_ptr)(title), displayName, flags, hwndOwner, pidlRoot, static_cast<C const*>(NULL));
}
\endcode
 *
 * \note The handling of Unicode strings under Windows 9x family operating
 * systems eschews the use of LoadStringW(), instead manipulating the resource
 * information via FindResourceEx() / LoadResource() / LockResource(). This
 * code kindly provided by Ryan Ginstrom.
 *
 * \param S The string class, e.g. std::string, stlsoft::simple_string, etc.
 * \param X The exception class
 */
template<   ss_typename_param_k S
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
# ifdef STLSOFT_CF_EXCEPTION_SUPPORT
        ,   ss_typename_param_k X = resource_exception_policy
# else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
        ,   ss_typename_param_k X = stlsoft_ns_qual(null_exception_policy)
# endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
#else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
        ,   ss_typename_param_k X /* = stlsoft_ns_qual(null_exception_policy) */
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
        >
// class basic_resource_string
class basic_resource_string
    : public S
    , protected X
{
private:
    typedef S                                          parent_class_type;
public:
    /// The type of the underlying string
    typedef S                                          string_type;
Beispiel #12
0
XCONTRACT_CALL(void) xContract_violationReport( char const*                 file
                                            ,   unsigned                    line
                                            ,   char const*                 function
                                            ,   char const*                 expression
                                            ,   char const*                 message
                                            ,   char const*                 qualifier
                                            ,   xContract_violation_type_t  type
                                            ,   int                         level)
{
    /* 1. formulate the termination messages */

    char        sz[2001];
    size_t      type_len = 0;
    char const* type_str = xcontract_lookup_violation_type_string_(type, &type_len);
    int         cch;

    STLSOFT_SUPPRESS_UNUSED(level);

#ifdef XCONTRACT_USING_SAFE_STR_FUNCTIONS
    cch = sprintf_s(
#else /* ? XCONTRACT_USING_SAFE_STR_FUNCTIONS */
    cch = snprintf(
#endif /* XCONTRACT_USING_SAFE_STR_FUNCTIONS */
                    &sz[0]
                ,   STLSOFT_NUM_ELEMENTS(sz) - 2
                ,   "Contract violation: %s at %s(%d)%s%s: %s%s%s%s%s"
                /* %s */
                ,   type_str
                /* %s(%d)%s%s */
                ,   file
                ,   line
                ,   (NULL == function) ? "" : " in function "
                ,   stlsoft_ns_qual(c_str_ptr_a)(function)
                /* %s%s%s */
                ,   message
                ,   (NULL == expression) ? "" : " - failed expression: "
                ,   stlsoft_ns_qual(c_str_ptr_a)(expression)
                /* %s%s */
                ,   (NULL == qualifier || '\0' == 0[qualifier]) ? "" : ": "
                ,   stlsoft_ns_qual(c_str_ptr_a)(qualifier)
                );

    if(cch < 0)
    {
        cch = STLSOFT_NUM_ELEMENTS(sz) - 2;
    }

    sz[cch]     = '\n';
    sz[cch + 1] = '\0';

    /* 2. write out the termination messages */

    fputs(sz, stderr);

#ifdef XCONTRACT_USE_WIN_OUTPUTDEBUGSTRING
    OutputDebugStringA(sz);
#endif /* XCONTRACT_USE_WIN_OUTPUTDEBUGSTRING */

    sz[cch] = '\0';

#ifdef XCONTRACT_USE_WIN_EVENTLOG
    {
        HANDLE hEvLog = RegisterEventSource(NULL, "xContract");

        if(NULL != hEvLog)
        {
            WORD        wType       =   EVENTLOG_ERROR_TYPE;
            WORD        category    =   XCONTRACT_WIN_EVENTLOG_CATEGORY;
            DWORD       eventId     =   XCONTRACT_WIN_EVENTLOG_EVENTID;
            PSID        lpUserSid   =   NULL;
            WORD        wNumStrings =   1;
            LPCSTR      entry       =   &sz[0];
            LPCSTR*     lpStrings   =   &entry;
            DWORD       dwDataSize  =   0;
            LPVOID      lpRawData   =   NULL;

            ReportEventA(   hEvLog
                        ,   wType
                        ,   category
                        ,   eventId
                        ,   lpUserSid
                        ,   wNumStrings
                        ,   dwDataSize
                        ,   lpStrings
                        ,   lpRawData);

            DeregisterEventSource(hEvLog);
        }
    }
#endif /* XCONTRACT_USE_WIN_EVENTLOG */

#ifdef XCONTRACT_USE_SYSLOG
    syslog(XCONTRACT_SYSLOG_FLAGS, "%s", sz);
#endif /* XCONTRACT_USE_SYSLOG */
}
Beispiel #13
0
us_size_t path_squeeze_impl2(S const& path, us_char_w_t* buffer, us_size_t cchBuffer)
{
    return path_squeeze_impl(stlsoft_ns_qual(c_str_ptr_w)(path), stlsoft_ns_qual(c_str_len)(path), buffer, cchBuffer);
}
Beispiel #14
0
inline double atof(S const& s)
{
    return atof_helper::call(stlsoft_ns_qual(c_str_ptr)(s));
}
Beispiel #15
0
inline ws_uint64_t load_text_file_impl(S1 const& fileName, S2 &contents)
{
    typedef string_traits<S1>                               string_traits_t;

    STLSOFT_STATIC_ASSERT(sizeof(string_traits_t));     // Fires if S1 does not have a traits specialisation defined

    typedef string_traits<S2>                               string_traits2_t;

    STLSOFT_STATIC_ASSERT(sizeof(string_traits2_t));    // Fires if S2 does not have a traits specialisation defined

    typedef ss_typename_type_k string_traits_t::char_type   C;

    STLSOFT_STATIC_ASSERT(sizeof(C));                   // Fires if the traits is not correctly defined

    typedef ss_typename_type_k string_traits2_t::char_type  char_2_type;

    STLSOFT_STATIC_ASSERT(sizeof(char_2_type));         // Fires if the traits is not correctly defined

    typedef filesystem_traits<C>                            filesys_traits_t;

    STLSOFT_STATIC_ASSERT(sizeof(filesys_traits_t));    // Fires if no corresponding filesystem_traits defined

    scoped_handle<HANDLE>   h(  filesys_traits_t::create_file(  stlsoft_ns_qual(c_str_ptr)(fileName)
                                                            ,   GENERIC_READ
                                                            ,   FILE_SHARE_READ
                                                            ,   NULL
                                                            ,   OPEN_EXISTING
                                                            ,   0
                                                            ,   NULL)
                            ,   (void (STLSOFT_CDECL *)(HANDLE))&filesys_traits_t::close_handle // This cast required by VC++ 5
                            ,   INVALID_HANDLE_VALUE);

    if(INVALID_HANDLE_VALUE == h.get())
    {
        STLSOFT_THROW_X(windows_exception("File does not exist", ::GetLastError()));
    }

    ws_uint64_t             size    =   filesys_traits_t::get_file_size(h.get());

    if( 0 != size &&
        static_cast<ws_uint64_t>(~0) != size)
    {
        if(size > 0xFFFFFFFF)
        {
            STLSOFT_THROW_X(winstl_ns_qual_std(out_of_range)("Cannot read in files larger than 4GB"));
        }
        else
        {
// TODO: Catch the out-of-memory exception and translate to a std::out_of_range()

            typedef ::stlsoft::auto_buffer_old< char_2_type
                                            ,   processheap_allocator<char_2_type>
                                            ,   1024
                                            >                   buffer_t;

            buffer_t    buffer(static_cast<ss_typename_type_k buffer_t::size_type>(size));
            DWORD       dw;

            if(!::ReadFile(h.get(), &buffer[0], buffer.size(), &dw, NULL))
            {
                STLSOFT_THROW_X(windows_exception("Read operation failed", ::GetLastError()));
            }
            else
            {
                contents.assign(&buffer[0], dw);

                return size;
            }
        }
    }

    return 0;
}
Beispiel #16
0
inline int atoi(S const& s)
{
    return atoi_helper::call(stlsoft_ns_qual(c_str_ptr)(s));
}
Beispiel #17
0
inline int system(S const& s)
{
    return ::system(stlsoft_ns_qual(c_str_ptr)(s));
}
Beispiel #18
0
 */

/** \brief STL-like sequence for edit control contents
 *
 * \ingroup group__library__windows_controls
 *
 * This class presents an STL-like sequence interface to an edit control
 *
 * \param C The character type
 * \param A The allocator type. Defaults to winstl::processheap_allocator
 * \param S The string type. Defaults to stlsoft::simple_string
 * \param Q The queue container type. Defaults to std::vector
 */
template<   ss_typename_param_k C
        ,   ss_typename_param_k A = processheap_allocator<C>
        ,   ss_typename_param_k S = stlsoft_ns_qual(basic_simple_string)<C, stlsoft_ns_qual(char_traits)<C>, A>
        ,   ss_typename_param_k Q = stlsoft_ns_qual_std(vector)<S>
        >
class edit_line_sequence
    : public stlsoft_ns_qual(stl_collection_tag)
{
/// \name Member Types
/// @{
public:
    /// \brief The character type
    typedef C                                                       char_type;
    /// \brief The allocator type
    typedef A                                                       allocator_type;
    /// \brief The string type
    typedef S                                                       string_type;
    /// \brief The value type
 * This class converts a relative path to an absolute one, and effectively acts
 * as a C-string of its value.
 */

/** \brief Represents an environment variable
 *
 * \ingroup group__library__system
 *
 * \param C The character type
 * \param T The traits type. Defaults to system_traits<C>. On translators that do not support default template arguments, it must be explicitly stipulated
 * \param A The allocator class. Defaults to stlsoft::allocator_selector<C>::allocator_type. On translators that do not support default template arguments, it is not part of the template parameter list.
 */
template<   ss_typename_param_k C
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
        ,   ss_typename_param_k T = system_traits<C>
        ,   ss_typename_param_k A = ss_typename_type_def_k stlsoft_ns_qual(allocator_selector)<C>::allocator_type
#else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
        ,   ss_typename_param_k T /* = system_traits<C> */
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
        >
class basic_environment_variable
{
public:
    /// The char type
    typedef C                                   char_type;
    /// The traits type
    typedef T                                   traits_type;
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
    /// The allocator type
    typedef A                                   allocator_type;
    /// The current parameterisation of the type
Beispiel #20
0
/** \brief \ref group__concept__shim__string_access__c_str_len function
 *    for <code>struct dirent</code>.
 *
 * \ingroup group__concept__shim__string_access
 *
 * \return Length (in bytes) of the string form of <code>d</code>.
 */
inline us_size_t c_str_len_a(struct dirent const* d)
{
    return stlsoft_ns_qual(c_str_len)(c_str_data(d));
}
Beispiel #21
0
inline long atol(S const& s)
{
    return atol_helper::call(stlsoft_ns_qual(c_str_ptr)(s));
}
Beispiel #22
0
 static ws_bool_t set_window_text(HWND hwnd, S const& s)
 {
     return class_type::set_window_text(hwnd, stlsoft_ns_qual(c_str_ptr_w)(s));
 }
Beispiel #23
0
const CLSID CLSID_pantheios_COM_LoggerManager  = { 0x4E7D5C47, 0x8F96, 0x45DE, { 0x90, 0x5D, 0xAA, 0x3E, 0x9E, 0x59, 0x2D, 0xE3 } };

stlsoft::ref_ptr<IDispatch> logmgr;
if(SUCCEEDED(comstl::co_create_instance(CLSID_pantheios_COM_LoggerManager, logmgr)))
{
  . . .
} // Release() automatically invoked here
\endcode
 */
template<   ss_typename_param_k T
        ,   ss_typename_param_k I
        ,   ss_typename_param_k U
        >
inline HRESULT co_create_instance(
    REFCLSID                            clsid
,   stlsoft_ns_qual(ref_ptr)<T, I, U>&  wi
,   DWORD                               dwClsContext = CLSCTX_ALL
)
{
    I*      pi;
    HRESULT hr = co_create_instance(clsid, &pi, dwClsContext);

    if(FAILED(hr))
    {
        pi = NULL;
    }

    wi.set(pi, false); // Eat the reference

    return hr;
}