Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cLanguage.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cLanguage_H
7 #define _INC_cLanguage_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../GrayLibBase.h"
13 #include "../UID/cFourCC.h"
15 
16 namespace GrayLib
17 {
19  {
25 #define cLanguageDEF(a,b,c,d,e,f) CLANG_##b = MAKEFOURCC(c,d,e,'\0'),
26 #include "cLanguages.tbl"
27 #undef cLanguageDEF
28  };
29 
31  {
37  public:
38  static const char* const k_ENU; // = "ENU";
39  protected:
41  protected:
42  void SetLangTerminated() noexcept
43  {
44  // The last byte is always 0.
45  m_u.u_c[3] = '\0';
46  }
47  bool isLangTerminated() const noexcept
48  {
49  return m_u.u_c[3] == '\0';
50  }
51  public:
52  cLanguageID() noexcept
53  {
54  SetLangDefault();
55  }
56  cLanguageID(const char* pszInit)
57  {
58  put_LangStr(pszInit);
59  }
60  cLanguageID(UINT32 dwLang) noexcept // CLANG_CODE_TYPE
61  {
63  m_u.u_dw = dwLang;
64  SetLangTerminated();
65  }
66  bool isLangSet() const noexcept
67  {
68  return(m_u.u_c[0] != '\0');
69  }
70  bool isLangValid() const noexcept
71  {
72  return StrChar::IsUpperA(m_u.u_c[0])
73  && StrChar::IsUpperA(m_u.u_c[1])
74  && StrChar::IsUpperA(m_u.u_c[2])
75  && m_u.u_c[3] == '\0';
76  }
77  const char* get_LangStr() const
78  {
80  return(m_u.u_c);
81  }
82  const char* get_LangStrDef() const
83  {
84  if (isLangSet())
85  return get_LangStr();
86  return k_ENU; // default language.
87  }
88  bool put_LangStr(const char* pszLang = nullptr)
89  {
90  // MUST be 3 upper case letters. no '\0' is required.
91  if (pszLang != nullptr)
92  {
93  ::memcpy(m_u.u_c, pszLang, 3); // assume upper case ?
94  SetLangTerminated();
95  if (isLangValid())
96  {
97  return true;
98  }
99  // not valid ! clear it.
100  }
101  SetLangDefault();
102  return false;
103  }
104  UINT32 get_LangDWord() const // CLANG_CODE_TYPE
105  {
108  return m_u.u_dw;
109  }
110  bool put_LangDWord(UINT32 dwLang) // CLANG_CODE_TYPE
111  {
112  return put_LangStr((const char*)&dwLang);
113  }
114  bool operator == (const cLanguageID& lang) const
115  {
117  return lang.m_u.u_dw == lang.m_u.u_dw;
118  }
119  void SetLangDefault() noexcept
120  {
121  m_u.u_dw = 0;
122  }
123  };
124 };
125 #endif // _INC_cLanguage_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
Definition: cLanguage.h:31
void SetLangDefault() noexcept
Definition: cLanguage.h:119
void SetLangTerminated() noexcept
Definition: cLanguage.h:42
UINT32 get_LangDWord() const
Definition: cLanguage.h:104
cLanguageID(const char *pszInit)
Definition: cLanguage.h:56
cLanguageID(UINT32 dwLang) noexcept
Definition: cLanguage.h:60
const char * get_LangStr() const
Definition: cLanguage.h:77
bool put_LangDWord(UINT32 dwLang)
Definition: cLanguage.h:110
cUnion32 m_u
UNICODE language pref. ('ENU'=English)
Definition: cLanguage.h:40
bool isLangTerminated() const noexcept
Definition: cLanguage.h:47
bool isLangValid() const noexcept
Definition: cLanguage.h:70
static const char *const k_ENU
Definition: cLanguage.h:38
const char * get_LangStrDef() const
Definition: cLanguage.h:82
bool isLangSet() const noexcept
Definition: cLanguage.h:66
bool put_LangStr(const char *pszLang=nullptr)
Definition: cLanguage.h:88
cLanguageID() noexcept
Definition: cLanguage.h:52
Definition: cMesh.h:22
CLANG_CODE_TYPE
Definition: cLanguage.h:19
bool operator==(const cTimeDouble &dt1, const cTimeDouble &dt2)
Definition: cTimeDouble.h:250
static bool IsUpperA(wchar_t ch) noexcept
Definition: StrChar.h:111
Definition: cTypes.h:66
char u_c[4]
Definition: cTypes.h:74
UINT32 u_dw
32 bit unsigned
Definition: cTypes.h:78