Go to the documentation of this file.00001 #ifndef gevd_memory_mixin_h_
00002 #define gevd_memory_mixin_h_
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 #include "gevd_status_mixin.h"
00028
00029
00030
00031
00032
00033
00034
00035 #define MM_PROTECTED_FLAGS 0x000001CE // bits that may not be altered
00036
00037
00038
00039 #define MM_MEMORY_ERROR 0x00000083 // unable to allocate buffer
00040 #define MM_DATA_OVERFLOW 0x00000004 // past initialized data
00041 #define MM_OVERFLOW 0x00000088 // past allocated space
00042 #define MM_UNDERFLOW 0x000000C0 // read before allocated space
00043
00044
00045
00046 #define MM_NIL_BUFFER 0x00000001 // buffer is nil buffer
00047 #define MM_DIRTY 0x00000010 // buffer changed since alloced
00048 #define MM_FOREIGN_BLOCK 0x00000020 // foreign memory used for buffer
00049 #define MM_ERROR 0x00000080 // error has occurred
00050 #define MM_WARN 0x00000100 // warning has occurred
00051
00052
00053
00054
00055
00056 #define MM_READ 0x00000200 // buffer can be read.
00057 #define MM_WRITE 0x00000400 // buffer can be written to.
00058 #define MM_PROTECTED 0x00000800 // buffer cannot be deleted.
00059 #define MM_FIXED 0x00001000 // buffer cannot be replaced.
00060 #define MM_CLEAR 0x00002000 // buffer cleared at creation. A
00061
00062
00063 #define MM_CREATION_FLAGS 0x00003E00 // Flags used at creation.
00064
00065
00066
00067 class gevd_memory_mixin : public gevd_status_mixin
00068 {
00069 private:
00070 int size;
00071 int touched;
00072 unsigned char* buffer;
00073
00074 int curr_into;
00075 unsigned char* current;
00076
00077 int offset;
00078
00079 protected:
00080 void SetMemoryPtr(int s, void* ib = 0);
00081
00082 inline unsigned char* GetBufferPtr() { return buffer; }
00083 const unsigned char* GetBufferPtr() const { return buffer; }
00084 inline unsigned char* GetCurrentPtr() { return current; }
00085 inline int GetSize() const { return size; }
00086 inline void SetStatus(int x=0) {gevd_status_mixin::SetStatus(x); }
00087 inline void ClearStatus(int x=0) {gevd_status_mixin::ClearStatus(x);}
00088 public:
00089
00090
00091 gevd_memory_mixin(int s = 0, void* ib = 0,
00092 unsigned int type = MM_READ|MM_WRITE);
00093
00094 virtual ~gevd_memory_mixin();
00095 gevd_memory_mixin(gevd_memory_mixin const&);
00096
00097
00098
00099 int GetOffset() const { return offset; }
00100 void SetOffset() { offset = curr_into; }
00101 #define min_(a,b) ((a)<(b)?a:b)
00102 void SkipBytes(int b) { int skip = min_(b,size-curr_into);
00103 current += skip; curr_into += skip;
00104 if (skip<b) SetStatus(MM_OVERFLOW);
00105 if (curr_into>touched)
00106 SetStatus(MM_DATA_OVERFLOW | MM_WARN); }
00107 #undef min_
00108 void SkipToByte(int b) { if (b>size) SetStatus(MM_OVERFLOW);
00109 else {if (b>touched)
00110 SetStatus(MM_DATA_OVERFLOW|MM_WARN);
00111 current = buffer + b;
00112 curr_into = b;} }
00113 void SkipToStart() { current = buffer; curr_into = 0; }
00114 void SkipToDataStart() { current = buffer+offset; curr_into = offset; }
00115
00116
00117
00118 int ReadBytes(void* ib, int b);
00119 int ReadBytes(void* ib, int b, int loc);
00120 int ReadBytes(void* ib, int b, int* mapping);
00121 int ReadBytes(void* ib, int b, int loc, int* mapping);
00122 int WriteBytes(const void* ib, int b);
00123 int WriteBytes(const void* ib, int b, int loc);
00124 void Clear();
00125 };
00126
00127
00128
00129 #endif // gevd_memory_mixin_h_