![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2009 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 /****************************************************************************** 00006 ** $RCSfile: DtReadSettingsLock.h,v $ $Revision: 1.6 $ $State: Exp $ 00007 ******************************************************************************/ 00008 00012 00013 #ifndef DtReadSettingsLock_H_ 00014 #define DtReadSettingsLock_H_ 00015 00016 #include <vrvCore/vrvCore.h> 00017 #include <vrvCore/DtSharedSettingsManager.h> 00018 00019 #include <boost/thread/shared_mutex.hpp> 00020 #include <boost/thread/locks.hpp> 00021 00022 namespace makVrv 00023 { 00024 class DtSharedSettingsManager; 00025 00051 template <typename SettingsClass> 00052 class DtReadSettingsLock 00053 { 00054 public: 00055 00056 //Acquired an instance of the SettingsClass with a read lock. 00057 DtReadSettingsLock(DtSharedSettingsManager& manager); 00058 00059 //release the lock on the object. 00060 ~DtReadSettingsLock(); 00061 00062 //Access the instance using pointer notation. 00063 inline const SettingsClass* operator->() { return myObject; } 00064 inline const SettingsClass* operator->() const { return myObject; } 00065 00066 //Access the instance using deref notation. 00067 inline const SettingsClass& operator*() { return *myObject; } 00068 inline const SettingsClass& operator*() const { return *myObject; } 00069 00070 private: 00071 //Not copyable or assignable. 00072 DtReadSettingsLock(const DtReadSettingsLock&); 00073 DtReadSettingsLock& operator=(const DtReadSettingsLock&); 00074 00075 private: 00076 DtSharedSettingsManager& myManager; 00077 SettingsClass* myObject; 00078 00079 boost::shared_lock<boost::shared_mutex> myManagerLock; 00080 boost::shared_lock<boost::shared_mutex> myObjectLock; 00081 }; 00082 } 00083 00084 #define DtReadSettingsLock_INL_ 00085 #include <vrvCore/DtReadSettingsLock.inl> 00086 #undef DtReadSettingsLock_INL_ 00087 00088 #endif 00089