Apache Geode Native C++ Reference 1.15.0
CacheableEnum.hpp
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_CACHEABLEENUM_H_
21#define GEODE_CACHEABLEENUM_H_
22
23#include <iosfwd>
24#include <memory>
25#include <string>
26
27#include "CacheableKey.hpp"
28#include "CacheableString.hpp"
29#include "internal/geode_base.hpp"
30
31namespace apache {
32namespace geode {
33namespace client {
34
35class DataInput;
36class DataOutput;
37class Serializable;
38
53class APACHE_GEODE_EXPORT CacheableEnum
54 : public internal::DataSerializablePrimitive,
55 public CacheableKey {
56 private:
57 std::string m_enumClassName;
58 std::string m_enumName;
59 int32_t m_ordinal;
60 int32_t m_hashcode;
61
62 public:
63 inline CacheableEnum()
64 : m_enumClassName(nullptr),
65 m_enumName(nullptr),
66 m_ordinal(-1),
67 m_hashcode(0) {}
68 inline CacheableEnum(std::string enumClassName, std::string enumName,
69 int32_t ordinal)
70 : m_enumClassName(std::move(enumClassName)),
71 m_enumName(std::move(enumName)),
72 m_ordinal(ordinal),
73 m_hashcode(0) {}
74 ~CacheableEnum() noexcept override = default;
75 void operator=(const CacheableEnum& other) = delete;
76 CacheableEnum(const CacheableEnum& other) = delete;
77
81 static std::shared_ptr<Serializable> createDeserializable() {
82 return std::make_shared<CacheableEnum>();
83 }
84
85 void toData(DataOutput& output) const override;
86
87 virtual void fromData(DataInput& input) override;
88
89 virtual size_t objectSize() const override {
90 auto size = sizeof(CacheableEnum);
91 size += m_enumClassName.length();
92 size += m_enumName.length();
93 return size;
94 }
95
96 virtual DSCode getDsCode() const override { return DSCode::PDX_ENUM; }
97
101 virtual std::string toString() const override { return "CacheableEnum"; }
102
113 static std::shared_ptr<CacheableEnum> create(std::string enumClassName,
114 std::string enumName,
115 int32_t ordinal) {
116 return std::make_shared<CacheableEnum>(enumClassName, enumName, ordinal);
117 }
118
120 const std::string& getEnumClassName() const { return m_enumClassName; }
121
123 const std::string& getEnumName() const { return m_enumName; }
124
126 int32_t getEnumOrdinal() const { return m_ordinal; }
127
129 virtual int32_t hashcode() const override { return m_hashcode; }
130
132 virtual bool operator==(const CacheableKey& other) const override;
133
134 protected:
135 void calculateHashcode();
136};
137
138} // namespace client
139} // namespace geode
140} // namespace apache
141
142#endif // GEODE_CACHEABLEENUM_H_
Since C++ enums cannot be directly passed as a parameter to PdxWriter's writeObject and PdxReader's r...
Definition: CacheableEnum.hpp:55
static std::shared_ptr< Serializable > createDeserializable()
creation function for enum.
Definition: CacheableEnum.hpp:81
int32_t getEnumOrdinal() const
Definition: CacheableEnum.hpp:126
virtual bool operator==(const CacheableKey &other) const override
const std::string & getEnumName() const
Definition: CacheableEnum.hpp:123
virtual size_t objectSize() const override
return the size in bytes of the instance being serialized.
Definition: CacheableEnum.hpp:89
const std::string & getEnumClassName() const
Definition: CacheableEnum.hpp:120
virtual int32_t hashcode() const override
Definition: CacheableEnum.hpp:129
virtual std::string toString() const override
Display this object as c string.
Definition: CacheableEnum.hpp:101
static std::shared_ptr< CacheableEnum > create(std::string enumClassName, std::string enumName, int32_t ordinal)
Factory method for creating an instance of CacheableEnum.
Definition: CacheableEnum.hpp:113
Represents a cacheable key.
Definition: CacheableKey.hpp:40
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

Apache Geode C++ Cache API Documentation