parse_string.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #ifndef ANDROID_VINTF_PARSE_STRING_H
  17. #define ANDROID_VINTF_PARSE_STRING_H
  18. #include <iostream>
  19. #include <sstream>
  20. #include <string>
  21. #include "CompatibilityMatrix.h"
  22. #include "RuntimeInfo.h"
  23. #include "HalManifest.h"
  24. namespace android {
  25. namespace vintf {
  26. std::ostream &operator<<(std::ostream &os, HalFormat hf);
  27. std::ostream &operator<<(std::ostream &os, Transport tr);
  28. std::ostream &operator<<(std::ostream &os, Arch ar);
  29. std::ostream &operator<<(std::ostream &os, KernelConfigType il);
  30. std::ostream &operator<<(std::ostream &os, Tristate tr);
  31. std::ostream &operator<<(std::ostream &os, SchemaType ksv);
  32. std::ostream& operator<<(std::ostream& os, XmlSchemaFormat f);
  33. std::ostream& operator<<(std::ostream& os, Level l);
  34. std::ostream& operator<<(std::ostream& os, KernelSepolicyVersion v);
  35. std::ostream &operator<<(std::ostream &os, const ManifestHal &hal);
  36. std::ostream &operator<<(std::ostream &os, const Version &ver);
  37. std::ostream &operator<<(std::ostream &os, const VersionRange &vr);
  38. #pragma clang diagnostic push
  39. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  40. std::ostream &operator<<(std::ostream &os, const VndkVersionRange &vr);
  41. #pragma clang diagnostic pop
  42. std::ostream &operator<<(std::ostream &os, const KernelVersion &ver);
  43. std::ostream &operator<<(std::ostream &os, const TransportArch &ta);
  44. std::ostream &operator<<(std::ostream &os, const ManifestHal &hal);
  45. std::ostream &operator<<(std::ostream &os, const MatrixHal &req);
  46. std::ostream &operator<<(std::ostream &os, const KernelConfigTypedValue &kcv);
  47. std::ostream& operator<<(std::ostream& os, const FqInstance& fqInstance);
  48. template <typename T>
  49. std::string to_string(const T &obj) {
  50. std::ostringstream oss;
  51. oss << obj;
  52. return oss.str();
  53. }
  54. bool parse(const std::string &s, HalFormat *hf);
  55. bool parse(const std::string &s, Transport *tr);
  56. bool parse(const std::string &s, Arch *ar);
  57. bool parse(const std::string &s, KernelConfigType *il);
  58. bool parse(const std::string &s, KernelConfigKey *key);
  59. bool parse(const std::string &s, Tristate *tr);
  60. bool parse(const std::string &s, SchemaType *ver);
  61. bool parse(const std::string& s, XmlSchemaFormat* ver);
  62. bool parse(const std::string& s, Level* l);
  63. bool parse(const std::string &s, KernelSepolicyVersion *ksv);
  64. bool parse(const std::string &s, Version *ver);
  65. bool parse(const std::string &s, VersionRange *vr);
  66. #pragma clang diagnostic push
  67. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  68. bool parse(const std::string &s, VndkVersionRange *vr);
  69. #pragma clang diagnostic pop
  70. bool parse(const std::string &s, KernelVersion *ver);
  71. // if return true, ta->isValid() must be true.
  72. bool parse(const std::string &s, TransportArch *ta);
  73. // if return true, hal->isValid() must be true.
  74. bool parse(const std::string &s, ManifestHal *hal);
  75. bool parse(const std::string &s, MatrixHal *req);
  76. bool parse(const std::string& s, FqInstance* fqInstance);
  77. bool parseKernelConfigInt(const std::string &s, int64_t *i);
  78. bool parseKernelConfigInt(const std::string &s, uint64_t *i);
  79. bool parseRange(const std::string &s, KernelConfigRangeValue *range);
  80. // Parse the KernelConfigValue in s, assuming type kctv->type, and store it in
  81. // kctv->value.
  82. bool parseKernelConfigValue(const std::string &s, KernelConfigTypedValue *kctv);
  83. // Parse the KernelConfigTypedValue in s (type is guessed) and store it in kctv.
  84. // Do not expect quotes in strings.
  85. bool parseKernelConfigTypedValue(const std::string& s, KernelConfigTypedValue* kctv);
  86. // A string that describes the whole object, with versions of all
  87. // its components. For debugging and testing purposes only. This is not
  88. // the XML string.
  89. std::string dump(const HalManifest &vm);
  90. std::string dump(const RuntimeInfo& ki, bool verbose = true);
  91. std::vector<std::string> expandInstances(const MatrixHal& req);
  92. std::string toFQNameString(const std::string& package, const Version& version,
  93. const std::string& intf = "", const std::string& instance = "");
  94. std::string toFQNameString(const Version& version, const std::string& intf,
  95. const std::string& instance);
  96. // [email protected]::IFoo/default.
  97. // Note that the format is extended to support a range of versions.
  98. std::string toFQNameString(const std::string& package, const VersionRange& range,
  99. const std::string& interface, const std::string& instance);
  100. std::string toFQNameString(const VersionRange& range, const std::string& interface,
  101. const std::string& instance);
  102. } // namespace vintf
  103. } // namespace android
  104. #endif // ANDROID_VINTF_PARSE_STRING_H