Add explicit phases to order ParamContext initializations.
--HG-- extra : convert_revision : c24fba2bded2493a892fa93de0c61f9674cfedbb
This commit is contained in:
parent
400daa7e41
commit
e852f9e31a
4 changed files with 43 additions and 11 deletions
|
@ -43,7 +43,7 @@ SimObjectBuilder::SimObjectBuilder(const string &_configClass,
|
||||||
const string &_instanceName,
|
const string &_instanceName,
|
||||||
ConfigNode *_configNode,
|
ConfigNode *_configNode,
|
||||||
const string &_simObjClassName)
|
const string &_simObjClassName)
|
||||||
: ParamContext(_configClass, true),
|
: ParamContext(_configClass, NoAutoInit),
|
||||||
instanceName(_instanceName),
|
instanceName(_instanceName),
|
||||||
configNode(_configNode),
|
configNode(_configNode),
|
||||||
simObjClassName(_simObjClassName)
|
simObjClassName(_simObjClassName)
|
||||||
|
|
20
sim/param.cc
20
sim/param.cc
|
@ -560,15 +560,27 @@ SimObjectBaseParam::parse(const string &s, vector<SimObject *>&value)
|
||||||
|
|
||||||
list<ParamContext *> *ParamContext::ctxList = NULL;
|
list<ParamContext *> *ParamContext::ctxList = NULL;
|
||||||
|
|
||||||
ParamContext::ParamContext(const string &_iniSection, bool noAutoParse)
|
ParamContext::ParamContext(const string &_iniSection, InitPhase _initPhase)
|
||||||
: iniFilePtr(NULL), // initialized on call to parseParams()
|
: iniFilePtr(NULL), // initialized on call to parseParams()
|
||||||
iniSection(_iniSection), paramList(NULL)
|
iniSection(_iniSection), paramList(NULL),
|
||||||
|
initPhase(_initPhase)
|
||||||
{
|
{
|
||||||
if (!noAutoParse) {
|
// Put this context on global list for initialization
|
||||||
|
if (initPhase != NoAutoInit) {
|
||||||
if (ctxList == NULL)
|
if (ctxList == NULL)
|
||||||
ctxList = new list<ParamContext *>();
|
ctxList = new list<ParamContext *>();
|
||||||
|
|
||||||
(*ctxList).push_back(this);
|
// keep list sorted by ascending initPhase values
|
||||||
|
list<ParamContext *>::iterator i = ctxList->begin();
|
||||||
|
list<ParamContext *>::iterator end = ctxList->end();
|
||||||
|
for (; i != end; ++i) {
|
||||||
|
if (initPhase <= (*i)->initPhase) {
|
||||||
|
// found where we want to insert
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// (fall through case: insert at end)
|
||||||
|
ctxList->insert(i, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
29
sim/param.hh
29
sim/param.hh
|
@ -74,11 +74,30 @@ class ParamContext
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Second arg, if set to true, says don't put on paramContextList
|
/// Initialization phases for ParamContext objects.
|
||||||
// (i.e. don't automatically parse params). Used by derived
|
enum InitPhase {
|
||||||
// SimObjectBuilder class, where parsing is done in
|
NoAutoInit = -1, ///< Don't initialize at all... params
|
||||||
// SimObject::create()
|
/// will be parsed later (used by
|
||||||
ParamContext(const std::string &_iniSection, bool noAutoParse = false);
|
/// SimObjectBuilder, which parses
|
||||||
|
/// params in SimObject::create().
|
||||||
|
OutputInitPhase = 0, ///< Output stream initialization
|
||||||
|
TraceInitPhase = 1, ///< Trace context initialization:
|
||||||
|
/// depends on output streams, but
|
||||||
|
/// needs to come before others so we
|
||||||
|
/// can use tracing in other
|
||||||
|
/// ParamContext init code
|
||||||
|
StatsInitPhase = 2, ///< Stats output initialization
|
||||||
|
DefaultInitPhase = 3 ///< Everything else
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Records the initialization phase for this ParamContext.
|
||||||
|
InitPhase initPhase;
|
||||||
|
|
||||||
|
/// Constructor.
|
||||||
|
/// @param _iniSection Name of .ini section corresponding to this context.
|
||||||
|
/// @param _initPhase Initialization phase (see InitPhase).
|
||||||
|
ParamContext(const std::string &_iniSection,
|
||||||
|
InitPhase _initPhase = DefaultInitPhase);
|
||||||
|
|
||||||
virtual ~ParamContext() {}
|
virtual ~ParamContext() {}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,8 @@ ostream *configStream;
|
||||||
class UniverseParamContext : public ParamContext
|
class UniverseParamContext : public ParamContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UniverseParamContext(const string &is) : ParamContext(is) {}
|
UniverseParamContext(const string &is)
|
||||||
|
: ParamContext(is, OutputInitPhase) {}
|
||||||
void checkParams();
|
void checkParams();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue