add two more utility functions
This commit is contained in:
parent
9d5801ef7f
commit
aeb07d43a7
@ -56,8 +56,7 @@ stringToUnsigned (string str)
|
||||
ss << str;
|
||||
ss >> val;
|
||||
if (val < 0) {
|
||||
cerr << "error: the value tried to read is negative" << endl;
|
||||
abort();
|
||||
abort ("error: the value tried to read is negative");
|
||||
}
|
||||
return static_cast<unsigned> (val);
|
||||
}
|
||||
@ -297,6 +296,15 @@ setHorusFlag (string key, string value)
|
||||
|
||||
|
||||
|
||||
void
|
||||
abort (string msg)
|
||||
{
|
||||
cerr << msg << endl;
|
||||
std::abort();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
printHeader (string header, std::ostream& os)
|
||||
{
|
||||
|
@ -34,6 +34,8 @@ template <typename T> bool contains (const set<T>&, const T&);
|
||||
template <typename K, typename V> bool contains (
|
||||
const unordered_map<K, V>&, const K&);
|
||||
|
||||
template <typename T> int vectorIndex (const vector<T>&, const T&);
|
||||
|
||||
template <typename T> std::string toString (const T&);
|
||||
|
||||
template <> std::string toString (const bool&);
|
||||
@ -76,6 +78,8 @@ vector<string> getStateLines (const Vars&);
|
||||
|
||||
bool setHorusFlag (string key, string value);
|
||||
|
||||
void abort (string msg);
|
||||
|
||||
void printHeader (string, std::ostream& os = std::cout);
|
||||
|
||||
void printSubHeader (string, std::ostream& os = std::cout);
|
||||
@ -138,6 +142,19 @@ Util::contains (const unordered_map<K, V>& m, const K& k)
|
||||
|
||||
|
||||
|
||||
template <typename T> int
|
||||
Util::vectorIndex (const vector<T>& v, const T& e)
|
||||
{
|
||||
int pos = std::distance (v.begin(),
|
||||
std::find (v.begin(), v.end(), e));
|
||||
if (pos == (int)v.size()) {
|
||||
pos = -1;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T> std::string
|
||||
Util::toString (const T& t)
|
||||
{
|
||||
|
Reference in New Issue
Block a user