![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2009 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 /****************************************************************************** 00006 ** $RCSfile: DtWriteSettingsLock.h,v $ $Revision: 1.6 $ $State: Exp $ 00007 ******************************************************************************/ 00008 00012 00013 #ifndef DtWriteSettingsLock_H_ 00014 #define DtWriteSettingsLock_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 DtWriteSettingsLock 00053 { 00054 public: 00055 00056 //Acquired an instance of the SettingsClass with a read lock. 00057 DtWriteSettingsLock(DtSharedSettingsManager& manager); 00058 00059 //release the lock on the object. 00060 ~DtWriteSettingsLock(); 00061 00062 //Access the instance using pointer notation. 00063 inline SettingsClass* operator->() { return myObject; } 00064 00065 //Access the instance using deref notation. 00066 inline SettingsClass& operator*() { return *myObject; } 00067 00068 private: 00069 //Not copyable or assignable. 00070 DtWriteSettingsLock(const DtWriteSettingsLock&); 00071 DtWriteSettingsLock& operator=(const DtWriteSettingsLock&); 00072 00073 private: 00074 DtSharedSettingsManager& myManager; 00075 SettingsClass* myObject; 00076 00077 boost::shared_lock<boost::shared_mutex> myManagerLock; 00078 boost::unique_lock<boost::shared_mutex> myObjectLock; 00079 00080 }; 00081 } 00082 00083 #define DtWriteSettingsLock_INL_ 00084 #include <vrvCore/DtWriteSettingsLock.inl> 00085 #undef DtWriteSettingsLock_INL_ 00086 00087 #endif 00088