Skip to content

Commit ef27076

Browse files
committed
creating new settings files
1 parent cc5d403 commit ef27076

File tree

3 files changed

+194
-0
lines changed

3 files changed

+194
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "firestore/src/include/firebase/firestore/local_cache_settings.h"
18+
#include <memory>
19+
20+
#include "firestore/src/common/hard_assert_common.h"
21+
#if defined(__ANDROID__)
22+
#else
23+
#include "firestore/src/main/local_cache_settings_main.h"
24+
#endif // defined(__ANDROID__)
25+
26+
namespace firebase {
27+
namespace firestore {
28+
29+
PersistentCacheSettings PersistentCacheSettings::Create() { return {}; }
30+
31+
PersistentCacheSettings::PersistentCacheSettings() {
32+
settings_internal_ = std::make_unique<PersistentCacheSettingsInternal>(
33+
CorePersistentSettings{});
34+
}
35+
36+
PersistentCacheSettings::~PersistentCacheSettings() {
37+
settings_internal_.reset();
38+
}
39+
40+
PersistentCacheSettings::PersistentCacheSettings(
41+
const PersistentCacheSettingsInternal& other) {
42+
settings_internal_ = std::make_unique<PersistentCacheSettingsInternal>(other);
43+
}
44+
45+
PersistentCacheSettings PersistentCacheSettings::WithSizeBytes(
46+
int64_t size) const {
47+
return {PersistentCacheSettingsInternal{
48+
settings_internal_->core_settings().WithSizeBytes(size)}};
49+
}
50+
51+
MemoryCacheSettings MemoryCacheSettings::Create() { return {}; }
52+
53+
MemoryCacheSettings::MemoryCacheSettings() {
54+
settings_internal_ =
55+
std::make_unique<MemoryCacheSettingsInternal>(CoreMemorySettings{});
56+
}
57+
58+
MemoryCacheSettings::~MemoryCacheSettings() { settings_internal_.reset(); }
59+
60+
MemoryCacheSettings::MemoryCacheSettings(
61+
const MemoryCacheSettingsInternal& other) {
62+
settings_internal_ = std::make_unique<MemoryCacheSettingsInternal>(other);
63+
}
64+
} // namespace firestore
65+
} // namespace firebase
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef FIREBASE_FIRESTORE_SRC_INCLUDE_FIREBASE_FIRESTORE_LOCAL_CACHE_SETTINGS_H_
18+
#define FIREBASE_FIRESTORE_SRC_INCLUDE_FIREBASE_FIRESTORE_LOCAL_CACHE_SETTINGS_H_
19+
20+
#include <cstdint>
21+
#include <memory>
22+
23+
#include "Firestore/core/src/api/settings.h"
24+
25+
namespace firebase {
26+
namespace firestore {
27+
28+
using CoreMemorySettings = api::MemoryCacheSettings;
29+
using CorePersistentSettings = api::PersistentCacheSettings;
30+
31+
class PersistentCacheSettingsInternal;
32+
class MemoryCacheSettingsInternal;
33+
34+
class LocalCacheSettings {
35+
virtual ~LocalCacheSettings() = 0;
36+
};
37+
38+
class PersistentCacheSettings : public LocalCacheSettings {
39+
public:
40+
static PersistentCacheSettings Create();
41+
42+
PersistentCacheSettings WithSizeBytes(int64_t size) const;
43+
44+
private:
45+
PersistentCacheSettings();
46+
PersistentCacheSettings(const PersistentCacheSettingsInternal& other);
47+
~PersistentCacheSettings();
48+
49+
std::unique_ptr<PersistentCacheSettingsInternal> settings_internal_;
50+
};
51+
52+
class MemoryCacheSettings : public LocalCacheSettings {
53+
public:
54+
static MemoryCacheSettings Create();
55+
56+
private:
57+
MemoryCacheSettings();
58+
MemoryCacheSettings(const MemoryCacheSettingsInternal& other);
59+
~MemoryCacheSettings();
60+
61+
std::unique_ptr<MemoryCacheSettingsInternal> settings_internal_;
62+
};
63+
64+
} // namespace firestore
65+
} // namespace firebase
66+
67+
#endif // FIREBASE_FIRESTORE_SRC_INCLUDE_FIREBASE_FIRESTORE_LOCAL_CACHE_SETTINGS_H_
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef FIREBASE_FIRESTORE_SRC_MAIN_LOCAL_CACHE_SETINGS_MAIN_H_
18+
#define FIREBASE_FIRESTORE_SRC_MAIN_LOCAL_CACHE_SETINGS_MAIN_H_
19+
20+
#include <cstdint>
21+
22+
#include "Firestore/core/src/api/settings.h"
23+
24+
namespace firebase {
25+
namespace firestore {
26+
27+
using CoreMemorySettings = api::MemoryCacheSettings;
28+
using CorePersistentSettings = api::PersistentCacheSettings;
29+
30+
class LocalCacheSettingsInternal {};
31+
32+
class PersistentCacheSettingsInternal : public LocalCacheSettingsInternal {
33+
public:
34+
explicit PersistentCacheSettingsInternal(
35+
const CorePersistentSettings& core_settings)
36+
: settings_(std::move(core_settings)) {}
37+
const CorePersistentSettings& core_settings() { return settings_; }
38+
void set_core_settings(const CorePersistentSettings& settings) {
39+
settings_ = settings;
40+
}
41+
42+
private:
43+
CorePersistentSettings settings_;
44+
};
45+
46+
class MemoryCacheSettingsInternal : public LocalCacheSettingsInternal {
47+
public:
48+
explicit MemoryCacheSettingsInternal(const CoreMemorySettings& core_settings)
49+
: settings_(std::move(core_settings)) {}
50+
const CoreMemorySettings& core_settings() { return settings_; }
51+
void set_core_settings(const CoreMemorySettings& settings) {
52+
settings_ = settings;
53+
}
54+
55+
private:
56+
CoreMemorySettings settings_;
57+
};
58+
59+
} // namespace firestore
60+
} // namespace firebase
61+
62+
#endif // FIREBASE_FIRESTORE_SRC_MAIN_LOCAL_CACHE_SETINGS_MAIN_H_

0 commit comments

Comments
 (0)