You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
5.2 KiB

13 years ago
  1. /*
  2. * constants.h
  3. *
  4. * Created on: 11.10.2012
  5. * Author: Thomas Heinemann
  6. */
  7. #ifndef STORM_UTILITY_CONSTTEMPLATES_H_
  8. #define STORM_UTILITY_CONSTTEMPLATES_H_
  9. #ifdef max
  10. # undef max
  11. #endif
  12. #ifdef min
  13. # undef min
  14. #endif
  15. #include <limits>
  16. #include "src/exceptions/InvalidArgumentException.h"
  17. #include "src/storage/BitVector.h"
  18. #include "src/storage/LabeledValues.h"
  19. namespace storm {
  20. namespace utility {
  21. /*!
  22. * Returns a constant value of 0 that is fit to the type it is being written to.
  23. * As (at least) gcc has problems to use the correct template by the return value
  24. * only, the function gets a pointer as a parameter to infer the return type.
  25. *
  26. * @note
  27. * The template parameter is just inferred by the return type; GCC is not able to infer this
  28. * automatically, hence the type should always be stated explicitly (e.g. @c constantZero<int>();)
  29. *
  30. * @return Value 0, fit to the return type
  31. */
  32. template<typename _Scalar>
  33. static inline _Scalar constantZero() {
  34. return _Scalar(0);
  35. }
  36. /*! @cond TEMPLATE_SPECIALIZATION
  37. * (By default, the template specifications are not included in the documentation)
  38. */
  39. /*!
  40. * Template specialization for int_fast32_t
  41. * @return Value 0, fit to the type int_fast32_t
  42. */
  43. template <>
  44. inline int_fast32_t constantZero() {
  45. return 0;
  46. }
  47. /*!
  48. * Template specialization for uint_fast64_t
  49. * @return Value 0, fit to the type uint_fast64_t
  50. */
  51. template <>
  52. inline uint_fast64_t constantZero() {
  53. return 0;
  54. }
  55. /*!
  56. * Template specialization for double
  57. * @return Value 0.0, fit to the type double
  58. */
  59. template <>
  60. inline double constantZero() {
  61. return 0.0;
  62. }
  63. /*!
  64. * Template specialization for LabeledValues.
  65. * @return A LabeledValues object that represents a value of 0.
  66. */
  67. template<>
  68. inline storm::storage::LabeledValues<double> constantZero() {
  69. return storm::storage::LabeledValues<double>(0.0);
  70. }
  71. /*! @endcond */
  72. /*!
  73. * Returns a constant value of 1 that is fit to the type it is being written to.
  74. * As (at least) gcc has problems to use the correct template by the return value
  75. * only, the function gets a pointer as a parameter to infer the return type.
  76. *
  77. * @note
  78. * The template parameter is just inferred by the return type; GCC is not able to infer this
  79. * automatically, hence the type should always be stated explicitly (e.g. @c constantOne<int>();)
  80. *
  81. * @return Value 1, fit to the return type
  82. */
  83. template<typename _Scalar>
  84. static inline _Scalar constantOne() {
  85. return _Scalar(1);
  86. }
  87. /*! @cond TEMPLATE_SPECIALIZATION
  88. * (By default, the template specializations are not included in the documentation)
  89. */
  90. /*!
  91. * Template specialization for int_fast32_t
  92. * @return Value 1, fit to the type int_fast32_t
  93. */
  94. template<>
  95. inline int_fast32_t constantOne() {
  96. return 1;
  97. }
  98. /*!
  99. * Template specialization for uint_fast64_t
  100. * @return Value 1, fit to the type uint_fast61_t
  101. */
  102. template<>
  103. inline uint_fast64_t constantOne() {
  104. return 1;
  105. }
  106. /*!
  107. * Template specialization for double
  108. * @return Value 1.0, fit to the type double
  109. */
  110. template<>
  111. inline double constantOne() {
  112. return 1.0;
  113. }
  114. /*!
  115. * Template specialization for LabeledValues.
  116. * @return A LabeledValues object that represents a value of 1.
  117. */
  118. template<>
  119. inline storm::storage::LabeledValues<double> constantOne() {
  120. return storm::storage::LabeledValues<double>(1.0);
  121. }
  122. /*! @endcond */
  123. /*!
  124. * Returns a constant value of infinity that is fit to the type it is being written to.
  125. * As (at least) gcc has problems to use the correct template by the return value
  126. * only, the function gets a pointer as a parameter to infer the return type.
  127. *
  128. * @note
  129. * The template parameter is just inferred by the return type; GCC is not able to infer this
  130. * automatically, hence the type should always be stated explicitly (e.g. @c constantOne<int>();)
  131. *
  132. * @return Value Infinity, fit to the return type
  133. */
  134. template<typename _Scalar>
  135. static inline _Scalar constantInfinity() {
  136. return std::numeric_limits<_Scalar>::infinity();
  137. }
  138. /*! @cond TEMPLATE_SPECIALIZATION
  139. * (By default, the template specializations are not included in the documentation)
  140. */
  141. /*!
  142. * Template specialization for int_fast32_t
  143. * @return Value Infinity, fit to the type uint_fast32_t
  144. */
  145. template<>
  146. inline int_fast32_t constantInfinity() {
  147. throw storm::exceptions::InvalidArgumentException() << "Integer has no infinity.";
  148. return std::numeric_limits<int_fast32_t>::max();
  149. }
  150. /*!
  151. * Template specialization for uint_fast64_t
  152. * @return Value Infinity, fit to the type uint_fast64_t
  153. */
  154. template<>
  155. inline uint_fast64_t constantInfinity() {
  156. throw storm::exceptions::InvalidArgumentException() << "Integer has no infinity.";
  157. return std::numeric_limits<uint_fast64_t>::max();
  158. }
  159. /*!
  160. * Template specialization for double
  161. * @return Value Infinity, fit to the type double
  162. */
  163. template<>
  164. inline double constantInfinity() {
  165. return std::numeric_limits<double>::infinity();
  166. }
  167. /*!
  168. * Template specialization for LabeledValues.
  169. * @return Value Infinity, fit to the type LabeledValues.
  170. */
  171. template<>
  172. inline storm::storage::LabeledValues<double> constantInfinity() {
  173. return storm::storage::LabeledValues<double>(std::numeric_limits<double>::infinity());
  174. }
  175. /*! @endcond */
  176. } //namespace utility
  177. } //namespace storm
  178. #endif /* STORM_UTILITY_CONSTTEMPLATES_H_ */