xref: /aosp_15_r20/external/google-fruit/include/fruit/impl/bindings.h (revision a65addddcf69f38db5b288d787b6b7571a57bb8f)
1*a65addddSAndroid Build Coastguard Worker /*
2*a65addddSAndroid Build Coastguard Worker  * Copyright 2014 Google Inc. All rights reserved.
3*a65addddSAndroid Build Coastguard Worker  *
4*a65addddSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*a65addddSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*a65addddSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*a65addddSAndroid Build Coastguard Worker  *
8*a65addddSAndroid Build Coastguard Worker  *     http://www.apache.org/licenses/LICENSE-2.0
9*a65addddSAndroid Build Coastguard Worker  *
10*a65addddSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*a65addddSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*a65addddSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*a65addddSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*a65addddSAndroid Build Coastguard Worker  * limitations under the License.
15*a65addddSAndroid Build Coastguard Worker  */
16*a65addddSAndroid Build Coastguard Worker 
17*a65addddSAndroid Build Coastguard Worker #ifndef FRUIT_BINDINGS_H
18*a65addddSAndroid Build Coastguard Worker #define FRUIT_BINDINGS_H
19*a65addddSAndroid Build Coastguard Worker 
20*a65addddSAndroid Build Coastguard Worker #include <fruit/impl/meta/metaprogramming.h>
21*a65addddSAndroid Build Coastguard Worker 
22*a65addddSAndroid Build Coastguard Worker namespace fruit {
23*a65addddSAndroid Build Coastguard Worker namespace impl {
24*a65addddSAndroid Build Coastguard Worker 
25*a65addddSAndroid Build Coastguard Worker // The types here represent individual entries added in a PartialComponent.
26*a65addddSAndroid Build Coastguard Worker 
27*a65addddSAndroid Build Coastguard Worker /**
28*a65addddSAndroid Build Coastguard Worker  * Binds the base class I to the implementation C.
29*a65addddSAndroid Build Coastguard Worker  * I must be a base class of C. I=C is not allowed.
30*a65addddSAndroid Build Coastguard Worker  * I and/or C may be annotated using fruit::Annotated<>.
31*a65addddSAndroid Build Coastguard Worker  */
32*a65addddSAndroid Build Coastguard Worker template <typename I, typename C>
33*a65addddSAndroid Build Coastguard Worker struct Bind {};
34*a65addddSAndroid Build Coastguard Worker 
35*a65addddSAndroid Build Coastguard Worker /**
36*a65addddSAndroid Build Coastguard Worker  * Registers Signature as the constructor signature to use to inject a type.
37*a65addddSAndroid Build Coastguard Worker  * Signature must be a valid signature and its return type must be constructible with those argument
38*a65addddSAndroid Build Coastguard Worker  * types.
39*a65addddSAndroid Build Coastguard Worker  * The arguments and the return type can be annotated using fruit::Annotated<>.
40*a65addddSAndroid Build Coastguard Worker  */
41*a65addddSAndroid Build Coastguard Worker template <typename Signature>
42*a65addddSAndroid Build Coastguard Worker struct RegisterConstructor {};
43*a65addddSAndroid Build Coastguard Worker 
44*a65addddSAndroid Build Coastguard Worker /**
45*a65addddSAndroid Build Coastguard Worker  * Binds an instance (i.e., object) to the type C.
46*a65addddSAndroid Build Coastguard Worker  * AnnotatedC may be annotated using fruit::Annotated<>.
47*a65addddSAndroid Build Coastguard Worker  * NOTE: for this binding, the runtime binding is added in advance.
48*a65addddSAndroid Build Coastguard Worker  */
49*a65addddSAndroid Build Coastguard Worker template <typename AnnotatedC, typename C>
50*a65addddSAndroid Build Coastguard Worker struct BindInstance {};
51*a65addddSAndroid Build Coastguard Worker 
52*a65addddSAndroid Build Coastguard Worker /**
53*a65addddSAndroid Build Coastguard Worker  * A variant of BindInstance that binds a constant reference.
54*a65addddSAndroid Build Coastguard Worker  */
55*a65addddSAndroid Build Coastguard Worker template <typename AnnotatedC, typename C>
56*a65addddSAndroid Build Coastguard Worker struct BindConstInstance {};
57*a65addddSAndroid Build Coastguard Worker 
58*a65addddSAndroid Build Coastguard Worker template <typename... Params>
59*a65addddSAndroid Build Coastguard Worker struct RegisterProvider;
60*a65addddSAndroid Build Coastguard Worker 
61*a65addddSAndroid Build Coastguard Worker /**
62*a65addddSAndroid Build Coastguard Worker  * Registers `provider' as a provider of C, where provider is a lambda with no captures returning
63*a65addddSAndroid Build Coastguard Worker  * either C or C*.
64*a65addddSAndroid Build Coastguard Worker  */
65*a65addddSAndroid Build Coastguard Worker template <typename Lambda>
66*a65addddSAndroid Build Coastguard Worker struct RegisterProvider<Lambda> {};
67*a65addddSAndroid Build Coastguard Worker 
68*a65addddSAndroid Build Coastguard Worker /**
69*a65addddSAndroid Build Coastguard Worker  * Registers `provider' as a provider of C, where provider is a lambda with no captures returning
70*a65addddSAndroid Build Coastguard Worker  * either C or C*. Lambda must have the signature AnnotatedSignature (ignoring annotations).
71*a65addddSAndroid Build Coastguard Worker  */
72*a65addddSAndroid Build Coastguard Worker template <typename AnnotatedSignature, typename Lambda>
73*a65addddSAndroid Build Coastguard Worker struct RegisterProvider<Lambda, AnnotatedSignature> {};
74*a65addddSAndroid Build Coastguard Worker 
75*a65addddSAndroid Build Coastguard Worker /**
76*a65addddSAndroid Build Coastguard Worker  * Adds a multibinding for an instance (as a C&).
77*a65addddSAndroid Build Coastguard Worker  */
78*a65addddSAndroid Build Coastguard Worker template <typename C>
79*a65addddSAndroid Build Coastguard Worker struct AddInstanceMultibinding {};
80*a65addddSAndroid Build Coastguard Worker 
81*a65addddSAndroid Build Coastguard Worker /**
82*a65addddSAndroid Build Coastguard Worker  * Adds multibindings for a vector of instances (as a std::vector<C>&).
83*a65addddSAndroid Build Coastguard Worker  */
84*a65addddSAndroid Build Coastguard Worker template <typename C>
85*a65addddSAndroid Build Coastguard Worker struct AddInstanceVectorMultibindings {};
86*a65addddSAndroid Build Coastguard Worker 
87*a65addddSAndroid Build Coastguard Worker /**
88*a65addddSAndroid Build Coastguard Worker  * Similar to Bind<I, C>, but adds a multibinding instead.
89*a65addddSAndroid Build Coastguard Worker  */
90*a65addddSAndroid Build Coastguard Worker template <typename I, typename C>
91*a65addddSAndroid Build Coastguard Worker struct AddMultibinding {};
92*a65addddSAndroid Build Coastguard Worker 
93*a65addddSAndroid Build Coastguard Worker template <typename... Params>
94*a65addddSAndroid Build Coastguard Worker struct AddMultibindingProvider;
95*a65addddSAndroid Build Coastguard Worker 
96*a65addddSAndroid Build Coastguard Worker /**
97*a65addddSAndroid Build Coastguard Worker  * Similar to RegisterProvider, but adds a multibinding instead.
98*a65addddSAndroid Build Coastguard Worker  */
99*a65addddSAndroid Build Coastguard Worker template <typename Lambda>
100*a65addddSAndroid Build Coastguard Worker struct AddMultibindingProvider<Lambda> {};
101*a65addddSAndroid Build Coastguard Worker 
102*a65addddSAndroid Build Coastguard Worker /**
103*a65addddSAndroid Build Coastguard Worker  * Similar to RegisterProvider, but adds a multibinding instead.
104*a65addddSAndroid Build Coastguard Worker  * Lambda must have the signature AnnotatedSignature (ignoring annotations).
105*a65addddSAndroid Build Coastguard Worker  */
106*a65addddSAndroid Build Coastguard Worker template <typename AnnotatedSignature, typename Lambda>
107*a65addddSAndroid Build Coastguard Worker struct AddMultibindingProvider<AnnotatedSignature, Lambda> {};
108*a65addddSAndroid Build Coastguard Worker 
109*a65addddSAndroid Build Coastguard Worker /**
110*a65addddSAndroid Build Coastguard Worker  * Registers `Lambda' as a factory of C, where `Lambda' is a lambda with no captures returning C.
111*a65addddSAndroid Build Coastguard Worker  * Lambda must have signature DecoratedSignature (ignoring any fruit::Annotated<> and
112*a65addddSAndroid Build Coastguard Worker  * fruit::Assisted<>).
113*a65addddSAndroid Build Coastguard Worker  * Lambda must return a C by value, or a std::unique_ptr<C>.
114*a65addddSAndroid Build Coastguard Worker  */
115*a65addddSAndroid Build Coastguard Worker template <typename DecoratedSignature, typename Lambda>
116*a65addddSAndroid Build Coastguard Worker struct RegisterFactory {};
117*a65addddSAndroid Build Coastguard Worker 
118*a65addddSAndroid Build Coastguard Worker /**
119*a65addddSAndroid Build Coastguard Worker  * Adds the bindings (and multibindings) in `component' to the current component.
120*a65addddSAndroid Build Coastguard Worker  * OtherComponent must be of the form Component<...>.
121*a65addddSAndroid Build Coastguard Worker  * NOTE: for this binding, the runtime binding is added in advance.
122*a65addddSAndroid Build Coastguard Worker  */
123*a65addddSAndroid Build Coastguard Worker template <typename GetComponentFunction>
124*a65addddSAndroid Build Coastguard Worker struct InstallComponent {};
125*a65addddSAndroid Build Coastguard Worker 
126*a65addddSAndroid Build Coastguard Worker /**
127*a65addddSAndroid Build Coastguard Worker  * Installs all the specified ComponentFunction objects.
128*a65addddSAndroid Build Coastguard Worker  */
129*a65addddSAndroid Build Coastguard Worker template <typename... ComponentFunctions>
130*a65addddSAndroid Build Coastguard Worker struct InstallComponentFunctions {};
131*a65addddSAndroid Build Coastguard Worker 
132*a65addddSAndroid Build Coastguard Worker /**
133*a65addddSAndroid Build Coastguard Worker  * An in-progress ReplaceComponent operation, where we don't have all the required information yet.
134*a65addddSAndroid Build Coastguard Worker  */
135*a65addddSAndroid Build Coastguard Worker template <typename GetReplacedComponent>
136*a65addddSAndroid Build Coastguard Worker struct PartialReplaceComponent {};
137*a65addddSAndroid Build Coastguard Worker 
138*a65addddSAndroid Build Coastguard Worker /**
139*a65addddSAndroid Build Coastguard Worker  * Replaces install()s for a component with install()s for another one.
140*a65addddSAndroid Build Coastguard Worker  * The two Get*Component function signatures must return the same Component<...> type.
141*a65addddSAndroid Build Coastguard Worker  */
142*a65addddSAndroid Build Coastguard Worker template <typename GetReplacedComponent, typename GetReplacementComponent>
143*a65addddSAndroid Build Coastguard Worker struct ReplaceComponent {};
144*a65addddSAndroid Build Coastguard Worker 
145*a65addddSAndroid Build Coastguard Worker } // namespace impl
146*a65addddSAndroid Build Coastguard Worker } // namespace fruit
147*a65addddSAndroid Build Coastguard Worker 
148*a65addddSAndroid Build Coastguard Worker #endif // FRUIT_BINDINGS_H
149