cmatrix.cpp
来自「Visual C++ 游戏开发与设计实例 源代码(所有)」· C++ 代码 · 共 93 行
CPP
93 行
// 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));
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?