Răsfoiți Sursa

stringapi: Use strings for cache iterator values

Ben Boeckel 11 ani în urmă
părinte
comite
94fc63e2d5

+ 3 - 2
Source/CursesDialog/cmCursesCacheEntryComposite.cxx

@@ -51,7 +51,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
     {
     {
     case  cmCacheManager::BOOL:
     case  cmCacheManager::BOOL:
       this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
       this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
-      if (cmSystemTools::IsOn(it.GetValue()))
+      if (cmSystemTools::IsOn(it.GetValue().c_str()))
         {
         {
         static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
         static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
         }
         }
@@ -94,7 +94,8 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
         }
         }
       break;
       break;
     case cmCacheManager::UNINITIALIZED:
     case cmCacheManager::UNINITIALIZED:
-      cmSystemTools::Error("Found an undefined variable: ", it.GetName());
+      cmSystemTools::Error("Found an undefined variable: ",
+                           it.GetName().c_str());
       break;
       break;
     default:
     default:
       // TODO : put warning message here
       // TODO : put warning message here

+ 6 - 6
Source/QtDialog/QCMake.cxx

@@ -111,7 +111,7 @@ void QCMake::setBinaryDirectory(const QString& _dir)
     cmCacheManager::CacheIterator itm = cachem->NewIterator();
     cmCacheManager::CacheIterator itm = cachem->NewIterator();
     if ( itm.Find("CMAKE_HOME_DIRECTORY"))
     if ( itm.Find("CMAKE_HOME_DIRECTORY"))
       {
       {
-      setSourceDirectory(QString::fromLocal8Bit(itm.GetValue()));
+      setSourceDirectory(QString::fromLocal8Bit(itm.GetValue().c_str()));
       }
       }
     if ( itm.Find("CMAKE_GENERATOR"))
     if ( itm.Find("CMAKE_GENERATOR"))
       {
       {
@@ -201,11 +201,11 @@ void QCMake::setProperties(const QCMakePropertyList& newProps)
       }
       }
 
 
     QCMakeProperty prop;
     QCMakeProperty prop;
-    prop.Key = QString::fromLocal8Bit(i.GetName());
+    prop.Key = QString::fromLocal8Bit(i.GetName().c_str());
     int idx = props.indexOf(prop);
     int idx = props.indexOf(prop);
     if(idx == -1)
     if(idx == -1)
       {
       {
-      toremove.append(QString::fromLocal8Bit(i.GetName()));
+      toremove.append(QString::fromLocal8Bit(i.GetName().c_str()));
       }
       }
     else
     else
       {
       {
@@ -286,15 +286,15 @@ QCMakePropertyList QCMake::properties() const
       }
       }
 
 
     QCMakeProperty prop;
     QCMakeProperty prop;
-    prop.Key = QString::fromLocal8Bit(i.GetName());
+    prop.Key = QString::fromLocal8Bit(i.GetName().c_str());
     prop.Help = QString::fromLocal8Bit(i.GetProperty("HELPSTRING"));
     prop.Help = QString::fromLocal8Bit(i.GetProperty("HELPSTRING"));
