HPGCC3 Documentation 3.0 R003

memblock.h

Go to the documentation of this file.
00001 //& *** (c) 2006-2011 The HPGCC3 Team ***
00002 //& Claudio Lapilli
00003 //& Ingo Blank
00004 //&
00005 //& This file is licensed under the terms and conditions of the
00006 //& HPGCC3 license that is included with the source distribution.
00007 //& *** (c) 2006-2011 The HPGCC3 Team ***
00008 
00009 
00010 #ifndef MEMBLOCK_H_
00011 #define MEMBLOCK_H_
00012 
00013 // FLEXIBLE MEMORY BLOCK CLASS
00014 class MemFrag {
00015 public:
00016 int Offset,Size,Used;
00017 char *Data;
00018 MemFrag *Prev,*Next;
00019 BOOL Alloc(int size);
00020 MemFrag();      // DEFAULT CONSTRUCTOR
00021 ~MemFrag();     // DEFAULT DESTRUCTOR
00022 };
00023 
00024 class MemBlock : MemFrag {
00025 protected:
00026         MemFrag *Current,*Last;
00027 
00028         MemFrag *GetFrag(int offset);
00029         void ShiftOffset(MemFrag *block,int shift);
00030         void Consolidate(MemFrag *block);
00031         void MemMoveUp(int destoffset,char *src,int bytes);     // FROM EXTERNAL DATA BLOCK
00032         void MemMoveDn(int destoffset,char *src,int bytes);     // FROM EXTERNAL DATA BLOCK
00033 
00034 
00035 public:
00036 
00037 int TotalUsed;
00038 
00039 int WastedSpace();
00040 
00041 BOOL Append(int bytes,char *Data=NULL); // ADD BYTES AT THE END
00042 void Shrink(int bytes); // REMOVE BYTES AT THE END
00043 BOOL Insert(int offset,int bytes,char *Data=NULL);      // INSERT AT SPECIFIED OFFSET
00044 void Delete(int offset,int bytes);              // REMOVE BYTES AT SPECIFIED OFFSET
00045 
00046 inline char *GetPtr(int offset) { 
00047         return ((offset>=Current->Offset && offset<Current->Offset+Current->Used)?
00048                         (Current->Data+offset-Current->Offset)
00049                         : (Current=GetFrag(offset),(Current->Data+offset-Current->Offset)));
00050         };
00051 int GetLowerLimit(int offset);
00052 int GetUpperLimit(int offset);
00053 
00054 void MemMove(int destoffset,int srcoffset, int bytes);  // INTERNAL MEMORY MOVEMENT
00055 void MemMove(int destoffset,MemBlock &src,int srcoffset,int bytes);     // FROM EXTERNAL MemBlock OBJECT
00056 void MemMove(int destoffset,char *src,int bytes);       // FROM EXTERNAL DATA BLOCK
00057 void MemMove(char *dest,int srcoffset,int bytes);       // COPY TO EXTERNAL DATA BLOCK
00058 
00059 MemBlock();     // CREATE A MEMORY BLOCK OF 0 BYTES
00060 ~MemBlock();
00061 };
00062 
00063 
00064 
00065 
00066 #endif /*MEMBLOCK_H_*/