ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

util.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_UTIL_H
00024 #define COMMON_UTIL_H
00025 
00026 #include "common/scummsys.h"
00027 #include "common/str.h"
00028 
00033 #define IS_ALIGNED(value, alignment) \
00034           ((((size_t)value) & ((alignment) - 1)) == 0)
00035 
00036 #ifdef ABS
00037 #undef ABS
00038 #endif
00039 
00040 #ifdef MIN
00041 #undef MIN
00042 #endif
00043 
00044 #ifdef MAX
00045 #undef MAX
00046 #endif
00047 
00048 template<typename T> inline T ABS(T x)      { return (x >= 0) ? x : -x; }
00049 template<typename T> inline T MIN(T a, T b) { return (a < b) ? a : b; }
00050 template<typename T> inline T MAX(T a, T b) { return (a > b) ? a : b; }
00051 template<typename T> inline T CLIP(T v, T amin, T amax)
00052     {
00053 #if !defined(RELEASE_BUILD)
00054         // debug builds use this assert to pinpoint
00055         // any problematic cases, where amin and amax
00056         // are incorrectly ordered
00057         // and thus CLIP() would return an invalid result
00058         assert(amin <= amax);
00059 #endif
00060         if (v < amin) return amin;
00061         else if (v > amax) return amax;
00062         return v;
00063     }
00064 
00068 template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
00069 
00070 #ifdef ARRAYSIZE
00071 #undef ARRAYSIZE
00072 #endif
00073 
00077 #define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
00078 
00082 #define ARRAYEND(x) ((x) + ARRAYSIZE((x)))
00083 
00084 /*
00085  * Clear array using default or provided value
00086  */
00087 template<typename T, size_t N> inline void ARRAYCLEAR(T (&array) [N], const T &value = T()) {
00088     T * ptr = array;
00089     size_t n = N;
00090     while(n--)
00091         *ptr++ = value;
00092 }
00093 
00098 #if defined(__GNUC__)
00099 # define SCUMMVM_CURRENT_FUNCTION __PRETTY_FUNCTION__
00100 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
00101 #  define SCUMMVM_CURRENT_FUNCTION  __func__
00102 #elif defined(_MSC_VER)
00103 #  define SCUMMVM_CURRENT_FUNCTION __FUNCTION__
00104 #else
00105 #  define SCUMMVM_CURRENT_FUNCTION "<unknown>"
00106 #endif
00107 
00108 namespace Common {
00109 
00118 extern void hexdump(const byte * data, int len, int bytesPerLine = 16, int startOffset = 0);
00119 
00120 
00131 bool parseBool(const String &val, bool &valAsBool);
00132 
00133 
00142 bool isAlnum(int c);
00143 
00152 bool isAlpha(int c);
00153 
00162 bool isDigit(int c);
00163 
00172 bool isXDigit(int c);
00173 
00182 bool isLower(int c);
00183 
00194 bool isSpace(int c);
00195 
00204 bool isUpper(int c);
00205 
00216 bool isPrint(int c);
00217 
00225 bool isPunct(int c);
00226 
00233 bool isCntrl(int c);
00234 
00241 bool isGraph(int c);
00242 
00243 
00253 Common::String getHumanReadableBytes(uint64 bytes, Common::String &unitsOut);
00254 
00255 } // End of namespace Common
00256 
00257 #endif


Generated on Sat Sep 12 2020 05:00:44 for ResidualVM by doxygen 1.7.1
curved edge   curved edge