EnvironmentValue.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_ENVVALUE_HPP_
  14. #define _CONFIG2_ENVVALUE_HPP_
  15. #include <string>
  16. #include "SchemaValue.hpp"
  17. #include "Status.hpp"
  18. #include "platform.h"
  19. class EnvironmentNode;
  20. class DECL_EXPORT EnvironmentValue
  21. {
  22. public:
  23. EnvironmentValue(const std::shared_ptr<EnvironmentNode> &pMyNode, const std::shared_ptr<SchemaValue> &pCfgValue, const std::string &name="") :
  24. m_pMyEnvNode(pMyNode), m_pSchemaValue(pCfgValue), m_name(name), m_forcedSet(false) { }
  25. EnvironmentValue(const std::shared_ptr<EnvironmentNode> &pMyNode, const std::shared_ptr<SchemaValue> &pCfgValue, const std::string &name, const std::string initValue) :
  26. EnvironmentValue(pMyNode, pCfgValue, name) { m_value = initValue; }
  27. ~EnvironmentValue() { }
  28. bool setValue(const std::string &value, Status *pStatus, bool forceSet=false);
  29. bool isValueSet() const { return !m_value.empty(); }
  30. const std::string &getValue() const { return m_value; }
  31. const std::string &getDefaultValue() const { return m_pSchemaValue->getDefaultValue(); }
  32. bool hasDefaultValue() const { return m_pSchemaValue->hasDefaultValue(); }
  33. const std::shared_ptr<SchemaValue> &getSchemaValue() const { return m_pSchemaValue; }
  34. const std::string &getName() const { return m_name; }
  35. bool wasForced() const { return m_forcedSet; }
  36. bool isValueValid(const std::string &value) const;
  37. void validate(Status &status, const std::string &myId) const;
  38. void getAllValuesForSiblings(std::vector<std::string> &result) const;
  39. std::string getNodeId() const;
  40. void initialize();
  41. private:
  42. bool m_forcedSet; // true when last set value was a forced set
  43. std::string m_name;
  44. std::string m_value;
  45. std::shared_ptr<SchemaValue> m_pSchemaValue;
  46. std::weak_ptr<EnvironmentNode> m_pMyEnvNode;
  47. };
  48. #endif