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_COMPONENT_STORAGE_H 18 #define FRUIT_COMPONENT_STORAGE_H 19 20 #include <fruit/impl/data_structures/fixed_size_vector.h> 21 #include <fruit/impl/fruit_internal_forward_decls.h> 22 23 namespace fruit { 24 namespace impl { 25 26 /** 27 * A component where all types have to be explicitly registered, and all checks are at runtime. 28 * Used to implement Component<>, don't use directly. 29 * This merely stores the ComponentStorageEntry objects. The real processing will be done in NormalizedComponentStorage 30 * and InjectorStorage. 31 * 32 * This class handles the creation of bindings for types of the forms: 33 * - shared_ptr<C>, [const] C*, [const] C&, C (where C is an atomic type) 34 * - Annotated<Annotation, T> (with T of the above forms) 35 * - Injector<T1, ..., Tk> (with T1, ..., Tk of the above forms). 36 */ 37 class ComponentStorage { 38 private: 39 // The entries for this component storage (potentially including lazy component), *in reverse order*. 40 FixedSizeVector<ComponentStorageEntry> entries; 41 42 void destroy(); 43 44 public: 45 ComponentStorage() = default; 46 explicit ComponentStorage(FixedSizeVector<ComponentStorageEntry>&& entries) noexcept; 47 ComponentStorage(const ComponentStorage&); 48 ComponentStorage(ComponentStorage&&) noexcept; 49 50 ~ComponentStorage(); 51 52 FixedSizeVector<ComponentStorageEntry> release() &&; 53 54 std::size_t numEntries() const; 55 56 ComponentStorage& operator=(const ComponentStorage&); 57 ComponentStorage& operator=(ComponentStorage&&) noexcept; 58 }; 59 60 } // namespace impl 61 } // namespace fruit 62 63 #include <fruit/impl/component_storage/component_storage.defn.h> 64 65 #endif // FRUIT_COMPONENT_STORAGE_H 66