📄 code.cpp
字号:
#include "StdAfx.h"
#include "Code.h"
CCode::CCode(void)
: m_LineNumber(0)
{
this->m_Code = new codelinelist_t();
}
CCode::~CCode(void)
{
codelinelist_t::iterator cLine = this->m_Code->begin();
while(cLine != this->m_Code->end())
{
CCodeLine *currentLine = *cLine;
delete currentLine;
cLine++;
}
delete this->m_Code;
}
// Add a line of code to the listing
void CCode::Add(CCodeLine * CodeLine)
{
// If there is already a line of code under this
// line number, replace it
CCodeLine *thisCodeLine = this->Find(CodeLine->GetLineNumber());
if(thisCodeLine != NULL)
{
// Check to see if we were passed an empty line,
// in which case, just delete the line of code
if(CodeLine->GetCode().length() == 0)
{
this->m_Code->remove(thisCodeLine);
}
else
{
thisCodeLine->SetCode(CodeLine->GetCode());
}
}
else
{
// Otherwise, push the symbol onto the list
this->m_Code->push_back(CodeLine);
}
// Sort the source listing into ascending numeric order
this->m_Code->sort(CCodeLine::Compare);
// Make sure that the iterator is pointing at the end of the listing,
// since we're adding lines of code
this->m_CodeIterator = this->m_Code->end();
}
// Find a line of code by line number
CCodeLine * CCode::Find(unsigned int LineNumber)
{
// Iterate over the source listing, find the line that
// matches and return
codelinelist_t::iterator codeline = this->m_Code->begin();
while(codeline != this->m_Code->end())
{
CCodeLine *thisCodeLine = *codeline;
if(thisCodeLine->GetLineNumber() == LineNumber)
{
this->m_LineNumber = LineNumber;
// Set the iterator to equal the codeline in question
this->m_CodeIterator = codeline;
return thisCodeLine;
}
codeline++;
}
// If it wasn't found, just return null
return NULL;
}
// Get the next code line
CCodeLine * CCode::GetNext(void)
{
if(this->m_CodeIterator == this->m_Code->end())
{
return NULL;
}
CCodeLine *curline = *this->m_CodeIterator;
this->m_LineNumber = curline->GetLineNumber();
this->m_CodeIterator++;
return curline;
}
// Reset the code iterator
void CCode::Reset(void)
{
this->m_CodeIterator = this->m_Code->begin();
this->m_LineNumber = 0;
}
// Get the current line number
int CCode::GetCurrentLineNumber(void)
{
return this->m_LineNumber;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -