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 
00089 #if defined(__GNUC__)
00090 # define SCUMMVM_CURRENT_FUNCTION __PRETTY_FUNCTION__
00091 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
00092 #  define SCUMMVM_CURRENT_FUNCTION  __func__
00093 #elif defined(_MSC_VER)
00094 #  define SCUMMVM_CURRENT_FUNCTION __FUNCTION__
00095 #else
00096 #  define SCUMMVM_CURRENT_FUNCTION "<unknown>"
00097 #endif
00098 
00099 namespace Common {
00100 
00109 extern void hexdump(const byte * data, int len, int bytesPerLine = 16, int startOffset = 0);
00110 
00111 
00122 bool parseBool(const String &val, bool &valAsBool);
00123 
00124 
00133 bool isAlnum(int c);
00134 
00143 bool isAlpha(int c);
00144 
00153 bool isDigit(int c);
00154 
00163 bool isXDigit(int c);
00164 
00173 bool isLower(int c);
00174 
00185 bool isSpace(int c);
00186 
00195 bool isUpper(int c);
00196 
00207 bool isPrint(int c);
00208 
00216 bool isPunct(int c);
00217 
00224 bool isCntrl(int c);
00225 
00232 bool isGraph(int c);
00233 
00234 
00244 Common::String getHumanReadableBytes(uint64 bytes, Common::String &unitsOut);
00245 
00246 } // End of namespace Common
00247 
00248 #endif


Generated on Sat Jul 4 2020 05:01:03 for ResidualVM by doxygen 1.7.1
curved edge   curved edge