📄 l3_arrex.h
字号:
#ifndef _INCLUDED_L3_ARREX_H#define _INCLUDED_L3_ARREX_H// *Array Exceptions* Copyright (C) Krzysztof Bosak, 2000-11-10...2000-11-20// All rights reserved.// kbosak@box43.pl// http://www.kbosak.prv.pl// neither <exception> nor <stdexcept> are not widely implemented, as for 2000-11-19.#include <string.h>#ifndef NDEBUG #include <string.h>#endif#ifdef USE_ARRAY_EXCEPTIONSclass ArrayEx{protected: static char * const _description; static const unsigned MAX_DESCRIPTION_LENGTH; inline ArrayEx(const char * const strf, int strl, int arrlen) { // protected constructor: you can create an object derived from this class assert(strf!=NULL); assert(_description!=NULL); sprintf(const_cast<char*>(_description), "Compilation stardate is %s, %s.\n" "Array Exception thrown in file %s at line %d.\n" "Last recorded array size was %d.\n", __DATE__, __TIME__, strf, strl, arrlen); assert( strlen(_description)+1 < MAX_DESCRIPTION_LENGTH ); } friend ostream& operator<<(ostream& str, const ArrayEx&) { assert(ArrayEx::_description!=NULL); return str<<ArrayEx::_description; }};char * const ArrayEx::_description=new char[MAX_DESCRIPTION_LENGTH];const unsigned ArrayEx::MAX_DESCRIPTION_LENGTH=1024;class OutOfMemoryEx: public ArrayEx{public: inline OutOfMemoryEx(int cells, int cellsize, const char * const strf, int strl, int arrlen) : ArrayEx(strf, strl, arrlen) { assert( strlen(_description)+1 < MAX_DESCRIPTION_LENGTH ); sprintf(const_cast<char*>(_description)+strlen(_description), "Out Of Memory, tried to allocate %d cell(s), %d byte(s) each (%dKB total).\n", cells, cellsize, static_cast<int>(cells*cellsize/1024.0+0.5)); }};class SentinelOverwrittenEx: public ArrayEx{public: inline SentinelOverwrittenEx(const char * const strf, int strl, int arrlen) : ArrayEx(strf, strl, arrlen) { assert( strlen(_description)+1 < MAX_DESCRIPTION_LENGTH ); sprintf(const_cast<char*>(_description)+strlen(_description), "One of two terminating sentinels were overwritten.\n"); }};class BadIndexEx: public ArrayEx{public: inline BadIndexEx(int bad_array_index, const char * const strf, int strl, int arrlen) : ArrayEx(strf, strl, arrlen) { assert( strlen(_description)+1 < MAX_DESCRIPTION_LENGTH ); sprintf(const_cast<char*>(_description)+strlen(_description), "Unauthorized access out of array boundary, used index: %d.\n", bad_array_index); }};class TooLowIndexEx: public BadIndexEx{public: inline TooLowIndexEx(int bad_array_index, const char * const strf, int strl, int arrlen) : BadIndexEx(bad_array_index, strf, strl, arrlen) { assert( strlen(_description)+1 < MAX_DESCRIPTION_LENGTH ); sprintf(const_cast<char*>(_description)+strlen(_description), "Too low array index.\n"); }};class TooBigIndexEx: public BadIndexEx{public: inline TooBigIndexEx(int bad_array_index, const char * const strf, int strl, int arrlen) : BadIndexEx(bad_array_index, strf, strl, arrlen) { assert( strlen(_description)+1 < MAX_DESCRIPTION_LENGTH ); sprintf(const_cast<char*>(_description)+strlen(_description), "Too big array index.\n"); }};#endif // USE_ARRAY_EXCEPTIONS#endif //_INCLUDED_L3_ARREX_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -