SchemaValue.hpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 setForcedValue(const std::string &dflt) { m_forcedValue = dflt; }
  35. const std::string &getForcedValue() const { return m_forcedValue; }
  36. bool hasForcedValue() const { return !m_forcedValue.empty(); }
  37. void setReadOnly(bool readOnly) { bitMask.m_readOnly = readOnly; }
  38. bool isReadOnly() const { return bitMask.m_readOnly; }
  39. void setHiddenIf(const std::string &hiddenIf) { m_hiddenIf = hiddenIf; }
  40. void setInvertHiddenIf(bool invert) { m_invertHiddenIf = invert; }
  41. bool getInvertHiddenIf() const { return m_invertHiddenIf; }
  42. void setHidden(bool hidden) { bitMask.m_hidden = hidden; }
  43. bool isHidden(const EnvironmentValue *pEnvValue=nullptr) const;
  44. void setDeprecated(bool deprecated) { bitMask.m_deprecated = deprecated; }
  45. bool isDeprecated() const { return bitMask.m_deprecated; }
  46. void setTooltip(const std::string &tooltip) { m_tooltip = tooltip; }
  47. const std::string &getTooltip() const { return m_tooltip; }
  48. void addModifer(const std::string &mod) { m_modifiers.push_back(mod); }
  49. void setModifiers(const std::vector<std::string> &list) { m_modifiers = list; }
  50. const std::vector<std::string> &getModifiers() const { return m_modifiers; }
  51. bool hasModifiers() const { return m_modifiers.size() != 0; }
  52. bool hasModifier(const std::string &modifier) const;
  53. void setUniqueValue(bool isUnique) { bitMask.m_isUnique = isUnique; }
  54. bool isUniqueValue() const { return bitMask.m_isUnique; }
  55. void setUniqueValueSetRef(const std::shared_ptr<SchemaValue> &pValue) { m_pUniqueValueSetRefs.push_back(pValue); }
  56. bool isFromUniqueValueSet() const { return !m_pUniqueValueSetRefs.empty(); }
  57. const std::vector<std::weak_ptr<SchemaValue>> &getUniqueValueSetRefs() const { return m_pUniqueValueSetRefs; }
  58. bool isDefined() const { return bitMask.m_isDefined; }
  59. void resetEnvironment();
  60. void setMirrorFromPath(const std::string &path) { m_mirrorFromPath = path; }
  61. const std::string &getMirrorFromPath() const { return m_mirrorFromPath; }
  62. bool isMirroredValue() const { return m_mirrorFromPath.length() != 0; }
  63. void addMirroredSchemaValue(const std::shared_ptr<SchemaValue> &pVal) { m_mirrorToSchemaValues.push_back(pVal); }
  64. void mirrorValueToEnvironment(const std::string &oldValue, const std::string &newValue, Status *pStatus = nullptr);
  65. void addEnvironmentValue(const std::shared_ptr<EnvironmentValue> &pEnvValue) { m_envValues.push_back(pEnvValue); }
  66. void getAllEnvironmentValues(std::vector<std::shared_ptr<EnvironmentValue>> &envValues) const;
  67. void removeEnvironmentValue(const std::shared_ptr<EnvironmentValue> &pEnvValue);
  68. void validate(Status &status, const std::string &id, const EnvironmentValue *pEnvValue = nullptr) const;
  69. bool getAllowedValues(std::vector<AllowedValue> &allowedValues, const std::shared_ptr<const EnvironmentNode> &pEnvNode) const;
  70. void setAutoGenerateType(const std::string &type) { m_autoGenerateType = type; }
  71. const std::string &getAutoGenerateType() const { return m_autoGenerateType; }
  72. void setAutoGenerateValue(const std::string &value) { m_autoGenerateValue = value; }
  73. const std::string &getAutoGenerateValue() const { return m_autoGenerateValue; }
  74. void getAllKeyRefValues(std::vector<std::string> &keyRefValues) const;
  75. void setPresetValue(const std::string &value) { m_presetValue = value; }
  76. const std::string &getPresetValue() const { return m_presetValue; }
  77. void setValueLimitRuleType(const std::string &type) { m_valueLimitRuleType = type; }
  78. const std::string &getValueLimitRuleType() { return m_valueLimitRuleType; }
  79. void setValueLimitRuleData(const std::string &data) { m_valueLimitRuleData = data; }
  80. const std::string &getValueLimitRuleData() { return m_valueLimitRuleData; }
  81. void setRequiredIf(const std::string &reqIf) { m_requiredIf = reqIf; }
  82. const std::string &getRequiredIf() const { return m_requiredIf; }
  83. void setGroupByName(const std::string &group) { m_groupByName = group; }
  84. const std::string &getGroupByName() const { return m_groupByName; }
  85. void setNoOutput(bool noOutput) { bitMask.m_noOutput = noOutput; }
  86. bool isNoOutput() const { return bitMask.m_noOutput; }
  87. protected:
  88. void doMirroroToEnvironmentValues(const std::string &oldValue, const std::string &newValue, Status *pStatus = nullptr);
  89. protected:
  90. // DON'T FORGET IF DATA ADDED, IT MAY MAY TO BE COPIED IN THE COPY CONSTRUCTOR!!
  91. std::shared_ptr<SchemaType> m_pType;
  92. std::string m_name;
  93. std::string m_displayName;
  94. std::string m_mirrorFromPath;
  95. std::string m_autoGenerateValue;
  96. std::string m_autoGenerateType;
  97. std::string m_valueLimitRuleType;
  98. std::string m_valueLimitRuleData;
  99. std::string m_requiredIf;
  100. std::string m_groupByName;
  101. std::string m_hiddenIf;
  102. bool m_invertHiddenIf;
  103. // DON'T FORGET IF DATA ADDED, IT MAY MAY TO BE COPIED IN THE COPY CONSTRUCTOR!!
  104. struct {
  105. unsigned m_required : 1;
  106. unsigned m_readOnly : 1;
  107. unsigned m_hidden : 1;
  108. unsigned m_deprecated: 1;
  109. unsigned m_isUnique : 1;
  110. unsigned m_isDefined : 1;
  111. unsigned m_noOutput : 1;
  112. } bitMask;
  113. // DON'T FORGET IF DATA ADDED, IT MAY MAY TO BE COPIED IN THE COPY CONSTRUCTOR!!
  114. std::string m_forcedValue; // value written to environment if no user value supplied
  115. std::string m_presetValue; // informational value nform user code default if no value supplied
  116. std::string m_tooltip;
  117. std::vector<std::string> m_modifiers;
  118. // DON'T FORGET IF DATA ADDED, IT MAY MAY TO BE COPIED IN THE COPY CONSTRUCTOR!!
  119. // These values are NOT copied in the copy constructor
  120. std::vector<std::weak_ptr<EnvironmentValue>> m_envValues;
  121. std::vector<std::shared_ptr<SchemaValue>> m_mirrorToSchemaValues;
  122. std::vector<std::weak_ptr<SchemaValue>> m_pUniqueValueSetRefs; // this value serves as the key from which values are valid
  123. };
  124. #endif // _CONFIG2_VALUE_HPP_