cMatrix.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:2k
- // CMAIN LIB - APPLICATION AND DIRECT WRAPPER
- //
- // Written by Mauricio Teichmann Ritter
- //
- // Copyright (C) 2002, Brazil. All rights reserved.
- //
- //
- // cMatrix.cpp: implementation of the cMatrix class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "cMatrix.h"
- #include <crtdbg.h>
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- cMatrix::cMatrix()
- {
- // Create a growable heap
- hHeap = HeapCreate(0L, 0, 0);
- m_iCols = 0;
- m_iRows = 0;
- pBuffer = NULL;
- }
- cMatrix::~cMatrix()
- {
- Destroy();
- HeapDestroy(hHeap);
- }
- void cMatrix::Create(int iCols, int iRows)
- {
- pBuffer = (int*) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, iCols * iRows * sizeof(int));
- m_iCols = iCols;
- m_iRows = iRows;
- }
- void cMatrix::Destroy()
- {
- if(pBuffer != NULL)
- {
- HeapFree(hHeap, 0L, (LPVOID) pBuffer);
- pBuffer = NULL;
- }
- }
- int cMatrix::GetValue(int iCol, int iRow)
- {
- _ASSERT(pBuffer != NULL);
- _ASSERT(iCol <= m_iCols - 1);
- _ASSERT(iRow <= m_iRows - 1);
- int* pIterator;
- pIterator = pBuffer;
- pIterator += (iRow * m_iCols);
- pIterator += (iCol);
- return *pIterator;
- }
- void cMatrix::SetValue(int iCol, int iRow, int iValue)
- {
- _ASSERT(pBuffer != NULL);
- _ASSERT(iCol <= m_iCols - 1);
- _ASSERT(iRow <= m_iRows - 1);
- int* pIterator;
- pIterator = pBuffer;
- pIterator += (iRow * m_iCols);
- pIterator += (iCol);
- *pIterator = iValue;
- }
- void cMatrix::SetBuffer(void *pSrcBuffer)
- {
- memcpy((void*) pBuffer, pSrcBuffer, m_iCols * m_iRows * sizeof(int));
- }