VMware VMware GemFire Native C++ Reference 10.4.3
Loading...
Searching...
No Matches
Properties.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_PROPERTIES_H_
21#define GEODE_PROPERTIES_H_
22
27#include <memory>
28#include <string>
29#include <unordered_map>
30
31#include "CacheableKey.hpp"
32#include "internal/DataSerializablePrimitive.hpp"
33#include "internal/chrono/duration.hpp"
34#include "internal/geode_globals.hpp"
35
36namespace apache {
37namespace geode {
38namespace client {
39
40using apache::geode::internal::chrono::duration::to_string;
41
42class DataInput;
43class DataOutput;
44class CacheableString;
45
51class APACHE_GEODE_EXPORT Properties
52 : public internal::DataSerializablePrimitive {
53 public:
54 class Visitor {
55 public:
56 virtual void visit(const std::shared_ptr<CacheableKey>& key,
57 const std::shared_ptr<Cacheable>& value) = 0;
58 virtual ~Visitor() noexcept = default;
59 };
60
61 Properties() = default;
62 ~Properties() noexcept override = default;
63 Properties(const Properties&) = delete;
64 Properties& operator=(const Properties&) = delete;
65
71 std::shared_ptr<CacheableString> find(const std::string& key);
72
79 std::shared_ptr<Cacheable> find(const std::shared_ptr<CacheableKey>& key);
80
86 void insert(std::string key, std::string value);
87
93 void insert(std::string key, const int value);
94
100 void insert(const std::shared_ptr<CacheableKey>& key,
101 const std::shared_ptr<Cacheable>& value);
102
103 template <class _Rep, class _Period>
104 void insert(std::string key,
105 const std::chrono::duration<_Rep, _Period>& value) {
106 insert(key, to_string(value));
107 }
108
114 void remove(const std::string& key);
115
121 void remove(const std::shared_ptr<CacheableKey>& key);
122
127 void foreach (Visitor& visitor) const;
128
130 size_t getSize() const;
131
135 void addAll(const std::shared_ptr<Properties>& other);
136
138 static std::shared_ptr<Properties> create();
139
143 void load(const std::string& fileName);
144
146 static std::shared_ptr<Serializable> createDeserializable();
147
148 void toData(DataOutput& output) const override;
149
150 void fromData(DataInput& input) override;
151
152 internal::DSCode getDsCode() const override;
153
154 private:
155 HashMapOfCacheable m_map;
156};
157
158} // namespace client
159} // namespace geode
160} // namespace apache
161
162#endif // GEODE_PROPERTIES_H_
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
Contains a set of (key, value) pair properties with key being the name of the property; value,...
Definition Properties.hpp:52
void addAll(const std::shared_ptr< Properties > &other)
Add the contents of other to this instance, replacing any existing values with those from other.
void insert(std::string key, std::string value)
Add or update the string value for key.
void remove(const std::string &key)
Remove the key from the collection.
size_t getSize() const
Return the number of entries in the collection.
void load(const std::string &fileName)
Read property values from a file, overriding what is currently in the properties object.
static std::shared_ptr< Properties > create()
Factory method, returns an empty collection.
static std::shared_ptr< Serializable > createDeserializable()
Return an empty instance for deserialization.
std::shared_ptr< CacheableString > find(const std::string &key)
Return the value for the given key, or nullptr if not found.
void insert(const std::shared_ptr< CacheableKey > &key, const std::shared_ptr< Cacheable > &value)
Add or update Cacheable value for CacheableKey.
std::shared_ptr< Cacheable > find(const std::shared_ptr< CacheableKey > &key)
Return the value for the given CacheableKey, or nullptr if not found.
void remove(const std::shared_ptr< CacheableKey > &key)
Remove the CacheableKey from the collection.
void insert(std::string key, const int value)
Add or update the int value for key.

Apache Geode C++ Cache API Documentation