-    prop.Value = QString::fromLocal8Bit(i.GetValue());
+    prop.Value = QString::fromLocal8Bit(i.GetValue().c_str());
     prop.Advanced = i.GetPropertyAsBool("ADVANCED");
     prop.Advanced = i.GetPropertyAsBool("ADVANCED");
 
 
     if(i.GetType() == cmCacheManager::BOOL)
     if(i.GetType() == cmCacheManager::BOOL)
       {
       {
       prop.Type = QCMakeProperty::BOOL;
       prop.Type = QCMakeProperty::BOOL;
-      prop.Value = cmSystemTools::IsOn(i.GetValue());
+      prop.Value = cmSystemTools::IsOn(i.GetValue().c_str());
       }
       }
     else if(i.GetType() == cmCacheManager::PATH)
     else if(i.GetType() == cmCacheManager::PATH)
       {
       {

+ 3 - 3
Source/cmCacheManager.h

@@ -56,8 +56,8 @@ public:
     bool Find(const std::string&);
     bool Find(const std::string&);
     bool IsAtEnd() const;
     bool IsAtEnd() const;
     void Next();
     void Next();
-    const char *GetName() const {
-      return this->Position->first.c_str(); }
+    std::string GetName() const {
+      return this->Position->first; }
     const char* GetProperty(const std::string&) const ;
     const char* GetProperty(const std::string&) const ;
     bool GetPropertyAsBool(const std::string&) const ;
     bool GetPropertyAsBool(const std::string&) const ;
     bool PropertyExists(const std::string&) const;
     bool PropertyExists(const std::string&) const;
@@ -65,7 +65,7 @@ public:
     void AppendProperty(const std::string& property, const char* value,
     void AppendProperty(const std::string& property, const char* value,
                         bool asString=false);
                         bool asString=false);
     void SetProperty(const std::string& property, bool value);
     void SetProperty(const std::string& property, bool value);
-    const char* GetValue() const { return this->GetEntry().Value.c_str(); }
+    std::string GetValue() const { return this->GetEntry().Value; }
     bool GetValueAsBool() const;
     bool GetValueAsBool() const;
     void SetValue(const char*);
     void SetValue(const char*);
     CacheEntryType GetType() const { return this->GetEntry().Type; }
     CacheEntryType GetType() const { return this->GetEntry().Type; }

+ 6 - 2
Source/cmMakefile.cxx

@@ -1796,7 +1796,8 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
                                     cmCacheManager::CacheEntryType type,
                                     cmCacheManager::CacheEntryType type,
                                     bool force)
                                     bool force)
 {
 {
-  const char* val = value;
+  bool haveVal = value ? true : false;
+  std::string val = haveVal ? value : "";
   cmCacheManager::CacheIterator it =
   cmCacheManager::CacheIterator it =
     this->GetCacheManager()->GetCacheIterator(name.c_str());
     this->GetCacheManager()->GetCacheIterator(name.c_str());
   if(!it.IsAtEnd() && (it.GetType() == cmCacheManager::UNINITIALIZED) &&
   if(!it.IsAtEnd() && (it.GetType() == cmCacheManager::UNINITIALIZED) &&
@@ -1807,6 +1808,7 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
     if(!force)
     if(!force)
       {
       {
       val = it.GetValue();
       val = it.GetValue();
+      haveVal = true;
       }
       }
     if ( type == cmCacheManager::PATH || type == cmCacheManager::FILEPATH )
     if ( type == cmCacheManager::PATH || type == cmCacheManager::FILEPATH )
       {
       {
@@ -1829,10 +1831,12 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
 
 
       this->GetCacheManager()->AddCacheEntry(name, nvalue.c_str(), doc, type);
       this->GetCacheManager()->AddCacheEntry(name, nvalue.c_str(), doc, type);
       val = it.GetValue();
       val = it.GetValue();
+      haveVal = true;
       }
       }
 
 
     }
     }
-  this->GetCacheManager()->AddCacheEntry(name, val, doc, type);
+  this->GetCacheManager()->AddCacheEntry(name, haveVal ? val.c_str() : 0, doc,
+                                         type);
   // if there was a definition then remove it
   // if there was a definition then remove it
   this->Internal->VarStack.top().Set(name, 0);
   this->Internal->VarStack.top().Set(name, 0);
 }
 }

+ 1 - 4
Source/cmOptionCommand.cxx

@@ -55,10 +55,7 @@ bool cmOptionCommand
       it.SetProperty("HELPSTRING", args[1].c_str());
       it.SetProperty("HELPSTRING", args[1].c_str());
       return true;
       return true;
       }
       }
-    if ( it.GetValue() )
-      {
-      initialValue = it.GetValue();
-      }
+    initialValue = it.GetValue();
     }
     }
   if(args.size() == 3)
   if(args.size() == 3)
     {
     {