Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cTextLocMgr.h
Go to the documentation of this file.
1 //
11 //
12 #ifndef _INC_cTextLocMgr_H
13 #define _INC_cTextLocMgr_H
14 #ifndef NO_PRAGMA_ONCE
15 #pragma once
16 #endif
17 
18 #include "cLanguage.h"
19 #include "../WinAPI/cWinResource.h"
22 
23 namespace GrayLib
24 {
26 
29  typedef const GChar_t* TEXTLOC_t;
30 
32  {
35  public:
39  public:
40  cTextLocEntry() noexcept
41  : m_idRes(0)
42  , m_nHashCode(k_HASHCODE_CLEAR)
43  {
44  }
46  : m_idRes(entry.m_idRes)
47  , m_sText(entry.m_sText)
48  , m_nHashCode(entry.m_nHashCode)
49  {
50  }
52  : m_idRes(idRes)
53  , m_sText(sOrigText)
54  , m_nHashCode(StrT::GetHashCode32(sOrigText.get_CPtr(), k_StrLen_UNK, 0))
55  {
56  ASSERT(!sOrigText.IsEmpty());
57  }
58  cTextLocEntry(cString sOrigText, cString sTransText, RESOURCEID_t idRes)
59  : m_idRes(idRes)
60  , m_sText(sTransText)
61  , m_nHashCode(StrT::GetHashCode32(sOrigText.get_CPtr(), k_StrLen_UNK, 0))
62  {
63  // Converting from sm_LangDef to some other language.
64  ASSERT(!sOrigText.IsEmpty());
65  ASSERT(!sTransText.IsEmpty());
66  }
67  RESOURCEID_t get_SortValue() const noexcept
68  {
70  return m_idRes;
71  }
72  HASHCODE32_t get_HashCode() const noexcept
73  {
74  return m_nHashCode;
75  }
76  };
77 
79  {
84 
85  public:
86  static const cLanguageID sm_LangDef;
87 
88  private:
89  cLanguageID m_Lang;
92 
93  private:
94  static cString GRAYCALL FormatArgV(const GChar_t* pszFormat, const GChar_t** ppszArgs, int iQty);
95 
96  public:
97  cTextLocMgr(cLanguageID lang = sm_LangDef) noexcept;
98  ~cTextLocMgr();
99 
100  cString GetStringId(RESOURCEID_t id);
101  cString GetStringTest(TEXTLOC_t idTextLoc); // allow failure.
102  cString GetString(TEXTLOC_t idTextLoc); // NOT expecting failure.
103 
104  // With arguments %1,%2, etc
105  cString GetStringV(TEXTLOC_t idTextLoc, const GChar_t** ppszArgs, int iQty);
106  cString GetString1(TEXTLOC_t idTextLoc, const GChar_t* pszArg1);
107  cString GetString2(TEXTLOC_t idTextLoc, const GChar_t* pszArg1, const GChar_t* pszArg2);
108  // cString GetString3(TEXTLOC_t idTextLoc, const GChar_t* pszArg1, const GChar_t* pszArg2, const GChar_t* pszArg3);
109  // cString GetString4(TEXTLOC_t idTextLoc, const GChar_t* pszArg1, const GChar_t* pszArg2, const GChar_t* pszArg3, const GChar_t* pszArg4);
110  // cString GetString5(TEXTLOC_t idTextLoc, const GChar_t* pszArg1, const GChar_t* pszArg2, const GChar_t* pszArg3, const GChar_t* pszArg4, const GChar_t* pszArg5);
111 
112  bool isLangDefault() const;
113  void put_Language(const cLanguageID& Lang);
114  const cLanguageID& get_Language() const noexcept
115  {
117  return m_Lang;
118  }
119 
120  HRESULT LoadLangFromFile(cStringF sLangFilePath);
121 
123  };
124 
126 };
127 #endif // _INC_cTextLocMgr_H
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cLanguage.h:31
Definition: cTextLocMgr.h:32
cTextLocEntry(const cTextLocEntry &entry)
Definition: cTextLocMgr.h:45
HASHCODE32_t get_HashCode() const noexcept
Definition: cTextLocMgr.h:72
cString m_sText
the translated text.
Definition: cTextLocMgr.h:37
RESOURCEID_t get_SortValue() const noexcept
Definition: cTextLocMgr.h:67
cTextLocEntry() noexcept
Definition: cTextLocMgr.h:40
cTextLocEntry(cString sOrigText, RESOURCEID_t idRes)
Definition: cTextLocMgr.h:51
cTextLocEntry(cString sOrigText, cString sTransText, RESOURCEID_t idRes)
Definition: cTextLocMgr.h:58
HASHCODE32_t m_nHashCode
hash code made from the Original (un-translated) string. GetHashCode32(inline text)
Definition: cTextLocMgr.h:38
RESOURCEID_t m_idRes
arbitrary value to reflect what might be in Windows resource. (0=don't care)
Definition: cTextLocMgr.h:36
Definition: cTextLocMgr.h:79
UNITTEST_FRIEND(cTextLocMgr)
const cLanguageID & get_Language() const noexcept
Definition: cTextLocMgr.h:114
static const cLanguageID sm_LangDef
Definition: cTextLocMgr.h:86
bool IsEmpty() const noexcept
Definition: cString.h:176
Definition: cArraySort.h:575
Definition: cArraySort.h:363
Definition: cMesh.h:22
__DECL_IMPORT cTextLocMgr g_Text
default application language. ENU. Not cSingleton
Definition: cTextLocMgr.cpp:18
const GChar_t * TEXTLOC_t
id for a string from resource or some other file. (might be a "string" or a MAKINTRESOURCE(RESOURCEID...
Definition: cTextLocMgr.h:29
UNITTEST2_PREDEF(cQuadtree)
const StrLen_t k_StrLen_UNK
use the default/current length of the string argument.
Definition: StrConst.h:34
const HASHCODE_t k_HASHCODE_CLEAR
not a valid index.
Definition: GrayCore.h:118
UINT32 HASHCODE32_t
always 32 bits.
Definition: GrayCore.h:117
WORD RESOURCEID_t
A resource in .RC attached to a file/module. like MAKEINTRESOURCE(). https://docs....
Definition: cResourceBase.h:19
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26
Definition: StrT.h:69