Serialization: Allow serialization of stl lists
This commit is contained in:
parent
a05032f4df
commit
ded4d319f2
2 changed files with 63 additions and 1 deletions
|
@ -201,6 +201,23 @@ arrayParamOut(ostream &os, const string &name, const vector<T> ¶m)
|
|||
os << "\n";
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void
|
||||
arrayParamOut(ostream &os, const string &name, const list<T> ¶m)
|
||||
{
|
||||
typename list<T>::const_iterator it = param.begin();
|
||||
|
||||
os << name << "=";
|
||||
if (param.size() > 0)
|
||||
showParam(os, *it);
|
||||
it++;
|
||||
while (it != param.end()) {
|
||||
os << " ";
|
||||
showParam(os, *it);
|
||||
it++;
|
||||
}
|
||||
os << "\n";
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void
|
||||
|
@ -326,6 +343,37 @@ arrayParamIn(Checkpoint *cp, const string §ion,
|
|||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void
|
||||
arrayParamIn(Checkpoint *cp, const string §ion,
|
||||
const string &name, list<T> ¶m)
|
||||
{
|
||||
string str;
|
||||
if (!cp->find(section, name, str)) {
|
||||
fatal("Can't unserialize '%s:%s'\n", section, name);
|
||||
}
|
||||
param.clear();
|
||||
|
||||
vector<string> tokens;
|
||||
tokenize(tokens, str, ' ');
|
||||
|
||||
for (vector<string>::size_type i = 0; i < tokens.size(); i++) {
|
||||
T scalar_value = 0;
|
||||
if (!parseParam(tokens[i], scalar_value)) {
|
||||
string err("could not parse \"");
|
||||
|
||||
err += str;
|
||||
err += "\"";
|
||||
|
||||
fatal(err);
|
||||
}
|
||||
|
||||
// assign parsed value to vector
|
||||
param.push_back(scalar_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
objParamIn(Checkpoint *cp, const string §ion,
|
||||
const string &name, SimObject * ¶m)
|
||||
|
@ -356,7 +404,13 @@ arrayParamOut(ostream &os, const string &name, \
|
|||
const vector<type> ¶m); \
|
||||
template void \
|
||||
arrayParamIn(Checkpoint *cp, const string §ion, \
|
||||
const string &name, vector<type> ¶m);
|
||||
const string &name, vector<type> ¶m); \
|
||||
template void \
|
||||
arrayParamOut(ostream &os, const string &name, \
|
||||
const list<type> ¶m); \
|
||||
template void \
|
||||
arrayParamIn(Checkpoint *cp, const string §ion, \
|
||||
const string &name, list<type> ¶m);
|
||||
|
||||
INSTANTIATE_PARAM_TEMPLATES(char)
|
||||
INSTANTIATE_PARAM_TEMPLATES(signed char)
|
||||
|
|
|
@ -69,6 +69,10 @@ template <class T>
|
|||
void arrayParamOut(std::ostream &os, const std::string &name,
|
||||
const std::vector<T> ¶m);
|
||||
|
||||
template <class T>
|
||||
void arrayParamOut(std::ostream &os, const std::string &name,
|
||||
const std::list<T> ¶m);
|
||||
|
||||
template <class T>
|
||||
void arrayParamIn(Checkpoint *cp, const std::string §ion,
|
||||
const std::string &name, T *param, unsigned size);
|
||||
|
@ -77,6 +81,10 @@ template <class T>
|
|||
void arrayParamIn(Checkpoint *cp, const std::string §ion,
|
||||
const std::string &name, std::vector<T> ¶m);
|
||||
|
||||
template <class T>
|
||||
void arrayParamIn(Checkpoint *cp, const std::string §ion,
|
||||
const std::string &name, std::list<T> ¶m);
|
||||
|
||||
void
|
||||
objParamIn(Checkpoint *cp, const std::string §ion,
|
||||
const std::string &name, SimObject * ¶m);
|
||||
|
|
Loading…
Reference in a new issue