Apache Geode Native C++ Reference 1.15.0
CacheableDate.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#ifndef GEODE_CACHEABLEDATE_H_
21#define GEODE_CACHEABLEDATE_H_
22
23#include <chrono>
24#include <ctime>
25#include <string>
26
27#include "CacheableKey.hpp"
28#include "CacheableString.hpp"
29#include "ExceptionTypes.hpp"
30#include "internal/geode_globals.hpp"
31
34namespace apache {
35namespace geode {
36namespace client {
37
43class APACHE_GEODE_EXPORT CacheableDate
44 : public internal::DataSerializablePrimitive,
45 public CacheableKey {
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
59 explicit CacheableDate(const time_t value = 0);
60
64 explicit CacheableDate(const time_point& value);
65
69 explicit CacheableDate(const duration& value);
70
71 ~CacheableDate() noexcept override = default;
72
73 void operator=(const CacheableDate& other) = delete;
74 CacheableDate(const CacheableDate& other) = delete;
75
76 void toData(DataOutput& output) const override;
77
78 virtual void fromData(DataInput& input) override;
79
83 static std::shared_ptr<Serializable> createDeserializable();
84
85 virtual DSCode getDsCode() const override;
86
88 virtual size_t objectSize() const override { return sizeof(CacheableDate); }
89
91 virtual bool operator==(const CacheableKey& other) const override;
92
94 virtual int64_t milliseconds() const;
95
102 virtual int32_t hashcode() const override;
103
104 explicit operator time_t() const { return m_timevalue / 1000; }
105 explicit operator time_point() const {
106 return clock::from_time_t(0) + duration(m_timevalue);
107 }
108 explicit operator duration() const { return duration(m_timevalue); }
109
113 static std::shared_ptr<CacheableDate> create() {
114 return std::make_shared<CacheableDate>();
115 }
116
117 static std::shared_ptr<CacheableDate> create(const time_t& value) {
118 return std::make_shared<CacheableDate>(value);
119 }
120
121 static std::shared_ptr<CacheableDate> create(const time_point& value) {
122 return std::make_shared<CacheableDate>(value);
123 }
124
125 static std::shared_ptr<CacheableDate> create(const duration& value) {
126 return std::make_shared<CacheableDate>(value);
127 }
128
129 std::string toString() const override;
130};
131
132template <>
133inline std::shared_ptr<CacheableKey> CacheableKey::create(
134 CacheableDate::time_point value) {
135 return CacheableDate::create(value);
136}
137
138template <>
139inline std::shared_ptr<Serializable> Serializable::create(
140 CacheableDate::time_point value) {
141 return CacheableDate::create(value);
142}
143
144} // namespace client
145} // namespace geode
146} // namespace apache
147
148#endif // GEODE_CACHEABLEDATE_H_
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
std::string toString() const override
Display this object as 'string', which depends on the implementation in the subclasses.
virtual bool operator==(const CacheableKey &other) const override
CacheableDate(const time_point &value)
Construct from std::chrono::time_point<std::chrono::system_clock>.
CacheableDate(const time_t value=0)
Constructor, used for deserialization.
CacheableDate(const duration &value)
Construct from std::chrono::seconds since POSIX epoch.
static std::shared_ptr< CacheableDate > create()
Factory method for creating an instance of CacheableDate.
Definition: CacheableDate.hpp:113
virtual int64_t milliseconds() const
virtual int32_t hashcode() const override
Returns a hash code value for this object.
Represents a cacheable key.
Definition: CacheableKey.hpp:40
static std::shared_ptr< CacheableKey > create(_T value)
Factory method that creates the key type that matches the type of value.
Provide operations for reading primitive data values, byte arrays, strings, Serializable objects from...
Definition: DataInput.hpp:59
Provide operations for writing primitive data values, byte arrays, strings, Serializable objects to a...
Definition: DataOutput.hpp:48
This base class is the superclass of all user objects in the cache that can be serialized.
Definition: Serializable.hpp:53
static std::shared_ptr< Serializable > create(_T value)
Factory method that creates the Serializable object that matches the type of value.

Apache Geode C++ Cache API Documentation