SchemaValue.hpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 EnvironmentNode;
  20. class DECL_EXPORT SchemaValue
  21. {
  22. public:
  23. SchemaValue(const std::string &name, bool isDefined = true);
  24. SchemaValue(const SchemaValue &value);
  25. virtual ~SchemaValue() { }
  26. void setType(const std::shared_ptr<SchemaType> pType) { m_pType = pType; }
  27. const std::shared_ptr<SchemaType> &getType() const { return m_pType; }
  28. const std::string &getName() const { return m_name; }
  29. bool isValueValid(const std::string &newValue, const EnvironmentValue *pEnvValue = nullptr) const;
  30. void setDisplayName(const std::string &displayName) { m_displayName = displayName; }
  31. const std::string &getDisplayName() const { return m_displayName; }
  32. void setRequired(bool reqd) { bitMask.m_required = reqd; }
  33. bool isRequired() const { return bitMask.m_required; }
  34. void setDefaultValue(const std::string &dflt) { m_default = dflt; }
  35. const std::string &getDefaultValue() const { return m_default; }
  36. bool hasDefaultValue() const { return !m_default.empty(); }
  37. void setReadOnly(bool readOnly) { bitMask.m_readOnly = readOnly; }
  38. bool isReadOnly() const { return bitMask.m_readOnly; }
  39. void setHidden(bool hidden) { bitMask.m_hidden = hidden; }
  40. bool isHidden() const { return bitMask.m_hidden; }
  41. void setDeprecated(bool deprecated) { bitMask.m_deprecated = deprecated; }
  42. bool isDeprecated() const { return bitMask.m_deprecated; }
  43. void setTooltip(const std::string &tooltip) { m_tooltip = tooltip; }
  44. const std::string &getTooltip() const { return m_tooltip; }
  45. void addModifer(const std::string &mod) { m_modifiers.push_back(mod); }
  46. void setModifiers(const std::vector<std::string> &list) { m_modifiers = list; }
  47. const std::vector<std::string> &getModifiers() const { return m_modifiers; }
  48. bool hasModifiers() const { return m_modifiers.size() != 0; }
  49. bool hasModifier(const std::string &modifier) const;
  50. void setUniqueValue(bool isUnique) { bitMask.m_isUnique = isUnique; }
  51. bool isUniqueValue() const { return bitMask.m_isUnique; }
  52. void setUniqueValueSetRef(const std::shared_ptr<SchemaValue> &pValue) { m_pUniqueValueSetRefs.push_back(pValue); }
  53. bool isFromUniqueValueSet() const { return !m_pUniqueValueSetRefs.empty(); }
  54. const std::vector<std::weak_ptr<SchemaValue>> &getUniqueValueSetRefs() const { return m_pUniqueValueSetRefs; }
  55. bool isDefined() const { return bitMask.m_isDefined; }
  56. void resetEnvironment();
  57. void setMirrorFromPath(const std::string &path) { m_mirrorFromPath = path; }
  58. const std::string &getMirrorFromPath() const { return m_mirrorFromPath; }
  59. bool isMirroredValue() const { return m_mirrorFromPath.length() != 0; }
  60. void addMirroredSchemaValue(const std::shared_ptr<SchemaValue> &pVal) { m_mirrorToSchemaValues.push_back(pVal); }
  61. void mirrorValueToEnvironment(const std::string &oldValue, const std::string &newValue, Status *pStatus = nullptr);
  62. void addEnvironmentValue(const std::shared_ptr<EnvironmentValue> &pEnvValue) { m_envValues.push_back(pEnvValue); }
  63. void getAllEnvironmentValues(std::vector<std::shared_ptr<EnvironmentValue>> &envValues) const;
  64. void validate(Status &status, const std::string &id, const EnvironmentValue *pEnvValue = nullptr) const;
  65. void getAllowedValues(std::vector<AllowedValue> &allowedValues, const std::shared_ptr<const EnvironmentNode> &pEnvNode) const;
  66. void setAutoGenerateType(const std::string &type) { m_autoGenerateType = type; }
  67. const std::string &getAutoGenerateType() const { return m_autoGenerateType; }
  68. void setAutoGenerateValue(const std::string &value) { m_autoGenerateValue = value; }
  69. const std::string &getAutoGenerateValue() const { return m_autoGenerateValue; }
  70. void getAllKeyRefValues(std::vector<std::string> &keyRefValues) const;
  71. void setCodeDefault(const std::string &value) { m_codeDefault = value; }
  72. const std::string &getCodeDefault() const { return m_codeDefault; }
  73. void setValueLimitRuleType(const std::string &type) { m_valueLimitRuleType = type; }
  74. const std::string &getValueLimitRuleType() { return m_valueLimitRuleType; }
  75. void setValueLimitRuleData(const std::string &data) { m_valueLimitRuleData = data; }
  76. const std::string &getValueLimitRuleData() { return m_valueLimitRuleData; }
  77. void setRequiredIf(const std::string &reqIf) { m_requiredIf = reqIf; }
  78. const std::string &getRequiredIf() const { return m_requiredIf; }
  79. void setGroupByName(const std::string &group) { m_groupByName = group; }
  80. const std::string &getGroupByName() const { return m_groupByName; }
  81. protected:
  82. // DON'T FORGET IF DATA ADDED, IT MAY MAY TO BE COPIED IN THE COPY CONSTRUCTOR!!
  83. std::shared_ptr<SchemaType> m_pType;
  84. std::vector<std::weak_ptr<EnvironmentValue>> m_envValues;
  85. std::vector<std::shared_ptr<SchemaValue>> m_mirrorToSchemaValues;
  86. std::string m_name;
  87. std::string m_displayName;
  88. std::string m_mirrorFromPath;
  89. std::string m_autoGenerateValue;
  90. std::string m_autoGenerateType;
  91. std::string m_valueLimitRuleType;
  92. std::string m_valueLimitRuleData;
  93. std::string m_requiredIf;
  94. std::string m_groupByName;
  95. // DON'T FORGET IF DATA ADDED, IT MAY MAY TO BE COPIED IN THE COPY CONSTRUCTOR!!
  96. struct {
  97. unsigned m_required : 1;
  98. unsigned m_readOnly : 1;
  99. unsigned m_hidden : 1;
  100. unsigned m_deprecated: 1;
  101. unsigned m_isUnique : 1;
  102. unsigned m_isDefined : 1;
  103. } bitMask;
  104. // DON'T FORGET IF DATA ADDED, IT MAY MAY TO BE COPIED IN THE COPY CONSTRUCTOR!!
  105. std::string m_default; // value written to environment if no user value supplied
  106. std::string m_codeDefault; // informational value nform user code default if no value supplied
  107. std::string m_tooltip;
  108. std::vector<std::string> m_modifiers;
  109. std::vector<std::weak_ptr<SchemaValue>> m_pUniqueValueSetRefs; // this value serves as the key from which values are valid
  110. // DON'T FORGET IF DATA ADDED, IT MAY MAY TO BE COPIED IN THE COPY CONSTRUCTOR!!
  111. };
  112. #endif // _CONFIG2_VALUE_HPP_