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