Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef IntH
00033 #define IntH
00034
00035 #include <zeusbase/System/ZValueType.hpp>
00036 #include <zeusbase/System/BitCodedValue.h>
00037 #include <zeusbase/System/Time.h>
00038 #include <zeusbase/System/Interfaces/IMap.hpp>
00039
00040 BEGIN_NAMESPACE_Zeus
00041
00042
00045
00046 zeusbase_class TInt : public TZValueType<Int>
00047 {
00048 public:
00049 TInt();
00050 TInt(Int iValue);
00051 TInt(const TInt& rIn);
00052 virtual ~TInt();
00053
00055 static inline Int convertBool(bool b) { return b ? 1 : 0; }
00056
00057 void factorize(IMap<Int, Int>& rFactors) const;
00058 TString format(Uint uiLeadingZeros) const;
00059 Int getDigitCount(Uint uiNumBase = 10) const;
00060 Int64 getFactorial() const;
00061 bool isPrime() const;
00062 TString toBinary(bool bTrimZeros = false, bool bAddPreamble = true) const;
00063 TString toHex(bool bTrimZeros = false, bool bAddPreamble = true) const;
00064
00065
00066 static void factorize(Int iValue, IMap<Int, Int>& rFactors);
00067 static Int getDigitCount(Int iValue, Uint uiNumBase);
00068 static Int64 getFactorial(Int iVal);
00069 static bool isPrime(Int iValue);
00070 static Int log2(Int iValue);
00071
00072 static Int randomInt(Int iFrom, Int iTo);
00073 static Int8 randomInt8();
00074 static Int8 randomInt8(Int8 cFrom, Int8 cTo);
00075 static Int16 randomInt16();
00076 static Int16 randomInt16(Int16 lFrom, Int16 lTo);
00077 static Int32 randomInt32();
00078 static Int32 randomInt32(Int32 lFrom, Int32 lTo);
00079 static Int64 randomInt64();
00080 static Int64 randomInt64(const Int64& rldFrom, const Int64& rldTo);
00081
00082
00083 static const Int8 MaxInt8;
00084 static const Int8 MinInt8;
00085 static const Int16 MaxInt16;
00086 static const Int16 MinInt16;
00087 static const Int32 MaxInt32;
00088 static const Int32 MinInt32;
00089 static const Int64 MaxInt64;
00090 static const Int64 MinInt64;
00091 static const Uint8 MaxUint8;
00092 static const Uint16 MaxUint16;
00093 static const Uint32 MaxUint32;
00094 static const Uint64 MaxUint64;
00095
00096 protected:
00097
00098 };
00099
00100
00101
00104
00105 inline Int TInt::getDigitCount(Uint uiNumBase ) const
00106 {
00107 return TInt::getDigitCount(this->m_tValue, uiNumBase);
00108 }
00109
00110
00113
00114 inline Int64 TInt::getFactorial() const
00115 {
00116 return TInt::getFactorial(this->m_tValue);
00117 }
00118
00119
00123
00124 inline void TInt::factorize(IMap<Int, Int>& rFactors) const
00125 {
00126 TInt::factorize(this->m_tValue, rFactors);
00127 }
00128
00129
00132
00133 inline bool TInt::isPrime() const
00134 {
00135 return TInt::isPrime(this->m_tValue);
00136 }
00137
00138
00144
00145 inline Int TInt::randomInt(Int iFrom, Int iTo)
00146 {
00147 return TTime::randomInt(iFrom, iTo);
00148 }
00149
00150
00153
00154 inline Int8 TInt::randomInt8()
00155 {
00156 return static_cast<Int8>(TTime::randomInt(TInt::MinInt8, TInt::MaxInt8));
00157 }
00158
00159
00164
00165 inline Int8 TInt::randomInt8(Int8 cFrom, Int8 cTo)
00166 {
00167 return static_cast<Int8>(TTime::randomInt(cFrom, cTo));
00168 }
00169
00170
00173
00174 inline Int16 TInt::randomInt16()
00175 {
00176 return static_cast<Int16>(TTime::randomInt(TInt::MinInt16, TInt::MaxInt16));
00177 }
00178
00179
00184
00185 inline Int16 TInt::randomInt16(Int16 sFrom, Int16 sTo)
00186 {
00187 return static_cast<Int16>(TTime::randomInt(sFrom, sTo));
00188 }
00189
00190
00193
00194 inline Int32 TInt::randomInt32()
00195 {
00196 return static_cast<Int32>(TTime::randomInt(TInt::MinInt32, TInt::MaxInt32));
00197 }
00198
00199
00204
00205 inline Int32 TInt::randomInt32(Int32 lFrom, Int32 lTo)
00206 {
00207 return static_cast<Int32>(TTime::randomInt(lFrom, lTo));
00208 }
00209
00210
00213
00214 inline Int64 TInt::randomInt64()
00215 {
00216 Int iRandMax = RAND_MAX/2;
00217 Float dValue = TTime::random(-iRandMax, iRandMax)/(double)iRandMax;
00218 Int64 ldValue = static_cast<Int64>(dValue * TInt::MaxInt64);
00219 return ldValue;
00220 }
00221
00222
00228
00229 inline Int64 TInt::randomInt64(const Int64& rldFrom, const Int64& rldTo)
00230 {
00231 Int iRandMax = RAND_MAX;
00232 Float dValue = TTime::random(0, iRandMax)/(double)iRandMax;
00233 Int64 ldValue = static_cast<Int64>(dValue * rldTo);
00234 return rldFrom + ldValue;
00235 }
00236
00237
00243
00244 inline TString TInt::toBinary(bool bTrimZeros , bool bAddPreamble ) const
00245 {
00246 return TBitCodedValue::convertToBinary(this->m_tValue, 32, bTrimZeros, bAddPreamble);
00247 }
00248
00249
00255
00256 inline TString TInt::toHex(bool bTrimZeros , bool bAddPreamble ) const
00257 {
00258 return TBitCodedValue::convertToHex(this->m_tValue, 32, bTrimZeros, bAddPreamble);
00259 }
00260
00261 END_NAMESPACE_Zeus
00262
00263 #endif