/**
* Add a timestep at any position. The
- * position may be zero (at the start)
- * through #N# (at the end), where
- * #N# is the number of timesteps
- * stored in this object previously.
+ * position is a pointer to an existing
+ * time step object, or a null pointer
+ * denoting the end of the timestep
+ * sequence. If #position# is non-null,
+ * the new time step will be inserted
+ * before the respective element.
*
* Note that by giving an object
* to this function, the
* ownership of the object; it will
* therefore also take care of
* deletion of the objects its manages.
- * This mechanism usually will result
- * in a set-up loop like this
- * \begin{verbatim}
- * for (i=0; i<N; ++i)
- * manager.add_timestep(new MyTimeStep());
- * \end{verbatim}
*
* There is another function,
* #add_timestep#, which inserts a
* one can always use the timestep numbers
* that were used in the previous sweep.
*/
- void insert_timestep (TimeStepBase *new_timestep,
- const unsigned int position);
+ void insert_timestep (const TimeStepBase *position,
+ TimeStepBase *new_timestep);
/**
* Just like #insert_timestep#, but
* insert at the end.
+ *
+ * This mechanism usually will result
+ * in a set-up loop like this
+ * \begin{verbatim}
+ * for (i=0; i<N; ++i)
+ * manager.add_timestep(new MyTimeStep());
+ * \end{verbatim}
*/
void add_timestep (TimeStepBase *new_timestep);
/**
* Exception.
*/
- DeclException2 (ExcInvalidPosition,
- int, int,
- << "Can\'t insert time step at position " << arg1
- << " since there only " << arg2 << " positions at all.");
+ DeclException0 (ExcInvalidPosition);
protected:
/**
void
-TimeDependent::insert_timestep (TimeStepBase *new_timestep,
- const unsigned int position)
+TimeDependent::insert_timestep (const TimeStepBase *position,
+ TimeStepBase *new_timestep)
{
- Assert (position<=timesteps.size(),
- ExcInvalidPosition(position, timesteps.size()));
+ Assert (find(timesteps.begin(), timesteps.end(), position) != timesteps.end(),
+ ExcInvalidPosition());
// lock this timestep from deletion
new_timestep->subscribe();
// first insert the new time step
// into the doubly linked list
// of timesteps
- if (position == timesteps.size())
+ if (position == 0)
{
// at the end
new_timestep->set_next_timestep (0);
new_timestep->set_previous_timestep (0);
}
else
- if (position == 0)
+ if (position == timesteps[0])
{
// at the beginning
new_timestep->set_previous_timestep (0);
else
{
// inner time step
- timesteps[position-1]->set_next_timestep (new_timestep);
- new_timestep->set_next_timestep (timesteps[position]);
- timesteps[position]->set_previous_timestep (new_timestep);
+ vector<TimeStepBase*>::iterator insert_position
+ = find(timesteps.begin(), timesteps.end(), position);
+
+ (*(insert_position-1))->set_next_timestep (new_timestep);
+ new_timestep->set_next_timestep (*insert_position);
+ (*insert_position)->set_previous_timestep (new_timestep);
};
// finally enter it into the
// array
- timesteps.insert (×teps[position], new_timestep);
+ timesteps.insert ((position == 0 ?
+ timesteps.end() :
+ find(timesteps.begin(), timesteps.end(), position)),
+ new_timestep);
};
void
TimeDependent::add_timestep (TimeStepBase *new_timestep)
{
- insert_timestep (new_timestep, timesteps.size());
+ insert_timestep (0, new_timestep);
};
void TimeDependent::delete_timestep (const unsigned int position)
{
Assert (position<timesteps.size(),
- ExcInvalidPosition(position, timesteps.size()));
+ ExcInvalidPosition());
timesteps[position]->unsubscribe();
delete timesteps[position];