AppCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UniversalDictionary.h
Go to the documentation of this file.
1 #ifndef UNIVERSALDICTIONARY_H
2 #define UNIVERSALDICTIONARY_H
3 
4 #include "StorageItem.h"
5 #include <qvariant.h>
6 #include <utility>
7 #include <map>
8 #include "core/common/eplatform.h"
9 
11 {
12 public:
13  UniversalDictionary( const int32_t &storageDataType );
14  UniversalDictionary( const UniversalDictionary &otherInstance );
15  virtual ~UniversalDictionary();
16 
17  virtual StorageItem *Clone();
18  virtual QString WhoAmI() const;
19  virtual int32_t GetStorageDataType() const;
20 
21  void AddItem( const long key, const QVariant &value );
22  void AddItem( const long key, void *value );
23 
24  void AddExistingDictionary( const UniversalDictionary *copiedDictionary );
25 
26  DEPRECATED( bool GetBool( const long key, bool &data ) );
27  DEPRECATED( bool GetNumber( const long key, long &data ) );
28  DEPRECATED( bool GetNumber( const long key, unsigned long &data ) );
29  DEPRECATED( bool GetString( const long key, QString &data ) );
30  DEPRECATED( bool GetPointer( const long key, void *&data ) );
31 
32 #ifdef EMTEST_XSCALE
33  bool GetData( const int32_t key, QString &data )
34  {
35  QVariant qvariantValue;
36  bool ok = GetQVariantByKey( key, qvariantValue );
37  if ( ok == false )
38  {
39  return false;
40  }
41 
42  if ( qvariantValue.canCast( QVariant::String ) == true )
43  {
44  data = qvariantValue.toString();
45  return true;
46  }
47 
48  return false;
49  }
50 #endif
51 
52  template<typename T>
53  bool GetData( const int32_t key, T &data )
54  {
55  QVariant qvariantValue;
56  bool ok = GetQVariantByKey( key, qvariantValue );
57  if ( ok == false )
58  {
59  return false;
60  }
61 
62  QVariant returnValue( data );
63 #ifdef EMTEST_XSCALE
64  if ( qvariantValue.canCast( returnValue.type() ) == true )
65  {
66  QVariant::Type type = qvariantValue.type();
67  switch( type )
68  {
69  case QVariant::Bool:
70  {
71  data = qvariantValue.toBool();
72  }
73  break;
74 
75  case QVariant::String:
76  {
77  // RDU - toString() tu nemoze byt kvoli chybe kompilacie (invalidconversion from `const char*' to `int'). Na ziskanie QString sa pouzije samostatna metoda.
78  //data = qvariantValue.toString();
79  return false;
80  }
81  break;
82 
83  case QVariant::Int:
84  case QVariant::LongLong:
85  {
86  data = qvariantValue.toInt();
87  }
88  break;
89 
90  case QVariant::UInt:
91  case QVariant::ULongLong:
92  {
93  data = qvariantValue.toUInt();
94  }
95  break;
96 
97  default:
98  {
99  return false;
100  }
101  }
102  }
103 #else
104  if ( qvariantValue.canConvert( returnValue.type() ) == true )
105  {
106  data = qvariant_cast<T>( qvariantValue );
107  }
108 #endif
109  else
110  {
111  return false;
112  }
113 
114  return true;
115  }
116 
117  template<typename T>
118  bool GetPointer( const int32_t key, T &data )
119  {
120  void *rawPointer = NULL;
121  bool ok = GetRawPointerByKey( key, rawPointer );
122  if ( ok == false )
123  {
124  return false;
125  }
126 
127  data = ( T )rawPointer;
128  return true;
129  }
130 
131  bool RemoveItem( const int32_t &key );
132 
133  unsigned short GetSize();
134 
135  UniversalDictionary &operator =( const UniversalDictionary &otherInstance );
136  UniversalDictionary &operator =( const UniversalDictionary *otherInstance );
137 
138 #ifdef DEVELOP
139  virtual void PrintToLog();
140 #endif
141 
142 private:
144 
145  class DataClass;
146  DataClass *d;
147 
148  bool GetRawPointerByKey( const int32_t key, void *&rawPointer );
149  bool GetQVariantByKey( const int32_t key, QVariant &variant );
150 
152 };
153 
154 #endif // UniversalDictionary_H
Interface of information element which can be state input.
Definition: StorageItem.h:13
virtual ~UniversalDictionary()
Definition: UniversalDictionary.cpp:62
bool RemoveItem(const int32_t &key)
Definition: UniversalDictionary.cpp:129
EEventTripTicketPr __EDATAPTR d
Definition: EEventTripTicket.h:96
Definition: UniversalDictionary.h:10
DEPRECATED(bool GetBool(const long key, bool &data))
char Type
Definition: cardeventidxfilemanager.h:68
UniversalDictionary & operator=(const UniversalDictionary &otherInstance)
Definition: UniversalDictionary.cpp:268
UniversalDictionary(const int32_t &storageDataType)
Definition: UniversalDictionary.cpp:41
__ECLASS DataClass
Definition: EEventUpdateCustomerData.h:35
bool GetPointer(const int32_t key, T &data)
Definition: UniversalDictionary.h:118
virtual StorageItem * Clone()
Definition: UniversalDictionary.cpp:69
unsigned short GetSize()
Definition: UniversalDictionary.cpp:260
bool GetData(const int32_t key, T &data)
Definition: UniversalDictionary.h:53
void AddItem(const long key, const QVariant &value)
Definition: UniversalDictionary.cpp:93
virtual QString WhoAmI() const
Definition: UniversalDictionary.cpp:77
virtual int32_t GetStorageDataType() const
Definition: UniversalDictionary.cpp:85
void AddExistingDictionary(const UniversalDictionary *copiedDictionary)
Definition: UniversalDictionary.cpp:116