Restructure repository to include all source folders
Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
519
Server/RylServerProject/RylGameLibrary/Utility/DelimitedFile.cpp
Normal file
519
Server/RylServerProject/RylGameLibrary/Utility/DelimitedFile.cpp
Normal file
@@ -0,0 +1,519 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "DelimitedFile.h"
|
||||
|
||||
|
||||
CDelimitedFile::CDelimitedFile(const char* pszDelimiter)
|
||||
: m_fpFile(0), m_dwColumn(0), m_dwColumnCount(0)
|
||||
{
|
||||
m_ColumnNames.reserve(DEFAULT_COLUMN_NUM);
|
||||
strncpy(m_szDelimiter, pszDelimiter, MAX_DELIMITER_NUM);
|
||||
}
|
||||
|
||||
CDelimitedFile::~CDelimitedFile()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
CDelimitedFile::SectionInfo::SectionInfo(std::string& szSectionName, unsigned long dwLine)
|
||||
: m_szSectionName(szSectionName), m_dwLine(dwLine)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool CDelimitedFile::Open( LPCSTR szFilename, int nHeadLine, UINT nOpenFlags )
|
||||
{
|
||||
if ( m_fpFile )
|
||||
{
|
||||
::fclose( m_fpFile );
|
||||
m_fpFile = 0;
|
||||
}
|
||||
|
||||
m_fpFile = ::fopen( szFilename, (nOpenFlags & modeCreate) ? "wt" : "rt" );
|
||||
if (NULL == m_fpFile)
|
||||
{
|
||||
#ifdef ERRLOG2
|
||||
unsigned long dwError = ::GetLastError();
|
||||
ERRLOG2(g_Log, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> %s<><73> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. Error Code : %d", szFilename, dwError);
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nHeadLine > -1)
|
||||
{
|
||||
for (int i = 0; i < nHeadLine; )
|
||||
{
|
||||
if (true == ReadLine())
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
for (m_dwColumnCount = 0; true; ++m_dwColumnCount)
|
||||
{
|
||||
char* szColumnName = new char[MAX_COLUMN_LENGHT];
|
||||
|
||||
if (0 == szColumnName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (false == ReadString(szColumnName, MAX_COLUMN_LENGHT - 1))
|
||||
{
|
||||
delete szColumnName;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t nLength = strlen(szColumnName);
|
||||
while (nLength-- > 0)
|
||||
{
|
||||
if (szColumnName[nLength] == '\r' || szColumnName[nLength] == '\n')
|
||||
{
|
||||
szColumnName[nLength] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
szColumnName[MAX_COLUMN_LENGHT - 1] = 0;
|
||||
m_ColumnNames.push_back(szColumnName);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CDelimitedFile::Close( void )
|
||||
{
|
||||
if ( m_fpFile )
|
||||
{
|
||||
::fclose( m_fpFile );
|
||||
m_fpFile = 0;
|
||||
}
|
||||
|
||||
ColumnArray::size_type nTotalSize = m_ColumnNames.size();
|
||||
for (ColumnArray::size_type nCount = 0; nCount < nTotalSize; ++nCount)
|
||||
{
|
||||
delete [] m_ColumnNames[nCount];
|
||||
}
|
||||
|
||||
m_ColumnNames.clear();
|
||||
}
|
||||
|
||||
unsigned long CDelimitedFile::GetSection(std::string& szSectionName)
|
||||
{
|
||||
for (SectionArray::iterator it = m_SectionInfo.begin(); it != m_SectionInfo.end(); ++it)
|
||||
{
|
||||
if (szSectionName == it->m_szSectionName)
|
||||
{
|
||||
return it->m_dwLine;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadSection(void)
|
||||
{
|
||||
char szBuffer[MAX_LINE_LENGTH];
|
||||
unsigned long dwLine = 1;
|
||||
|
||||
m_SectionInfo.clear();
|
||||
|
||||
while (NULL != fgets(szBuffer, MAX_LINE_LENGTH, m_fpFile))
|
||||
{
|
||||
std::string strSectionIn = std::string(szBuffer);
|
||||
|
||||
if (';' == *(strSectionIn.begin()) || 0 == strcmp("\n", strSectionIn.c_str()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('[' == *(strSectionIn.begin()))
|
||||
{
|
||||
std::string::iterator end = std::find(strSectionIn.begin(), strSectionIn.end(), ']');
|
||||
if (end != strSectionIn.end())
|
||||
{
|
||||
std::string strSectionOut;
|
||||
strSectionOut.assign(strSectionIn.begin() + 1, end);
|
||||
m_SectionInfo.push_back(SectionInfo(strSectionOut, dwLine));
|
||||
}
|
||||
}
|
||||
|
||||
++dwLine;
|
||||
}
|
||||
|
||||
if (true == m_SectionInfo.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
rewind(m_fpFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadLine(void)
|
||||
{
|
||||
while (NULL != ::fgets(m_szLine, MAX_LINE_LENGTH, m_fpFile))
|
||||
{
|
||||
if (0 == strcmp("\n", m_szLine))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (';' != m_szLine[0])
|
||||
{
|
||||
m_dwColumn = 0;
|
||||
memcpy(m_szBackupLine, m_szLine, MAX_LINE_LENGTH);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><> C++ <20><>Ÿ<EFBFBD><C5B8> <20>ּ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
bool CDelimitedFile::ReadLine2nd(void)
|
||||
{
|
||||
while (NULL != ::fgets(m_szLine, MAX_LINE_LENGTH, m_fpFile))
|
||||
{
|
||||
// <20><><EFBFBD>ڿ<EFBFBD> ó<><C3B3><EFBFBD>κп<CEBA> <20>ִ<EFBFBD> Tab <20><><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>
|
||||
int iEnd = 0;
|
||||
while (true)
|
||||
{
|
||||
if ('\t' == m_szLine[iEnd])
|
||||
{
|
||||
++iEnd;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (0 != iEnd)
|
||||
{
|
||||
strcpy(m_szLine, m_szLine + iEnd);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == strcmp("\n", m_szLine))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('/' != m_szLine[0] && '/' != m_szLine[1])
|
||||
{
|
||||
m_dwColumn = 0;
|
||||
memcpy(m_szBackupLine, m_szLine, MAX_LINE_LENGTH);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData( bool &bNumber )
|
||||
{
|
||||
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
|
||||
|
||||
if ( !pszData || !(*pszData) )
|
||||
return false;
|
||||
|
||||
bNumber = false;
|
||||
if (atoi(pszData) == 1)
|
||||
bNumber = true;
|
||||
|
||||
char szString[2];
|
||||
strncpy(szString, pszData, 1);
|
||||
if (NULL == ::strcmp(szString, "O"))
|
||||
bNumber = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData( double &dNumber )
|
||||
{
|
||||
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
|
||||
|
||||
if ( !pszData || !(*pszData) )
|
||||
return false;
|
||||
dNumber = atof( pszData );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData( float &fNumber )
|
||||
{
|
||||
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
|
||||
|
||||
if ( !pszData || !(*pszData) )
|
||||
return false;
|
||||
fNumber = (float) atof( pszData );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData( long &lNumber )
|
||||
{
|
||||
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
|
||||
|
||||
if ( !pszData || !(*pszData) )
|
||||
return false;
|
||||
lNumber = (long) atol( pszData );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData( unsigned long &fNumber )
|
||||
{
|
||||
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
|
||||
|
||||
if ( !pszData || !(*pszData) )
|
||||
return false;
|
||||
fNumber = (unsigned long) atol( pszData );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData( int &iNumber )
|
||||
{
|
||||
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
|
||||
|
||||
if ( !pszData || !(*pszData) )
|
||||
return false;
|
||||
iNumber = atoi( pszData );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData( unsigned short &iNumber )
|
||||
{
|
||||
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
|
||||
|
||||
if ( !pszData || !(*pszData) )
|
||||
return false;
|
||||
iNumber = (unsigned short)atoi( pszData );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData( short &iNumber )
|
||||
{
|
||||
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
|
||||
|
||||
if ( !pszData || !(*pszData) )
|
||||
return false;
|
||||
iNumber = (short)atoi( pszData );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData( unsigned char &iNumber )
|
||||
{
|
||||
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
|
||||
|
||||
if ( !pszData || !(*pszData) )
|
||||
return false;
|
||||
iNumber = (unsigned char)atoi( pszData );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData( char &iNumber )
|
||||
{
|
||||
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
|
||||
|
||||
if ( !pszData || !(*pszData) )
|
||||
return false;
|
||||
iNumber = (char)atoi( pszData );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData( __int64 &i64Number )
|
||||
{
|
||||
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
|
||||
|
||||
if ( !pszData || !(*pszData) )
|
||||
return false;
|
||||
i64Number = _atoi64( pszData );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData( DWORD64 &i64Number )
|
||||
{
|
||||
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
|
||||
|
||||
if ( !pszData || !(*pszData) )
|
||||
return false;
|
||||
i64Number = (unsigned long)_atoi64( pszData );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadString( char *szString, unsigned long dwSize )
|
||||
{
|
||||
CHAR *pszData = ::strtok( (m_dwColumn++) ? NULL : m_szLine, m_szDelimiter );
|
||||
|
||||
if ( !pszData || !(*pszData) )
|
||||
return false;
|
||||
strncpy(szString, pszData, dwSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData(const char *szField, double &dNumber )
|
||||
{
|
||||
int nSearch;
|
||||
|
||||
if ( ((nSearch = FindColumn( szField )) == -1) )
|
||||
return false;
|
||||
GotoColumn( nSearch );
|
||||
return ReadData( dNumber );
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData(const char *szField, float &fNumber )
|
||||
{
|
||||
int nSearch;
|
||||
|
||||
if ( ((nSearch = FindColumn( szField )) == -1) )
|
||||
return false;
|
||||
GotoColumn( nSearch );
|
||||
return ReadData( fNumber );
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData(const char *szField, long &lNumber )
|
||||
{
|
||||
int nSearch;
|
||||
|
||||
if( ((nSearch = FindColumn( szField )) == -1) )
|
||||
return FALSE;
|
||||
GotoColumn( nSearch );
|
||||
return ReadData( lNumber );
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData(const char *szField, unsigned long &fNumber )
|
||||
{
|
||||
int nSearch;
|
||||
|
||||
if ( ((nSearch = FindColumn( szField )) == -1) )
|
||||
return false;
|
||||
GotoColumn( nSearch );
|
||||
return ReadData( fNumber );
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData(const char *szField, int &iNumber )
|
||||
{
|
||||
int nSearch;
|
||||
|
||||
if ( ((nSearch = FindColumn( szField )) == -1) )
|
||||
return false;
|
||||
GotoColumn( nSearch );
|
||||
return ReadData( iNumber );
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData(const char *szField, unsigned short &iNumber )
|
||||
{
|
||||
int nSearch;
|
||||
|
||||
if ( ((nSearch = FindColumn( szField )) == -1) )
|
||||
return false;
|
||||
GotoColumn( nSearch );
|
||||
return ReadData( iNumber );
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData(const char *szField, short &iNumber )
|
||||
{
|
||||
int nSearch;
|
||||
|
||||
if ( ((nSearch = FindColumn( szField )) == -1) )
|
||||
return false;
|
||||
GotoColumn( nSearch );
|
||||
return ReadData( iNumber );
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData(const char *szField, unsigned char &iNumber )
|
||||
{
|
||||
int nSearch;
|
||||
|
||||
if ( ((nSearch = FindColumn( szField )) == -1) )
|
||||
return false;
|
||||
GotoColumn( nSearch );
|
||||
return ReadData( iNumber );
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData(const char *szField, char &iNumber )
|
||||
{
|
||||
int nSearch;
|
||||
|
||||
if ( ((nSearch = FindColumn( szField )) == -1) )
|
||||
return false;
|
||||
GotoColumn( nSearch );
|
||||
return ReadData( iNumber );
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData(const char *szField, __int64 &i64Number )
|
||||
{
|
||||
int nSearch;
|
||||
|
||||
if ( ((nSearch = FindColumn( szField )) == -1) )
|
||||
return false;
|
||||
GotoColumn( nSearch );
|
||||
return ReadData( i64Number );
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadData(const char *szField, DWORD64 &i64Number )
|
||||
{
|
||||
int nSearch;
|
||||
|
||||
if ( ((nSearch = FindColumn( szField )) == -1) )
|
||||
return false;
|
||||
GotoColumn( nSearch );
|
||||
return ReadData( i64Number );
|
||||
}
|
||||
|
||||
bool CDelimitedFile::ReadString(const char *szField, char *szString, unsigned long dwSize )
|
||||
{
|
||||
int nSearch;
|
||||
|
||||
if ( ((nSearch = FindColumn( szField )) == -1) )
|
||||
return false;
|
||||
GotoColumn( nSearch );
|
||||
return ReadString( szString, dwSize );
|
||||
}
|
||||
|
||||
bool CDelimitedFile::GotoColumn( int nColumn )
|
||||
{
|
||||
CHAR* pszPos = 0;
|
||||
|
||||
if (nColumn < 0 || (unsigned long)nColumn > m_dwColumnCount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((m_dwColumn == (unsigned long) nColumn)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( nColumn == 0 ) {
|
||||
m_dwColumn = 0;
|
||||
strtok(m_szLine, m_szDelimiter);
|
||||
}
|
||||
else {
|
||||
for (;m_dwColumn < m_dwColumnCount && nColumn != m_dwColumn; ++m_dwColumn )
|
||||
pszPos = strtok(0, m_szDelimiter);
|
||||
|
||||
if (m_dwColumn == m_dwColumnCount) {
|
||||
memcpy(m_szLine, m_szBackupLine, MAX_LINE_LENGTH);
|
||||
pszPos = strtok(m_szLine, m_szDelimiter);
|
||||
for (m_dwColumn = 1; m_dwColumn < (unsigned long)nColumn && nColumn != m_dwColumn; ++m_dwColumn ) {
|
||||
pszPos = strtok(NULL, m_szDelimiter );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int CDelimitedFile::FindColumn(const char *szField)
|
||||
{
|
||||
for (ColumnArray::size_type nCount = 0; nCount < m_ColumnNames.size(); ++nCount)
|
||||
{
|
||||
const char* szColumnName = m_ColumnNames[nCount];
|
||||
if (0 == strcmp(szField, szColumnName))
|
||||
{
|
||||
return static_cast<int>(nCount);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
103
Server/RylServerProject/RylGameLibrary/Utility/DelimitedFile.h
Normal file
103
Server/RylServerProject/RylGameLibrary/Utility/DelimitedFile.h
Normal file
@@ -0,0 +1,103 @@
|
||||
#ifndef _DELIMITED_FILE_H_
|
||||
#define _DELIMITED_FILE_H_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class CDelimitedFile
|
||||
{
|
||||
public:
|
||||
|
||||
// MAX Delimiter num is 32;
|
||||
CDelimitedFile(const char* pszDelimiter = "\t");
|
||||
~CDelimitedFile();
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_LINE_LENGTH = 16384,
|
||||
MAX_DELIMITER_NUM = 32,
|
||||
MAX_COLUMN_LENGHT = 64,
|
||||
DEFAULT_COLUMN_NUM = 32
|
||||
};
|
||||
|
||||
enum OpenFlags
|
||||
{
|
||||
modeRead = (int) 0x00000,
|
||||
modeCreate = (int) 0x01000
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
struct SectionInfo
|
||||
{
|
||||
unsigned long m_dwLine;
|
||||
std::string m_szSectionName;
|
||||
|
||||
SectionInfo() : m_dwLine(0) { m_szSectionName.clear(); }
|
||||
SectionInfo(std::string& szSectionName, unsigned long dwLine);
|
||||
};
|
||||
|
||||
|
||||
FILE* m_fpFile;
|
||||
|
||||
unsigned long m_dwColumn;
|
||||
unsigned long m_dwColumnCount;
|
||||
|
||||
char m_szLine[MAX_LINE_LENGTH];
|
||||
char m_szBackupLine[MAX_LINE_LENGTH];
|
||||
char m_szDelimiter[MAX_DELIMITER_NUM];
|
||||
|
||||
typedef std::vector<char*> ColumnArray;
|
||||
typedef std::vector<SectionInfo> SectionArray;
|
||||
|
||||
ColumnArray m_ColumnNames;
|
||||
SectionArray m_SectionInfo;
|
||||
|
||||
|
||||
int FindColumn(const char *szField );
|
||||
bool GotoColumn( int nColumn );
|
||||
|
||||
public:
|
||||
|
||||
bool Open(LPCSTR szFilename, int nHeadLine = -1, UINT nOpenFlags = modeRead );
|
||||
void Close();
|
||||
|
||||
unsigned long GetSection(std::string& szSectionName);
|
||||
bool ReadSection(void);
|
||||
bool ReadLine2nd(void); // <20><><EFBFBD><EFBFBD> <20><> C++ <20><>Ÿ<EFBFBD><C5B8> <20>ּ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
bool ReadLine(); // ; <20>ּ<EFBFBD><D6BC><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
bool ReadData(bool &bNumber);
|
||||
bool ReadData(double &dNumber);
|
||||
bool ReadData(float &fNumber);
|
||||
bool ReadData(long &lNumber);
|
||||
bool ReadData(unsigned long &fNumber);
|
||||
bool ReadData(int &iNumber);
|
||||
bool ReadData(unsigned short &iNumber);
|
||||
bool ReadData(short &iNumber);
|
||||
bool ReadData(unsigned char &iNumber);
|
||||
bool ReadData(char &iNumber);
|
||||
bool ReadData(__int64 &i64Number);
|
||||
bool ReadData(DWORD64 &i64Number);
|
||||
bool ReadString(char *szString, unsigned long dwSize);
|
||||
|
||||
bool ReadData(const char *szField, double &dNumber);
|
||||
bool ReadData(const char *szField, float &fNumber);
|
||||
bool ReadData(const char *szField, long &lNumber );
|
||||
bool ReadData(const char *szField, unsigned long &fNumber);
|
||||
bool ReadData(const char *szField, int &iNumber);
|
||||
bool ReadData(const char *szField, unsigned short &iNumber);
|
||||
bool ReadData(const char *szField, short &iNumber);
|
||||
bool ReadData(const char *szField, unsigned char &iNumber);
|
||||
bool ReadData(const char *szField, char &iNumber);
|
||||
bool ReadData(const char *szField, __int64 &i64Number);
|
||||
bool ReadData(const char *szField, DWORD64 &i64Number);
|
||||
bool ReadString(const char *szField, char *szString, unsigned long dwSize);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,159 @@
|
||||
#include "stdafx.h"
|
||||
#include "TokenlizedFile.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <Utility/Math/Math.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
char* trim_string(char* szString)
|
||||
{
|
||||
while(*szString == '\r'|| *szString == '\n' || *szString == ' ')
|
||||
{
|
||||
++szString;
|
||||
}
|
||||
|
||||
char* szTail = szString + strlen(szString);
|
||||
|
||||
while(szString != szTail
|
||||
&& (*szTail == '\r'|| *szTail == '\n' || *szTail == ' ' || *szTail == '\0'))
|
||||
{
|
||||
*szTail = 0;
|
||||
--szTail;
|
||||
}
|
||||
|
||||
return szString;
|
||||
}
|
||||
|
||||
|
||||
CTokenlizedFile::ColumnInfo::ColumnInfo(const char* szColumnName, unsigned int dwIndex)
|
||||
: m_dwHashKey(Math::HashFunc::sdbmHash(reinterpret_cast<const unsigned char*>(szColumnName))),
|
||||
m_szColumnName(szColumnName), m_dwIndex(dwIndex)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CTokenlizedFile::CTokenlizedFile(const char* lpszDelimiter)
|
||||
: m_lpFile(0), m_nLine(0)
|
||||
{
|
||||
strncpy(m_szDelimiter, lpszDelimiter, MAX_DELIMITER_NUM - 1);
|
||||
m_szDelimiter[MAX_DELIMITER_NUM - 1] = '\0';
|
||||
|
||||
m_ColumnInfo.reserve(DEFAULT_COLUMN_NUM);
|
||||
m_ColumnValues.reserve(DEFAULT_COLUMN_NUM);
|
||||
}
|
||||
|
||||
CTokenlizedFile::~CTokenlizedFile()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CTokenlizedFile::Close(void)
|
||||
{
|
||||
if (0 != m_lpFile)
|
||||
{
|
||||
fclose(m_lpFile);
|
||||
m_lpFile = 0;
|
||||
}
|
||||
|
||||
m_ColumnInfo.clear();
|
||||
m_ColumnValues.clear();
|
||||
}
|
||||
|
||||
|
||||
bool CTokenlizedFile::Open(const char* szFilename, const char* szOpenMode)
|
||||
{
|
||||
Close();
|
||||
|
||||
m_nLine = 0;
|
||||
m_lpFile = fopen(szFilename, szOpenMode);
|
||||
return (0 != m_lpFile) ? true : false;
|
||||
}
|
||||
|
||||
|
||||
bool CTokenlizedFile::ReadColumn(void)
|
||||
{
|
||||
m_ColumnInfo.clear();
|
||||
|
||||
if (0 != fgets(m_szColumn, MAX_LINE_BUFFER, m_lpFile))
|
||||
{
|
||||
char* szToken = strtok(m_szColumn, m_szDelimiter);
|
||||
unsigned int dwIndex = 0;
|
||||
|
||||
do
|
||||
{
|
||||
m_ColumnInfo.push_back(ColumnInfo(trim_string(szToken), dwIndex));
|
||||
++dwIndex;
|
||||
|
||||
} while (0 != (szToken = strtok(0, m_szDelimiter)));
|
||||
|
||||
++m_nLine;
|
||||
std::sort(m_ColumnInfo.begin(), m_ColumnInfo.end());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CTokenlizedFile::ReadLine(void)
|
||||
{
|
||||
m_ColumnValues.clear();
|
||||
|
||||
if (0 != fgets(m_szLine, MAX_LINE_BUFFER, m_lpFile))
|
||||
{
|
||||
if (0 == strcmp("\n", m_szLine))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
char* szToken = strtok(m_szLine, m_szDelimiter);
|
||||
|
||||
do
|
||||
{
|
||||
m_ColumnValues.push_back(trim_string(szToken));
|
||||
|
||||
} while (0 != (szToken = strtok(0, m_szDelimiter)));
|
||||
|
||||
++m_nLine;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const char* CTokenlizedFile::GetStringValue(const char* szColumnName)
|
||||
{
|
||||
ColumnInfo Info(szColumnName, 0);
|
||||
|
||||
pair<ColumnArray::iterator, ColumnArray::iterator> pair =
|
||||
std::equal_range(m_ColumnInfo.begin(), m_ColumnInfo.end(), Info);
|
||||
|
||||
for(;pair.first != pair.second; ++pair.first)
|
||||
{
|
||||
ColumnInfo& Index = *pair.first;
|
||||
|
||||
if (0 == strcmp(Info.m_szColumnName, Index.m_szColumnName))
|
||||
{
|
||||
return GetStringValue(Index.m_dwIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const char* CTokenlizedFile::GetColumnName(size_t nIndex)
|
||||
{
|
||||
return (nIndex < m_ColumnInfo.size()) ?
|
||||
m_ColumnInfo[nIndex].m_szColumnName : 0;
|
||||
}
|
||||
|
||||
const char* CTokenlizedFile::GetStringValue(size_t nIndex)
|
||||
{
|
||||
return (nIndex < m_ColumnValues.size()) ?
|
||||
m_ColumnValues[nIndex] : 0;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
#ifndef _CUSTOM_TOKENLIZED_FILE_H_
|
||||
#define _CUSTOM_TOKENLIZED_FILE_H_
|
||||
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
class CTokenlizedFile
|
||||
{
|
||||
public:
|
||||
|
||||
CTokenlizedFile(const char* lpszDelimiter = "\t");
|
||||
~CTokenlizedFile();
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_LINE_BUFFER = 16384,
|
||||
MAX_DELIMITER_NUM = 16,
|
||||
DEFAULT_COLUMN_NUM = 64
|
||||
};
|
||||
|
||||
bool Open(const char* szFilename, const char* szOpenMode = "rt");
|
||||
void Close(void);
|
||||
|
||||
bool ReadColumn(void); // <20>÷<EFBFBD> <20≯<EFBFBD><CCB8><EFBFBD> <20>д´<D0B4>.
|
||||
bool ReadLine(void); // <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>д´<D0B4>.
|
||||
|
||||
bool IsEOF(void) { return (NULL != m_lpFile) ? (0 != feof(m_lpFile)) : false; }
|
||||
|
||||
size_t GetColumnNum(void) { return m_ColumnInfo.size(); }
|
||||
size_t GetCurrentLine(void) { return m_nLine; }
|
||||
size_t GetValueNum(void) { return m_ColumnValues.size(); }
|
||||
|
||||
const char* GetColumnName(size_t nIndex);
|
||||
const char* GetStringValue(size_t nIndex);
|
||||
const char* GetStringValue(const char* szColumnName);
|
||||
|
||||
private:
|
||||
|
||||
struct ColumnInfo
|
||||
{
|
||||
unsigned long m_dwHashKey;
|
||||
unsigned int m_dwIndex;
|
||||
const char* m_szColumnName;
|
||||
|
||||
ColumnInfo() : m_dwHashKey(0), m_dwIndex(0), m_szColumnName(0) { }
|
||||
ColumnInfo(const char* szColumnName, unsigned int dwIndex);
|
||||
|
||||
bool operator < (const ColumnInfo& rhsInfo) const { return m_dwHashKey < rhsInfo.m_dwHashKey; }
|
||||
};
|
||||
|
||||
FILE* m_lpFile;
|
||||
size_t m_nLine;
|
||||
|
||||
char m_szDelimiter[MAX_DELIMITER_NUM];
|
||||
char m_szColumn[MAX_LINE_BUFFER];
|
||||
char m_szLine[MAX_LINE_BUFFER];
|
||||
|
||||
typedef std::vector<ColumnInfo> ColumnArray;
|
||||
typedef std::vector<char*> ValueArray;
|
||||
|
||||
ColumnArray m_ColumnInfo;
|
||||
ValueArray m_ColumnValues;
|
||||
};
|
||||
|
||||
#endif
|
||||
18
Server/RylServerProject/RylGameLibrary/Utility/TypeArray.cpp
Normal file
18
Server/RylServerProject/RylGameLibrary/Utility/TypeArray.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "TypeArray.h"
|
||||
|
||||
|
||||
bool CTypeName::Test(const CTypeName* lpTypeArray, int nArrayNum, const char* lpTypeArrayName)
|
||||
{
|
||||
for(int nCount = 0; nCount < nArrayNum; ++nCount)
|
||||
{
|
||||
if(lpTypeArray[nCount].m_nType != nCount)
|
||||
{
|
||||
ERRLOG2(g_Log, "<EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD> Ÿ<>Ե<EFBFBD><D4B5><EFBFBD> <20>迭 <20>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD> Ÿ<><C5B8> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>."
|
||||
"Ÿ<EFBFBD><EFBFBD> <20><><EFBFBD>̺<EFBFBD> <20≯<EFBFBD><CCB8><EFBFBD> %s<>̰<EFBFBD>, <20><><EFBFBD><EFBFBD> <20>ʴ<EFBFBD> Ŀ<>ǵ<EFBFBD> <20><>ȣ<EFBFBD><C8A3> %d<>Դϴ<D4B4>.", lpTypeArrayName, nCount);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
22
Server/RylServerProject/RylGameLibrary/Utility/TypeArray.h
Normal file
22
Server/RylServerProject/RylGameLibrary/Utility/TypeArray.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef _TYPE_ARRAY_H_
|
||||
#define _TYPE_ARRAY_H_
|
||||
|
||||
class CTypeName
|
||||
{
|
||||
public:
|
||||
|
||||
CTypeName() : m_nType(0), m_lpszName(0) { }
|
||||
CTypeName(unsigned char nType, char* lpszName) : m_nType(nType), m_lpszName(lpszName) { }
|
||||
|
||||
unsigned char GetTypeValue() const { return m_nType; }
|
||||
const char* GetTypeName() const { return m_lpszName; }
|
||||
|
||||
static bool Test(const CTypeName* lpTypeArray, int nArrayNum, const char* lpTypeArrayName);
|
||||
|
||||
private:
|
||||
|
||||
unsigned char m_nType;
|
||||
char* m_lpszName;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user