stec-platform
platform_global.h
1 #ifndef PLATFORM_GLOBAL_H
2 #define PLATFORM_GLOBAL_H
3 
4 #include <QDebug>
5 #include <QFileInfo>
6 #include <QList>
7 #include <QMap>
8 #include <QMutex>
9 #include <QObject>
10 #include <QReadLocker>
11 #include <QReadWriteLock>
12 #include <QSettings>
13 #include <QString>
14 #include <QStringList>
15 #include <QtCore/qglobal.h>
16 #include <QThread>
17 #include <QVariant>
18 #include <QVarLengthArray>
19 #include <QWriteLocker>
20 #include <QDataStream>
21 
22 
23 
24 #if QT_VERSION >= 0x050000
25 
26 #ifdef Q_OS_WIN32
27 #ifndef Q_WS_WIN
28 #define Q_WS_WIN
29 #endif
30 #endif
31 
32 #ifdef Q_OS_WIN64
33 #ifndef Q_WS_WIN
34 #define Q_WS_WIN
35 #endif
36 #endif
37 
38 #endif
39 
40 class Subscription;
41 
42 typedef QVarLengthArray<QVariant> VremVArray;
43 typedef QList<QVariant> VremList;
44 typedef QVarLengthArray<Subscription *> VremSubArray;
45 
46 #if defined(PLATFORM_LIBRARY)
47 # define PLATFORMSHARED_EXPORT Q_DECL_EXPORT
48 #else
49 # define PLATFORMSHARED_EXPORT Q_DECL_IMPORT
50 #endif
51 
52 
53 #if QT_VERSION >= 0x050500
54 #define STEAMVERSION QDataStream::Qt_DefaultCompiledVersion
55 #else
56 #define STEAMVERSION QDataStream::Qt_5_0
57 #endif
58 
59 #include "definitions.h"
60 
61 
62 
63 #define VSETTINGS() \
64  QSettings settings( Definitions::GetApplicationPath(Definitions::GetApplicationName()),QSettings::IniFormat)
65 
66 
67 class Publication;
69 
70 
71 PLATFORMSHARED_EXPORT Publication* CreatePublication(const QString name);
72 PLATFORMSHARED_EXPORT QStringList GetAllPublicationNames(void);
73 PLATFORMSHARED_EXPORT QStringList GetAllPossibleNames(void);
74 
75 PLATFORMSHARED_EXPORT PublicationRegistration *InitCloudInstance(QObject *parent = 0);
76 PLATFORMSHARED_EXPORT PublicationRegistration *GetCloudInstance(void);
77 
78 
79 PLATFORMSHARED_EXPORT void MountLibraryInstance(int argc, char *argv[]);
80 PLATFORMSHARED_EXPORT void MountLibraryInstance(QStringList xargv, QStringList qargv);
81 PLATFORMSHARED_EXPORT void UnMountLibraryInstance();
82 
83 
112 class PLATFORMSHARED_EXPORT RecursiveLock : public QReadWriteLock
113 {
114 public :
115 
120  {
121 
122  }
123 };
124 
125 
131 template<class T>
132 T VClear(void)
133 {
134  T v = { { 0 }};
135  return v;
136 }
137 
138 
139 
145 template<class T>
146 class DLock
147 {
148 private :
149  QMutex classLock;
150  T Value;
151 public:
153  DLock( T v)
154  {
155  Value = v;
156  }
157 
158  DLock( )
159  {
160 
161  }
163  T operator=(const T &v)
164  {
165  QMutexLocker k (&classLock);
166  Value = v;
167  return v;
168  }
169 
171  const T value(void)
172  {
173  QMutexLocker k (&classLock);
174  T v;
175  v = Value;
176  return v;
177  }
178 };
179 
180 
181 
182 
183 
188 template<class T>
189 class DRWLock
190 {
191 private :
192  RecursiveLock classLock;
193  T Value;
194 public:
196  DRWLock( T v)
197  {
198  Value = v;
199  }
202  {
203  }
204 
206  T operator=(const T &v)
207  {
208  classLock.lockForWrite();
209  Value = v;
210  classLock.unlock();
211  return v;
212  }
214  const T value(void)
215  {
216  classLock.lockForRead();
217  T v;
218  v = Value;
219  classLock.unlock();
220  return v;
221  }
222 };
223 
224 
225 
226 template <class T>
227 
228 
233 struct TP {
234  T p1;
235  T p2;
236  TP(void) : p1((T) 0), p2((T) 0) {}
237  TP( T v1, T v2) : p1(v1), p2(v2) {}
238 
239 
240 friend bool Between ( TP<T> i1, TP<T> i2 )
241  {
242  T range1 = (i1.p1 + i1.p2) - (T)1;
243  T range2 = (i2.p1 + i2.p2) - (T)1;
244  if( (i2.p1 >= i1.p1 && i2.p1 <= range1) || (range2 >= i1.p1 && range2 <= range1))
245  return true;
246  return false;
247  }
248 };
249 
250 
255 template <class T>
256 class AUTOD
257 {
258 private :
259  QMap<int,QList<T> > Channels;
260 
261 public :
262 
263 
267  void ClearAll( )
268  {
269  foreach ( QList<T>vlist, Channels.values() )
270  {
271  foreach( T v, vlist)
272  {
273  delete v;
274  }
275  }
276  }
277 
282  void ClearAll( int uniqueId)
283  {
284 
285  typename QMap<int,QList<T> >::iterator it;
286  if( (it = Channels.find(uniqueId)) != Channels.end() )
287  {
288 
289  foreach( T v, it.value())
290  {
291  delete v;
292  }
293  Channels.erase(it);
294  }
295 
296  }
297 
303  void Add( int uniqueId, T v)
304  {
305  typename QMap<int,QList<T> >::iterator it;
306  if ( (it = Channels.find(uniqueId)) != Channels.end() )
307  {
308  it.push_back(v);
309  }
310  else {
311  QList<T> lst;
312  lst.push_back(v);
313  Channels.insert(uniqueId,lst);
314  }
315 
316  }
317 
318 
322  virtual ~AUTOD( )
323  {
324  ClearAll( );
325  }
326 };
327 
328 
329 #endif // PLATFORM_GLOBAL_H
The AUTOD class.
Definition: platform_global.h:257
void ClearAll()
ClearAll.
Definition: platform_global.h:267
virtual ~AUTOD()
~AUTOD
Definition: platform_global.h:322
void ClearAll(int uniqueId)
ClearAll.
Definition: platform_global.h:282
void Add(int uniqueId, T v)
Add.
Definition: platform_global.h:303
The DLock class Lock for storage of data.
Definition: platform_global.h:147
const T value(void)
Returns a value from DLock.
Definition: platform_global.h:171
T operator=(const T &v)
Operator to load a value into DLock.
Definition: platform_global.h:163
DLock(T v)
constructor for DLock
Definition: platform_global.h:153
The DRWLock class.
Definition: platform_global.h:190
const T value(void)
Returns a value from DLock.
Definition: platform_global.h:214
DRWLock(T v)
constructor for DLock
Definition: platform_global.h:196
DRWLock()
constructor for DLock
Definition: platform_global.h:201
T operator=(const T &v)
Operator to load a value into DLock.
Definition: platform_global.h:206
The PublicationRegistration Multiverse Cloud.
Definition: publicationregistration.h:29
QStringList GetAllPublicationNames(void)
GetAllPublicationNames.
Definition: publicationregistration.cpp:88
QStringList GetAllPossibleNames(void)
GetAllPossibleNames.
Definition: publicationregistration.cpp:94
Publication * CreatePublication(const QString name)
CreatePublication.
Definition: publicationregistration.cpp:40
The Publication class this is only used by the cloud, users should never use this class....
Definition: publication.h:17
The RecursiveLock class Allows a recursive read write lock to occur.
Definition: platform_global.h:113
RecursiveLock()
RecursiveLock.
Definition: platform_global.h:119
The Subscription class A platform subscriber must use or inheit this class.
Definition: subscription.h:43
T VClear(void)
VClear.
Definition: platform_global.h:132
The TP class.
Definition: platform_global.h:233