SchemaValue.hpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2017 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef _CONFIG2_VALUE_HPP_
  14. #define _CONFIG2_VALUE_HPP_
  15. #include <memory>
  16. #include "SchemaType.hpp"
  17. #include "Status.hpp"
  18. #include "platform.h"
  19. class DECL_EXPORT SchemaValue
  20. {
  21. public:
  22. SchemaValue(const std::string &name, bool isDefined = true);
  23. virtual ~SchemaValue() { }
  24. void setType(const std::shared_ptr<SchemaType> pType) { m_pType = pType; }
  25. const std::shared_ptr<SchemaType> &getType() const { return m_pType; }
  26. const std::string &getName() const { return m_name; }
  27. bool isValueValid(const std::string &newValue, const EnvironmentValue *pEnvValue = nullptr) const;
  28. void setDisplayName(const std::string &displayName) { m_displayName = displayName; }
  29. const std::string &getDisplayName() const { return m_displayName; }
  30. void setRequired(bool reqd) { bitMask.m_required = reqd; }
  31. bool isRequired() const { return bitMask.m_required; }
  32. void setDefaultValue(const std::string &dflt) { m_default = dflt; }
  33. const std::string &getDefaultValue() const { return m_default; }
  34. bool hasDefaultValue() const { return !m_default.empty(); }
  35. void setReadOnly(bool readOnly) { bitMask.m_readOnly = readOnly; }
  36. bool isReadOnly() const { return bitMask.m_readOnly; }
  37. void setHidden(bool hidden) { bitMask.m_hidden = hidden; }
  38. bool isHidden() const { return bitMask.m_hidden; }
  39. void setDeprecated(bool deprecated) { bitMask.m_deprecated = deprecated; }
  40. bool isDeprecated() const { return bitMask.m_deprecated; }
  41. void setTooltip(const std::string &tooltip) { m_tooltip = tooltip; }
  42. const std::string &getTooltip() const { return m_tooltip; }
  43. void addModifer(const std::string &mod) { m_modifiers.push_back(mod); }
  44. void setModifiers(const std::vector<std::string> &list) { m_modifiers = list; }
  45. const std::vector<std::string> &getModifiers() const { return m_modifiers; }
  46. bool hasModifiers() const { return m_modifiers.size() != 0; }
  47. void setUniqueValue(bool isUnique) { bitMask.m_isUnique = isUnique; }
  48. bool isUniqueValue() const { return bitMask.m_isUnique; }
  49. void setUniqueValueSetRef(const std::shared_ptr<SchemaValue> &pValue) { m_pUniqueValueSetRefs.push_back(pValue); }
  50. bool isFromUniqueValueSet() const { return !m_pUniqueValueSetRefs.empty(); }
  51. const std::vector<std::weak_ptr<SchemaValue>> &getUniqueValueSetRefs() const { return m_pUniqueValueSetRefs; }
  52. bool isDefined() const { return bitMask.m_isDefined; }
  53. void resetEnvironment();
  54. void setMirrorFromPath(const std::string &path) { m_mirrorFromPath = path; }
  55. const std::string &getMirrorFromPath() const { return m_mirrorFromPath; }
  56. bool isMirroredValue() const { return m_mirrorFromPath.length() != 0; }
  57. void addMirroredSchemaValue(const std::shared_ptr<SchemaValue> &pVal) { m_mirrorToSchemaValues.push_back(pVal); }
  58. void mirrorValueToEnvironment(const std::string &oldValue, const std::string &newValue);
  59. void addEnvironmentValue(const std::shared_ptr<EnvironmentValue> &pEnvValue) { m_envValues.push_back(pEnvValue); }
  60. void getAllEnvironmentValues(std::vector<std::string> &values) const;
  61. void setMirroredEnvironmentValues(const std::string &oldValue, const std::string &newValue);
  62. void validate(Status &status, const std::string &id, const EnvironmentValue *pEnvValue = nullptr) const;
  63. void getAllowedValues(std::vector<AllowedValue> &allowedValues, const EnvironmentValue *pEnvValue = nullptr) const;
  64. void setAutoGenerateType(const std::string &type) { m_autoGenerateType = type; }
  65. const std::string &getAutoGenerateType() const { return m_autoGenerateType; }
  66. void setAutoGenerateValue(const std::string &value) { m_autoGenerateValue = value; }
  67. const std::string &getAutoGenerateValue() const { return m_autoGenerateValue; }
  68. void getAllKeyRefValues(std::vector<std::string> &keyRefValues) const;
  69. protected:
  70. std::shared_ptr<SchemaType> m_pType;
  71. std::vector<std::weak_ptr<EnvironmentValue>> m_envValues;
  72. std::vector<std::shared_ptr<SchemaValue>> m_mirrorToSchemaValues;
  73. std::string m_name;
  74. std::string m_displayName;
  75. std::string m_mirrorFromPath;
  76. std::string m_autoGenerateValue;
  77. std::string m_autoGenerateType;
  78. struct {
  79. unsigned m_required : 1;
  80. unsigned m_readOnly : 1;
  81. unsigned m_hidden : 1;
  82. unsigned m_deprecated: 1;
  83. unsigned m_isUnique : 1;
  84. unsigned m_isDefined : 1;
  85. } bitMask;
  86. std::string m_default;
  87. std::string m_tooltip;
  88. std::vector<std::string> m_modifiers;
  89. std::vector<std::weak_ptr<SchemaValue>> m_pUniqueValueSetRefs; // this value serves as the key from which values are valid
  90. };
  91. #endif // _CONFIG2_VALUE_HPP_