OpenZWave Library  1.6.887
Localization.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // Localization.h
4 //
5 // Localization for CC and Value Classes
6 //
7 // Copyright (c) 2018 Justin Hammond <justin@dynam.ac>
8 //
9 // SOFTWARE NOTICE AND LICENSE
10 //
11 // This file is part of OpenZWave.
12 //
13 // OpenZWave is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU Lesser General Public License as published
15 // by the Free Software Foundation, either version 3 of the License,
16 // or (at your option) any later version.
17 //
18 // OpenZWave is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public License
24 // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
25 //
26 //-----------------------------------------------------------------------------
27 
28 #ifndef VALUEHELP_H
29 #define VALUEHELP_H
30 
31 #include <cstdio>
32 #include <string>
33 #include <map>
34 #include "Defs.h"
35 #include "Driver.h"
37 
38 namespace OpenZWave
39 {
40  namespace Internal
41  {
42 
44  {
45  public:
46  LabelLocalizationEntry(uint16 _index, uint32 _pos = -1);
48  {
49  }
50  void AddLabel(string label, string lang = "");
51  string GetLabel(string lang);
52  uint64 GetIdx();
53  bool HasLabel(string lang);
54 
55  private:
56  uint16 m_index;
57  uint32 m_pos;
58  map<string, string> m_Label;
59  string m_defaultLabel;
60  };
61 
63  {
64  public:
65  ValueLocalizationEntry(uint8 _commandClass, uint16 _index, uint32 _pos = -1);
67  {
68 
69  }
70  uint64 GetIdx();
71  string GetHelp(string lang);
72  void AddHelp(string HelpText, string lang = "");
73  bool HasHelp(string lang);
74  string GetLabel(string lang);
75  void AddLabel(string Label, string lang = "");
76  bool HasLabel(string lang);
77  void AddItemLabel(string label, int32 itemIndex, string lang = "");
78  string GetItemLabel(string lang, int32 itemIndex);
79  bool HasItemLabel(int32 itemIndex, string lang);
80  void AddItemHelp(string label, int32 itemIndex, string lang = "");
81  string GetItemHelp(string lang, int32 itemIndex);
82  bool HasItemHelp(int32 itemIndex, string lang);
83 
84  private:
85  uint8 m_commandClass;
86  uint16 m_index;
87  uint32 m_pos;
88  map<string, string> m_HelpText;
89  map<string, string> m_LabelText;
90  map<string, map<int32, string> > m_ItemLabelText;
91  map<string, map<int32, string> > m_ItemHelpText;
92  string m_DefaultHelpText;
93  string m_DefaultLabelText;
94  map<int32, string> m_DefaultItemLabelText;
95  map<int32, string> m_DefaultItemHelpText;
96  };
97 
99  {
100  //-----------------------------------------------------------------------------
101  // Construction
102  //-----------------------------------------------------------------------------
103  private:
104  Localization();
105  ~Localization();
106 
107  static void ReadXML();
108  static void ReadCCXMLLabel(uint8 ccID, const TiXmlElement *labelElement);
109  static void ReadXMLValue(uint8 node, uint8 ccID, const TiXmlElement *valueElement);
110  static void ReadXMLVIDItemLabel(uint8 node, uint8 ccID, uint16 indexId, uint32 pos, const TiXmlElement *labelElement);
111  static void ReadGlobalXMLLabel(const TiXmlElement *labelElement);
112  static uint64 GetValueKey(uint8 _node, uint8 _commandClass, uint16 _index, uint32 _pos, bool unique = false);
113  public:
114  static Localization* Get();
117  {
118  return Localization::m_selectedLang;
119  }
120  ;
121  bool SetValueHelp(uint8 node, uint8 ccID, uint16 indexID, uint32 pos, string help, string lang = "");
122  string const GetValueHelp(uint8 node, uint8 ccID, uint16 indexId, uint32 pos);
123  bool SetValueLabel(uint8 node, uint8 ccID, uint16 indexID, uint32 pos, string label, string lang = "");
124  string const GetValueLabel(uint8 node, uint8 ccID, uint16 indexId, int32 pos) const;
125  string const GetValueItemLabel(uint8 node, uint8 ccID, uint16 indexId, int32 pos, int32 itemIndex) const;
126  bool SetValueItemLabel(uint8 node, uint8 ccID, uint16 indexId, int32 pos, int32 itemIndex, string label, string lang = "");
127  string const GetValueItemHelp(uint8 node, uint8 ccID, uint16 indexId, int32 pos, int32 itemIndex) const;
128  bool SetValueItemHelp(uint8 node, uint8 ccID, uint16 indexId, int32 pos, int32 itemIndex, string label, string lang = "");
129  string const GetGlobalLabel(string text);
130  bool SetGlobalLabel(string index, string text, string lang);
131  static void ReadXMLVIDLabel(uint8 node, uint8 ccID, uint16 indexId, uint32 pos, const TiXmlElement *labelElement);
132  static void ReadXMLVIDHelp(uint8 node, uint8 ccID, uint16 indexId, uint32 pos, const TiXmlElement *helpElement);
133  bool WriteXMLVIDHelp(uint8 node, uint8 ccID, uint16 indexId, uint32 pos, TiXmlElement *valueElement);
134  //-----------------------------------------------------------------------------
135  // Instance Functions
136  //-----------------------------------------------------------------------------
137  private:
138  static Localization* m_instance;
139  static map<uint64, std::shared_ptr<ValueLocalizationEntry> > m_valueLocalizationMap;
140  static map<uint8, std::shared_ptr<LabelLocalizationEntry> > m_commandClassLocalizationMap;
141  static map<string, std::shared_ptr<LabelLocalizationEntry> > m_globalLabelLocalizationMap;
142  static string m_selectedLang;
143  static uint32 m_revision;
144 
145  };
146  } // namespace Internal
147 } // namespace OpenZWave
148 #endif // VALUEHELP_H
static void ReadXMLVIDLabel(uint8 node, uint8 ccID, uint16 indexId, uint32 pos, const TiXmlElement *labelElement)
Definition: Localization.cpp:423
static void ReadXMLVIDHelp(uint8 node, uint8 ccID, uint16 indexId, uint32 pos, const TiXmlElement *helpElement)
Definition: Localization.cpp:456
uint64 GetIdx()
Definition: Localization.cpp:93
void AddLabel(string label, string lang="")
Definition: Localization.cpp:57
Definition: Bitfield.cpp:30
bool SetValueItemLabel(uint8 node, uint8 ccID, uint16 indexId, int32 pos, int32 itemIndex, string label, string lang="")
Definition: Localization.cpp:654
bool HasLabel(string lang)
Definition: Localization.cpp:79
string GetLabel(string lang)
Definition: Localization.cpp:70
bool HasLabel(string lang)
Definition: Localization.cpp:131
unsigned short uint16
Definition: Defs.h:89
bool HasItemLabel(int32 itemIndex, string lang)
Definition: Localization.cpp:177
bool SetValueHelp(uint8 node, uint8 ccID, uint16 indexID, uint32 pos, string help, string lang="")
Definition: Localization.cpp:571
Definition: Localization.h:62
static Localization * Get()
Definition: Localization.cpp:763
~LabelLocalizationEntry()
Definition: Localization.h:47
string const GetValueLabel(uint8 node, uint8 ccID, uint16 indexId, int32 pos) const
Definition: Localization.cpp:627
ValueLocalizationEntry(uint8 _commandClass, uint16 _index, uint32 _pos=-1)
Definition: Localization.cpp:88
string GetHelp(string lang)
Definition: Localization.cpp:98
bool HasItemHelp(int32 itemIndex, string lang)
Definition: Localization.cpp:219
Base class for all Z-Wave command classes.
Definition: CommandClass.h:60
bool SetValueItemHelp(uint8 node, uint8 ccID, uint16 indexId, int32 pos, int32 itemIndex, string label, string lang="")
Definition: Localization.cpp:692
Definition: Localization.h:98
bool WriteXMLVIDHelp(uint8 node, uint8 ccID, uint16 indexId, uint32 pos, TiXmlElement *valueElement)
Definition: Localization.cpp:747
string GetItemHelp(string lang, int32 itemIndex)
Definition: Localization.cpp:197
string const GetValueHelp(uint8 node, uint8 ccID, uint16 indexId, uint32 pos)
Definition: Localization.cpp:616
void AddItemLabel(string label, int32 itemIndex, string lang="")
Definition: Localization.cpp:148
bool HasHelp(string lang)
Definition: Localization.cpp:107
signed int int32
Definition: Defs.h:91
Definition: Localization.h:43
string GetItemLabel(string lang, int32 itemIndex)
Definition: Localization.cpp:160
bool SetGlobalLabel(string index, string text, string lang)
Definition: Localization.cpp:723
unsigned int uint32
Definition: Defs.h:92
void AddHelp(string HelpText, string lang="")
Definition: Localization.cpp:116
void SetupCommandClass(Internal::CC::CommandClass *cc)
Definition: Localization.cpp:557
bool SetValueLabel(uint8 node, uint8 ccID, uint16 indexID, uint32 pos, string label, string lang="")
Definition: Localization.cpp:593
void AddLabel(string Label, string lang="")
Definition: Localization.cpp:140
void AddItemHelp(string label, int32 itemIndex, string lang="")
Definition: Localization.cpp:184
LabelLocalizationEntry(uint16 _index, uint32 _pos=-1)
Definition: Localization.cpp:52
~ValueLocalizationEntry()
Definition: Localization.h:66
uint64 GetIdx()
Definition: Localization.cpp:64
string const GetGlobalLabel(string text)
Definition: Localization.cpp:713
string const GetValueItemLabel(uint8 node, uint8 ccID, uint16 indexId, int32 pos, int32 itemIndex) const
Definition: Localization.cpp:638
string GetLabel(string lang)
Definition: Localization.cpp:124
string const GetValueItemHelp(uint8 node, uint8 ccID, uint16 indexId, int32 pos, int32 itemIndex) const
Definition: Localization.cpp:675
string GetSelectedLang()
Definition: Localization.h:116
unsigned char uint8
Definition: Defs.h:86