Show gs_param.h syntax highlighted
/*
* gs_param.h
* gstlm_projects
*
* Created by Klingauf on 07.01.07.
* Copyright 2007 __MyCompanyName__. All rights reserved.
*
*/
#ifndef _GS_PARAM_H_
#define _GS_PARAM_H_
#include "gs_param_root.h"
#include "gs_configurable.h"
#include "gs_datatypes.h"
//-----------------------------------------------------------------------------
// gs_param
//-----------------------------------------------------------------------------
namespace tlm {
/**
* A class wrapper for runtime configurable SC_MODULE parameters.
* May only be used in classes that inherit from gs_configurable.
* All gs_param parameters must be initialized by the GS_PARAM macro.
* You can write your own template specialization for this class
* to support user data types.
*/
template <typename T>
class gs_param : public gs_param_root
{
public:
T value;
gs_param() {}
gs_param(const char *n) : gs_param_root(n) {}
gs_param(const char *n, T v) : gs_param_root(n), value(v) {}
gs_param(const T& v) : value(v) {}
/**
* Get the value of this parameter.
*/
operator const T& () const {
return value;
// TODO: could inform callback function here
}
/**
* Set the value of this parameter.
*/
T& operator = (const T& v) {
return value = v;
// TODO: could inform callback function here
}
/**
* Set the value of this parameter with a string.
* The default implementation uses stringstream to convert the string input to
* the parameter type. This works with most of the POD and STL data types.
* However, for special user data types, a template specialisation is necessary.
* @param str The new value for this parameter, represented as a string.
*/
void set(const std::string str) {
std::istringstream is(str);
is >> value;
std::cout << "GS_PARAM: Param [" << getName() << "] set method called. Value now " << value << std::endl;
// TODO: could inform callback function here
}
/**
* Get the value of this parameter as a string.
* The default implementation uses stringstream to convert the parameter
* type into a string representation. This works with most of the POD and STL
* data atypes. However, for special user data types, a template specialisation
* is necessary.
* @return String representation of the current value of this parameter.
*/
const std::string get() {
std::ostringstream os;
os << value;
std::cout << "GS_PARAM: Param " << getName() << " string get method called. Output stringstream is " << os << std::endl;
return os.str();
// TODO: could inform callback function here
}
};
//-----------------------------------------------------------------------------
// GS_PARAM macro
//-----------------------------------------------------------------------------
/**
* Use this macro inside SC_MODULE constructor to register a gs_param
* with the configuration framework.
*/
#define GS_PARAM(name,type) \
name = gs_param<type>(#name); \
addParam(name.getName(), &name)
} // end namespace tlm
#endif /* _GS_PARAM_H_ */
See more files for this project here