build-artifacts/win/product/include/gfcpp/CacheableDate.hpp

Go to the documentation of this file.
00001 #ifndef _GEMFIRE_CACHEABLEDATE_HPP_
00002 #define _GEMFIRE_CACHEABLEDATE_HPP_
00003 /*=========================================================================
00004  * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
00005  * This product is protected by U.S. and international copyright
00006  * and intellectual property laws. Pivotal products are covered by
00007  * more patents listed at http://www.pivotal.io/patents.
00008  *=========================================================================
00009  */
00010 #include "gfcpp_globals.hpp"
00011 #include "gf_types.hpp"
00012 #include "CacheableKey.hpp"
00013 #include "CacheableString.hpp"
00014 #include "GemfireTypeIds.hpp"
00015 #include "ExceptionTypes.hpp"
00016 #include <time.h>
00017 #ifdef _WIN32
00018 #include <WinSock2.h> //for struct timeval
00019 #define GF_LOCALTIME(X,Y) localtime_s(Y,X)
00020 #else
00021 #include <sys/time.h>
00022 #if defined(_LINUX) || defined(_SOLARIS)
00023 #define GF_LOCALTIME(X,Y) localtime_r(X,Y)
00024 #endif
00025 #endif
00026 
00029 namespace gemfire {
00030 
00031 
00036 class CPPCACHE_EXPORT CacheableDate
00037   : public CacheableKey
00038 {
00039   private:
00040 
00041     struct timeval m_timevalue;
00042     uint32_t m_hash;
00043 
00044   public:
00045 
00049   virtual void toData( DataOutput& output ) const;
00050 
00054   virtual Serializable* fromData( DataInput& input );
00055 
00059   static Serializable* createDeserializable( );
00060 
00066   virtual int32_t classId( ) const;
00067 
00073   virtual int8_t typeId( ) const;
00074 
00076   virtual uint32_t objectSize() const {
00077     return sizeof(CacheableDate);
00078   }
00079 
00081   virtual bool operator==( const CacheableKey& other ) const;
00082 
00084   virtual int day() const;
00085 
00087   virtual int month() const;
00088 
00090   virtual int year() const;
00091 
00093   virtual int64_t milliseconds() const;
00094 
00096   virtual uint32_t hashcode( ) const;
00097 
00101   static CacheableDatePtr create( )
00102   {
00103     return CacheableDatePtr(new CacheableDate());
00104   }
00105 
00106   static CacheableDatePtr create( const time_t& value )
00107   {
00108     return CacheableDatePtr(new CacheableDate(value));
00109   }
00110 
00111   static CacheableDatePtr create( const timeval& value )
00112   {
00113     return CacheableDatePtr(new CacheableDate(value));
00114   }
00115 
00116   virtual CacheableStringPtr toString( ) const;
00117 
00119   virtual ~CacheableDate( );
00120 
00122   virtual int32_t logString( char* buffer, int32_t maxLength ) const;
00123 
00124   protected:
00125 
00127   CacheableDate( const timeval& value );
00128 
00130   CacheableDate( const time_t value = 0 );
00131 
00132   private:
00133 
00134   // never implemented.
00135   void operator=( const CacheableDate& other );
00136   CacheableDate( const CacheableDate& other );
00137 
00138 };
00139 
00140 inline CacheableKeyPtr createKey( const timeval& value )
00141 {
00142   return CacheableKeyPtr( CacheableDate::create( value ) );
00143 }
00144 
00145 inline CacheablePtr createValue( const timeval& value )
00146 {
00147   return CacheablePtr( CacheableDate::create( value ) );
00148 }
00149 
00150 }
00151 
00152 #endif
00153 

GemFire C++ Cache API Documentation