SchemaTypeStringLimits.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_CFGSTRINGLIMITS_HPP_
  14. #define _CONFIG2_CFGSTRINGLIMITS_HPP_
  15. #include "SchemaTypeLimits.hpp"
  16. #include <limits.h>
  17. class SchemaTypeStringLimits : public SchemaTypeLimits
  18. {
  19. public:
  20. SchemaTypeStringLimits() : m_minLength(0), m_maxLength(INT_MAX), m_minSet(false), m_maxSet(false) { }
  21. virtual ~SchemaTypeStringLimits() { };
  22. void setLength(unsigned v) { m_minLength = v; m_maxLength = v; m_minSet = m_maxSet = true; }
  23. void setMinLength(int v) { m_minSet = true; m_minLength = v; }
  24. void setMaxLength(int v) { m_maxSet = true; m_maxLength = v; }
  25. void addPattern(const std::string &pattern) { m_patterns.push_back(pattern); }
  26. std::string getLimitString() const;
  27. virtual bool isMaxSet() const { return m_maxSet; }
  28. virtual bool isMinSet() const { return m_minSet; }
  29. virtual int getMax() const { return m_maxLength; }
  30. virtual int getMin() const { return m_minLength; }
  31. protected:
  32. virtual bool doValueTest(const std::string &testValue) const;
  33. protected:
  34. int m_minLength;
  35. int m_maxLength;
  36. bool m_minSet;
  37. bool m_maxSet;
  38. std::vector<std::string> m_patterns;
  39. };
  40. #endif // _CONFIG2_CFGSTRINGLIMITS_HPP_