diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2011-11-19 13:08:21 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2011-11-19 13:08:21 +0800 |
commit | ec938e94e789b7f27ea103c81e5d05827cfd2d2c (patch) | |
tree | 8053239df06d1cc7153f5e3117e80f01e931e847 | |
parent | 5159a48989b4c552eb3213fe916206c6be44a3a7 (diff) |
SexyAppFramework: Check whether the factory is still valid
-rw-r--r-- | osframework/source/SexyAppFramework/DriverFactory.cpp | 43 | ||||
-rw-r--r-- | osframework/source/SexyAppFramework/DriverFactory.h | 24 |
2 files changed, 47 insertions, 20 deletions
diff --git a/osframework/source/SexyAppFramework/DriverFactory.cpp b/osframework/source/SexyAppFramework/DriverFactory.cpp index 0d6a0c3..bb5a9b1 100644 --- a/osframework/source/SexyAppFramework/DriverFactory.cpp +++ b/osframework/source/SexyAppFramework/DriverFactory.cpp @@ -3,8 +3,9 @@ using namespace Sexy; Driver::Driver (const std::string theName, - int thePriority) - : mName (theName), mPriority (thePriority) + int thePriority) + : mName (theName), mPriority (thePriority), + mDisabled (false) { } @@ -12,29 +13,47 @@ Driver::~Driver () { } +void Driver::Disable (bool disable) +{ + mDisabled = disable; +} + +bool Driver::IsDisabled () +{ + return mDisabled; +} + DriverFactory::DriverFactory () - : mDrivers () + : mDrivers (), mValid(true) { } DriverFactory::~DriverFactory () { + mValid = false; } void DriverFactory::AddDriver (Driver * theDriver) { + if (!mValid) + return; + mDrivers.insert (theDriver); } void DriverFactory::RemoveDriver (Driver * theDriver) { - Drivers::iterator anItr = mDrivers.find (theDriver); - if (anItr != mDrivers.end ()) - mDrivers.erase (anItr); + if (!mValid) + return; + + mDrivers.erase (theDriver); } Driver* DriverFactory::Find (const std::string name) { + if (!mValid) + return 0; + if (name == "auto") { if (!mDrivers.size ()) return 0; @@ -52,13 +71,13 @@ Driver* DriverFactory::Find (const std::string name) Driver* DriverFactory::FindNext (Driver * theDriver) { - if (!theDriver) - return Find(); + if (!theDriver) + return Find(); - Drivers::iterator it = mDrivers.find(theDriver); - if (it == mDrivers.end () || ++it == mDrivers.end ()) - return 0; - return *it; + Drivers::iterator it = mDrivers.find(theDriver); + if (it == mDrivers.end () || ++it == mDrivers.end ()) + return 0; + return *it; } const DriverFactory::Drivers* DriverFactory::GetDrivers() diff --git a/osframework/source/SexyAppFramework/DriverFactory.h b/osframework/source/SexyAppFramework/DriverFactory.h index 1b2ff15..cc25467 100644 --- a/osframework/source/SexyAppFramework/DriverFactory.h +++ b/osframework/source/SexyAppFramework/DriverFactory.h @@ -3,26 +3,33 @@ #include "Common.h" #include "NativeDisplay.h" +#include "SexyAppBase.h" + +#include <string> +#include <set> namespace Sexy { class Driver { - public: + public: std::string mName; int mPriority; + bool mDisabled; Driver (const std::string theName, int thePriority = 0); virtual ~Driver (); + void Disable(bool disable = true); + bool IsDisabled(); + bool operator< (const Driver& other) const { return mPriority < other.mPriority; } }; - struct DriverCompare - { + struct DriverCompare { bool operator() (Driver* const & lhs, Driver* const & rhs) const { return *lhs < *rhs; @@ -31,22 +38,23 @@ namespace Sexy { class DriverFactory { - public: + public: typedef std::multiset<Driver*, DriverCompare> Drivers; void AddDriver (Driver * theDriver); void RemoveDriver (Driver * theDriver); Driver* Find (const std::string name = "auto"); - Driver* FindNext (Driver * theDriver); + Driver* FindNext (Driver * theDriver); - public: + public: const Drivers* GetDrivers(); - private: + private: Drivers mDrivers; + bool mValid; - public: + public: DriverFactory (); ~DriverFactory (); }; |