Get new serialization code to link.
sim/param.cc: Convert parseParam() and showParam() to templates, andd explicitly instantiate them for common types. sim/param.hh: Add declarations for parseParam() and showParam() function templates, so serialize.cc can use them. sim/serialize.cc: Don't need declarations for parseParam() and showParam() since we put them in param.hh. Also instantiate paramOut() etc. for bool. --HG-- extra : convert_revision : 1d84d0fbec64481996cbfa8b84c67c13c6244385
This commit is contained in:
parent
e12e64a071
commit
3761bcf076
3 changed files with 29 additions and 37 deletions
53
sim/param.cc
53
sim/param.cc
|
@ -88,53 +88,41 @@ BaseParam::die(const string &err) const
|
|||
// Integer types all use to_number for parsing and '<<' for
|
||||
// displaying
|
||||
//
|
||||
#define INT_PARAM(type) \
|
||||
bool \
|
||||
parseParam(const string &s, type &value) \
|
||||
{ \
|
||||
return to_number(s, value); \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
showParam(ostream &os, type value) \
|
||||
{ \
|
||||
os << value; \
|
||||
template <class T>
|
||||
bool
|
||||
parseParam(const string &s, T &value)
|
||||
{
|
||||
return to_number(s, value);
|
||||
}
|
||||
|
||||
INT_PARAM(unsigned long long)
|
||||
INT_PARAM(signed long long)
|
||||
INT_PARAM(unsigned long)
|
||||
INT_PARAM(signed long)
|
||||
INT_PARAM(unsigned int)
|
||||
INT_PARAM(signed int)
|
||||
INT_PARAM(unsigned short)
|
||||
INT_PARAM(signed short)
|
||||
INT_PARAM(unsigned char)
|
||||
INT_PARAM(signed char)
|
||||
|
||||
#undef INT_PARAM
|
||||
template <class T>
|
||||
void
|
||||
showParam(ostream &os, const T &value)
|
||||
{
|
||||
os << value;
|
||||
}
|
||||
|
||||
//
|
||||
// Floating-point types
|
||||
//
|
||||
template <>
|
||||
bool
|
||||
parseParam(const string &s, float &value)
|
||||
{
|
||||
return (sscanf(s.c_str(), "%f", &value) == 1);
|
||||
}
|
||||
|
||||
template <>
|
||||
bool
|
||||
parseParam(const string &s, double &value)
|
||||
{
|
||||
return (sscanf(s.c_str(), "%lf", &value) == 1);
|
||||
}
|
||||
|
||||
void showParam(ostream &os, float value) { os << value; }
|
||||
void showParam(ostream &os, double value) { os << value; }
|
||||
|
||||
//
|
||||
// bool
|
||||
//
|
||||
template <>
|
||||
bool
|
||||
parseParam(const string &s, bool &value)
|
||||
{
|
||||
|
@ -154,8 +142,9 @@ parseParam(const string &s, bool &value)
|
|||
}
|
||||
|
||||
|
||||
template <>
|
||||
void
|
||||
showParam(ostream &os, bool value)
|
||||
showParam(ostream &os, const bool &value)
|
||||
{
|
||||
os << (value ? "true" : "false");
|
||||
}
|
||||
|
@ -164,6 +153,7 @@ showParam(ostream &os, bool value)
|
|||
//
|
||||
// string
|
||||
//
|
||||
template <>
|
||||
bool
|
||||
parseParam(const string &s, string &value)
|
||||
{
|
||||
|
@ -171,13 +161,6 @@ parseParam(const string &s, string &value)
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
showParam(ostream &os, const string &value)
|
||||
{
|
||||
os << value;
|
||||
}
|
||||
|
||||
//
|
||||
// End of parseParam/showParam definitions. Now we move on to
|
||||
// incorporate them into the Param/VectorParam parse() and showValue()
|
||||
|
@ -274,6 +257,8 @@ template VectorParam<type>;
|
|||
// instantiate all four methods (parse/show, scalar/vector) for basic
|
||||
// types that can use the above templates
|
||||
#define INSTANTIATE_PARAM_TEMPLATES(type, typestr) \
|
||||
template bool parseParam<type>(const string &s, type &value); \
|
||||
template void showParam<type>(ostream &os, const type &value); \
|
||||
template void Param<type>::parse(const string &); \
|
||||
template void VectorParam<type>::parse(const string &); \
|
||||
template void Param<type>::showValue(ostream &) const; \
|
||||
|
|
|
@ -754,4 +754,13 @@ SimObjectVectorParam<OBJ_CLASS *>::showType(std::ostream &os) const \
|
|||
os << "vector of " << CLASS_NAME; \
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Declarations for low-level parsing & displaying functions. These
|
||||
// are used internally, but should not be used directly by clients of
|
||||
// the parameter mechanism, but are declared here so they can be
|
||||
// shared with the serialization code (see sim/serialize.cc).
|
||||
template <class T> bool parseParam(const std::string &str, T &data);
|
||||
template <class T> void showParam(std::ostream &os, const T &data);
|
||||
|
||||
#endif // _PARAM_HH
|
||||
|
|
|
@ -76,9 +76,6 @@ Serializeable::nameOut(ostream &os, const string &_name)
|
|||
os << "\n[" << _name << "]\n";
|
||||
}
|
||||
|
||||
template <class T> bool parseParam(const std::string &str, T &data);
|
||||
template <class T> void showParam(const std::ostream &os, T &data);
|
||||
|
||||
template <class T>
|
||||
void
|
||||
paramOut(ostream &os, const std::string &name, const T& param)
|
||||
|
@ -184,6 +181,7 @@ INSTANTIATE_PARAM_TEMPLATES(int32_t)
|
|||
INSTANTIATE_PARAM_TEMPLATES(uint32_t)
|
||||
INSTANTIATE_PARAM_TEMPLATES(int64_t)
|
||||
INSTANTIATE_PARAM_TEMPLATES(uint64_t)
|
||||
INSTANTIATE_PARAM_TEMPLATES(bool)
|
||||
INSTANTIATE_PARAM_TEMPLATES(string)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue