1 //=================================================================================================
2 /*!
3 // \file blazetest/mathtest/RandomMaximum.h
4 // \brief Header file for the RandomMaximum class template
5 //
6 // Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved
7 //
8 // This file is part of the Blaze library. You can redistribute it and/or modify it under
9 // the terms of the New (Revised) BSD License. Redistribution and use in source and binary
10 // forms, with or without modification, are permitted provided that the following conditions
11 // are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright notice, this list of
14 // conditions and the following disclaimer.
15 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
16 // of conditions and the following disclaimer in the documentation and/or other materials
17 // provided with the distribution.
18 // 3. Neither the names of the Blaze development group nor the names of its contributors
19 // may be used to endorse or promote products derived from this software without specific
20 // prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 // SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 // BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 */
33 //=================================================================================================
34
35 #ifndef _BLAZETEST_MATHTEST_RANDOMMAXIMUM_H_
36 #define _BLAZETEST_MATHTEST_RANDOMMAXIMUM_H_
37
38
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42
43 #include <new>
44 #include <blazetest/mathtest/RandomLimits.h>
45
46
47 namespace blazetest {
48
49 //=================================================================================================
50 //
51 // CLASS TEMPLATE
52 //
53 //=================================================================================================
54
55 //*************************************************************************************************
56 /*!\brief Maximum value for random initializations.
57 //
58 // The RandomMaximum class is a wrapper class around the functionality of the RandomLimits class
59 // template. It represents the largest allowed value for a random initialization of a numeric
60 // data type. The RandomMaximum class can be implicitly converted to all built-in, numeric data
61 // types.\n
62 // In order to handle maximum random values conveniently, the global RandomMaximum instance
63 // blazetest::randmax is provided, which can be used wherever a numeric built-in data type is
64 // required:
65
66 \code
67 int i = randmax; // Assigns the largest allowed signed integer value
68 float f = randmax; // Assigns the largest allowed single precision value
69 double d = randmax; // Assigns the largest allowed double precision value
70 \endcode
71 */
72 class RandomMaximum
73 {
74 public:
75 //**Constructor*********************************************************************************
76 /*!\name Constructor */
77 //@{
78 explicit inline RandomMaximum();
79 // No explicitly declared copy constructor.
80 //@}
81 //**********************************************************************************************
82
83 //**Destructor**********************************************************************************
84 // No explicitly declared destructor.
85 //**********************************************************************************************
86
87 //**Conversion operators************************************************************************
88 /*!\name Conversion operators */
89 //@{
90 template< typename T >
91 inline operator const T() const;
92 //@}
93 //**********************************************************************************************
94
95 private:
96 //**Forbidden operations************************************************************************
97 /*!\name Forbidden operations */
98 //@{
99 RandomMaximum& operator=( const RandomMaximum& );
100 void* operator&() const;
101
102 void* operator new ( std::size_t ) /*throw( std::bad_alloc )*/;
103 void* operator new[]( std::size_t ) /*throw( std::bad_alloc )*/;
104 void* operator new ( std::size_t, const std::nothrow_t& ) /*throw()*/;
105 void* operator new[]( std::size_t, const std::nothrow_t& ) /*throw()*/;
106
107 void operator delete ( void* ) /*throw()*/;
108 void operator delete[]( void* ) /*throw()*/;
109 void operator delete ( void*, const std::nothrow_t& ) /*throw()*/;
110 void operator delete[]( void*, const std::nothrow_t& ) /*throw()*/;
111 //@}
112 //**********************************************************************************************
113 };
114 //*************************************************************************************************
115
116
117
118
119 //=================================================================================================
120 //
121 // CONSTRUCTOR
122 //
123 //=================================================================================================
124
125 //*************************************************************************************************
126 /*!\brief The default constructor of the RandomMaximum class.
127 */
RandomMaximum()128 inline RandomMaximum::RandomMaximum()
129 {}
130 //*************************************************************************************************
131
132
133
134
135 //=================================================================================================
136 //
137 // CONVERSION OPERATORS
138 //
139 //=================================================================================================
140
141 //*************************************************************************************************
142 /*!\brief Conversion operator to the required data type.
143 //
144 // The conversion operator returns the largest allowed random value for the given data type \a T.
145 */
146 template< typename T >
T()147 inline RandomMaximum::operator const T() const
148 {
149 return RandomLimits<T>::max();
150 }
151 //*************************************************************************************************
152
153
154
155
156 //=================================================================================================
157 //
158 // GLOBAL RANDOMMAXIMUM VALUE
159 //
160 //=================================================================================================
161
162 //*************************************************************************************************
163 const RandomMaximum randmax;
164 //*************************************************************************************************
165
166 } // namespace blazetest
167
168 #endif
169