void replace_ellipsis (std::vector<ContainerT> const &arguments,
     typename ContainerT::size_type index, 
     ContainerT &expanded, PositionT const &pos)
 {
     using namespace cpplexer;
     typedef typename ContainerT::value_type token_type;
     
     token_type comma(T_COMMA, ",", pos);
     for (/**/; index < arguments.size(); ++index) {
     ContainerT const &arg = arguments[index];
     
         std::copy(arg.begin(), arg.end(), 
             std::inserter(expanded, expanded.end()));
             
         if (index < arguments.size()-1) 
             expanded.push_back(comma);
     }
 }
 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; 
 }
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 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();
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;
}
Beispiel #5
0
    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;
}
Beispiel #7
0
void tokenize(const std::string& str, ContainerT& tokens, const std::string& delimiters, const bool trimEmpty)
{
/*
 I usually choose to use std::vector<std::string> types as my second parameter
  (ContainerT)... but list<> is way faster than vector<> for when direct access
   is not needed, and you can even create your own string class and use something
    like std::list<SubString> where SubString does not do any copies for incredible speed increases.
It's more than double as fast as the fastest tokenize on this page and almost 5 times
faster than some others. Also with the perfect parameter types you can eliminate all string and list copies.
Additionally it does not do the (extremely inefficient) return of result, but rather
it passes the tokens as a reference, thus also allowing you to build up tokens using
multiple calls if you so wished.Lastly it allows you to specify whether to trim empty
tokens from the results via a last optional parameter.All it needs is std::string...
the rest are optional. It does not use streams or the boost library, but is flexible
enough to be able to accept some of these foreign types naturally.
 */
	std::string::size_type pos, lastPos = 0;
	while(true)
	{
		pos = str.find_first_of(delimiters, lastPos);
		if(pos == std::string::npos)
		{
			pos = str.length();
			if(pos != lastPos || !trimEmpty)
			{
				tokens.push_back(typename ContainerT::value_type(str.data()+lastPos, typename ContainerT::value_type::size_type(pos-lastPos)));
			}
			break;
		}
		else
		{
			if(pos != lastPos || !trimEmpty)
				tokens.push_back(typename ContainerT::value_type(str.data()+lastPos, typename ContainerT::value_type::size_type(pos-lastPos )));
		}

		lastPos = pos + 1;
	}
}
void tokenize(const std::string& str, ContainerT& tokens,
              const std::string& delimiters = " ", const bool trimEmpty = false)
{
  std::string::size_type pos, lastPos = 0;
  while (true)
  {
    pos = str.find_first_of(delimiters, lastPos);
    if (pos == std::string::npos)
    {
      pos = str.length();

      if (pos != lastPos || !trimEmpty)
        tokens.push_back(typename ContainerT::value_type(str.data() + lastPos, pos - lastPos));
      break;
    }
    else
    {
      if (pos != lastPos || !trimEmpty)
        tokens.push_back(typename ContainerT::value_type(str.data() + lastPos, pos - lastPos));
    }
    lastPos = pos + 1;
  }
};
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 
    emit_line_directive(ContextT const& ctx, ContainerT &pending, 
        typename ContextT::token_type const& act_token)
    {
        if (!need_emit_line_directives(ctx.get_language()) ||
            !enable_relative_names_in_line_directives())
        {
            return false;
        }

    // emit a #line directive showing the relative filename instead
    typename ContextT::position_type pos = act_token.get_position();
    unsigned int column = 6;

        typedef typename ContextT::token_type result_type;
        using namespace boost::wave;

        pos.set_column(1);
        pending.push_back(result_type(T_PP_LINE, "#line", pos));

        pos.set_column(column);      // account for '#line'
        pending.push_back(result_type(T_SPACE, " ", pos));

    // 21 is the max required size for a 64 bit integer represented as a 
    // string
    char buffer[22];

        using namespace std;    // for some systems sprintf is in namespace std
        sprintf (buffer, "%d", pos.get_line());

        pos.set_column(++column);                 // account for ' '
        pending.push_back(result_type(T_INTLIT, buffer, pos));
        pos.set_column(column += (unsigned int)strlen(buffer)); // account for <number>
        pending.push_back(result_type(T_SPACE, " ", pos));
        pos.set_column(++column);                 // account for ' '

    std::string file("\"");
    boost::filesystem::path filename(
        boost::wave::util::create_path(ctx.get_current_relative_filename().c_str()));

        using boost::wave::util::impl::escape_lit;
        file += escape_lit(boost::wave::util::native_file_string(filename)) + "\"";

        pending.push_back(result_type(T_STRINGLIT, file.c_str(), pos));
        pos.set_column(column += (unsigned int)file.size());    // account for filename
        pending.push_back(result_type(T_GENERATEDNEWLINE, "\n", pos));

        return true;
    }
