/** Evaluates and executes a dvisvgm special statement.
 *  @param[in] prefix special prefix read by the SpecialManager
 *  @param[in] is the special statement is read from this stream
 *  @param[in] actions object providing the actions that can be performed by the SpecialHandler */
bool DvisvgmSpecialHandler::process (const string &prefix, istream &is, SpecialActions &actions) {
	struct Command {
		const char *name;
		void (DvisvgmSpecialHandler::*handler)(InputReader&, SpecialActions&);
	};
	constexpr array<Command, 7> commands {{
		{"raw",       &DvisvgmSpecialHandler::processRaw},
		{"rawdef",    &DvisvgmSpecialHandler::processRawDef},
		{"rawset",    &DvisvgmSpecialHandler::processRawSet},
		{"endrawset", &DvisvgmSpecialHandler::processEndRawSet},
		{"rawput",    &DvisvgmSpecialHandler::processRawPut},
		{"bbox",      &DvisvgmSpecialHandler::processBBox},
		{"img",       &DvisvgmSpecialHandler::processImg}
	}};
	StreamInputReader ir(is);
	const string cmdstr = ir.getWord();
	auto it = find_if(commands.begin(), commands.end(), [&](const Command &cmd) {
		return cmd.name == cmdstr;
	});
	if (it != commands.end()) {
		ir.skipSpace();
		(this->*it->handler)(ir, actions);
	}
	return true;
}
Example #2
0
void anagram(array<string,sz> &arrStr){
//	for_each( arrStr.begin(), arrStr.end(), myStrSort);
	for( auto & str : arrStr )
		sort( str.begin(), str.end() );
	sort( arrStr.begin(), arrStr.end() );

	std::cout << "\nAfter in-place sorting, arrStr contains:\n\n";
	for ( auto it = arrStr.begin(); it != arrStr.end(); ++it )
		std::cout << ' ' << *it;
	std::cout << endl;
}
Example #3
0
BOOST_AUTO_TEST_CASE_TEMPLATE( real_valued, T, real_types )
{
    array<T,3> x = {{ 1, 2, 3 }};
    array<T,3> y = {{ 4, 5, 6 }};
    blas::swap(x.size(), x.c_array(), 1, y.c_array(), 1);

    const array<T,3> x_expected = {{ 4, 5, 6 }};
    const array<T,3> y_expected = {{ 1, 2, 3 }};
    BOOST_CHECK_EQUAL_COLLECTIONS(
            x.begin(), x.end(), x_expected.begin(), x_expected.end());
    BOOST_CHECK_EQUAL_COLLECTIONS(
            y.begin(), y.end(), y_expected.begin(), y_expected.end());
}
Example #4
0
int main() {
	size_t tCase;
	int tmp;
	in >> tCase;
	while (tCase--) {
		MaxResult = 0;
		SequenceNumber.clear();
		fill(DynamicMemory.begin(), DynamicMemory.end(), -1);
		in >> Seqnum;
		for (size_t i = 0; i < Seqnum;i ++) {
			in >> tmp;
			SequenceNumber.push_back(tmp);
		}
		for (size_t i = 0; i < Seqnum; i++) {
			if (DynamicMemory[i] == -1) LIS(SequenceNumber, i);
		}
		for (size_t i = 0; i < Seqnum; i++) {
			if (DynamicMemory[i] == -1) break;
			if (DynamicMemory[i] > MaxResult) {
				MaxResult = DynamicMemory[i];
			}
		}
		cout << MaxResult << endl;
	}

	return 0;
}
Example #5
0
void copy_out(array<T, S>& out, const array<J, D>& in)
{
	CHECK(out.length() <= in.length(), erange);
	typename array<J, D>::const_iterator it_src = in.begin();
	typename array<T, S>::iterator it_end = out.end();
	typename array<T, S>::iterator it = out.begin();

	while (it != it_end) *it++ = *it_src++;
}
Example #6
0
void copy(array<T, S>& out, const T& val,
		types::term as_element)
{
	typename array<T, S>::iterator it_end = out.end();
	typename array<T, S>::iterator it = out.begin();

	while (it != it_end)
		*(it++) = (val);
}
Example #7
0
File: main.cpp Project: heatre/Ein
    void stop() {
        if ( !started_) return;
        started_ = false;
        sock_.close();

        ptr self = shared_from_this();
        array::iterator it = std::find(clients.begin(), clients.end(), self);
        clients.erase(it);
        update_clients_changed();
    }
