Beispiel #1
0
bool Case::retirerPions(forward_list<Pion*> fl, int nbPionsToDel) {
  bool all_deleted = true;
  if(nbPions - nbPionsToDel < 0) {
    cout << "[Case.cpp/retirerPions] Erreur : Impossible de retirer les pions. Pas assez de pions." << endl;
    return false;
  }
  else {
    for(auto it=fl.begin() ; it!=fl.end(); ++it) {
      //cout << "RETIRER PIONS ON PASSE : " << *it << endl;
      if(!retirerPion(*it)) {
	cout << "[Case.cpp/retirerPions] Erreur : Impossible de retirer le pion. Il n'est pas present." << endl;
	all_deleted = false;
      }
    }
  }
  return all_deleted;
}
// input: two trees waiting to be compared, the resultpointer) repository
// output: the updated resultpointer) repository (it's a hashing table with "long int: int" pair in)
void IBD_hash(char * tree1, char * tree2, unordered_map<long int, double> * resultpointer)
{
	// NOTE:
	// in practice, we can store the second hashing table, and when next time we enter, we can directly use it
	// we can achieve this by storing the second hashing table as global in this scope

	(*resultpointer).clear();

	// clean the global variables
	h11.clear();
	list1.clear();
	list3.clear();
	rubbish.clear();

	parser1(tree1);

	// DEBUG
	/*
	for(auto itr = h11[124.8].begin(); itr != h11[124.8].end(); itr ++)
	{
		cout << (*itr)->tMRCA << ":" << (*itr)->start << " " << (*itr)->middle << " " << (*itr)->end << " " << endl;
	}
	*/


	parser2(tree2, resultpointer);

	// empty the temporary rubbish pool
	for(auto itr = rubbish.begin(); itr != rubbish.end(); itr ++)
	{
		free(*itr);
	}

	// free the h11 memory for fear that there will be memory overflow
	for(auto itr = h11.begin(); itr != h11.end(); itr ++)
	{
		// (*itr) is a forward_list<MRCA *>
		for(auto itr1 = (*itr).second.begin(); itr1 != (*itr).second.end(); itr1 ++)
		{
			// (*itr1) is a (MRCA *)
			free(*itr1);
		}
	}
	return;
}
TypeInfo getInfoAtPosit(forward_list<TypeInfo> laListe, int laPosition) throw (PrecondVioleeExcep) {
    // version itérative
    // un itérateur sur la liste
    auto it = laListe.begin();
    int positionCourante = 1;
    // tantque l'on a pas atteint laPosition et que l'on est pas à la fin de la liste
    while ((positionCourante < laPosition) && (it != laListe.end())) {
        positionCourante++;
        // avancer dans la liste sur l'itérateur
        ++it;
    }
    if (it != laListe.end()) { // si on eu accès à laPosition
        // rendre l'élément pointé par l'itérateur
        return *it;
    } else { // sinon on lève une exception
        throw PrecondVioleeExcep("Accès imposible à l'indice " + to_string(laPosition));
    }
}
Beispiel #4
0
// Merge a connected compontent of lines to a new line with width.
void merge(const forward_list<LineSegW*>& component, LineSegW& out) {
	// TODO: in principle no loop/collection is necessary
	// Note: profiling indicates this is not even close to a bottleneck, so ok for now

	float maxw = 0.0f;

	forward_list<Point*> component2i;
	for (auto vec = component.begin(); vec != component.end(); ++vec) {
		component2i.push_front(&(*vec)->s);
		component2i.push_front(&(*vec)->e);
		if ((*vec)->width > maxw) {
			maxw = (*vec)->width;
		}
	}

	line_fit(component2i, out);
	out.width = max(maxw, out.width);
}
Beispiel #5
0
void replace(forward_list<string> &sflst, const string &str1, const string &str2)
{
        int     flag = 0;
        auto    prev = sflst.before_begin();
        auto    curr = sflst.begin();
        auto    end = sflst.end();
        while (curr != end)
                if (*curr == str1)
                {
                        curr = sflst.emplace_after(curr, str2);
                        flag = 1;
                }
                else
                {
                        prev = curr;
                        ++curr;
                }
        if (!flag)
                sflst.insert_after(prev, str2);
}
void FindStringInsertString(forward_list<string>& strlist, string strtofind, string strtoinsert)
{
	forward_list<string>::iterator current = strlist.begin();
	forward_list<string>::iterator pre = strlist.before_begin();
	bool findflag = false;
	while (current != strlist.end())
	{
		if (*current == strtofind)
		{
			current = strlist.insert_after(current,strtoinsert);
			findflag = true;
		}
		pre = current;
		current++;
	}
	
	if (!findflag)
	{
		strlist.insert_after(pre, strtoinsert);
	}
	return;
}