WLEExponent::ContainerT WLEExponent::values()
{
    ContainerT con;

    con.insert( WLEExponent::KILO );
    con.insert( WLEExponent::BASE );
    con.insert( WLEExponent::CENTI );
    con.insert( WLEExponent::MILLI );
    con.insert( WLEExponent::MICRO );
    con.insert( WLEExponent::NANO );
    con.insert( WLEExponent::PICO );
    con.insert( WLEExponent::FEMTO );

    return con;
}
Beispiel #12
0
    /**
     * Constructs a DynamicGraph from a list of edges sorted by source node id.
     */
    template <class ContainerT> DynamicGraph(const NodeIterator nodes, const ContainerT &graph)
    {
        // we need to cast here because DeallocatingVector does not have a valid const iterator
        BOOST_ASSERT(std::is_sorted(const_cast<ContainerT&>(graph).begin(), const_cast<ContainerT&>(graph).end()));

        number_of_nodes = nodes;
        number_of_edges = static_cast<EdgeIterator>(graph.size());
        node_array.resize(number_of_nodes + 1);
        EdgeIterator edge = 0;
        EdgeIterator position = 0;
        for (const auto node : osrm::irange(0u, number_of_nodes))
        {
            EdgeIterator last_edge = edge;
            while (edge < number_of_edges && graph[edge].source == node)
            {
                ++edge;
            }
            node_array[node].first_edge = position;
            node_array[node].edges = edge - last_edge;
            position += node_array[node].edges;
        }
        node_array.back().first_edge = position;
        edge_list.reserve(static_cast<std::size_t>(edge_list.size() * 1.1));
        edge_list.resize(position);
        edge = 0;
        for (const auto node : osrm::irange(0u, number_of_nodes))
        {
            for (const auto i : osrm::irange(node_array[node].first_edge,
                                             node_array[node].first_edge + node_array[node].edges))
            {
                edge_list[i].target = graph[edge].target;
                BOOST_ASSERT(edge_list[i].target < number_of_nodes);
                edge_list[i].data = graph[edge].data;
                ++edge;
            }
        }
    }
Beispiel #13
0
 void initArgs(ContainerT& cc) {
     cc.arg( base::DataSourceBase::shared_ptr(ma1.value) );
     cc.arg( base::DataSourceBase::shared_ptr(ma2.value) );
     cc.arg( base::DataSourceBase::shared_ptr(ma3.value) );
     cc.arg( base::DataSourceBase::shared_ptr(ma4.value) );
 }
std::string containerStr (const ContainerT& c, int wrapLengthParam = 0, int numIndentationSpaces = 0)
{
	return elemsStr(c.begin(), c.end(), wrapLengthParam, numIndentationSpaces);
}
Beispiel #15
0
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);
}
 static void apply(ContainerT & container, ElementT & elem, IDGeneratorT & id_generator)
 {
   if (!container.is_present( elem ) )
     viennagrid::detail::set_id(elem, id_generator( viennagrid::detail::tag<ValueT>() ) );
 }
Beispiel #17
0
std::string
stringJoin(ContainerT const & a, C const & padding)
{
  return stringJoin(a.begin(), a.end(), padding);
}
Beispiel #18
0
	void visit( ContainerT& v, ::boost::any* data ){
		for( typename ContainerT::iterator it = v.begin(); it != v.end(); ++it ){
			SAFE_ACCEPT( *it );
		}
	}
Beispiel #19
0
  void DeleteAtExit( BaseGDL* toGuard)
    {
//	if( toDestroy == NULL)
//		toDestroy = new ContainerT();
      toDestroy.push_back( toGuard);
    }
 inline void insertion_sort_recursive(ContainerT &container) noexcept {
     detail::_insertion_sort_recursive(container, container.size() - 1, container.size() - 1);;
 }
Beispiel #21
0
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;
}
Beispiel #22
0
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;
    }
};
 forceinline void accumulate(const T& t)
 {
     container.push_back(t);
 }
Beispiel #24
0
 void initArgs(ContainerT& cc) {
     cc.arg( base::DataSourceBase::shared_ptr(ma1.value.get()) );
 }
Beispiel #25
0
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);
}
Beispiel #26
0
 void initRet(ContainerT& cc) {
     cc.ret(base::DataSourceBase::shared_ptr(result));
 }
Beispiel #27
0
inline long toNumber(ContainerT& digits) {
    return toNumber(digits.begin(), digits.end());
}