StoreRef.h
Go to the documentation of this file.
1 /****
2  * ConfigDB/StoreRef.h
3  *
4  * Copyright 2024 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the ConfigDB Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  ****/
19 
20 #pragma once
21 
22 #include <memory>
23 
24 namespace ConfigDB
25 {
26 class Store;
27 
31 class StoreRef : public std::shared_ptr<Store>
32 {
33 public:
34  StoreRef() = default;
35 
36  StoreRef(std::shared_ptr<Store> store) : shared_ptr(store)
37  {
38  }
39 
41 
42  explicit operator bool() const;
43 
44 private:
45  using shared_ptr::reset;
46 };
47 
51 class StoreUpdateRef : public StoreRef
52 {
53 public:
54  StoreUpdateRef() = default;
55 
56  StoreUpdateRef(const StoreRef& store)
57  {
58  *this = store;
59  }
60 
61  StoreUpdateRef(const StoreUpdateRef& store) : StoreUpdateRef(static_cast<const StoreRef&>(store))
62  {
63  }
64 
66 
68 
70  {
71  return operator=(static_cast<const StoreRef&>(other));
72  }
73 };
74 
75 } // namespace ConfigDB
Holds a strong reference to a store instance for reading.
Definition: StoreRef.h:32
StoreRef(std::shared_ptr< Store > store)
Definition: StoreRef.h:36
Holds a strong reference to a store instance for writing (updating)
Definition: StoreRef.h:52
StoreUpdateRef & operator=(const StoreRef &other)
StoreUpdateRef(const StoreRef &store)
Definition: StoreRef.h:56
StoreUpdateRef(const StoreUpdateRef &store)
Definition: StoreRef.h:61
StoreUpdateRef & operator=(const StoreUpdateRef &other)
Definition: StoreRef.h:69
Definition: Array.h:26