示例#1
0
void Viewport::paintEvent(QPaintEvent*)
{
	vector< shared_ptr<RowItem> > row_items(view_.begin(), view_.end());
	assert(none_of(row_items.begin(), row_items.end(),
		[](const shared_ptr<RowItem> &r) { return !r; }));

	stable_sort(row_items.begin(), row_items.end(),
		[](const shared_ptr<RowItem> &a, const shared_ptr<RowItem> &b) {
			return a->visual_v_offset() < b->visual_v_offset(); });

	const vector< shared_ptr<TimeItem> > time_items(view_.time_items());
	assert(none_of(time_items.begin(), time_items.end(),
		[](const shared_ptr<TimeItem> &t) { return !t; }));

	QPainter p(this);
	p.setRenderHint(QPainter::Antialiasing);

	const ViewItemPaintParams pp(rect(), view_.scale(), view_.offset());

	for (const shared_ptr<TimeItem> t : time_items)
		t->paint_back(p, pp);
	for (const shared_ptr<RowItem> r : row_items)
		r->paint_back(p, pp);

	for (const shared_ptr<TimeItem> t : time_items)
		t->paint_mid(p, pp);
	for (const shared_ptr<RowItem> r : row_items)
		r->paint_mid(p, pp);

	p.setRenderHint(QPainter::Antialiasing, false);

	for (const shared_ptr<RowItem> r : row_items)
		r->paint_fore(p, pp);
	for (const shared_ptr<TimeItem> t : time_items)
		t->paint_fore(p, pp);

	p.end();
}
//---------------------------------------------------------------------------
void Environment::addFunction(unique_ptr<Function> function)
{
   // ensures: functions.name equal => functions.returntype equal and functions.name equal => functions.arguments !equal
   assert(none_of(functions.begin(), functions.end(), [&function](unique_ptr<Function>& iter) {
      if(iter->getName()!=function->getName())
         return false;
      if(iter->getResultType()!=function->getResultType())
         return true;
      if(iter->getArgumentCount()!=function->getArgumentCount())
         return false;
      for(uint32_t i=0; i<iter->getArgumentCount(); i++)
         if(iter->getArgumentType(i) != function->getArgumentType(i))
            return false;
      return true;
   }));

   functions.push_back(::move(function));
}
void GCodeInterpreter::AssertExistingFunction(map<char, vector<float>>& data, char type, size_t line)
{
	assert(type == 'G' || type == 'M');
	map<char, vector<float>>::iterator dataIter;
	if((dataIter = data.find(type)) != data.end())
	{
		for_each(dataIter->second.begin(), dataIter->second.end(), [&](float f)
		{
			GFunction func(type, f);
			if(none_of(orderTable.begin(), orderTable.end(), [&func](GFunction& g){return g==func;}))
			{
				string error = "Nalezena neznámá funkce ";
				error += func.first;
				error += func.second;
				error += string(" na øádku ") + line + ".";
				throw exception(error.c_str());
			}
		});
	}
}
 vector<int> findOrder(int numCourses, vector<pair<int, int>>& prerequisites) {
     // graph
     // incoming count;
     // que, in all the one with incoming zeros, then, visit neighbor, when incoming zero , enque;
     unordered_map<int,int> incomings;
     unordered_map<int,vector<int>> neighbors;
     vector<int> result;
     
     //it's directed 
     for(auto pir:prerequisites)
     {
         incomings[pir.first]++;
         neighbors[pir.second].push_back(pir.first);
     }
     queue<int> que;
     for(int i=0;i<numCourses;++i)
     {
         if(incomings.find(i)==incomings.end()) {que.push(i);result.push_back(i);}
     }
     
     while(!que.empty())
     {
         int node=que.front(); que.pop();
        
         for(auto neg:neighbors[node])
         {
             incomings[neg]--;
             if(incomings[neg]==0)
             {
                 que.push(neg);  result.push_back(neg);
             }
         }
     }
     if (none_of(begin(incomings),end(incomings), [] (pair<int,int> node ) {return node.second>0;}))
     {
         return result;
     }
     else return vector<int> ();
 }
