ConfigPath.hpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2018 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_CONFIGPATH_HPP_
  14. #define _CONFIG2_CONFIGPATH_HPP_
  15. #include <string>
  16. #include <vector>
  17. #include <memory>
  18. class ConfigPathItem
  19. {
  20. public:
  21. ConfigPathItem() : m_isParentPathItem(false), m_isCurrentPathItem(false), m_isSchemaItem(false), m_isRoot(false), m_presentInList(true) {}
  22. ConfigPathItem(const std::string &elemName) : m_isParentPathItem(false), m_isCurrentPathItem(false), m_isSchemaItem(false), m_isRoot(false), m_elementName(elemName) {}
  23. void setElementName(const std::string &elemName) { m_elementName = elemName; }
  24. const std::string &getElementName() const { return m_elementName; }
  25. void setAttributeName(const std::string &attrName) { m_attributeName = attrName; }
  26. const std::string &getAttributeName() const { return m_attributeName; }
  27. void addAttributeValue(const std::string &attrValue) { m_attributeValues.push_back(attrValue); }
  28. bool hasAttributeValues() const { return m_attributeValues.size() > 0; }
  29. std::vector<std::string> getAttributeValues() const { return m_attributeValues; }
  30. bool checkValueAgainstValueList(const std::string val, bool returnTrueIfValueListEmpty = true) const;
  31. void setIsCurrentPathItem(bool currentItem) { m_isCurrentPathItem = currentItem; }
  32. bool isCurrentPathItem() const { return m_isCurrentPathItem; }
  33. void setIsParentPathItemn(bool parentElement) { m_isParentPathItem = parentElement; }
  34. bool isParentPathtItem() const { return m_isParentPathItem; }
  35. void setIsSchemaItem(bool isSchema) { m_isSchemaItem = isSchema; }
  36. bool isSchemaItem() const { return m_isSchemaItem; }
  37. void setIsRoot(bool root) { m_isRoot = root; }
  38. bool isRoot() const { return m_isRoot; }
  39. void setExcludeValueList(bool exclude) { m_presentInList = !exclude; }
  40. private:
  41. bool m_isParentPathItem;
  42. bool m_isCurrentPathItem;
  43. bool m_isSchemaItem;
  44. bool m_isRoot;
  45. bool m_presentInList;
  46. std::string m_elementName;
  47. std::string m_attributeName;
  48. std::vector<std::string> m_attributeValues;
  49. };
  50. class ConfigPath
  51. {
  52. public:
  53. ConfigPath(const std::string path) : m_path(path) {}
  54. ~ConfigPath() {}
  55. std::shared_ptr<ConfigPathItem> getNextPathItem();
  56. bool isPathRemaining() const { return (!m_path.empty()); }
  57. protected:
  58. void updatePath(std::size_t pos);
  59. void parsePathElement(std::size_t start, const std::shared_ptr<ConfigPathItem> &pPathItem);
  60. private:
  61. std::string m_path;
  62. };
  63. #endif