inline bool parameters_equal(ContainerT const ¶meters, 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(); const_iterator_type last2 = new_parameters.end(); while (first1 != last1 && first2 != last2) { // 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 && first2 == last2) ? true : false; }
template <typename ContainerT> StaticGraph(const int nodes, const ContainerT &edges) { BOOST_ASSERT(std::is_sorted(const_cast<ContainerT &>(edges).begin(), const_cast<ContainerT &>(edges).end())); InitializeFromSortedEdgeRange(nodes, edges.begin(), edges.end()); }
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); } }
inline typename ContainerT::value_type::string_type as_string (ContainerT const &token_sequence) { typedef typename ContainerT::value_type::string_type string_type; return as_string<string_type>(token_sequence.begin(), token_sequence.end()); }
void _copyData(const ContainerT& data, ResultT*& result) { if(data.size() == 0) { return; } result = new ResultT[data.size()]; std::copy(data.begin(), data.end(), result); }
bool found_unknown_directive(ContextT const& ctx, ContainerT const& line, ContainerT& pending) { BOOST_WAVETEST_OSSTREAM strm; strm << "21: " << repr((*line.begin()).get_position()) << ": " << boost::wave::util::impl::as_string(line) << std::endl; hooks_trace += BOOST_WAVETEST_GETSTRING(strm); return false; }
void eraseElementsIf(ContainerT& container, const PredicateT& predicate) { auto iter = container.begin(); while(iter != container.end()) { if(predicate(*iter) == true) { iter = container.erase(iter); } else { ++iter; } } }
inline bool is_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; }
bool found_unknown_directive(ContextT const& ctx, ContainerT const& line, ContainerT& pending) { namespace wave = boost::wave; typedef typename ContainerT::const_iterator iterator_type; iterator_type it = line.begin(); wave::token_id id = wave::util::impl::skip_whitespace(it, line.end()); if (id != wave::T_IDENTIFIER) return false; // nothing we could do if ((*it).get_value() == "version" || (*it).get_value() == "extension") { // handle #version and #extension directives std::copy(line.begin(), line.end(), std::back_inserter(pending)); return true; } return false; // unknown directive }
inline bool definition_equals(ContainerT const &definition, ContainerT const &new_definition) { typedef typename ContainerT::const_iterator const_iterator_type; const_iterator_type first1 = definition.begin(); const_iterator_type last1 = definition.end(); const_iterator_type first2 = new_definition.begin(); const_iterator_type last2 = new_definition.end(); while (first1 != last1 && first2 != last2 && token_equals(*first1, *first2)) { // skip whitespace, if both sequences have a whitespace next token_id id1 = next_token<const_iterator_type>::peek(first1, last1, false); token_id id2 = next_token<const_iterator_type>::peek(first2, last2, false); if (IS_CATEGORY(id1, WhiteSpaceTokenType) && IS_CATEGORY(id2, WhiteSpaceTokenType)) { // all consecutive whitespace tokens count as one whitespace // adjust first1 and first2 accordingly skip_whitespace(first1, last1); skip_whitespace(first2, last2); } else if (!IS_CATEGORY(id1, WhiteSpaceTokenType) && !IS_CATEGORY(id2, WhiteSpaceTokenType)) { ++first1; ++first2; } else { // the sequences differ break; } } return (first1 == last1 && first2 == last2) ? true : false; }
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; } } } }
inline typename ContainerT::value_type::string_type as_stringlit (ContainerT const &token_sequence, PositionT const &pos) { using namespace boost::wave; typedef typename ContainerT::value_type::string_type string_type; string_type result("\""); bool was_whitespace = false; typename ContainerT::const_iterator end = token_sequence.end(); for (typename ContainerT::const_iterator it = token_sequence.begin(); it != end; ++it) { token_id id = token_id(*it); if (IS_CATEGORY(*it, WhiteSpaceTokenType) || T_NEWLINE == id) { if (!was_whitespace) { // C++ standard 16.3.2.2 [cpp.stringize] // Each occurrence of white space between the argument's // preprocessing tokens becomes a single space character in the // character string literal. result += " "; was_whitespace = true; } } else if (T_STRINGLIT == id || T_CHARLIT == id) { // string literals and character literals have to be escaped result += impl::escape_lit((*it).get_value()); was_whitespace = false; } else #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0 if (T_PLACEMARKER != id) #endif { // now append this token to the string result += (*it).get_value(); was_whitespace = false; } } result += "\""; // validate the resulting literal to contain no invalid universal character // value (throws if invalid chars found) boost::wave::cpplexer::impl::validate_literal(result, pos.get_line(), pos.get_column(), pos.get_file()); return result; }
void push_front_test() { using namespace boost::spirit; const char* cp = "one,two,three"; const char* cp_first = cp; const char* cp_last = cp + test_impl::string_length(cp); const char* cp_i[] = {"one","two","three"};; int i; ContainerT c; typename ContainerT::const_iterator it; scanner<char const*> scan( cp_first, cp_last ); match<> hit; hit = list_p( (*alpha_p)[ push_front_a(c)] , ch_p(',') ).parse(scan); BOOST_CHECK(hit); BOOST_CHECK_EQUAL(scan.first, scan.last); BOOST_CHECK_EQUAL( c.size(), static_cast<typename ContainerT::size_type>(3)); for (i=2, it = c.begin();i>=0 && it != c.end();--i, ++it) BOOST_CHECK_EQUAL( cp_i[i], *it); scan.first = cp; }
bool CPreProcessor::found_unknown_directive(ContextT const& ctx, ContainerT const& line, ContainerT& pending) { typedef typename ContainerT::const_iterator iterator_type; iterator_type it = line.begin(); wave::token_id id = wave::util::impl::skip_whitespace(it, line.end()); if ( id != wave::T_IDENTIFIER ) { // nothing we could do return false; } if ((*it).get_value() == "version" || (*it).get_value() == "extension" ) { // Handle #version and #extension directives std::copy(line.begin(), line.end(), std::back_inserter(pending)); return true; } if ((*it).get_value() == "type" ) { // Handle type directive typedef typename ContextT::token_type result_type; for ( result_type t : line ) { const char* text = t.get_value().c_str(); if ( strcmp("#", text) != 0 && strcmp("type", text) != 0 && strcmp("na", text) != 0 ) { type_ += t.get_value().c_str(); } } alg::trim(type_); //std::cout << type_ << std::endl; return true; } if ((*it).get_value() == "name") { // Once the name is set, we ignore #name directives if ( name_.size() == 0 ) { // Handle name directive typedef typename ContextT::token_type result_type; for ( result_type t : line ) { const char* text = t.get_value().c_str(); if ( strcmp("#", text) != 0 && strcmp("name", text) != 0 ) { name_ += t.get_value().c_str(); } } alg::trim(name_); } //std::cout << name_ << std::endl; return true; } if ((*it).get_value() == "bind" ) { // Handle bind directive //typedef typename ContextT::token_type result_type; //for ( result_type t : line) { // std::cout << t.get_value() << std::endl; //} std::copy(line.begin(), line.end(), std::back_inserter(pending)); return true; } // Unknown directive return false; }
std::string containerStr (const ContainerT& c, int wrapLengthParam = 0, int numIndentationSpaces = 0) { return elemsStr(c.begin(), c.end(), wrapLengthParam, numIndentationSpaces); }
template<class ContainerT, class PredicateT> inline auto find_if(const ContainerT& _container, const PredicateT& _pred) { return sq::algo::find_if(_container.begin(), _container.end(), _pred); }
void erase_if(ContainerT& items, const PredicateT& predicate) { for(auto it = items.begin(); it != items.end();) { if(predicate(*it)) it = items.erase(it); else ++it; } };
void visit( ContainerT& v, ::boost::any* data ){ for( typename ContainerT::iterator it = v.begin(); it != v.end(); ++it ){ SAFE_ACCEPT( *it ); } }
template<class ContainerT, class ValueT> inline auto find_first(const ContainerT& _container, const ValueT& _value) { return sq::algo::find_first(_container.begin(), _container.end(), _value); }
std::string stringJoin(ContainerT const & a, C const & padding) { return stringJoin(a.begin(), a.end(), padding); }
inline long toNumber(ContainerT& digits) { return toNumber(digits.begin(), digits.end()); }