usata-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Usata-commits] Changes to usata2/src/object-registry.cpp


From: David Lau
Subject: [Usata-commits] Changes to usata2/src/object-registry.cpp
Date: Sun, 09 Jan 2005 03:51:52 -0500

Index: usata2/src/object-registry.cpp
diff -u usata2/src/object-registry.cpp:1.2 usata2/src/object-registry.cpp:1.3
--- usata2/src/object-registry.cpp:1.2  Thu Dec 30 16:41:17 2004
+++ usata2/src/object-registry.cpp      Sun Jan  9 08:17:14 2005
@@ -10,15 +10,18 @@
 // included in the software distribution, or visit
 // http://www.fsf.org/licenses/gpl.html.
 //
-// $Id: object-registry.cpp,v 1.2 2004/12/30 16:41:17 skunix Exp $
+// $Id: object-registry.cpp,v 1.3 2005/01/09 08:17:14 skunix Exp $
 
 #include "object-registry.hpp"
 #include <map>
 #include <string>
-
+#include "log.hpp"
 namespace usata
 {
-       std::auto_ptr<ObjectRegistry> ObjectRegistry::mInstance;
+       
+       ObjectRegistry *ObjectRegistry::Instance=0;
+
+       ObjectRegistry::StaticKilla die;
 
 /**
        \ingroup impl
@@ -30,6 +33,16 @@
                typedef std::map<std::string, BIOCF> BuiltinMap;
                BuiltinMap builtins;
                void add_builtin(const std::string&, BIOCF);
+               BIOCF lookup(const std::string& name)
+               {
+                       BIOCF retval = 0;
+                       BuiltinMap::iterator it = builtins.find(name);  
+                       if (it != builtins.end())
+                       {
+                               retval = it->second;
+                       }
+                       return retval;
+               }
        };
 
        void
@@ -42,18 +55,33 @@
                        it->second = creation_func;
                        return;
                }
-               builtins.insert(std::make_pair(name,creation_func));
+               builtins.insert(BuiltinMap::value_type(name,creation_func));
                return;         
        }
 
+       void
+       ObjectRegistry::die()
+       {
+               if (Instance)
+                       delete Instance;
+               Instance=0;
+       }
+       
+       ObjectRegistry
+       :: ~ObjectRegistry()throw()
+       {
+               log::BufferedStream L(log::Level::DEBUG);
+               L << "~ObjectRegistry" << log::commit;
+       }
+
        ObjectRegistry*
        ObjectRegistry::instance()
        {
-               if (mInstance.get()==0)
+               if (!Instance)
                {
-                       mInstance.reset(new ObjectRegistry);
+                       Instance = new ObjectRegistry;
                }
-               return mInstance.get();
+               return Instance;
        }
 
        ObjectRegistry::ObjectRegistry()
@@ -73,5 +101,19 @@
                mImpl->add_builtin(name,func);
                return; 
        }
+
+
+       Object *
+       ObjectRegistry::create(const std::string& name)
+       {
+               BIOCF f = mImpl->lookup(name);
+               
+               if (f!=0)
+               {
+                       return f();
+               }       
+
+               return 0;
+       }
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]