1/*
2 * Copyright (C) 2017 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#ifndef ANDROID_VINTF_PARSE_STRING_H
18#define ANDROID_VINTF_PARSE_STRING_H
19
20#include <iostream>
21#include <sstream>
22#include <string>
23
24#include "CompatibilityMatrix.h"
25#include "RuntimeInfo.h"
26#include "HalManifest.h"
27
28namespace android {
29namespace vintf {
30
31std::ostream &operator<<(std::ostream &os, HalFormat hf);
32std::ostream &operator<<(std::ostream &os, Transport tr);
33std::ostream &operator<<(std::ostream &os, Arch ar);
34std::ostream &operator<<(std::ostream &os, KernelConfigType il);
35std::ostream &operator<<(std::ostream &os, Tristate tr);
36std::ostream &operator<<(std::ostream &os, SchemaType ksv);
37std::ostream &operator<<(std::ostream &os, const ManifestHal &hal);
38std::ostream &operator<<(std::ostream &os, const Version &ver);
39std::ostream &operator<<(std::ostream &os, const VersionRange &vr);
40std::ostream &operator<<(std::ostream &os, const VndkVersionRange &vr);
41std::ostream &operator<<(std::ostream &os, const KernelVersion &ver);
42std::ostream &operator<<(std::ostream &os, const TransportArch &ta);
43std::ostream &operator<<(std::ostream &os, const ManifestHal &hal);
44std::ostream &operator<<(std::ostream &os, const MatrixHal &req);
45std::ostream &operator<<(std::ostream &os, const KernelConfigTypedValue &kcv);
46
47template <typename T>
48std::string to_string(const T &obj) {
49    std::ostringstream oss;
50    oss << obj;
51    return oss.str();
52}
53
54bool parse(const std::string &s, HalFormat *hf);
55bool parse(const std::string &s, Transport *tr);
56bool parse(const std::string &s, Arch *ar);
57bool parse(const std::string &s, KernelConfigType *il);
58bool parse(const std::string &s, KernelConfigKey *key);
59bool parse(const std::string &s, Tristate *tr);
60bool parse(const std::string &s, SchemaType *ver);
61bool parse(const std::string &s, KernelSepolicyVersion *ksv);
62bool parse(const std::string &s, Version *ver);
63bool parse(const std::string &s, VersionRange *vr);
64bool parse(const std::string &s, VndkVersionRange *vr);
65bool parse(const std::string &s, KernelVersion *ver);
66// if return true, ta->isValid() must be true.
67bool parse(const std::string &s, TransportArch *ta);
68// if return true, hal->isValid() must be true.
69bool parse(const std::string &s, ManifestHal *hal);
70bool parse(const std::string &s, MatrixHal *req);
71
72bool parseKernelConfigInt(const std::string &s, int64_t *i);
73bool parseKernelConfigInt(const std::string &s, uint64_t *i);
74bool parseRange(const std::string &s, KernelConfigRangeValue *range);
75
76// Parse the KernelConfigValue in s, assuming type kctv->type, and store it in
77// kctv->value.
78bool parseKernelConfigValue(const std::string &s, KernelConfigTypedValue *kctv);
79
80// A string that describes the whole object, with versions of all
81// its components. For debugging and testing purposes only. This is not
82// the XML string.
83std::string dump(const HalManifest &vm);
84
85std::string dump(const RuntimeInfo &ki);
86
87} // namespace vintf
88} // namespace android
89
90#endif // ANDROID_VINTF_PARSE_STRING_H
91