Example #8
0
		void copy(const array<T>& _ar){
			assign(_ar.size());
			const_iterator citr=_ar.begin(),cenditr=_ar.end();
			iterator itr=begin();
			while(citr!=cenditr){
				(*itr)=(*citr);
				++citr;
				++itr;
			}
		}
Example #9
0
void copy(array<T, S>& out, const J* it_src)
{
	CHECK(it_src != NULL, einvalid);

	typename array<T, S>::iterator it_end = out.end();
	typename array<T, S>::iterator it = out.begin();

	while (it != it_end)
		*it++ = cast<T>(*it_src++);
}
Example #10
0
static void con_add_buffer_line(const con_priority priority, const char *const buffer, const size_t len)
{
	/* shift con_buffer for one line */
	std::move(std::next(con_buffer.begin()), con_buffer.end(), con_buffer.begin());
	console_buffer &c = con_buffer.back();
	c.priority=priority;

	size_t copy = std::min(len, CON_LINE_LENGTH - 1);
	c.line[copy] = 0;
	memcpy(&c.line,buffer, copy);
}
Example #11
0
int main(int argc, char** argv)
{
	std::cout << "arrStr contains:\n";
	for ( auto it = arrStr.begin(); it != arrStr.end(); ++it )
		std::cout << ' ' << *it;
	std::cout << '\n';
	sortAnagram(arrStr);
	anagram(arrStr);

    return 0;
}
Example #12
0
BOOST_AUTO_TEST_CASE_TEMPLATE( real_valued, T, real_types )
{
    { // Contiguous
        array<T,3> x = {{ 1, 2, 3 }};
        blas::scal(x.size(), 2, x.c_array(), 1);

        const array<T,3> x_expected = {{ 2, 4, 6 }};
        BOOST_CHECK_EQUAL_COLLECTIONS(
                x.begin(), x.end(), x_expected.begin(), x_expected.end());
    }

    { // Strided
        array<T,6> x = {{ 1, -1, 2, -1, 3, -1 }};
        const long inc = 2;
        blas::scal(x.size()/inc, 2, x.c_array(), inc);

        const array<T,6> x_expected = {{ 2, -1, 4, -1, 6, -1 }};
        BOOST_CHECK_EQUAL_COLLECTIONS(
                x.begin(), x.end(), x_expected.begin(), x_expected.end());
    }
}
Example #13
0
    int main(std::string __name__) {
        sub::main("sub");
        #define sub SUB
        sub2::main("sub2");
        _var_a_ = (array<int, 2>){2, 3};
        b = std::vector<int>(_var_a_.begin(), _var_a_.end());
        _var_b_ = (array<array<int, 2>, 2>){ 4, 5 ,  6, 7 };
        c = std::vector<array<int, 2> >(_var_b_.begin(), _var_b_.end());
        _var_c_ = (array<int, 2>){9, 10};
        d = (_type_a_){8, std::vector<int>(_var_c_.begin(), _var_c_.end())};
        _var_d_ = (array<_type_a_, 2>){d, d};
        e = std::vector<_type_a_>(_var_d_.begin(), _var_d_.end());
        _var_e_ = (array<int, 2>){1, 2};
        _var_f_ = std::vector<int>(_var_e_.begin(), _var_e_.end());
        f = _var_f_[0];
        g = _var_f_[1];
        _var_g_ = (array<int, 2>){3, 4};
        _var_h_ = (_type_b_){std::vector<int>(_var_g_.begin(), _var_g_.end()), 5};
        h = _var_h_._0;
        i = _var_h_._1;
        _var_i_ = (_type_b_){h, i};
        _var_j_ = _var_i_._0;
        j = _var_j_[0];
        k = _var_j_[1];
        m = _var_i_._1;
        fun(0);
        #undef SUB

        return 0;
    }
