/* ---- This file is part of SECONDO. Copyright (C) 2007, Faculty of Mathematics and Computer Science, Database Systems for New Applications. SECONDO is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. SECONDO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SECONDO; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ---- */ /* 1 Some auxiliary Functions */ #ifndef FUNCTIONS_H #define FUNCTIONS_H #include #include #include /* 1.1 ~contains~ A function checking whether an object is contained within a vector. */ template bool contains(const std::vector& v, T elem){ typename std::vector::const_iterator it; for(it=v.begin(); it!=v.end();it++){ if(*it == elem){ return true; } } return false; } /* 1.2 ~printset~ This function just prints out a set of something. */ template std::ostream& printset(const std::set& s, std::ostream& o){ o << "{"; typename std::set::const_iterator it; for(it=s.begin();it!=s.end();it++){ if(it!=s.begin()){ o << ", "; } o << *it; } o << "}"; return o; } /* 1.3 ~printVector~ This function prints aout the content of a vector. */ template std::ostream& printVector(const std::vector& s, std::ostream& o){ o << "["; typename std::vector::const_iterator it; for(it=s.begin();it!=s.end();it++){ if(it!=s.begin()){ o << ", "; } o << *it; } o << "]"; return o; } /* 1.4 ~intersects~ Checks whether ttwo sets have at least one common element; */ template bool intersects( const std::set& s1, const std::set& s2){ typename std::set::const_iterator it1 = s1.begin(); typename std::set::const_iterator it2 = s2.begin(); while(it1!=s1.end() && it2!=s2.end()){ if(*it1==*it2){ return true; } else if(*it1 < *it2){ it1++; } else { it2++; } } return false; } /* 1.5 ~getVectorIndex~ Returns the first index within a vector having the same value as the given one. If the element is not found, -1 is returned. */ template int getVectorIndex(const std::vector& v, const T& elem){ for(unsigned int i=0;i& targets, int state); #endif