📄 strstore.cpp
字号:
// StrStore.cpp: implementation of the CStrStore class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "StrStore.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CStrStore::CStrStore()
{
m_pFirstData = NULL;
m_pEndData = NULL;
m_iAmount = 0;
}
CStrStore::~CStrStore()
{
DeleteAllData();
}
//----------------------------------------------------------------------
//Description:
// Add the TCHAR string
//----------------------------------------------------------------------
BOOL CStrStore::Add(const TCHAR * pszIn)
{
PSTOREDATA pNewData = new STOREDATA();
if(pNewData == NULL)
{
return FALSE;
}
int iLen = _tcslen(pszIn);
pNewData->pszString = new TCHAR [iLen + 1];
if(pNewData->pszString == NULL)
{
delete pNewData;
return FALSE;
}
_tcscpy(pNewData->pszString,pszIn);
pNewData->pNextData = NULL;
if(m_pFirstData == NULL)
{
m_pFirstData = pNewData;
}
else
{
m_pEndData->pNextData = pNewData;
}
m_pEndData = pNewData;
m_iAmount ++;
return TRUE;
}
//----------------------------------------------------------------------
//Description:
// Delete all the stored data
//----------------------------------------------------------------------
void CStrStore::DeleteAllData()
{
if(m_pFirstData == NULL)
{
return ;
}
PSTOREDATA pDeleteData = m_pFirstData;
while(m_pFirstData->pNextData != NULL)
{
m_pFirstData = m_pFirstData->pNextData;
delete []pDeleteData->pszString;
delete pDeleteData;
pDeleteData = m_pFirstData;
}
//Delete the last one
delete pDeleteData;
m_pFirstData = NULL;
m_pEndData = NULL;
m_iAmount = 0;
}
//----------------------------------------------------------------------
//Description:
// Get the amount
//----------------------------------------------------------------------
int CStrStore::GetAmount()
{
return m_iAmount;
}
//----------------------------------------------------------------------
//Description:
// Get the data base on the index. And the begin index is 0.
//----------------------------------------------------------------------
BOOL CStrStore::GetData(int iIndex, TCHAR *pszOut, int iSize)
{
if(iIndex < 0 || iIndex >= m_iAmount || pszOut == NULL)
{
return FALSE;
}
int iCount = 0;
PSTOREDATA pData = m_pFirstData;
while(iCount != iIndex)
{
pData = pData->pNextData;
iCount ++;
}
int iLen = _tcslen(pData->pszString);
if(iSize < iLen + 1)
{
return FALSE;
}
_tcscpy(pszOut,pData->pszString);
return TRUE;
}
//----------------------------------------------------------------------
//Description:
// Find the string data and return the index in the storage.
//
//Parameters:
// pcszFind: [in] The string to find
//
//Return Values:
// -1 : failed
// others: succeed.
//----------------------------------------------------------------------
int CStrStore::FindData(const TCHAR *pcszFind)
{
int iIndexFind = 0;
PSTOREDATA pData = m_pFirstData;
while(iIndexFind < m_iAmount)
{
if(_tcscmp(pData->pszString,pcszFind) == 0)
{
break;
}
pData = pData->pNextData;
iIndexFind ++;
}
if(iIndexFind >= m_iAmount)
{
//Failed in finding the string
iIndexFind = -1;
}
return iIndexFind;
}
//----------------------------------------------------------------------
//Description:
// Get the length of the string data base on the index. And the begin index is 0.
//
//Parameters:
// iIndex : [in] The index in the stored data,and it's base on 0.
//
//Return Values:
// -1 : failed
// others: succeed.
//----------------------------------------------------------------------
int CStrStore::GetDataLength(int iIndex)
{
if(iIndex < 0 || iIndex >= m_iAmount)
{
return -1;
}
int iCount = 0;
PSTOREDATA pData = m_pFirstData;
while(iCount != iIndex)
{
pData = pData->pNextData;
iCount ++;
}
return _tcslen(pData->pszString);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -