44 #ifndef _INCLUDED_Field3D_FieldCache_H_ 45 #define _INCLUDED_Field3D_FieldCache_H_ 49 #include <boost/thread/mutex.hpp> 77 template <
typename Data_T>
88 typedef std::map<std::string, CacheEntry>
Cache;
101 const std::string &layerPath);
103 void cacheField(FieldPtr field,
const std::string &filename,
104 const std::string &layerPath);
111 std::string
key(
const std::string &filename,
112 const std::string &layerPath);
130 template <
typename Data_T>
132 template <
typename Data_T>
134 template <
typename Data_T>
141 template <
typename Data_T>
153 template <
typename Data_T>
156 const std::string &layerPath)
160 typename Cache::iterator i =
m_cache.find(
key(filename, layerPath));
167 if (weakPtr.expired()) {
175 template <
typename Data_T>
177 const std::string &layerPath)
181 std::make_pair(field->weakPtr(), field.get());
186 template <
typename Data_T>
188 const std::string &layerPath)
190 return filename +
"/" + layerPath;
#define FIELD3D_NAMESPACE_HEADER_CLOSE
static boost::mutex ms_creationMutex
Mutex to prevent multiple allocaation of the singleton.
std::map< std::string, CacheEntry > Cache
FieldPtr getCachedField(const std::string &filename, const std::string &layerPath)
Checks the cache for a previously loaded field.
void cacheField(FieldPtr field, const std::string &filename, const std::string &layerPath)
Adds the given field to the cache.
static FieldCache * ms_singleton
The singleton instance.
static boost::mutex ms_accessMutex
Mutex to prevent reading from and writing to the cache concurrently.
boost::weak_ptr< RefBase > WeakPtr
static FieldCache & singleton()
Returns a reference to the FieldCache singleton.
Contains Field, WritableField and ResizableField classes.
std::pair< WeakPtr, Field_T * > CacheEntry
std::string key(const std::string &filename, const std::string &layerPath)
Constructs the cache key for a given file and layer path.
Cache m_cache
The cache itself. Maps a 'key' to a weak pointer and a raw pointer.
boost::intrusive_ptr< Field > Ptr