ConstantType.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef CONSTANTVARIABLE_H
  2. #define CONSTANTVARIABLE_H
  3. #include <boost/exception/get_error_info.hpp>
  4. #include <LayoutUtilities/CommonLayoutConstants.h>
  5. #include <LayoutException/LayoutExceptionConstants.h>
  6. #include <LayoutException/LayoutMemoryException.h>
  7. #include <LayoutException/LayoutFileIOException.h>
  8. #include <QObject>
  9. #define PI boost::math::constants::pi<double>()
  10. /**
  11. * @brief The ConstantType class
  12. *
  13. * The class provides constants and operators on these constants used in graph layouts.
  14. */
  15. template <typename VariableType>
  16. class ConstantType
  17. {
  18. public:
  19. ConstantType<VariableType>() : m_bAssigned(false) {}
  20. ConstantType& operator=(VariableType value)
  21. {
  22. //Q_ASSERT_X(!m_bAssigned, "Generic Constant Variable" , "Modifying constant variable");
  23. LAYOUT_ASSERT(m_bAssigned == false , LayoutException(__FUNCTION__ , LayoutExceptionEnum::INVALID_OPERATION
  24. , "Modifying constant variable after first assignment"
  25. , "Generic Constant Variable"));
  26. if(m_bAssigned == false)
  27. {
  28. m_Value = value;
  29. m_bAssigned = true;
  30. }
  31. return *this;
  32. }
  33. operator VariableType() const
  34. {
  35. //Q_ASSERT_X(m_bAssigned , "Generic Constant Variable" , "Value not set");
  36. LAYOUT_ASSERT(m_bAssigned == true , LayoutException(__FUNCTION__ , LayoutExceptionEnum::REQUIRED_PARAMETER_NOT_SET
  37. , "Generic Constant Variable"
  38. , ""));
  39. return m_Value;
  40. }
  41. bool isSet()
  42. {
  43. return m_bAssigned;
  44. }
  45. void reset()
  46. {
  47. m_bAssigned = false;
  48. }
  49. private:
  50. VariableType m_Value;
  51. bool m_bAssigned;
  52. };
  53. #endif // CONSTANTVARIABLE_H