SchemaTypeIntegerLimits.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_CFGINTEGERLIMITS_HPP_
  14. #define _CONFIG2_CFGINTEGERLIMITS_HPP_
  15. #include "SchemaTypeLimits.hpp"
  16. #include <limits.h>
  17. class SchemaTypeIntegerLimits : public SchemaTypeLimits
  18. {
  19. public:
  20. SchemaTypeIntegerLimits() : m_min(INT_MIN), m_max(INT_MAX), m_minSet(false), m_maxSet(false), m_minExclusiveTest(false), m_maxExclusiveTest(false) { }
  21. virtual ~SchemaTypeIntegerLimits() { };
  22. void setMinInclusive(int v) { m_minSet = true; m_min = v; }
  23. void setMinExclusive(int v) { m_minSet = true; m_min = v; m_minExclusiveTest = true; }
  24. void setMaxInclusive(int v) { m_maxSet = true; m_max = v; }
  25. void setMaxExclusive(int v) { m_maxSet = true; m_max = v; m_maxExclusiveTest = true; }
  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_maxExclusiveTest ? (m_max-1) : m_max); }
  30. virtual int getMin() const { return (m_minExclusiveTest ? (m_min+1) : m_min); }
  31. protected:
  32. virtual bool doValueTest(const std::string &testValue) const;
  33. protected:
  34. bool m_maxExclusiveTest;
  35. bool m_minExclusiveTest;
  36. bool m_minSet;
  37. bool m_maxSet;
  38. int m_min;
  39. int m_max;
  40. };
  41. #endif // _CONFIG2_CFGINTEGERLIMITS_HPP_