| {{/* |
| * Copyright (C) 2015 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */}} |
| |
| {{/* ---- Includes ---- */}} |
| {{Include "cpp_common.tmpl"}} |
| |
| {{/* ---- Overrides ---- */}} |
| {{Global "C++.EnumTypeOverride" "uint32_t"}} |
| |
| {{$filename := print (Global "API") "_types.h" }} |
| {{$ | Macro "Types" | Format (Global "clang-format") | Write $filename}} |
| |
| {{define "Types"}} |
| {{AssertType $ "API"}} |
| {{Macro "C++.AOSP.Copyright"}} |
| {{$guard := print "GAPII_" (Upper (Global "API")) "_TYPES_H"}} |
| ¶ |
| #ifndef {{$guard}} |
| #define {{$guard}} |
| ¶ |
| #include "slice.h" |
| ¶ |
| #include <memory> |
| #include <string> |
| #include <unordered_map> |
| #include <vector> |
| ¶ |
| #include <stdint.h> |
| #include <string.h> |
| ¶ |
| namespace gapii {« |
| ¶ |
| {{range $e := $.Enums}} |
| {{Macro "DeclareType" $e}} |
| {{end}} |
| {{range $p := $.Pseudonyms}} |
| {{Macro "DeclareType" $p}} |
| {{end}} |
| {{range $m := $.Maps}} |
| {{Macro "DeclareType" $m}} |
| {{end}} |
| {{range $c := $.Classes}} |
| {{Macro "DeclareType" $c}} |
| {{end}} |
| ¶ |
| »} // namespace gapii |
| ¶ |
| #endif // {{$guard}} |
| ¶ |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits the C++ type declaration specified AST type if it hasn't already been |
| declared. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "DeclareType"}} |
| {{if not (IsBuiltin $)}} |
| {{$key := printf "ApiType%dDeclared" $.Name}} |
| {{if not (Global $key)}} |
| {{Global $key "true"}} |
| {{ if IsClass $}}{{Macro "DeclareClass" $}} |
| {{else if IsEnum $}}{{Macro "DeclareEnum" $}} |
| {{else if IsMap $}}{{Macro "DeclareMap" $}} |
| {{else if IsPseudonym $}}{{Macro "DeclarePseudonym" $}} |
| {{else if IsPointer $}}{{Macro "DeclareType" $.To}} |
| {{else if IsReference $}}{{Macro "DeclareType" $.To}} |
| {{else if IsStaticArray $}}{{Macro "DeclareType" $.ValueType}} |
| {{else if IsReference $}} |
| {{else if IsSlice $}} |
| {{else}}{{Error "DeclareType does not support type '%T'" $}} |
| {{end}} |
| ¶ |
| {{end}} |
| {{end}} |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits the declarations for all non-declared field types of the class followed |
| by the class declaration. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "DeclareClass"}} |
| {{AssertType $ "Class"}} |
| |
| {{range $f := $.Fields}} |
| {{Macro "DeclareType" (TypeOf $f)}} |
| {{end}} |
| |
| struct {{Macro "C++.Type" $}} { |
| {{range $f := $.Fields}} |
| inline {{Macro "C++.Type" $}}& Set{{$f.Name}}({{Macro "C++.Type" $f}} v{{Macro "C++.ArrayPostfix" $f}}) { |
| {{if IsStaticArray $f.Type}} |
| {{$sa := Unpack $f.Type}} |
| memcpy(m{{$f.Name}}, v, sizeof({{Macro "C++.Type" $f}}) * {{$sa.Size}}); |
| {{else}} |
| m{{$f.Name}} = v; |
| {{end}} |
| return *this; |
| } |
| {{end}} |
| ¶ |
| {{range $f := $.Fields}} |
| {{Macro "C++.Type" $f}} m{{$f.Name}}{{Macro "C++.ArrayPostfix" $f}}; |
| {{end}} |
| }; |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits an enum declaration as a number of uint32_t constants in a namespace. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "DeclareEnum"}} |
| {{AssertType $ "Enum"}} |
| |
| namespace {{Macro "C++.EnumName" $}} { |
| {{range $entry := $.AllEntries}} |
| static const uint32_t {{Macro "C++.EnumEntryName" $entry}} = {{$entry.Value}}; |
| {{end}} |
| } |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits the declaration of the pseudonym's target type (if it is not already |
| declared) followed by the pseudonym's typedef declaration. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "DeclarePseudonym"}} |
| {{AssertType $ "Pseudonym"}} |
| |
| {{Macro "DeclareType" $.To}} |
| |
| typedef {{Macro "C++.Type" $.To}} {{Macro "C++.Type" $}}; |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits the declaration of the map's key and value types (if it is not already |
| declared) followed by the map's declaration as a std::unordered_map. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "DeclareMap"}} |
| {{AssertType $ "Map"}} |
| |
| {{Macro "DeclareType" $.KeyType}} |
| {{Macro "DeclareType" $.ValueType}} |
| |
| typedef std::unordered_map<{{Macro "C++.Type" $.KeyType}}, {{Macro "C++.Type" $.ValueType}}> {{Macro "C++.Type" $}}; |
| {{end}} |