forked from metin2/server
Add project files.
This commit is contained in:
234
game/src/group_text_parse_tree.h
Normal file
234
game/src/group_text_parse_tree.h
Normal file
@@ -0,0 +1,234 @@
|
||||
#ifndef __INC_METIN_II_GROUP_TEXT_PARSE_TREE_H__
|
||||
#define __INC_METIN_II_GROUP_TEXT_PARSE_TREE_H__
|
||||
|
||||
#include "../../common/d3dtype.h"
|
||||
#include "../../common/pool.h"
|
||||
#include "file_loader.h"
|
||||
#include <sstream>
|
||||
typedef std::map<std::string, TTokenVector> TTokenVectorMap;
|
||||
typedef std::map<std::string, int> TMapNameToIndex;
|
||||
|
||||
class CGroupNode
|
||||
{
|
||||
public:
|
||||
class CGroupNodeRow
|
||||
{
|
||||
public:
|
||||
CGroupNodeRow(CGroupNode* pGroupNode, TTokenVector& vec_values);
|
||||
virtual ~CGroupNodeRow();
|
||||
|
||||
template <typename T>
|
||||
bool GetValue(const std::string & stColKey, OUT T& value) const;
|
||||
template <typename T>
|
||||
bool GetValue(int idx, OUT T& value) const;
|
||||
|
||||
int GetSize() const;
|
||||
|
||||
private:
|
||||
CGroupNode* m_pOwnerGroupNode;
|
||||
TTokenVector m_vec_values;
|
||||
};
|
||||
public:
|
||||
CGroupNode();
|
||||
virtual ~CGroupNode();
|
||||
|
||||
bool Load(const char * c_szFileName);
|
||||
const char * GetFileName();
|
||||
|
||||
DWORD GetChildNodeCount();
|
||||
bool SetChildNode(const char * c_szKey, CGroupNode* pChildNode);
|
||||
CGroupNode* GetChildNode(const std::string & c_rstrKey) const;
|
||||
std::string GetNodeName() const;
|
||||
|
||||
bool IsToken(const std::string & c_rstrKey) const;
|
||||
|
||||
int GetRowCount();
|
||||
|
||||
template <typename T>
|
||||
bool GetValue(size_t i, const std::string & c_rstrColKey, T& tValue) const; // n<><6E>°(map<61><70> <20><><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>, txt<78><74> <20><><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>) row<6F><77> Ư<><C6AF> <20>÷<EFBFBD><C3B7><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ȯ<EFBFBD>ϴ<EFBFBD> <20>Լ<EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̱<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD>Ǹ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD>.
|
||||
template <typename T>
|
||||
bool GetValue(const std::string & c_rstrRowKey, const std::string & c_rstrColKey, T& tValue) const;
|
||||
template <typename T>
|
||||
bool GetValue(const std::string & c_rstrRowKey, int index, T& tValue) const;
|
||||
|
||||
bool GetRow(const std::string & c_rstrKey, OUT const CGroupNodeRow ** ppRow) const;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, idx<64><78> txt<78><74> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
bool GetRow(int idx, OUT const CGroupNodeRow ** ppRow) const;
|
||||
bool GetGroupRow(const std::string& stGroupName, const std::string& stRow, OUT const CGroupNode::CGroupNodeRow ** ppRow) const;
|
||||
|
||||
template <typename T>
|
||||
bool GetGroupValue(const std::string& stGroupName, const std::string& stRow, int iCol, OUT T& tValue) const;
|
||||
template <typename T>
|
||||
bool GetGroupValue(const std::string& stGroupName, const std::string& stRow, const std::string& stCol, OUT T& tValue) const;
|
||||
|
||||
int GetColumnIndexFromName(const std::string& stName) const;
|
||||
|
||||
private:
|
||||
typedef std::map <std::string, CGroupNode*> TMapGroup;
|
||||
typedef std::map <std::string, CGroupNode::CGroupNodeRow> TMapRow;
|
||||
TMapGroup m_mapChildNodes;
|
||||
std::string strGroupName;
|
||||
|
||||
TMapNameToIndex m_map_columnNameToIndex;
|
||||
TMapRow m_map_rows;
|
||||
friend class CGroupTextParseTreeLoader;
|
||||
};
|
||||
|
||||
class CGroupTextParseTreeLoader
|
||||
{
|
||||
public:
|
||||
CGroupTextParseTreeLoader();
|
||||
virtual ~CGroupTextParseTreeLoader();
|
||||
|
||||
bool Load(const char * c_szFileName);
|
||||
const char * GetFileName();
|
||||
|
||||
CGroupNode* GetGroup(const char * c_szGroupName);
|
||||
private:
|
||||
bool LoadGroup(CGroupNode * pGroupNode);
|
||||
|
||||
CGroupNode * m_pRootGroupNode;
|
||||
std::string m_strFileName;
|
||||
DWORD m_dwcurLineIndex;
|
||||
|
||||
CMemoryTextFileLoader m_fileLoader;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
bool from_string(OUT T& t, IN const std::string& s)
|
||||
{
|
||||
std::istringstream iss(s);
|
||||
return !(iss >> t).fail();
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool from_string <BYTE>(OUT BYTE& t, IN const std::string& s)
|
||||
{
|
||||
std::istringstream iss(s);
|
||||
int temp;
|
||||
bool b = !(iss >> temp).fail();
|
||||
t = (BYTE)temp;
|
||||
return b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool CGroupNode::GetValue(size_t i, const std::string & c_rstrColKey, T& tValue) const
|
||||
{
|
||||
if (i > m_map_rows.size())
|
||||
return FALSE;
|
||||
|
||||
TMapRow::const_iterator row_it = m_map_rows.begin();
|
||||
std::advance(row_it, i);
|
||||
|
||||
itertype(m_map_columnNameToIndex) col_idx_it = m_map_columnNameToIndex.find(c_rstrColKey);
|
||||
if (m_map_columnNameToIndex.end() == col_idx_it)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int index = col_idx_it->second;
|
||||
if (row_it->second.GetSize() <= index)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return row_it->second.GetValue(index, tValue);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool CGroupNode::GetValue(const std::string & c_rstrRowKey, const std::string & c_rstrColKey, T& tValue) const
|
||||
{
|
||||
TMapRow::const_iterator row_it = m_map_rows.find(c_rstrRowKey);
|
||||
if (m_map_rows.end() == row_it)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
itertype(m_map_columnNameToIndex) col_idx_it = m_map_columnNameToIndex.find(c_rstrColKey);
|
||||
if (m_map_columnNameToIndex.end() == col_idx_it)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int index = col_idx_it->second;
|
||||
if (row_it->second.GetSize() <= index)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return row_it->second.GetValue(index, tValue);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool CGroupNode::GetValue(const std::string & c_rstrRowKey, int index, T& tValue) const
|
||||
{
|
||||
TMapRow::const_iterator row_it = m_map_rows.find(c_rstrRowKey);
|
||||
if (m_map_rows.end() == row_it)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (row_it->second.GetSize() <= index)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return row_it->second.GetValue(index, tValue);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool CGroupNode::GetGroupValue(const std::string& stGroupName, const std::string& stRow, int iCol, OUT T& tValue) const
|
||||
{
|
||||
CGroupNode* pChildGroup = GetChildNode(stGroupName);
|
||||
if (NULL != pChildGroup)
|
||||
{
|
||||
if (pChildGroup->GetValue(stRow, iCol, tValue))
|
||||
return true;
|
||||
}
|
||||
// default group<75><70> <20><><EFBFBD>캽.
|
||||
pChildGroup = GetChildNode("default");
|
||||
if (NULL != pChildGroup)
|
||||
{
|
||||
if (pChildGroup->GetValue(stRow, iCol, tValue))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool CGroupNode::GetGroupValue(const std::string& stGroupName, const std::string& stRow, const std::string& stCol, OUT T& tValue) const
|
||||
{
|
||||
CGroupNode* pChildGroup = GetChildNode(stGroupName);
|
||||
if (NULL != pChildGroup)
|
||||
{
|
||||
if (pChildGroup->GetValue(stRow, stCol, tValue))
|
||||
return true;
|
||||
}
|
||||
// default group<75><70> <20><><EFBFBD>캽.
|
||||
pChildGroup = GetChildNode("default");
|
||||
if (NULL != pChildGroup)
|
||||
{
|
||||
if (pChildGroup->GetValue(stRow, stCol, tValue))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool CGroupNode::CGroupNodeRow::GetValue(const std::string & stColKey, OUT T& value) const
|
||||
{
|
||||
int idx = m_pOwnerGroupNode->GetColumnIndexFromName(stColKey);
|
||||
if (idx < 0 || idx >= m_vec_values.size())
|
||||
return false;
|
||||
return from_string(value, m_vec_values[idx]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool CGroupNode::CGroupNodeRow::GetValue(int idx, OUT T& value) const
|
||||
{
|
||||
if (idx < 0 || idx >= m_vec_values.size())
|
||||
return false;
|
||||
return from_string(value, m_vec_values[idx]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user