Show gs_configurable.h syntax highlighted
#ifndef __gsconfigurable_h__
#define __gsconfigurable_h__
#include <systemc>
#include <string>
#include <ostream>
#include <map>
#include "gs_param_root.h"
namespace tlm {
//-----------------------------------------------------------------------------
// gs_configurable
//-----------------------------------------------------------------------------
typedef std::map<std::string, gs_param_root*> param_map;
typedef std::map<std::string, gs_param_root*>::iterator param_iterator;
/**
* SC_MODULEs may inherit this class to provide a configuration interface
* to the outside world.
*/
class gs_configurable {
public:
gs_configurable() {}
virtual ~gs_configurable() {} // force to be polymorphic
void addParam(const std::string name, gs_param_root *param) {
params.insert(param_map::value_type(name, param));
//std::cout << "GS_CONFIGURABLE: Added param [" << name << "] to param map of [" << (dynamic_cast<sc_core::sc_object*>(this))->name() << "] (map size now " << params.size() << ")" << std::endl;
}
bool setParam(const std::string name, const std::string value) {
param_iterator pos;
pos = params.find(name);
if (pos == params.end()) {
char ch[256];
sprintf(ch, "Set param [%s] of [%s] to value=[%s] failed! Param doesn't exist.", name.c_str(), (dynamic_cast<sc_core::sc_object*>(this))->name(), value.c_str());
SC_REPORT_WARNING((dynamic_cast<sc_core::sc_object*>(this))->name(), ch);
return false;
}
//std::cout << "GS_CONFIGURABLE: Set param [" << name << "] of [" << (dynamic_cast<sc_core::sc_object*>(this))->name() << "] to value=[" << value.c_str() << "]" << std::endl;
gs_param_root *r = pos->second;
r->set(value);
return true;
}
std::string getParam(std::string name) {
param_iterator pos;
pos = params.find(name);
if (pos == params.end())
return NULL;
std::cout << "GS_CONFIGURABLE: Get param [" << name << "] of [" << (dynamic_cast<sc_core::sc_object*>(this))->name() << "] called (value=[" << pos->second->get().c_str() << "]" << std::endl;
return pos->second->get();
}
protected:
param_map params;
};
} // end of namespace tlm
// have to include gs_param.h here to avoid circular dependencies which cannot be resolved by the compiler
#include "gs_param.h"
#endif
See more files for this project here