Merge zizzer:/bk/m5 into zeep.eecs.umich.edu:/z/saidi/work/m5
[gem5.git] / sim / param.cc
index 5f3f604c1f75c4e1fb986062ade55578e5208f40..d20be8d3358bf215108fc2978714e29ce47b0da6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003 The Regents of The University of Michigan
+ * Copyright (c) 2002-2004 The Regents of The University of Michigan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -97,7 +97,7 @@ parseParam(const string &s, T &value)
 
 template <class T>
 void
-showParam(ostream &os, const T &value)
+showParam(ostream &os, T const &value)
 {
     os << value;
 }
@@ -147,14 +147,14 @@ template <>
 bool
 parseParam(const string &s, bool &value)
 {
-    const string &lower = to_lower(s);
+    const string &ls = to_lower(s);
 
-    if (lower == "true" || lower == "t" || lower == "yes" || lower == "y") {
+    if (ls == "true" || ls == "t" || ls == "yes" || ls == "y" || ls == "1") {
         value = true;
         return true;
     }
 
-    if (lower == "false" || lower == "f" || lower == "no" || lower == "n") {
+    if (ls == "false" || ls == "f" || ls == "no" || ls == "n" || ls == "0") {
         value = false;
         return true;
     }
@@ -211,6 +211,11 @@ template <class T>
 void
 VectorParam<T>::parse(const string &s)
 {
+    if (s.empty()) {
+        wasSet = true;
+        return;
+    }
+
     vector<string> tokens;
 
     tokenize(tokens, s, ' ');
@@ -277,7 +282,7 @@ template VectorParam<type>;
 // types that can use the above templates
 #define INSTANTIATE_PARAM_TEMPLATES(type, typestr)                     \
 template bool parseParam<type>(const string &s, type &value);          \
-template void showParam<type>(ostream &os, const type &value);         \
+template void showParam<type>(ostream &os, type const &value);         \
 template void Param<type>::parse(const string &);                      \
 template void VectorParam<type>::parse(const string &);                        \
 template void Param<type>::showValue(ostream &) const;                 \
@@ -555,15 +560,27 @@ SimObjectBaseParam::parse(const string &s, vector<SimObject *>&value)
 
 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()
-      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)
             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);
     }
 }