Function str2bm

Summary

#include <src/c4/bitmask.hpp>

(1) template <class Enum>
    std::underlying_type< Enum >::type str2bm(const char *str, size_t sz)

(2) template <class Enum>
    std::underlying_type< Enum >::type str2bm(const char *str)

Function overload

Synopsis

#include <src/c4/bitmask.hpp>

template <class Enum>
std::underlying_type< Enum >::type str2bm(const char *str, size_t sz)

Description

convert a string to a bitmask

Mentioned in

Source

Lines 242-301 in src/c4/bitmask.hpp.

template<class Enum>
typename std::underlying_type<Enum>::type str2bm(const char *str, size_t sz)
{
    using I = typename std::underlying_type<Enum>::type;

    I val = 0;
    bool started = false;
    bool alnum = false, num = false;
    const char *f = nullptr, *pc = str;
    for( ; pc < str+sz; ++pc)
    {
        const char c = *pc;
        if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_')
        {
            C4_CHECK(( ! num) || ((pc - f) == 1 && (c == 'x' || c == 'X'))); // accept hexadecimal numbers
            if( ! started)
            {
                f = pc;
                alnum = started = true;
            }
        }
        else if(c >= '0' && c <= '9')
        {
            C4_CHECK( ! alnum);
            if(!started)
            {
                f = pc;
                num = started = true;
            }
        }
        else if(c == ':' || c == ' ')
        {
            // skip this char
        }
        else if(c == '|' || c == '\0')
        {
            C4_ASSERT(num != alnum);
            C4_ASSERT(pc >= f);
            val |= detail::str2bm_read_one<Enum>(f, static_cast<size_t>(pc-f), alnum);
            started = num = alnum = false;
            if(c == '\0')
            {
                return val;
            }
        }
        else
        {
            C4_ERROR("bad character '%c' in bitmask string", c);
        }
    }

    if(f)
    {
        C4_ASSERT(num != alnum);
        C4_ASSERT(pc >= f);
        val |= detail::str2bm_read_one<Enum>(f, static_cast<size_t>(pc-f), alnum);
    }

    return val;
}

Synopsis

#include <src/c4/bitmask.hpp>

template <class Enum>
std::underlying_type< Enum >::type str2bm(const char *str)

Description

convert a string to a bitmask

Mentioned in

Source

Lines 304-308 in src/c4/bitmask.hpp.

template<class Enum>
typename std::underlying_type<Enum>::type str2bm(const char *str)
{
    return str2bm<Enum>(str, strlen(str));
}





Add Discussion as Guest

Log in