• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INJECTOR_ACCESSOR_FOR_TESTS_H
18 #define FRUIT_INJECTOR_ACCESSOR_FOR_TESTS_H
19 
20 #include <fruit/fruit.h>
21 
22 namespace fruit {
23 namespace impl {
24 
25 /**
26  * A class used to access Injector's internals in Fruit's own tests. Note that this is *not* meant to be used outside
27  * of Fruit.
28  */
29 struct InjectorAccessorForTests {
30 
31   /**
32    * If C was bound (directly or indirectly) in the component used to create this injector, returns a pointer to the
33    * instance of C (constructing it if necessary). Otherwise returns nullptr.
34    *
35    * This supports annotated injection, just use Annotated<Annotation, C> instead of just C.
36    * With a non-annotated parameter C, this returns a C*.
37    * With an annotated parameter C=Annotated<Annotation, SomeClass>, this returns a const SomeClass*.
38    *
39    * Note that this doesn't trigger auto-bindings: so even if the constructor of C was visible to some get*Component
40    * function (or to the place where unsafeGet is called), in order to successfully get an instance with this method
41    * you need all the following to be true:
42    * * C was explicitly bound in a component, or C was a dependency (direct or indirect) of a type that was explicitly
43    * bound
44    * * C was not bound to any interface (note however that if C was bound to I, you can do unsafeGet<I>() instead).
45    *
46    * Otherwise this method will return nullptr.
47    */
48   template <typename C, typename... Params>
49   static const fruit::impl::RemoveAnnotations<C>*
50   unsafeGet(fruit::Injector<Params...>& injector);
51 };
52 }
53 }
54 
55 #include <fruit/impl/injector/injector_accessor_for_tests.defn.h>
56 
57 #endif // FRUIT_INJECTOR_ACCESSOR_FOR_TESTS_H
58