cpp_macromap_utils.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 555 行 · 第 1/2 页
HPP
555 行
{ 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 voidremove_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 voidtrim_sequence_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 voidtrim_sequence_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 left and right sides of the given token // sequence/////////////////////////////////////////////////////////////////////////////////template <typename ContainerT>inline voidtrim_sequence (ContainerT &argument){ trim_sequence_left(argument); trim_sequence_right(argument);}/////////////////////////////////////////////////////////////////////////////////// Tests, whether the given token sequence consists out of whitespace only/////////////////////////////////////////////////////////////////////////////////template <typename ContainerT>inline boolis_whitespace_only (ContainerT const &argument){ 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, bool& seen_newline){ 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 (T_NEWLINE == token_id(*it)) seen_newline = true; 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::stringget_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;};///////////////////////////////////////////////////////////////////////////////// Convert a string of an arbitrary string compatible type to a internal // string (BOOST_WAVE_STRING)template <typename Target, typename Src>struct to_string_helper{ typedef Target type; static Target call(Src const& str) { return Target(str.c_str()); }};// do nothing if types are equaltemplate <typename Src>struct to_string_helper<Src, Src>{ typedef Src const& type; static Src const& call(Src const& str) { return str; }};template <typename Target>struct to_string_helper<Target, char const*>{ typedef Target type; static Target call(char const* str) { return Target(str); }};///////////////////////////////////////////////////////////////////////////////} // namespace impltemplate <typename Target, typename Src>inline typename impl::to_string_helper<Target, Src>::typeto_string(Src const& src){ return impl::to_string_helper<Target, Src>::call(src);}///////////////////////////////////////////////////////////////////////////////} // namespace util} // namespace wave} // namespace boost// the suffix header occurs after all of the code#ifdef BOOST_HAS_ABI_HEADERS#include BOOST_ABI_SUFFIX#endif#endif // !defined(CPP_MACROMAP_UTIL_HPP_HK041119)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?