1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 168 unchanged lines hidden (view full) --- 177 showParam(os, param); 178 os << "\n"; 179} 180 181template <class T> 182void 183arrayParamOut(ostream &os, const string &name, const vector<T> ¶m) 184{ |
185 typename vector<T>::size_type size = param.size(); |
186 os << name << "="; 187 if (size > 0) 188 showParam(os, param[0]); |
189 for (typename vector<T>::size_type i = 1; i < size; ++i) { |
190 os << " "; 191 showParam(os, param[i]); 192 } 193 os << "\n"; 194} 195 196 197template <class T> --- 4 unchanged lines hidden (view full) --- 202 if (!cp->find(section, name, str) || !parseParam(str, param)) { 203 fatal("Can't unserialize '%s:%s'\n", section, name); 204 } 205} 206 207 208template <class T> 209void |
210arrayParamOut(ostream &os, const string &name, const T *param, unsigned size) |
211{ 212 os << name << "="; 213 if (size > 0) 214 showParam(os, param[0]); |
215 for (unsigned i = 1; i < size; ++i) { |
216 os << " "; 217 showParam(os, param[i]); 218 } 219 os << "\n"; 220} 221 222 223template <class T> 224void 225arrayParamIn(Checkpoint *cp, const string §ion, const string &name, |
226 T *param, unsigned size) |
227{ 228 string str; 229 if (!cp->find(section, name, str)) { 230 fatal("Can't unserialize '%s:%s'\n", section, name); 231 } 232 233 // code below stolen from VectorParam<T>::parse(). 234 // it would be nice to unify these somehow... --- 4 unchanged lines hidden (view full) --- 239 240 // Need this if we were doing a vector 241 // value.resize(tokens.size()); 242 243 if (tokens.size() != size) { 244 fatal("Array size mismatch on %s:%s'\n", section, name); 245 } 246 |
247 for (vector<string>::size_type i = 0; i < tokens.size(); i++) { |
248 // need to parse into local variable to handle vector<bool>, 249 // for which operator[] returns a special reference class 250 // that's not the same as 'bool&', (since it's a packed 251 // vector) 252 T scalar_value; 253 if (!parseParam(tokens[i], scalar_value)) { 254 string err("could not parse \""); 255 --- 25 unchanged lines hidden (view full) --- 281 282 tokenize(tokens, str, ' '); 283 284 // Need this if we were doing a vector 285 // value.resize(tokens.size()); 286 287 param.resize(tokens.size()); 288 |
289 for (vector<string>::size_type i = 0; i < tokens.size(); i++) { |
290 // need to parse into local variable to handle vector<bool>, 291 // for which operator[] returns a special reference class 292 // that's not the same as 'bool&', (since it's a packed 293 // vector) 294 T scalar_value; 295 if (!parseParam(tokens[i], scalar_value)) { 296 string err("could not parse \""); 297 298 err += str; 299 err += "\""; 300 301 fatal(err); 302 } 303 304 // assign parsed value to vector 305 param[i] = scalar_value; 306 } 307} 308 |
309void 310objParamIn(Checkpoint *cp, const string §ion, 311 const string &name, SimObject * ¶m) 312{ 313 if (!cp->findObj(section, name, param)) { 314 fatal("Can't unserialize '%s:%s'\n", section, name); 315 } 316} 317 318 319#define INSTANTIATE_PARAM_TEMPLATES(type) \ 320template void \ 321paramOut(ostream &os, const string &name, type const ¶m); \ 322template void \ 323paramIn(Checkpoint *cp, const string §ion, \ 324 const string &name, type & param); \ 325template void \ 326arrayParamOut(ostream &os, const string &name, \ |
327 type const *param, unsigned size); \ |
328template void \ 329arrayParamIn(Checkpoint *cp, const string §ion, \ |
330 const string &name, type *param, unsigned size); \ |
331template void \ 332arrayParamOut(ostream &os, const string &name, \ 333 const vector<type> ¶m); \ 334template void \ 335arrayParamIn(Checkpoint *cp, const string §ion, \ 336 const string &name, vector<type> ¶m); 337 338INSTANTIATE_PARAM_TEMPLATES(signed char) --- 239 unchanged lines hidden --- |