示例#5
0
int main()
{
	vector<int> coll;
	vector<int>::iterator pos;

	insert_elements(coll, 1, 9);
	print_elements(coll, "coll: ");

	// define an object for the predicate (using a lambda)
	auto isEven = [](int elem) {
		return elem % 2 == 0;
	};

	// print whether all, any, or none of the elements are/is even
	cout << boolalpha << "all even?:  "
		<< all_of(coll.cbegin(), coll.cend(), isEven) << endl;
	cout << "any even?:  "
		<< any_of(coll.cbegin(), coll.cend(), isEven) << endl;
	cout << "none even?: "
		<< none_of(coll.cbegin(), coll.cend(), isEven) << endl;


}
示例#6
0
QJsonObject copySelected(const Scenario_T& sm, QObject* parent)
{
    auto selectedConstraints = selectedElements(getConstraints(sm));
    auto selectedEvents = selectedElements(getEvents(sm));
    auto selectedTimeNodes = selectedElements(getTimeNodes(sm));
    auto selectedStates = selectedElements(getStates(sm));

    for(const ConstraintModel* constraint : selectedConstraints)
    {
        auto start_it = find_if(selectedStates,
                                [&] (const StateModel* state) { return state->id() == constraint->startState();});
        if(start_it == selectedStates.end())
        {
            selectedStates.push_back(&sm.state(constraint->startState()));
        }

        auto end_it = find_if(selectedStates,
                              [&] (const StateModel* state) { return state->id() == constraint->endState();});
        if(end_it == selectedStates.end())
        {
            selectedStates.push_back(&sm.state(constraint->endState()));
        }
    }

    for(const StateModel* state : selectedStates)
    {
        auto ev_it = find_if(selectedEvents,
                             [&] (const EventModel* event) { return state->eventId() == event->id(); });
        if(ev_it == selectedEvents.end())
        {
            selectedEvents.push_back(&sm.event(state->eventId()));
        }

        // If the previous or next constraint is not here, we set it to null in a copy.
    }
    for(const EventModel* event : selectedEvents)
    {
        auto tn_it = find_if(selectedTimeNodes,
                             [&] (const TimeNodeModel* tn) { return tn->id() == event->timeNode(); });
        if(tn_it == selectedTimeNodes.end())
        {
            selectedTimeNodes.push_back(&sm.timeNode(event->timeNode()));
        }

        // If some events aren't there, we set them to null in a copy.
    }

    std::vector<TimeNodeModel*> copiedTimeNodes;
    copiedTimeNodes.reserve(selectedTimeNodes.size());
    for(const auto& tn : selectedTimeNodes)
    {
        auto clone_tn = new TimeNodeModel(*tn, tn->id(), parent);
        auto events = clone_tn->events();
        for(const auto& event : events)
        {
            auto absent = none_of(selectedEvents,
                                  [&] (const EventModel* ev) { return ev->id() == event; });
            if(absent)
                clone_tn->removeEvent(event);
        }

        copiedTimeNodes.push_back(clone_tn);
    }


    std::vector<EventModel*> copiedEvents;
    copiedEvents.reserve(selectedEvents.size());
    for(const auto& ev : selectedEvents)
    {
        auto clone_ev = new EventModel(*ev, ev->id(), parent);
        auto states = clone_ev->states();
        for(const auto& state : states)
        {
            auto absent = none_of(selectedStates,
                                  [&] (const StateModel* st) { return st->id() == state; });
            if(absent)
                clone_ev->removeState(state);
        }

        copiedEvents.push_back(clone_ev);
    }

    std::vector<StateModel*> copiedStates;
    copiedStates.reserve(selectedStates.size());
    auto& stack = iscore::IDocument::documentContext(*parent).commandStack;
    for(const StateModel* st : selectedStates)
    {
        auto clone_st = new StateModel(*st, st->id(), stack, parent);

        // NOTE : we must not serialize the state with their previous / next constraint
        // since they will change once pasted and cause crash at the end of the ctor
        // of StateModel. They are saved in the previous / next state of constraint anyway.
        SetNoPreviousConstraint(*clone_st);
        SetNoNextConstraint(*clone_st);

        copiedStates.push_back(clone_st);
    }


    QJsonObject base;
    base["Constraints"] = arrayToJson(selectedConstraints);
    base["Events"] = arrayToJson(copiedEvents);
    base["TimeNodes"] = arrayToJson(copiedTimeNodes);
    base["States"] = arrayToJson(copiedStates);

    for(auto elt : copiedTimeNodes)
        delete elt;
    for(auto elt : copiedEvents)
        delete elt;
    for(auto elt : copiedStates)
        delete elt;

    return base;
}
//---------------------------------------------------------------------------
void Environment::add(const string& identifier, Value&& value)
{
   assert(none_of(data.begin(), data.end(), [&identifier](const pair<string,Value>& iter){return iter.first==identifier;}));
   data.push_back(make_pair(identifier, ::move(value)));
}
示例#8
0
bool SearchQuery::Recursion::isComplete() const noexcept {
	return none_of(positions.begin(), positions.end(), CompareFirst<size_t, int>(string::npos));
}
示例#9
0
void QbsPluginManager::registerStaticPlugin(QbsPluginLoadFunction load,
                                            QbsPluginUnloadFunction unload)
{
    if (none_of(d->staticPlugins, [&load](const QbsPlugin &p) { return p.load == load; }))
        d->staticPlugins.push_back(QbsPlugin { load, unload, false });
}