serialize.cc (6225:ec76e5c7cdd3) serialize.cc (6227:a17798f2a52c)
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> &param)
184{
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> &param)
184{
185 int size = param.size();
185 typename vector<T>::size_type size = param.size();
186 os << name << "=";
187 if (size > 0)
188 showParam(os, param[0]);
186 os << name << "=";
187 if (size > 0)
188 showParam(os, param[0]);
189 for (int i = 1; i < size; ++i) {
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
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, int size)
210arrayParamOut(ostream &os, const string &name, const T *param, unsigned size)
211{
212 os << name << "=";
213 if (size > 0)
214 showParam(os, param[0]);
211{
212 os << name << "=";
213 if (size > 0)
214 showParam(os, param[0]);
215 for (int i = 1; i < size; ++i) {
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 &section, const string &name,
216 os << " ";
217 showParam(os, param[i]);
218 }
219 os << "\n";
220}
221
222
223template <class T>
224void
225arrayParamIn(Checkpoint *cp, const string &section, const string &name,
226 T *param, int size)
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
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 (int i = 0; i < tokens.size(); i++) {
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
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 (int i = 0; i < tokens.size(); i++) {
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
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
309
310
311void
312objParamIn(Checkpoint *cp, const string &section,
313 const string &name, SimObject * &param)
314{
315 if (!cp->findObj(section, name, param)) {
316 fatal("Can't unserialize '%s:%s'\n", section, name);
317 }
318}
319
320
321#define INSTANTIATE_PARAM_TEMPLATES(type) \
322template void \
323paramOut(ostream &os, const string &name, type const &param); \
324template void \
325paramIn(Checkpoint *cp, const string &section, \
326 const string &name, type & param); \
327template void \
328arrayParamOut(ostream &os, const string &name, \
309void
310objParamIn(Checkpoint *cp, const string &section,
311 const string &name, SimObject * &param)
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 &param); \
322template void \
323paramIn(Checkpoint *cp, const string &section, \
324 const string &name, type & param); \
325template void \
326arrayParamOut(ostream &os, const string &name, \
329 type const *param, int size); \
327 type const *param, unsigned size); \
330template void \
331arrayParamIn(Checkpoint *cp, const string &section, \
328template void \
329arrayParamIn(Checkpoint *cp, const string &section, \
332 const string &name, type *param, int size); \
330 const string &name, type *param, unsigned size); \
333template void \
334arrayParamOut(ostream &os, const string &name, \
335 const vector<type> &param); \
336template void \
337arrayParamIn(Checkpoint *cp, const string &section, \
338 const string &name, vector<type> &param);
339
340INSTANTIATE_PARAM_TEMPLATES(signed char)

--- 239 unchanged lines hidden ---
331template void \
332arrayParamOut(ostream &os, const string &name, \
333 const vector<type> &param); \
334template void \
335arrayParamIn(Checkpoint *cp, const string &section, \
336 const string &name, vector<type> &param);
337
338INSTANTIATE_PARAM_TEMPLATES(signed char)

--- 239 unchanged lines hidden ---