This repository was archived by the owner on Jul 15, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +16
-12
lines changed
Expand file tree Collapse file tree 6 files changed +16
-12
lines changed Original file line number Diff line number Diff line change 4444#ifndef _INCLUDED_Field3D_ClassFactory_H_
4545#define _INCLUDED_Field3D_ClassFactory_H_
4646
47+ #include < boost/scoped_ptr.hpp>
4748#include < map>
4849#include < vector>
4950
@@ -161,7 +162,7 @@ class FIELD3D_API ClassFactory
161162 NameVec m_fieldMappingIONames;
162163
163164 // ! Pointer to static instance
164- static ClassFactory * ms_instance;
165+ static boost::scoped_ptr< ClassFactory> ms_instance;
165166
166167};
167168
Original file line number Diff line number Diff line change 4646
4747// ----------------------------------------------------------------------------//
4848
49+ #include < boost/scoped_ptr.hpp>
4950#include < boost/thread/mutex.hpp>
5051#include < boost/foreach.hpp>
5152
@@ -119,7 +120,7 @@ class FieldCache
119120 // ! The cache itself. Maps a 'key' to a weak pointer and a raw pointer.
120121 Cache m_cache;
121122 // ! The singleton instance
122- static FieldCache * ms_singleton;
123+ static boost::scoped_ptr< FieldCache> ms_singleton;
123124 // ! Mutex to prevent multiple allocaation of the singleton
124125 static boost::mutex ms_creationMutex;
125126 // ! Mutex to prevent reading from and writing to the cache concurrently.
@@ -134,8 +135,8 @@ template <typename Data_T>
134135FieldCache<Data_T>& FieldCache<Data_T>::singleton()
135136{
136137 boost::mutex::scoped_lock lock (ms_creationMutex);
137- if (! ms_singleton) {
138- ms_singleton = new FieldCache;
138+ if (ms_singleton. get () == NULL ) {
139+ ms_singleton. reset ( new FieldCache) ;
139140 }
140141 return *ms_singleton;
141142}
Original file line number Diff line number Diff line change 4646
4747// ----------------------------------------------------------------------------//
4848
49+ #include < boost/scoped_ptr.hpp>
4950#include < deque>
5051#include < list>
5152#include < vector>
@@ -494,7 +495,7 @@ class FIELD3D_API SparseFileManager
494495 SparseFileManager ();
495496
496497 // ! Pointer to singleton
497- static SparseFileManager * ms_singleton;
498+ static boost::scoped_ptr< SparseFileManager> ms_singleton;
498499
499500 // ! Adds the newly loaded block to the cache, managed by the paging algorithm
500501 void addBlockToCache (DataTypeEnum blockType, int fileId, int blockIdx);
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ FIELD3D_NAMESPACE_OPEN
5656// Static instances
5757// ----------------------------------------------------------------------------//
5858
59- ClassFactory* ClassFactory::ms_instance = NULL ;
59+ boost::scoped_ptr< ClassFactory> ClassFactory::ms_instance;
6060
6161// ----------------------------------------------------------------------------//
6262// ClassFactory implementations
@@ -277,8 +277,9 @@ ClassFactory::createFieldMappingIO(const std::string &className) const
277277ClassFactory&
278278ClassFactory::singleton ()
279279{
280- if (!ms_instance)
281- ms_instance = new ClassFactory;
280+ if (ms_instance.get () == NULL ) {
281+ ms_instance.reset (new ClassFactory);
282+ }
282283 return *ms_instance;
283284}
284285
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ boost::mutex FieldCache<Data_T>::ms_creationMutex;
5858template <typename Data_T>
5959boost::mutex FieldCache<Data_T>::ms_accessMutex;
6060template <typename Data_T>
61- FieldCache<Data_T>* FieldCache<Data_T>::ms_singleton;
61+ boost::scoped_ptr< FieldCache<Data_T> > FieldCache<Data_T>::ms_singleton;
6262
6363template class FieldCache <half>;
6464template class FieldCache <float >;
Original file line number Diff line number Diff line change @@ -57,16 +57,16 @@ FIELD3D_NAMESPACE_OPEN
5757// Static instances
5858// ----------------------------------------------------------------------------//
5959
60- SparseFileManager * SparseFileManager::ms_singleton = 0 ;
60+ boost::scoped_ptr< SparseFileManager> SparseFileManager::ms_singleton;
6161
6262// ----------------------------------------------------------------------------//
6363// SparseFileManager
6464// ----------------------------------------------------------------------------//
6565
6666SparseFileManager & SparseFileManager::singleton ()
6767{
68- if (! ms_singleton) {
69- ms_singleton = new SparseFileManager;
68+ if (ms_singleton. get () == NULL ) {
69+ ms_singleton. reset ( new SparseFileManager) ;
7070 }
7171 return *ms_singleton;
7272}
You can’t perform that action at this time.
0 commit comments