[ µwe||e ].Coding.Cpp.CArray


[Home] + [Coding] + [Downloads] + [Bookmarks]

C++

      [ Get a sample Snippet ]

[ CArray.hpp ]

//-------------------------------------------------------------------------------------//
//+++++++++++++++++[ Array_Class_Header ]++++++++++++++++++++++++++++++++++++++++++++++//
//-------------------------------------------------------------------------------------//
//
//
// [::STATIC ARRAY CLASS::]
//
// [::Last modi: 15.03.07 L.ey (µ~)::]  
//
//
#ifndef _C_ARRAY_H_
 #define _C_ARRAY_H_

 #include <windows.h>

 //+++++++++++++++++[ Const C_Array ]+++++++++++++++++++++++++++++++++++++++++++++++++++//
 const ARRAY_STATUS_READY = 1;
const ARRAY_STATUS_ERROR = 0;

//+++++++++++++++++[ Class C_Array ]+++++++++++++++++++++++++++++++++++++++++++++++++++// class C_Array
{
public://+++++++öffentlicher Zugriff+++++++// C_Array(); ~C_Array(); unsigned long _Create(unsigned long nItem, unsigned long cItem);
unsigned long _Destroy();

// (!) offset[0] = Item nr.1 // unsigned long _Get_Item(unsigned long offset, void* pDataDst);
unsigned long _Set_Item(unsigned long offset, void* pDataSrc);

unsigned long _Get_pItem(unsigned long offset);

char* _Get_pBuffer() const;
unsigned long _Get_cBuffer() const;

unsigned long _Get_nItem() const;
unsigned long _Get_cItem() const;

unsigned long _Get_Status() const;

private://++++++privater Zugriff+++++++++++// protected://++++geschützter Zugriff++++++++// char* _pBuffer; // DeltaPointer unsigned long _cBuffer; // FullSize unsigned long _nItem; // Item count unsigned long _cItem; // Item size unsigned long _Status; // }; #endif // _C_ARRAY_H_



[ CArray.cpp ]

//-------------------------------------------------------------------------------------//
//+++++++++++++++++[ Array_Class_Source ]++++++++++++++++++++++++++++++++++++++++++++++//
//-------------------------------------------------------------------------------------//
#include "C_Array.hpp"

/////////////////////////////////////////////////////////////////////////////////////////
////////  [Konstructor]  ////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
C_Array::C_Array()
{
   _Status  = ARRAY_STATUS_ERROR;

   _cItem   = 0;
_nItem = 0;
_cBuffer = 0;
_pBuffer = 0;
}
///////////////////////////////////////////////////////////////////////////////////////// //////// [Destructor] ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// C_Array::~C_Array() { _Destroy(); } ///////////////////////////////////////////////////////////////////////////////////////// //////// [_Create] //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// unsigned long C_Array::_Create(unsigned long nItem, unsigned long cItem)
{
if(_Status == ARRAY_STATUS_READY) return(2); // First Destroy the Array _pBuffer = new char[nItem * cItem];

if(_pBuffer == 0) return(0);

_Status = ARRAY_STATUS_READY;

_nItem = nItem;
_cItem = cItem;
_cBuffer = nItem * cItem;

return(1);
}
///////////////////////////////////////////////////////////////////////////////////////// //////// [_Destroy] /////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// unsigned long C_Array::_Destroy()
{
if(_Status == ARRAY_STATUS_ERROR) return(2);

delete [] _pBuffer;

_Status = ARRAY_STATUS_ERROR;

_nItem = 0;
_cItem = 0;
_cBuffer = 0;
_pBuffer = 0;

return(1);
}
///////////////////////////////////////////////////////////////////////////////////////// //////// [_Get_Status] //////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// unsigned long C_Array::_Get_Status() const { return(_Status);
}
///////////////////////////////////////////////////////////////////////////////////////// //////// [_Get_pItem] ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// unsigned long C_Array::_Get_pItem(unsigned long offset)
{
if(_Status == ARRAY_STATUS_ERROR) return(0);

return( (unsigned long)_pBuffer + (offset * _cItem) );
}
///////////////////////////////////////////////////////////////////////////////////////// //////// [_Get_Item] ////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// unsigned long C_Array::_Get_Item(unsigned long offset, void* pDataDst)
{
char* pDataSrc = 0;
unsigned long cDataSrc = _cItem;

if(!pDataDst) return(0);

if(offset > _nItem) return(0); // OverFlow pDataSrc = (char*) _pBuffer;
pDataSrc += offset * _cItem;

memcpy(pDataDst, pDataSrc, _cItem);

return(1);
}
///////////////////////////////////////////////////////////////////////////////////////// //////// [_Set_Item] ////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// unsigned long C_Array::_Set_Item(unsigned long offset, void* pDataSrc)
{
char* pDataDst = 0;
unsigned long cDataDst = _cItem;

if(!pDataSrc) return(0);

if(offset > _nItem) return(0); // OverFlow pDataDst = (char*) _pBuffer;
pDataDst += offset * _cItem;

memcpy(pDataDst, pDataSrc, _cItem);

return(1);
}
///////////////////////////////////////////////////////////////////////////////////////// //////// [_Get_pBuffer] /////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// char* C_Array::_Get_pBuffer() const { return(_pBuffer);
}
///////////////////////////////////////////////////////////////////////////////////////// //////// [_Get_Size] ////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// unsigned long C_Array::_Get_cBuffer() const { return(_cBuffer);
}
///////////////////////////////////////////////////////////////////////////////////////// //////// [_Get_ItemSize] ////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// unsigned long C_Array::_Get_cItem() const { return(_cItem);
}
///////////////////////////////////////////////////////////////////////////////////////// //////// [_Get_ItemCount] ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// unsigned long C_Array::_Get_nItem() const { return(_nItem);
}

[Сê] `.´ [µwe||e]
Hosted by www.Geocities.ws

1