Added comments

This commit is contained in:
Pavol Marko 2004-08-19 16:37:32 +00:00
parent 008474fbe5
commit 213694cccc

View File

@ -60,98 +60,140 @@ class CLangMngr
class CLang class CLang
{ {
public: public:
// Construct an empty CLang object
CLang(); CLang();
// Construct a CLang object initialized with a language name
CLang(const char *lang); CLang(const char *lang);
// Destructor
~CLang(); ~CLang();
// Get the definition
const char *GetDef(const char *key); const char *GetDef(const char *key);
// Add definitions to this language
void MergeDefinitions(CQueue <sKeyDef*> & vec); void MergeDefinitions(CQueue <sKeyDef*> & vec);
// Reset this language
void Clear(); void Clear();
// compare this language to a language name
friend bool operator == (const CLang &left, const char *right) friend bool operator == (const CLang &left, const char *right)
{ {
return strcmp(left.m_LanguageName, right)==0 ? true : false; return strcmp(left.m_LanguageName, right)==0 ? true : false;
} }
// Get language name
const char *GetName() { return m_LanguageName; } const char *GetName() { return m_LanguageName; }
// Save to file
bool Save(FILE *fp, int &defOffset, uint32_t &curOffset); bool Save(FILE *fp, int &defOffset, uint32_t &curOffset);
bool SaveDefinitions(FILE *fp, uint32_t &curOffset); bool SaveDefinitions(FILE *fp, uint32_t &curOffset);
// Load
bool Load(FILE *fp); bool Load(FILE *fp);
void SetMngr(CLangMngr *l) { lman = l; } void SetMngr(CLangMngr *l) { m_LMan = l; }
// Get number of entries
int Entries() { return m_LookUpTable.size(); } int Entries() { return m_LookUpTable.size(); }
private: protected:
// Make a hash from a string; convert to lowercase first if needed
static uint32_t MakeHash(const char *src, bool makeLower = false); static uint32_t MakeHash(const char *src, bool makeLower = false);
// An entry in the language
class LangEntry class LangEntry
{ {
// the definition hash
uint32_t m_DefHash; uint32_t m_DefHash;
// index into the lookup table?
int key; int key;
// the definition
String m_pDef; String m_pDef;
public: public:
// Set
void SetKey(int key); void SetKey(int key);
void SetDef(const char *pDef); void SetDef(const char *pDef);
// Get
uint32_t GetDefHash(); uint32_t GetDefHash();
int GetKey(); int GetKey();
const char *GetDef(); const char *GetDef();
int GetDefLength(); int GetDefLength();
// Constructors / destructors
LangEntry(); LangEntry();
LangEntry(int key); LangEntry(int key);
LangEntry(int key, const char *pDef); LangEntry(int key, const char *pDef);
LangEntry(const LangEntry &other); LangEntry(const LangEntry &other);
LangEntry(int pKey, uint32_t defHash, const char *pDef); LangEntry(int pKey, uint32_t defHash, const char *pDef);
// Reset
void Clear(); void Clear();
}; };
// Get (construct if needed) an entry
LangEntry * GetEntry(int key); LangEntry * GetEntry(int key);
typedef CVector<LangEntry*> LookUpVec; typedef CVector<LangEntry*> LookUpVec;
typedef LookUpVec::iterator LookUpVecIter; typedef LookUpVec::iterator LookUpVecIter;
char m_LanguageName[3]; char m_LanguageName[3];
// our lookup table
LookUpVec m_LookUpTable; LookUpVec m_LookUpTable;
CLangMngr *lman; CLangMngr *m_LMan;
public: public:
LangEntry *AddEntry(int pKey, uint32_t defHash, const char *def); LangEntry *AddEntry(int pKey, uint32_t defHash, const char *def);
}; };
// Merge definitions into a language
void MergeDefinitions(const char *lang, CQueue <sKeyDef*> &tmpVec); void MergeDefinitions(const char *lang, CQueue <sKeyDef*> &tmpVec);
// strip lowercase; make lower if needed
static size_t strip(char *str, char *newstr, bool makelower=false); static size_t strip(char *str, char *newstr, bool makelower=false);
typedef CVector<CLang*> LangVec; typedef CVector<CLang*> LangVec;
typedef CVector<CLang*>::iterator LangVecIter; typedef CVector<CLang*>::iterator LangVecIter;
LangVec m_Languages; LangVec m_Languages;
CVector<md5Pair *> FileList; CVector<md5Pair *> FileList;
CVector<keyEntry*> KeyList; CVector<keyEntry*> KeyList;
// Get a lang object (construct if needed)
CLang * GetLang(const char *name); CLang * GetLang(const char *name);
// Current global client-id for functions like client_print with first parameter 0
int m_CurGlobId; int m_CurGlobId;
public: public:
// Merge a definitions file
int MergeDefinitionFile(const char *file); int MergeDefinitionFile(const char *file);
// Get a definition from a lang name and a kyer
const char *GetDef(const char *langName, const char *key); const char *GetDef(const char *langName, const char *key);
// Format a string
const char *Format(const char *src, ...); const char *Format(const char *src, ...);
// Format a string for an AMX plugin
char *FormatAmxString(AMX *amx, cell *params, int parm, int &len); char *FormatAmxString(AMX *amx, cell *params, int parm, int &len);
// Save
bool Save(const char *filename); bool Save(const char *filename);
// Load
bool Load(const char *filename); bool Load(const char *filename);
// Cache
bool LoadCache(const char *filename); bool LoadCache(const char *filename);
bool SaveCache(const char *filename); bool SaveCache(const char *filename);
// Get index
int GetKeyEntry(String &key); int GetKeyEntry(String &key);
int GetKeyEntry(const char *key); int GetKeyEntry(const char *key);
int GetKeyHash(int key); int GetKeyHash(int key);
// Get key from index
const char *GetKey(int key); const char *GetKey(int key);
// Add key
int AddKeyEntry(String &key); int AddKeyEntry(String &key);
// Make a hash from a string; convert to lowercase first if needed
uint32_t MakeHash(const char *src, bool makeLower); uint32_t MakeHash(const char *src, bool makeLower);
// Get the number of languages
int GetLangsNum(); int GetLangsNum();
// Get the name of a language
const char *GetLangName(int langId); const char *GetLangName(int langId);
// Check if a language exists
bool LangExists(const char *langName); bool LangExists(const char *langName);
// When a language id in a format string in FormatAmxString is 0, the glob id decides which language to take. // When a language id in a format string in FormatAmxString is LANG_PLAYER, the glob id decides which language to take.
void SetDefLang(int id); void SetDefLang(int id);
// Reset
void Clear(); void Clear();
CLangMngr(); CLangMngr();