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

📄 cpp_macromap_utils.hpp

📁 C++的一个好库。。。现在很流行
💻 HPP
📖 第 1 页 / 共 2 页
字号:
template <typename ContainerT>
inline bool 
parameters_equal(ContainerT const &parameters, ContainerT const &new_parameters)
{
    if (parameters.size() != new_parameters.size())
        return false;   // different parameter count

    typedef typename ContainerT::const_iterator const_iterator_type;
    
const_iterator_type first1 = parameters.begin();
const_iterator_type last1 = parameters.end();
const_iterator_type first2 = new_parameters.begin();

    while (first1 != last1) {
    // parameters are different, if the corresponding tokens are different
        using namespace boost::wave;
        if (token_id(*first1) != token_id(*first2) ||
            (*first1).get_value() != (*first2).get_value())
        {
            break;
        }
        ++first1;
        ++first2;
    }
    return (first1 == last1) ? true : false;
}

///////////////////////////////////////////////////////////////////////////////
//
//  Strip leading and trailing whitespace from the given token sequence
//
///////////////////////////////////////////////////////////////////////////////
template <typename ContainerT>
inline void
trim_replacement_list (ContainerT &replacement_list)
{
    using namespace boost::wave;

// strip leading whitespace
    if (replacement_list.size() > 0) {
    typename ContainerT::iterator end = replacement_list.end();
    typename ContainerT::iterator it = replacement_list.begin();
    
        while (it != end && IS_CATEGORY(*it, WhiteSpaceTokenType)) { 
            if (T_PLACEHOLDER != token_id(*it)) {
                typename ContainerT::iterator next = it;
                ++next;
                replacement_list.erase(it);
                it = next;
            }
            else {
                ++it;
            }
        }
    }
        
// strip trailing whitespace
    if (replacement_list.size() > 0) {
    typename ContainerT::reverse_iterator rend = replacement_list.rend();
    typename ContainerT::reverse_iterator rit = replacement_list.rbegin();
    
        while (rit != rend && IS_CATEGORY(*rit, WhiteSpaceTokenType)) 
            ++rit;

    typename ContainerT::iterator end = replacement_list.end();
    typename ContainerT::iterator it = rit.base();
    
        while (it != end && IS_CATEGORY(*it, WhiteSpaceTokenType)) { 
            if (T_PLACEHOLDER != token_id(*it)) {
                typename ContainerT::iterator next = it;
                ++next;
                replacement_list.erase(it);
                it = next;
            }
            else {
                ++it;
            }
        }
    }
}

///////////////////////////////////////////////////////////////////////////////
//
//  Remove all placeholder tokens from the given token sequence
//
///////////////////////////////////////////////////////////////////////////////
template <typename ContainerT>
inline void
remove_placeholders (ContainerT &replacement_list)
{
    using namespace boost::wave;

// strip leading whitespace
    if (replacement_list.size() > 0) {
    typename ContainerT::iterator end = replacement_list.end();
    typename ContainerT::iterator it = replacement_list.begin();
    
        while (it != end) {
            if (T_PLACEHOLDER == token_id(*it)) {
                typename ContainerT::iterator next = it;
                ++next;
                replacement_list.erase(it);
                it = next;
            }
            else {
                ++it;
            }
        }
        
    // remove all 'new' leading and trailing whitespace 
        trim_replacement_list(replacement_list);
    }
}

///////////////////////////////////////////////////////////////////////////////
//
//  Remove all whitespace tokens on the left side of the given token sequence
//
///////////////////////////////////////////////////////////////////////////////
template <typename ContainerT>
inline void
trim_argument_left (ContainerT &argument)
{
    using namespace boost::wave;
    
// strip leading whitespace (should be only one token)
    if (argument.size() > 0 &&
        IS_CATEGORY(argument.front(), WhiteSpaceTokenType))
    {
        argument.pop_front();
    }
}
    
///////////////////////////////////////////////////////////////////////////////
//
//  Remove all whitespace tokens on the right side of the given token sequence
//
///////////////////////////////////////////////////////////////////////////////
template <typename ContainerT>
inline void
trim_argument_right (ContainerT &argument)
{
    using namespace boost::wave;
    
// strip trailing whitespace (should be only one token)
    if (argument.size() > 0 &&
        IS_CATEGORY(argument.back(), WhiteSpaceTokenType))
    {
        argument.pop_back();
    }
}

///////////////////////////////////////////////////////////////////////////////
//
//  Remove all whitespace tokens on the keft and right sides of the given token 
//  sequence
//
///////////////////////////////////////////////////////////////////////////////
template <typename ContainerT>
inline void
trim_argument (ContainerT &argument)
{
    trim_argument_left(argument);
    trim_argument_right(argument);
}

///////////////////////////////////////////////////////////////////////////////
//
//  Tests, whether the given token sequence consists out of whitespace only
//
///////////////////////////////////////////////////////////////////////////////
template <typename ContainerT>
inline bool
is_whitespace_only (ContainerT const &argument)
{
    using namespace cpplexer;
    
    typename ContainerT::const_iterator end = argument.end();
    for (typename ContainerT::const_iterator it = argument.begin();
          it != end; ++it)
    {
        if (!IS_CATEGORY(*it, WhiteSpaceTokenType))
            return false;
    }
    return true;
}

///////////////////////////////////////////////////////////////////////////////
//
//  Skip forward to a given token
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT>
inline bool 
skip_to_token(IteratorT &it, IteratorT const &end, token_id id)
{
    using namespace boost::wave;
    if (token_id(*it) == id) 
        return true;
    if (++it == end) 
        return false;

    while (IS_CATEGORY(*it, WhiteSpaceTokenType) || 
            T_NEWLINE == token_id(*it)) 
    {
        if (++it == end)
            return false;
    }
    return token_id(*it) == id;
}

///////////////////////////////////////////////////////////////////////////////
//
//  Get the full name of a given macro name (concatenate the string 
//  representations of the single tokens).
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT>
inline std::string
get_full_name(IteratorT const &begin, IteratorT const &end)
{
    std::string full_name;
    for (IteratorT err_it = begin; err_it != end; ++err_it) 
        full_name += (*err_it).get_value().c_str();

    return full_name;
}

///////////////////////////////////////////////////////////////////////////////
//
//  The following predicate is used in conjunction with the remove_copy_if
//  algorithm to allow the detection of an eventually copied operator ##.
//  No removal is performed in any case.
//
///////////////////////////////////////////////////////////////////////////////
class find_concat_operator {
public:
    find_concat_operator(bool &found_) : found_concat(found_) {}
    
    template <typename TokenT>
    bool operator()(TokenT const &tok)
    {
        using namespace boost::wave;
        if (T_POUND_POUND == BASE_TOKEN(token_id(tok)))
            found_concat = true;
        return false;
    }

private:
    bool &found_concat;
};

///////////////////////////////////////////////////////////////////////////////
}   // namespace impl

///////////////////////////////////////////////////////////////////////////////
}   // namespace util
}   // namespace wave
}   // namespace boost

#endif // !defined(CPP_MACROMAP_UTIL_HPP_HK041119)

⌨️ 快捷键说明

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