[Orxonox-commit 2938] r7638 - code/branches/releasetodo/src/orxonox

dafrick at orxonox.net dafrick at orxonox.net
Thu Nov 11 11:21:28 CET 2010


Author: dafrick
Date: 2010-11-11 11:21:28 +0100 (Thu, 11 Nov 2010)
New Revision: 7638

Modified:
   code/branches/releasetodo/src/orxonox/LevelInfo.cc
   code/branches/releasetodo/src/orxonox/LevelInfo.h
Log:

Adding restriction to possible tags. 


Modified: code/branches/releasetodo/src/orxonox/LevelInfo.cc
===================================================================
--- code/branches/releasetodo/src/orxonox/LevelInfo.cc	2010-11-11 00:46:59 UTC (rev 7637)
+++ code/branches/releasetodo/src/orxonox/LevelInfo.cc	2010-11-11 10:21:28 UTC (rev 7638)
@@ -41,6 +41,9 @@
 {
 
     // LevelInfoItem
+    
+    //! The list of allowed tags.
+    /*static*/ std::set<std::string> LevelInfoItem::possibleTags_s = std::set<std::string>();
 
     /**
     @brief
@@ -73,6 +76,18 @@
     {
 
     }
+    
+    void LevelInfoItem::initializeTags(void)
+    {
+        if(!LevelInfoItem::initialized_s)
+        {
+            LevelInfoItem::possibleTags_s.insert("test");
+            LevelInfoItem::possibleTags_s.insert("singleplayer");
+            LevelInfoItem::possibleTags_s.insert("multiplayer");
+            LevelInfoItem::possibleTags_s.insert("showcase");
+            LevelInfoItem::possibleTags_s.insert("tutorial");
+        }
+    }
 
     /**
     @brief
@@ -102,6 +117,11 @@
     */
     bool LevelInfoItem::addTag(const std::string& tag, bool update)
     {
+        if(!this->validateTag(tag))
+        {
+            COUT(2) << "Bad tag '" << tag << "' in " << this->getXMLFilename() << ". Ignoring..." << std::endl;
+            return false;
+        }
         bool success = this->tags_.insert(std::string(tag)).second;
         if(update && success)
             this->tagsUpdated();

Modified: code/branches/releasetodo/src/orxonox/LevelInfo.h
===================================================================
--- code/branches/releasetodo/src/orxonox/LevelInfo.h	2010-11-11 00:46:59 UTC (rev 7637)
+++ code/branches/releasetodo/src/orxonox/LevelInfo.h	2010-11-11 10:21:28 UTC (rev 7638)
@@ -37,6 +37,7 @@
 
 #include "OrxonoxPrereqs.h"
 
+#include <map>
 #include <set>
 #include <string>
 
@@ -119,6 +120,12 @@
 
         private:
             void tagsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
+            
+            static std::set<std::string> possibleTags_s;
+            static const bool initialized_s = false;
+            void initializeTags(void);
+            bool validateTag(const std::string& tag)
+                { this->initializeTags(); return LevelInfoItem::possibleTags_s.find(tag) != LevelInfoItem::possibleTags_s.end(); }
 
             std::string name_; //!< The name of the Level.
             std::string description_; //!< The description of the Level.




More information about the Orxonox-commit mailing list