H:/gfcppsancout/product/include/gfcpp/CacheableDate.hpp

Go to the documentation of this file.
00001 #ifndef _GEMFIRE_CACHEABLEDATE_HPP_
00002 #define _GEMFIRE_CACHEABLEDATE_HPP_
00003 /*=========================================================================
00004  * (c) Copyright 2002-2007, GemStone Systems, Inc. All Rights Reserved.  
00005  * 1260 NW Waterhouse Ave., Suite 200,  Beaverton, OR 97006
00006  *=========================================================================
00007  */
00008 #include "gfcpp_globals.hpp"
00009 #include "gf_types.hpp"
00010 #include "CacheableKey.hpp"
00011 #include "CacheableString.hpp"
00012 #include "GemfireTypeIds.hpp"
00013 #include "ExceptionTypes.hpp"
00014 #include <time.h>
00015 #ifdef _WIN32
00016 #include <WinSock2.h> //for struct timeval
00017 #define GF_LOCALTIME(X,Y) localtime_s(Y,X)
00018 #else
00019 #include <sys/time.h>
00020 #if defined(_LINUX) || defined(_SOLARIS)
00021 #define GF_LOCALTIME(X,Y) localtime_r(X,Y)
00022 #endif
00023 #endif
00024 
00027 namespace gemfire {
00028 
00029 
00034 class CPPCACHE_EXPORT CacheableDate
00035   : public CacheableKey
00036 {
00037   private:
00038 
00039     struct timeval m_timevalue;
00040     uint32_t m_hash;
00041 
00042   public:
00043 
00047   virtual void toData( DataOutput& output ) const;
00048 
00052   virtual Serializable* fromData( DataInput& input );
00053   
00057   static Serializable* createDeserializable( );
00058 
00064   virtual int8_t classId( ) const;
00065 
00071   virtual int8_t typeId( ) const;
00072 
00074   virtual uint32_t objectSize() const {
00075     return sizeof(CacheableDate);
00076   }
00077 
00079   virtual bool operator==( const CacheableKey& other ) const;
00080 
00082   virtual int day() const; 
00083 
00085   virtual int month() const;
00086 
00088   virtual int year() const;
00089 
00091   virtual int64_t milliseconds() const; 
00092 
00094   virtual uint32_t hashcode( ) const;
00095 
00099   static CacheableDatePtr create( )
00100   {
00101     return new CacheableDate( );
00102   }
00103 
00104   static CacheableDatePtr create( const time_t& value )
00105   {
00106     return new CacheableDate( value );
00107   }
00108 
00109   static CacheableDatePtr create( const timeval& value )
00110   {
00111     return new CacheableDate( value );
00112   }
00113 
00114   virtual CacheableStringPtr toString( ) const;
00115 
00117   virtual ~CacheableDate( );
00118 
00120   virtual size_t logString( char* buffer, size_t maxLength ) const;
00121   
00122   protected:
00123 
00125   CacheableDate( const timeval& value );
00126 
00128   CacheableDate( const time_t value = 0 );
00129 
00130   private:
00131 
00132   // never implemented.
00133   void operator=( const CacheableDate& other );
00134   CacheableDate( const CacheableDate& other );
00135 
00136 };
00137 
00138 inline CacheableKeyPtr createKey( const time_t& value )
00139 {
00140   return CacheableKeyPtr( CacheableDate::create( value ) );
00141 }
00142 
00143 inline CacheableKeyPtr createKey( const timeval& value )
00144 {
00145   return CacheableKeyPtr( CacheableDate::create( value ) );
00146 }
00147 
00148 inline CacheablePtr createValue( const time_t& value )
00149 {
00150   return CacheablePtr( CacheableDate::create( value ) );
00151 }
00152 
00153 inline CacheablePtr createValue( const timeval& value )
00154 {
00155   return CacheablePtr( CacheableDate::create( value ) );
00156 }
00157 
00158 }
00159 
00160 #endif
00161 

GemFire C++ Cache API Documentation