1 /* 2 * Copyright 2014 Google Inc. All rights reserved. 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 FRUIT_NORMALIZED_COMPONENT_STORAGE_HOLDER_H 18 #define FRUIT_NORMALIZED_COMPONENT_STORAGE_HOLDER_H 19 20 #include <fruit/fruit_forward_decls.h> 21 #include <fruit/impl/data_structures/arena_allocator.h> 22 #include <fruit/impl/data_structures/memory_pool.h> 23 #include <fruit/impl/fruit_internal_forward_decls.h> 24 #include <memory> 25 26 namespace fruit { 27 namespace impl { 28 29 /** 30 * A wrapper around NormalizedComponentStorage, holding the NormalizedComponentStorage 31 * through a unique_ptr so that we don't need to include NormalizedComponentStorage in 32 * fruit.h. 33 */ 34 class NormalizedComponentStorageHolder { 35 private: 36 std::unique_ptr<NormalizedComponentStorage> storage; 37 38 friend class InjectorStorage; 39 40 template <typename... P> 41 friend class fruit::Injector; 42 43 public: 44 // These are just used as tags to select the desired constructor. 45 struct WithUndoableCompression {}; 46 struct WithPermanentCompression {}; 47 48 NormalizedComponentStorageHolder() = default; 49 50 /** 51 * The MemoryPool is only used during construction, the constructed object *can* outlive the memory pool. 52 */ 53 NormalizedComponentStorageHolder(ComponentStorage&& component, 54 const std::vector<TypeId, ArenaAllocator<TypeId>>& exposed_types, 55 MemoryPool& memory_pool, WithUndoableCompression); 56 57 NormalizedComponentStorageHolder(NormalizedComponentStorage&&) = delete; 58 NormalizedComponentStorageHolder(const NormalizedComponentStorage&) = delete; 59 60 NormalizedComponentStorageHolder& operator=(NormalizedComponentStorageHolder&&) = delete; 61 NormalizedComponentStorageHolder& operator=(const NormalizedComponentStorageHolder&) = default; 62 63 // We don't use the default destructor because that would require the inclusion of 64 // normalized_component_storage.h. We define this in the cpp file instead. 65 ~NormalizedComponentStorageHolder(); 66 }; 67 68 } // namespace impl 69 } // namespace fruit 70 71 #endif // FRUIT_NORMALIZED_COMPONENT_STORAGE_HOLDER_H 72