Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // util/Cache.h
- #ifndef UTIL_CACHE_H
- #define UTIL_CACHE_H
- namespace util
- {
- template < class T >
- class Cache
- {
- public:
- Cache();
- Cache( T theCached );
- T& Get();
- const T& Get() const;
- operator T&();
- operator const T&() const;
- void Set( const T& theCached );
- Cache< T >& operator =( const T& theCached );
- bool IsValid();
- operator bool() const;
- void Invalidate();
- protected:
- T cached;
- bool isValid;
- };
- #include "util/Cache.inl"
- }
- #endif // UTIL_CACHE_H
- // util/Cache.inl
- template < class T >
- Cache< T >::Cache()
- : cached(),
- isValid( false )
- {
- }
- template < class T >
- Cache< T >::Cache( T theCached )
- : cached( theCached ),
- isValid( true )
- {
- }
- template < class T >
- T& Cache< T >::Get()
- {
- return cached;
- }
- template < class T >
- const T& Cache< T >::Get() const
- {
- return cached;
- }
- template < class T >
- Cache< T >::operator T&()
- {
- return cached;
- }
- template < class T >
- Cache< T >::operator const T&() const
- {
- return cached;
- }
- template < class T >
- void Cache< T >::Set( const T& theCached )
- {
- cached = theCached;
- isValid = true;
- }
- template < class T >
- Cache< T >& Cache< T >::operator =( const T& theCached )
- {
- cached = theCached;
- isValid = true;
- }
- template < class T >
- bool Cache< T >::IsValid()
- {
- return isValid;
- }
- template < class T >
- Cache< T >::operator bool() const
- {
- return isValid;
- }
- template < class T >
- void Cache< T >::Invalidate()
- {
- isValid = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement