generatoroptions.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #include "generatoroptions.h"
  26. #include "utils.h"
  27. #include <iostream>
  28. static const std::string MultifileBuildOption("MULTI");
  29. static const std::string QmlPluginOption("QML");
  30. static const std::string CommentsGenerationOption("COMMENTS");
  31. static const std::string FolderGenerationOption("FOLDER");
  32. static const std::string FieldEnumGenerationOption("FIELDENUM");
  33. static const std::string ExtraNamespaceGenerationOption("EXTRA_NAMESPACE");
  34. using namespace ::QtProtobuf::generator;
  35. GeneratorOptions::GeneratorOptions() : mIsMulti(false)
  36. , mHasQml(false)
  37. , mGenerateComments(false)
  38. , mIsFolder(false)
  39. , mGenerateFieldEnum(false)
  40. {
  41. }
  42. void GeneratorOptions::parseFromEnv(const std::string &options)
  43. {
  44. std::vector<std::string> optionsList = utils::split(options, ':');
  45. for (auto option : optionsList) {
  46. QT_PROTOBUF_DEBUG("option: " << option);
  47. if (option.compare(MultifileBuildOption) == 0) {
  48. QT_PROTOBUF_DEBUG("set mIsMulti: true");
  49. mIsMulti = true;
  50. } else if (option.compare(QmlPluginOption) == 0) {
  51. QT_PROTOBUF_DEBUG("set mHasQml: true");
  52. mHasQml = true;
  53. } else if (option.compare(CommentsGenerationOption) == 0) {
  54. QT_PROTOBUF_DEBUG("set mGenerateComments: true");
  55. mGenerateComments = true;
  56. } else if (option.compare(FolderGenerationOption) == 0) {
  57. QT_PROTOBUF_DEBUG("set mIsFolder: true");
  58. mIsFolder = true;
  59. } else if (option.compare(FieldEnumGenerationOption) == 0) {
  60. QT_PROTOBUF_DEBUG("set mGenerateFieldEnum: true");
  61. mGenerateFieldEnum = true;
  62. } else if (option.find(ExtraNamespaceGenerationOption) == 0) {
  63. QT_PROTOBUF_DEBUG("set mGenerateFieldEnum: true");
  64. std::vector<std::string> compositeOption = utils::split(options, '=');
  65. if (compositeOption.size() == 2) {
  66. mExtraNamespace = compositeOption[1];
  67. if (mExtraNamespace.size() > 1 && mExtraNamespace[0] == '\"'
  68. && mExtraNamespace[mExtraNamespace.size() - 1] == '\"') {
  69. mExtraNamespace = mExtraNamespace.substr(1, mExtraNamespace.size() - 2);
  70. }
  71. }
  72. }
  73. }
  74. }