xref: /aosp_15_r20/external/google-fruit/examples/simple_injection/main.cpp (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 #include "incrementer_component.h"
18*a65addddSAndroid Build Coastguard Worker #include <iostream>
19*a65addddSAndroid Build Coastguard Worker 
20*a65addddSAndroid Build Coastguard Worker using fruit::Component;
21*a65addddSAndroid Build Coastguard Worker using fruit::Injector;
22*a65addddSAndroid Build Coastguard Worker 
23*a65addddSAndroid Build Coastguard Worker // Try e.g.:
24*a65addddSAndroid Build Coastguard Worker // echo 5 | ./incrementer
25*a65addddSAndroid Build Coastguard Worker // echo 2147483647 | ./incrementer
26*a65addddSAndroid Build Coastguard Worker // echo 2147483647 | ./incrementer --checked
main(int argc,const char * argv[])27*a65addddSAndroid Build Coastguard Worker int main(int argc, const char* argv[]) {
28*a65addddSAndroid Build Coastguard Worker 
29*a65addddSAndroid Build Coastguard Worker   bool checked = false;
30*a65addddSAndroid Build Coastguard Worker 
31*a65addddSAndroid Build Coastguard Worker   if (argc == 2 && std::string(argv[1]) == "--checked")
32*a65addddSAndroid Build Coastguard Worker     checked = true;
33*a65addddSAndroid Build Coastguard Worker 
34*a65addddSAndroid Build Coastguard Worker   Injector<Incrementer> injector(getIncrementerComponent, checked);
35*a65addddSAndroid Build Coastguard Worker   Incrementer* incrementer(injector);
36*a65addddSAndroid Build Coastguard Worker 
37*a65addddSAndroid Build Coastguard Worker   int x;
38*a65addddSAndroid Build Coastguard Worker   std::cin >> x;
39*a65addddSAndroid Build Coastguard Worker   std::cout << incrementer->increment(x) << std::endl;
40*a65addddSAndroid Build Coastguard Worker 
41*a65addddSAndroid Build Coastguard Worker   return 0;
42*a65addddSAndroid Build Coastguard Worker }
43