amxmodx/amxmodx/CLang.h

164 lines
3.6 KiB
C
Raw Normal View History

2014-08-04 08:36:20 +00:00
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
#ifndef _INCLUDE_CLANG_H
#define _INCLUDE_CLANG_H
#include "sh_tinyhash.h"
#include "sm_stringhashmap.h"
#define LANG_SERVER 0
#define LANG_PLAYER -1
2004-07-28 18:31:30 +00:00
2006-01-24 18:47:08 +00:00
#define ERR_BADKEY 1 // Lang key not found
#define ERR_BADLANG 2 // Invalid lang
2005-11-20 03:47:47 +00:00
struct sKeyDef
{
String *definition;
int key;
};
2006-01-24 18:47:08 +00:00
struct lang_err
{
lang_err() : last(0.0f)
{
};
float last;
};
class defentry
{
public:
defentry() : definition(NULL)
{
};
defentry(const defentry &src)
{
definition = src.definition;
}
~defentry()
{
}
String *definition;
};
struct keytbl_val
{
keytbl_val() : index(-1)
{
};
int index;
};
class CLangMngr
{
class CLang
{
public:
2004-08-19 16:37:32 +00:00
// Construct an empty CLang object
CLang();
2004-08-19 16:37:32 +00:00
// Construct a CLang object initialized with a language name
CLang(const char *lang);
2004-08-19 16:37:32 +00:00
// Destructor
~CLang();
2004-08-19 16:37:32 +00:00
// Get the definition
const char *GetDef(int key, int &status);
2004-08-19 16:37:32 +00:00
// Add definitions to this language
void MergeDefinitions(CQueue <sKeyDef> & vec);
2004-08-19 16:37:32 +00:00
// Reset this language
void Clear();
2004-08-19 16:37:32 +00:00
// compare this language to a language name
friend bool operator == (const CLang &left, const char *right)
{
2005-09-16 23:48:51 +00:00
return strcmp(left.m_LanguageName, right) == 0 ? true : false;
}
2005-09-10 00:38:42 +00:00
2004-08-19 16:37:32 +00:00
// Get language name
const char *GetName() { return m_LanguageName; }
2004-08-19 16:37:32 +00:00
void SetMngr(CLangMngr *l) { m_LMan = l; }
// Get number of entries
int Entries();
protected:
typedef THash<int, defentry> LookUpVec;
typedef LookUpVec::iterator LookUpVecIter;
char m_LanguageName[3];
2004-08-19 16:37:32 +00:00
// our lookup table
LookUpVec m_LookUpTable;
int m_entries;
2004-08-19 16:37:32 +00:00
CLangMngr *m_LMan;
public:
void AddEntry(int key, const char *definition);
};
public:
2004-08-19 16:37:32 +00:00
// Merge definitions into a language
void MergeDefinitions(const char *lang, CQueue <sKeyDef> &tmpVec);
private:
2004-08-19 16:37:32 +00:00
// strip lowercase; make lower if needed
2005-09-10 00:38:42 +00:00
static size_t strip(char *str, char *newstr, bool makelower = false);
typedef CVector<CLang*> LangVec;
typedef CVector<CLang*>::iterator LangVecIter;
LangVec m_Languages;
2004-08-19 16:37:32 +00:00
StringHashMap<time_t> FileList;
CVector<String *> KeyList;
THash<String, keytbl_val> KeyTable;
2004-08-19 16:37:32 +00:00
// Get a lang object (construct if needed)
CLang * GetLang(const char *name);
CLang * GetLangR(const char *name);
2004-08-19 16:37:32 +00:00
// Current global client-id for functions like client_print with first parameter 0
2004-07-28 18:31:30 +00:00
int m_CurGlobId;
public:
2004-08-19 16:37:32 +00:00
// Merge a definitions file
int MergeDefinitionFile(const char *file);
2005-11-20 03:47:47 +00:00
// Get a definition from a lang name and a key
const char *GetDef(const char *langName, const char *key, int &status);
2004-08-19 16:37:32 +00:00
// Format a string for an AMX plugin
2004-07-28 18:31:30 +00:00
char *FormatAmxString(AMX *amx, cell *params, int parm, int &len);
void InvalidateCache();
2004-08-19 16:37:32 +00:00
// Get index
int GetKeyEntry(String &key);
int GetKeyEntry(const char *key);
2004-08-19 16:37:32 +00:00
// Get key from index
const char *GetKey(int key);
2004-08-19 16:37:32 +00:00
// Add key
int AddKeyEntry(String &key);
int AddKeyEntry(const char *key);
2004-07-28 18:31:30 +00:00
2004-08-19 16:37:32 +00:00
// Get the number of languages
2004-07-28 18:31:30 +00:00
int GetLangsNum();
2004-08-19 16:37:32 +00:00
// Get the name of a language
2004-07-28 18:31:30 +00:00
const char *GetLangName(int langId);
2004-08-19 16:37:32 +00:00
// Check if a language exists
2004-07-28 18:31:30 +00:00
bool LangExists(const char *langName);
2004-08-19 16:37:32 +00:00
// When a language id in a format string in FormatAmxString is LANG_PLAYER, the glob id decides which language to take.
2004-07-28 18:31:30 +00:00
void SetDefLang(int id);
2004-08-19 16:37:32 +00:00
inline int GetDefLang() const { return m_CurGlobId; }
2004-08-19 16:37:32 +00:00
// Reset
2004-07-28 18:31:30 +00:00
void Clear();
CLangMngr();
~CLangMngr();
};
#endif //_INCLUDE_CLANG_H