SchemaTypeLimits.hpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_CFGLIMITS_HPP_
  14. #define _CONFIG2_CFGLIMITS_HPP_
  15. #include <memory>
  16. #include <vector>
  17. #include <string>
  18. #include "platform.h"
  19. #include "Status.hpp"
  20. class EnvironmentValue;
  21. struct DECL_EXPORT DependentValue
  22. {
  23. DependentValue(const std::string &attribute, const std::string &value) : m_attribute(attribute), m_value(value) { }
  24. std::string m_attribute;
  25. std::string m_value;
  26. };
  27. struct DECL_EXPORT AllowedValue
  28. {
  29. AllowedValue() {}
  30. AllowedValue(const std::string &value, const std::string &desc="") : m_value(value), m_displayName(value), m_description(desc) { }
  31. void addDependentValue(const std::string &attribute, const std::string &value);
  32. const std::vector<DependentValue> &getDependencies() const { return m_dependencies; }
  33. bool hasDependencies() const { return m_dependencies.size() > 0; }
  34. std::string m_displayName;
  35. std::string m_value;
  36. std::string m_description;
  37. std::string m_userMessageType;
  38. std::string m_userMessage;
  39. std::vector<DependentValue> m_dependencies;
  40. };
  41. class DECL_EXPORT SchemaTypeLimits
  42. {
  43. public:
  44. SchemaTypeLimits() { }
  45. virtual ~SchemaTypeLimits() { }
  46. void addAllowedValue(const std::string &value, const std::string &desc="") { m_enumeratedValues.push_back(AllowedValue(value, desc)); }
  47. void addAllowedValue(const AllowedValue &val) { m_enumeratedValues.push_back(val); }
  48. void addDependentAttributeValue(const std::string &value, const std::string &depAttr, const std::string &depAttrVal);
  49. std::vector<AllowedValue> getEnumeratedValues() const;
  50. bool isEnumerated() const { return !m_enumeratedValues.empty(); }
  51. bool isValueValid(const std::string &testValue) const;
  52. virtual std::string getLimitString() const { return "No value limits"; }
  53. virtual bool isMaxSet() const { return false; }
  54. virtual bool isMinSet() const { return false; }
  55. virtual int getMax() const { return 0; }
  56. virtual int getMin() const { return 0; }
  57. const std::string &getValidateMsg() const { return m_validateMsg; }
  58. const std::string &getValidateMsgType() const { return m_validateMsgType; }
  59. protected:
  60. virtual bool isValidEnumeratedValue(const std::string &testValue) const;
  61. virtual bool doValueTest(const std::string &testValue) const { return true; }
  62. protected:
  63. std::vector<AllowedValue> m_enumeratedValues;
  64. mutable std::string m_validateMsg;
  65. mutable std::string m_validateMsgType;
  66. };
  67. #endif // _CONFIG2_CFGLIMITS_HPP_