• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
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 
18 #include <frameworks/base/core/proto/android/os/incident.pb.h>
19 
20 
21 #include <map>
22 
23 using namespace android::os;
24 using namespace google::protobuf;
25 using namespace google::protobuf::io;
26 using namespace google::protobuf::internal;
27 using namespace std;
28 
29 int
main(int,const char **)30 main(int, const char**)
31 {
32     map<string,FieldDescriptor const*> sections;
33     int N;
34 
35     printf("// Auto generated file. Do not modify\n");
36     printf("\n");
37     printf("#include \"incident_sections.h\"\n");
38     printf("\n");
39 
40     Descriptor const* descriptor = IncidentProto::descriptor();
41     N = descriptor->field_count();
42     for (int i=0; i<N; i++) {
43         const FieldDescriptor* field = descriptor->field(i);
44         if (field->type() == FieldDescriptor::TYPE_MESSAGE) {
45             sections[field->name()] = field;
46         }
47     }
48 
49     printf("IncidentSection const INCIDENT_SECTIONS[] = {\n");
50     N = sections.size();
51     int i = 0;
52     for (map<string,FieldDescriptor const*>::const_iterator it = sections.begin();
53             it != sections.end(); it++, i++) {
54         const FieldDescriptor* field = it->second;
55         printf("    { %d, \"%s\" }", field->number(), field->name().c_str());
56         if (i != N-1) {
57             printf(",\n");
58         } else {
59             printf("\n");
60         }
61     }
62     printf("};\n");
63 
64     printf("const int INCIDENT_SECTION_COUNT = %d;\n", N);
65 
66     return 0;
67 }
68