54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
/*
|
|
* Utils.h
|
|
*
|
|
* Created on: Apr 3, 2014
|
|
* Author: robert
|
|
*/
|
|
|
|
#ifndef UTILS_COMMON_UTILS_H_
|
|
#define UTILS_COMMON_UTILS_H_
|
|
|
|
#include <systemc.h>
|
|
#include <map>
|
|
#include <string>
|
|
#include <ostream>
|
|
#include <tlm.h>
|
|
|
|
#include "third_party/tinyxml2.h"
|
|
|
|
template<typename Key, typename Val>
|
|
Val getElementFromMap(std::map<Key, Val>& m, Key key)
|
|
{
|
|
if (m.count(key) == 0)
|
|
{
|
|
SC_REPORT_FATAL("Map", "Element not in map");
|
|
}
|
|
|
|
return m.at(key);
|
|
}
|
|
|
|
template<typename T>
|
|
bool isIn(const T& value, const std::vector<T>& collection)
|
|
{
|
|
for (T t : collection)
|
|
{
|
|
if (t == value)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void reportFatal(std::string sender, std::string message);
|
|
std::string phaseNameToString(tlm::tlm_phase phase);
|
|
|
|
std::string loadTextFileContents(std::string filename);
|
|
void loadXML(std::string uri, tinyxml2::XMLDocument& doc);
|
|
|
|
bool parameterExists(tinyxml2::XMLElement* node, std::string name);
|
|
unsigned int queryUIntParameter(tinyxml2::XMLElement* node, std::string name);
|
|
std::string queryStringParameter(tinyxml2::XMLElement* node, std::string name);
|
|
bool queryBoolParameter(tinyxml2::XMLElement* node, std::string name);
|
|
double queryDoubleParameter(tinyxml2::XMLElement* node, std::string name);
|
|
|
|
#endif /* UTILS_COMMON_H_ */
|