Example #14
0
int main()
{
	int tests;
	int citiesN;
	int relationsN;
	int paths;
	string name;
	cin >> tests;

	for (int t = 0; t < tests; t++)
	{
		cityId.clear();
		graph.clear();
		cin >> citiesN;
		for(int c = 1; c <= citiesN; c++)
		{
			distances[c] = infinity;
			emptyDistances[c] = infinity;

			city city;
			cin >> city.name;
			graph[c] = city;
			cityId[city.name] = c;
			cin >> relationsN;

			for(int r = 0; r < relationsN; r++)
			{
				way way1;
				cin >> way1.destination >> way1.cost;
				graph[c].adjacent.push_back(way1);
				way way2 = way1;
				way2.destination = c;
				graph[way2.destination].adjacent.push_back(way2);
			}

		}

		cin >> paths;

		for (int p = 0; p < paths; p++)
		{
			string source, destination;
			cin >> source >> destination;
			distances = emptyDistances;
			fill(visited.begin(), visited.end(), false);
			dijkstra(cityId[source], cityId[destination]);
			cout << distances[cityId[destination]] << endl;
		}
	}
	
	return 0;
}
Example #15
0
BOOST_AUTO_TEST_CASE_TEMPLATE( real_valued, T, real_types )
{
    const array<T,6> x = {{   1, -555,   2, -555,   3, -555 }};
    array<T,3> y       = {{ 555,  555, 555 }};
    const long incx = 2, incy = 1;

    BOOST_REQUIRE_EQUAL(x.size()/incx, y.size()/incy);
    blas::copy(x.size()/incx, x.data(), incx, y.c_array(), incy);

    const array<T,3> expected = {{ 1, 2, 3 }};
    BOOST_CHECK_EQUAL_COLLECTIONS(
            y.begin(), y.end(), expected.begin(), expected.end());
}
Example #16
0
    __agency_exec_check_disable__
    __AGENCY_ANNOTATION
    array(const array& other)
      : array(other.shape())
    {
      auto iter = other.begin();
      auto result = begin();

      for(; iter != other.end(); ++iter, ++result)
      {
        *result = *iter;
      }
    }
Example #17
0
void sort_edges(array<iPair,4>& marker) {
  /* y has the lowest y-coordinate (top left), stick it
     at the end of the list */
  sort(marker.begin(), marker.end()
       , [](const iPair &a, const iPair &b) {
	 return a.y > b.y;
       });

  /* Sorting green blobs - if marker[0] has a greater X value,
   * it's not the origin so swap it around */
  if(marker[0].x > marker[1].x) swap(marker[0], marker[1]);
  if(marker[2].x > marker[3].x) swap(marker[2], marker[3]);
}
Example #18
0
BOOST_AUTO_TEST_CASE_TEMPLATE( real_valued, T, real_types )
{
    const array<T,6> x = {{ 1, -1, 2, -1, 3, -1 }};
    const long incx = 2;
    array<T,3> y = {{ 4, 5, 6 }};
    const int incy = 1;

    BOOST_REQUIRE_EQUAL(x.size()/incx, y.size()/incy);
    blas::axpby(x.size()/incx, 3, x.data(), incx, 7, y.c_array(), incy);

    const array<T,3> expected = {{ 1*3+7*4, 2*3+7*5, 3*3+7*6 }};
    BOOST_CHECK_EQUAL_COLLECTIONS(
            y.begin(), y.end(), expected.begin(), expected.end());
}
Example #19
0
int main() {
	size_t tCase;
	in >> tCase;
	while (tCase--) {
		fill(DynamicMemory.begin(), DynamicMemory.end(), 0);
		vector<int> Triangle(1, 1);
		in >> TriCount;
		Triangle[0] = TriCount;
		int TotalNum = SumSigma(TriCount);
		for (int i = 1; i <= TotalNum; i++) {
			in >> TriCount;
			Triangle.push_back(TriCount);
		}
		out << TRIPATHCNT(Triangle, TotalNum) << endl;
	}
}
Example #20
0
static void readDouble(const File& file,
                       const string& name,
                       const array<size_t, dimension>& start,
                       const array<size_t, dimension>& count,
                       Type* values,
                       PropertyType Type::*property,
                       const Converter& converter) {
    size_t size = accumulate(count.begin(), count.end(), 1, [](size_t n, size_t m) { return n*m; });
    vector<double> v(size);
    const Var var(file.var(name));
    var.get(start, count, v.data());
    size_t n = 0;
    for (auto it = v.begin(); it != v.end(); ++it, ++n) {
        values[n].*property = converter(*it);
    }
}
Example #21
0
  /** \brief Create a structured cube grid

      \param lowerLeft  Lower left corner of the grid
      \param upperRight Upper right corner of the grid
      \param elements   Number of elements in each coordinate direction

      \note YaspGrid only supports lowerLeft at the origin.  This
            function throws a GridError if this requirement is not met.
  */
  static std::unique_ptr<GridType>
  createCubeGrid(const FieldVector<ctype, dimworld> &lowerLeft,
                 const FieldVector<ctype, dimworld> &upperRight,
                 const array<int, dim> &elements) {
    for (int d = 0; d < dimworld; ++d)
      if (std::abs(lowerLeft[d]) > std::abs(upperRight[d]) * 1e-10)
        DUNE_THROW(GridError,
                   className<BemppStructuredGridFactory>()
                       << "::createCubeGrid(): The lower coordinates "
                          "must be at the origin for YaspGrid.");

    FieldVector<int, dim> elements_;
    std::copy(elements.begin(), elements.end(), elements_.begin());

    return std::unique_ptr<GridType>(
        new GridType(upperRight, elements_, FieldVector<bool, dim>(false), 0));
  }
