Revision 1181 branches/threaded2merge/src/nh99/model.cpp

model.cpp (revision 1181)
1230 1230
}
1231 1231
#endif
1232 1232

  
1233
  pinitial_params & adlist_ptr::operator [] (int i)
1233
pinitial_params& adlist_ptr::operator[](int i)
1234
{
1235
  return (pinitial_params&)ptr[i];
1236
}
1237
/**
1238
Constructor
1239
*/
1240
adlist_ptr::adlist_ptr(int init_size)
1241
{
1242
  current = 0;
1243
  ptr = new ptovoid[init_size];
1244
  if (ptr == 0)
1234 1245
  {
1235
    return (pinitial_params &) ptr[i];
1246
    cerr << "Error: allocating memory in adlist_ptr" << endl;
1247
    ad_exit(0);
1236 1248
  }
1237

  
1238
  adlist_ptr::adlist_ptr(int init_size)
1249
  current_size = init_size;
1250
  for (int i = 0; i < current_size; i++)
1239 1251
  {
1240
    current=0;
1241
    ptr = new ptovoid[init_size];
1242
    if (ptr==0)
1243
    {
1244
      cerr << "Errorl allocating memory in adlist_ptr" << endl;
1245
    }
1246
    current_size=init_size;
1252
    ptr[i] = 0;
1247 1253
  }
1248
  void adlist_ptr::resize(void)
1254
}
1255
/**
1256
*/
1257
void adlist_ptr::reinitialize()
1258
{
1259
  current = 0;
1260
  for (int i = 0; i < current_size; i++)
1249 1261
  {
1250
    current_size*=2;
1251
    ptovoid * tmp = new ptovoid[current_size];
1252
    if (tmp==0)
1253
    {
1254
      cerr << "Errorl allocating memory in adlist_ptr" << endl;
1255
    }
1256
    for (int i=0;i<current;i++)
1257
    {
1258
      tmp[i]=ptr[i];
1259
    }
1260
    delete [] ptr;
1261
    ptr = tmp;
1262
    ptr[i] = 0;
1262 1263
  }
1263
  void adlist_ptr::add_to_list(void * p)
1264
}
1265
/**
1266
Reallocate buffers.
1267
*/
1268
void adlist_ptr::resize(void)
1269
{
1270
  current_size *= 2;
1271
  ptovoid* tmp = new ptovoid[current_size];
1272
  if (tmp == 0)
1264 1273
  {
1265
    if (current>current_size)
1266
    {
1267
      cerr << "This can't happen in adlist_ptr" << endl;
1268
      exit(1);
1269
    }
1270
    if (current==current_size)
1271
    {
1272
      resize();
1273
    }
1274
    ptr[current++]=p;
1274
    cerr << "Error: allocating memory in adlist_ptr::resize." << endl;
1275 1275
  }
1276
  for (int i = 0; i < current; i++)
1277
  {
1278
    tmp[i] = ptr[i];
1279
  }
1280
  for (int i = current; i < current_size; i++)
1281
  {
1282
    tmp[i] = 0;
1283
  }
1284
  delete [] ptr;
1285
  ptr = tmp;
1286
  tmp = 0;
1287
}
1288
/**
1289
Add ptr(p) to list.
1290
*/
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff