VMware GemFire Native C++ Reference  9.1
CacheableDate.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef GEODE_CACHEABLEDATE_H_
4 #define GEODE_CACHEABLEDATE_H_
5 
6 /*
7  * Licensed to the Apache Software Foundation (ASF) under one or more
8  * contributor license agreements. See the NOTICE file distributed with
9  * this work for additional information regarding copyright ownership.
10  * The ASF licenses this file to You under the Apache License, Version 2.0
11  * (the "License"); you may not use this file except in compliance with
12  * the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include "geode_globals.hpp"
24 #include "geode_types.hpp"
25 #include "CacheableKey.hpp"
26 #include "CacheableString.hpp"
27 #include "GeodeTypeIds.hpp"
28 #include "ExceptionTypes.hpp"
29 
30 #include <string>
31 #include <chrono>
32 #include <ctime>
33 
36 namespace apache {
37 namespace geode {
38 namespace client {
39 
46  private:
51  int64_t m_timevalue;
52 
53  public:
54  typedef std::chrono::system_clock clock;
55  typedef std::chrono::time_point<clock> time_point;
56  typedef std::chrono::milliseconds duration;
57 
61  virtual void toData(DataOutput& output) const;
62 
66  virtual Serializable* fromData(DataInput& input);
67 
71  static Serializable* createDeserializable();
72 
78  virtual int32_t classId() const;
79 
85  virtual int8_t typeId() const;
86 
88  virtual uint32_t objectSize() const { return sizeof(CacheableDate); }
89 
91  virtual bool operator==(const CacheableKey& other) const;
92 
97  __DEPRECATED__("Use localtime or similar for calendar conversions.")
98  virtual int day() const;
99 
104  __DEPRECATED__("Use localtime or similar for calendar conversions.")
105  virtual int month() const;
106 
111  __DEPRECATED__("Use localtime or similar for calendar conversions.")
112  virtual int year() const;
113 
115  virtual int64_t milliseconds() const;
116 
123  virtual int32_t hashcode() const;
124 
125  operator time_t() const { return m_timevalue / 1000; }
126  operator time_point() const {
127  return clock::from_time_t(0) + duration(m_timevalue);
128  }
129  operator duration() const { return duration(m_timevalue); }
130 
135  return CacheableDatePtr(new CacheableDate());
136  }
137 
138  static CacheableDatePtr create(const time_t& value) {
139  return CacheableDatePtr(new CacheableDate(value));
140  }
141 
142  static CacheableDatePtr create(const time_point& value) {
143  return CacheableDatePtr(new CacheableDate(value));
144  }
145 
146  static CacheableDatePtr create(const duration& value) {
147  return CacheableDatePtr(new CacheableDate(value));
148  }
149 
150  virtual CacheableStringPtr toString() const;
151 
153  virtual ~CacheableDate();
154 
156  virtual int32_t logString(char* buffer, int32_t maxLength) const;
157 
158  protected:
160  CacheableDate(const time_t value = 0);
161 
165  CacheableDate(const time_point& value);
166 
170  CacheableDate(const duration& value);
171 
172  private:
173  // never implemented.
174  void operator=(const CacheableDate& other);
175  CacheableDate(const CacheableDate& other);
176 };
177 
178 inline CacheableKeyPtr createKey(const CacheableDate::time_point& value) {
179  return CacheableKeyPtr(CacheableDate::create(value));
180 }
181 
182 inline CacheablePtr createValue(const CacheableDate::time_point& value) {
183  return CacheablePtr(CacheableDate::create(value));
184 }
185 
186 } // namespace client
187 } // namespace geode
188 } // namespace apache
189 
190 #endif // GEODE_CACHEABLEDATE_H_
Each enum represents a predefined RegionAttributes in a Cache.
Definition: Assert.hpp:31
#define CPPCACHE_EXPORT
Defines a Geode CPPCACHE export.
Definition: geode_base.hpp:58
static CacheableDatePtr create()
Factory method for creating an instance of CacheableDate.
Definition: CacheableDate.hpp:134
virtual uint32_t objectSize() const
Definition: CacheableDate.hpp:88
Provide operations for writing primitive data values, byte arrays, strings, Serializable objects to a...
Definition: DataOutput.hpp:74
Implement a date object based on epoch of January 1, 1970 00:00:00 GMT that can serve as a distributa...
Definition: CacheableDate.hpp:45
Defines a reference counted shared pointer.
Definition: SharedPtr.hpp:52
This abstract base class is the superclass of all user objects in the cache that can be serialized...
Definition: Serializable.hpp:53
Provide operations for reading primitive data values, byte arrays, strings, Serializable objects from...
Definition: DataInput.hpp:56
Represents a cacheable key.
Definition: CacheableKey.hpp:36
This namespace contains all the Geode C++ API classes, enumerations and globals.

Pivotal GemFire C++ Cache API Documentation