Example #22
0
int main() {
	size_t tCase;
	in >> tCase;
	while (tCase--) {
#ifdef LOCAL
		tstart = NowTime();
#endif
		fill(DynamicMemory.begin(), DynamicMemory.end(), -1);
		in >> PINumbers;
		out << PI(PINumbers) << endl;
#ifdef LOCAL
		tend = NowTime();
		out << "Operating time: " << chrono::duration_cast<std::chrono::milliseconds>(tend - tstart).count() << endl;
#endif
	}
	return 0;
}
Example #23
0
    __AGENCY_ANNOTATION
    friend bool operator==(const array& lhs, const Range& rhs)
    {
      if(lhs.size() != rhs.size()) return false;

      auto i = lhs.begin();
      auto j = rhs.begin();

      for(; i != lhs.end(); ++i, ++j)
      {
        if(*i != *j)
        {
          return false;
        }
      }

      return true;
    }
Example #24
0
static void get_message_name(const char *&message, array<char, 32> &result, const char *const trailer)
{
	auto p = message;
	for (; *p == ' '; ++p)
	{
	}
	const auto e = std::prev(result.end(), sizeof(".bbm"));
	auto i = result.begin();
	char c;
	for (; (c = *p) && c != ' ' && c != '\n'; ++p)
	{
		*i++ = c;
		if (i == e)
			/* Avoid buffer overflow; this was not present in the
			 * original code.
			 */
			break;
	}
	/* This is inconsistent.  If the copy loop terminated on a newline,
	 * then `p` points to the newline and the next loop is skipped.  If
	 * the copy loop terminated on a null, the next loop is attempted,
	 * but exits immediately.  In both those cases, `p` is unchanged.
	 * If the copy loop terminated on any other character, the next loop
	 * will advance `p` to point to a null (consistent with the copy
	 * loop terminating on a null) or past the newline (inconsistent
	 * with the copy loop).
	 *
	 * This inconsistency was present in the prior version of the code,
	 * and is retained in case there exist briefings which rely on this
	 * inconsistency.
	 */
	if (c != '\n')
		while ((c = *p) && (++p, c) != '\n')		//	Get and drop eoln
		{
		}
	message = p;
	strcpy(i, trailer);
}
Example #25
0
 constexpr bool operator<(array<T, M> a, array<U, N> b) {
     return M < N || constexpr_::lexicographical_compare(
                                 a.begin(), a.end(), b.begin(), b.end());
 }
Example #26
0
 constexpr bool operator==(array<T, M> a, array<U, N> b)
 { return M == N && constexpr_::equal(a.begin(), a.end(), b.begin(), b.end()); }
Example #27
0
 bool operator< (const array<T,N>& x, const array<T,N>& y) {
     return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
 }
Example #28
0
 bool operator== (const array<T,N>& x, const array<T,N>& y) {
     return std::equal(x.begin(), x.end(), y.begin());
 }
Example #29
0
 RingBuffer()
 {
     fill(ring.begin(), ring.end(), nullptr);
 }
Example #30
0
std::size_t hash_value(const array<T,N>& arr)
{
    return boost::hash_range(arr.begin(), arr.end());
}