X-Git-Url: https://jfr.im/git/irc/gameservirc.git/blobdiff_plain/1134c36807a7fb7ffcfd9ce84f8f3ccf8b8aa8c7..9920617b5f77fa9d420300fdc9bfe5357938eecf:/gameserv-2.0/libgameservcore/include/GameServ/Types.h?ds=sidebyside diff --git a/gameserv-2.0/libgameservcore/include/GameServ/Types.h b/gameserv-2.0/libgameservcore/include/GameServ/Types.h index 1d8fcfc..de0fab2 100644 --- a/gameserv-2.0/libgameservcore/include/GameServ/Types.h +++ b/gameserv-2.0/libgameservcore/include/GameServ/Types.h @@ -6,6 +6,27 @@ using std::string; #include using GameServ::Exceptions::GameServException; +#include +#include +#include +#include +#include +// Sun CC doesn't handle boost::iterator_adaptor yet +#if !defined(__SUNPRO_CC) || (__SUNPRO_CC > 0x530) +#include +#endif + +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std { + using ::time; +} +#endif + +// This is a typedef for a random number generator. +// Try boost::mt19937 or boost::ecuyer1988 instead of boost::minstd_rand +typedef boost::minstd_rand base_generator_type; + + namespace GameServ { namespace Types @@ -101,35 +122,82 @@ namespace GameServ static const modifierinfo mModifierInfoTable[]; }; // Modifiers class + template class Range { public: - Range(); - Range(const int &high, const int &low); - ~Range(); + + Range() + { + } + + Range(const T &high, const T &low) + { + mHigh = high; + mLow = low; + } + + ~Range() + { + } //! Generate a random number within the range - int Random(); + T Random() + { + static base_generator_type generator(static_cast(std::time(0))); + if (mLow == mHigh) + { + return mLow; + } + else + { + boost::uniform_int<> uni_dist(mLow, mHigh); + boost::variate_generator > uni(generator, uni_dist); + mLastRandom = uni(); + return mLastRandom; + } + } //! Property get - High - int High(void) const; + T High(void) const + { + return mHigh; + } //! Property set - High - void High(const int &value); + void High(const T &value) + { + if (value >= mLow) + { + mHigh = value; + } + } //! Property get - Low - int Low(void) const; + T Low(void) const + { + return mLow; + } //! Property set - Low - void Low(const int &value); + void Low(const T &value) + { + if (value <= mHigh) + { + mLow = value; + } + } //! Property get - Last random number to be generated - int LastRandom(void) const; + T LastRandom(void) const + { + return mLastRandom; + } private: - int mHigh; - int mLow; - int mLastRandom; + T mHigh; + T mLow; + T mLastRandom; }; } }