📄 cmatrix.cpp
字号:
// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -