Общая библиотека для работы с торговым оборудованием.  1.0.0
conv.h
1 /****************************************************************************
2 ** $Id: conv.h,v 1.9 2009/01/31 14:14:15 leader Exp $
3 **
4 ** Trade equipment common portable library project
5 **
6 ** Copyright (C) 1999-2006 Leader InfoTech. All rights reserved.
7 **
8 ** This file is part of the Library of the Ananas
9 ** automation accounting system.
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 as published by the Free Software
13 ** Foundation and appearing in the file LICENSE.GPL included in the
14 ** packaging of this file.
15 **
16 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
17 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 **
19 ** See http://www.leaderit.ru/ or email sales@leaderit.ru
20 **
21 ** Contact org@leaderit.ru if any conditions of this licensing are
22 ** not clear to you.
23 **
24 **********************************************************************/
25 
26 #ifndef _CONV_H_217412934_
27 #define _CONV_H_217412934_
28 
29 #include "teglobal.h"
30 #include <qstring.h>
31 #include <qvaluevector.h>
32 #include <qdatetime.h>
33 #include <qvariant.h>
34 #include <qcstring.h>
35 
36 template <class T>
37 struct LocVarType
38 {
39  typedef T Type;
40 };
41 
42 template <>
43 struct LocVarType<const QString &>
44 {
45  typedef QString Type;
46 };
47 
48 template <>
49 struct LocVarType<QString &>
50 {
51  typedef QString Type;
52 };
53 
54 template <>
55 struct LocVarType<const int &>
56 {
57  typedef int Type;
58 };
59 
60 template <>
61 struct LocVarType<int &>
62 {
63  typedef int Type;
64 };
65 
66 template <>
67 struct LocVarType<const QDateTime &>
68 {
69  typedef QDateTime Type;
70 };
71 
72 template <>
73 struct LocVarType<QDateTime &>
74 {
75  typedef QDateTime Type;
76 };
77 
78 template <>
79 struct LocVarType<const float &>
80 {
81  typedef float Type;
82 };
83 
84 template <>
85 struct LocVarType<float &>
86 {
87  typedef float Type;
88 };
89 
90 template <>
91 struct LocVarType<double &>
92 {
93  typedef double Type;
94 };
95 
96 template <>
97 struct LocVarType<const double &>
98 {
99  typedef double Type;
100 };
101 
102 template <>
103 struct LocVarType<const char *>
104 {
105  typedef QCString Type;
106 };
107 
108 template <class T>
109 QString toString(T v)
110 {
111  return QString("%1").arg(v);
112 };
113 
114 template <>
115 LIB_EXPORT QString toString<double>(double v);
116 
117 template <>
118 LIB_EXPORT QString toString<QVariant>(QVariant v);
119 
120 template <>
121 LIB_EXPORT QString toString<float>(float v);
122 
123 template <class T>
124 T fromQVariant(const QVariant & s)
125 {
126  return (T)s;
127 };
128 
129 template <>
130 LIB_EXPORT bool fromQVariant<bool>(const QVariant &);
131 
132 template <>
133 LIB_EXPORT int fromQVariant<int>(const QVariant &);
134 
135 template <>
136 LIB_EXPORT uint fromQVariant<uint>(const QVariant &);
137 
138 template <>
139 LIB_EXPORT float fromQVariant<float>(const QVariant &);
140 
141 template <>
142 LIB_EXPORT double fromQVariant<double>(const QVariant &);
143 
144 template <>
145 LIB_EXPORT Q_LLONG fromQVariant<Q_LLONG>(const QVariant &);
146 
147 template <>
148 LIB_EXPORT Q_ULLONG fromQVariant<Q_ULLONG>(const QVariant &);
149 
150 template <>
151 LIB_EXPORT Q_ULONG fromQVariant<Q_ULONG>(const QVariant &);
152 
153 template <>
154 LIB_EXPORT Q_LONG fromQVariant<Q_LONG>(const QVariant &);
155 
156 template <>
157 LIB_EXPORT QString fromQVariant<QString>(const QVariant &);
158 
159 template <>
160 LIB_EXPORT QCString fromQVariant<QCString>(const QVariant &);
161 
162 struct LIB_EXPORT memFunc
163 {
164  virtual int argc()=0;
165  // This function returns zero on successful execution, and nonzero otherwise.
166  virtual int operator()(const QValueVector<QVariant> & , QString & , QString & )=0;
167  virtual ~memFunc(){};
168 };
169 
170 template <class T, class R>
172 {
173  typedef R (T::*memFunPtr)();
174 };
175 
176 template <class T>
178 {
179  typedef void (T::*Type)();
180 };
181 
182 template <class T>
184 {
185  typedef void (T::*Type)() const;
186 };
187 
188 template <class T, class R, class P1>
190 {
191  typedef R (T::*memFunPtr)(P1);
192 };
193 
194 template <class T, class R, class P1, class P2>
196 {
197  typedef R (T::*memFunPtr)(P1,P2);
198 };
199 
200 template <class T, class R, class P1, class P2, class P3>
202 {
203  typedef R (T::*memFunPtr)(P1,P2,P3);
204 };
205 
206 template <class T, class R, class P1, class P2, class P3, class P4>
208 {
209  typedef R (T::*memFunPtr)(P1,P2,P3,P4);
210 };
211 
212 template <class T, class R, class P1, class P2, class P3, class P4, class P5>
214 {
215  typedef R (T::*memFunPtr)(P1,P2,P3,P4,P5);
216 };
217 
218 template <class T, class R>
220 {
221  typedef R (T::*memFunPtr)() const;
222 };
223 
224 template <class T, class R, class P1>
226 {
227  typedef R (T::*memFunPtr)(P1) const;
228 };
229 
230 template <class T, class R, class P1, class P2>
232 {
233  typedef R (T::*memFunPtr)(P1,P2) const;
234 };
235 
236 template <class T, class R, class P1, class P2, class P3>
238 {
239  typedef R (T::*memFunPtr)(P1,P2,P3) const;
240 };
241 
242 template <class T, class R, class P1, class P2, class P3, class P4>
244 {
245  typedef R (T::*memFunPtr)(P1,P2,P3,P4) const;
246 };
247 
248 template <class T, class R, class P1, class P2, class P3, class P4, class P5>
250 {
251  typedef R (T::*memFunPtr)(P1,P2,P3,P4,P5) const;
252 };
253 
254 
255 // We are using compiler generated copyctor, it's ok for now.
256 
257 template <class T, class R, class Func=NonConstFunc0<T,R> >
259 {
260  typedef typename Func::memFunPtr memFunPtr;
261  memFunPtr m_pfunc;
262  T * m_pobj;
263  enum {arity=0};
264  memFunc0(T * pobj, memFunPtr pfunc):m_pfunc(pfunc),m_pobj(pobj){};
265  virtual int operator()(const QValueVector<QVariant> & parms, QString & res, QString & err)
266  {
267  if (parms.size()!=arity)
268  {
269  err=QString("Number of provided parameters doesn't match function definition");
270  return 1;
271  };
272  res=toString<R>((m_pobj->*m_pfunc)());
273  return 0;
274  };
275  virtual int argc()
276  {
277  return arity;
278  };
279 };
280 
281 template <class T, class R, class P1, class Func=NonConstFunc1<T,R,P1> >
283 {
284  typedef typename LocVarType<P1>::Type PL1;
285  typedef typename Func::memFunPtr memFunPtr;
286  memFunPtr m_pfunc;
287  T * m_pobj;
288  enum {arity=1};
289  memFunc1(T * pobj, memFunPtr pfunc):m_pfunc(pfunc),m_pobj(pobj){};
290  virtual int operator()(const QValueVector<QVariant> & parms, QString & res, QString & err)
291  {
292  if (parms.size()!=arity)
293  {
294  err=QString("Number of provided parameters doesn't match function definition");
295  return 1;
296  };
297  PL1 p1=fromQVariant<PL1>(parms[0]);
298  res=toString<R>((m_pobj->*m_pfunc)(p1));
299  return 0;
300  };
301  virtual int argc()
302  {
303  return arity;
304  };
305 };
306 
307 template <class T, class R, class P1, class P2, class Func=NonConstFunc2<T,R,P1,P2> >
309 {
310  typedef typename LocVarType<P1>::Type PL1;
311  typedef typename LocVarType<P2>::Type PL2;
312  typedef typename Func::memFunPtr memFunPtr;
313  memFunPtr m_pfunc;
314  T * m_pobj;
315  enum {arity=2};
316  memFunc2(T * pobj, memFunPtr pfunc):m_pfunc(pfunc),m_pobj(pobj){};
317  virtual int operator()(const QValueVector<QVariant> & parms, QString & res, QString & err)
318  {
319  if (parms.size()!=arity)
320  {
321  err=QString("Number of provided parameters doesn't match function definition");
322  return 1;
323  };
324  PL1 p1=fromQVariant<PL1>(parms[0]);
325  PL2 p2=fromQVariant<PL2>(parms[1]);
326  res=toString<R>((m_pobj->*m_pfunc)(p1,p2));
327  return 0;
328  };
329  virtual int argc()
330  {
331  return arity;
332  };
333 };
334 
335 template <class T, class R, class P1, class P2, class P3, class Func=NonConstFunc3<T,R,P1,P2,P3> >
337 {
338  typedef typename LocVarType<P1>::Type PL1;
339  typedef typename LocVarType<P2>::Type PL2;
340  typedef typename LocVarType<P3>::Type PL3;
341  typedef typename Func::memFunPtr memFunPtr;
342  memFunPtr m_pfunc;
343  T * m_pobj;
344  enum {arity=3};
345  memFunc3(T * pobj, memFunPtr pfunc):m_pfunc(pfunc),m_pobj(pobj){};
346  virtual int operator()(const QValueVector<QVariant> & parms, QString & res, QString & err)
347  {
348  if (parms.size()!=arity)
349  {
350  err=QString("Number of provided parameters doesn't match function definition");
351  return 1;
352  };
353  PL1 p1=fromQVariant<PL1>(parms[0]);
354  PL2 p2=fromQVariant<PL2>(parms[1]);
355  PL3 p3=fromQVariant<PL3>(parms[2]);
356  res=toString<R>((m_pobj->*m_pfunc)(p1,p2,p3));
357  return 0;
358  };
359  virtual int argc()
360  {
361  return arity;
362  };
363 };
364 
365 template <class T, class R, class P1, class P2, class P3, class P4, class Func=NonConstFunc4<T,R,P1,P2,P3,P4> >
367 {
368  typedef typename LocVarType<P1>::Type PL1;
369  typedef typename LocVarType<P2>::Type PL2;
370  typedef typename LocVarType<P3>::Type PL3;
371  typedef typename LocVarType<P4>::Type PL4;
372  typedef typename Func::memFunPtr memFunPtr;
373  memFunPtr m_pfunc;
374  T * m_pobj;
375  enum {arity=4};
376  memFunc4(T * pobj, memFunPtr pfunc):m_pfunc(pfunc),m_pobj(pobj){};
377  virtual int operator()(const QValueVector<QVariant> & parms, QString & res, QString & err)
378  {
379  if (parms.size()!=arity)
380  {
381  err=QString("Number of provided parameters doesn't match function definition");
382  return 1;
383  };
384  PL1 p1=fromQVariant<PL1>(parms[0]);
385  PL2 p2=fromQVariant<PL2>(parms[1]);
386  PL3 p3=fromQVariant<PL3>(parms[2]);
387  PL4 p4=fromQVariant<PL4>(parms[3]);
388  res=toString<R>((m_pobj->*m_pfunc)(p1,p2,p3,p4));
389  return 0;
390  };
391  virtual int argc()
392  {
393  return arity;
394  };
395 };
396 
397 template <class T, class R, class P1, class P2, class P3, class P4, class P5,
400 {
401  typedef typename LocVarType<P1>::Type PL1;
402  typedef typename LocVarType<P2>::Type PL2;
403  typedef typename LocVarType<P3>::Type PL3;
404  typedef typename LocVarType<P4>::Type PL4;
405  typedef typename LocVarType<P5>::Type PL5;
406  typedef typename Func::memFunPtr memFunPtr;
407  memFunPtr m_pfunc;
408  T * m_pobj;
409  enum {arity=5};
410  memFunc5(T * pobj, memFunPtr pfunc):m_pfunc(pfunc),m_pobj(pobj){};
411  virtual int operator()(const QValueVector<QVariant> & parms, QString & res, QString & err)
412  {
413  if (parms.size()!=arity)
414  {
415  err=QString("Number of provided parameters doesn't match function definition");
416  return 1;
417  };
418  PL1 p1=fromQVariant<PL1>(parms[0]);
419  PL2 p2=fromQVariant<PL2>(parms[1]);
420  PL3 p3=fromQVariant<PL3>(parms[2]);
421  PL4 p4=fromQVariant<PL4>(parms[3]);
422  PL5 p5=fromQVariant<PL5>(parms[4]);
423  res=toString<R>((m_pobj->*m_pfunc)(p1,p2,p3,p4,p5));
424  return 0;
425  };
426  virtual int argc()
427  {
428  return arity;
429  };
430 };
431 
432 struct memProc
433 {
434  virtual int operator()(const QValueVector<QVariant> & , QString & )
435  {
436  return 0;
437  };
438  virtual int argc()
439  {
440  return 0;
441  };
442  virtual ~memProc(){};
443 };
444 
445 template <class T, class FT=NonConstProc0<T> >
447 {
448  typedef typename FT::Type memProcPtr;
449  T * m_pobj;
450  memProcPtr m_pproc;
451  enum {arity=0};
452  memProc0(T * pobj, memProcPtr pproc):m_pobj(pobj),m_pproc(pproc){};
453  virtual int operator()(const QValueVector<QVariant> & parms, QString & err)
454  {
455  if (parms.size()!=arity)
456  {
457  err=QString("Number of provided parameters doesn't match function definition");
458  return 1;
459  };
460  (m_pobj->*m_pproc)();
461  return 0;
462  };
463  virtual int argc()
464  {
465  return arity;
466  };
467 };
468 
469 template <class T, class P1>
471 {
472  typedef void (T::*memProcPtr)(P1);
473  typedef typename LocVarType<P1>::Type PL1;
474  T * m_pobj;
475  memProcPtr m_pproc;
476  enum {arity=1};
477  memProc1(T * pobj, memProcPtr pproc):m_pobj(pobj),m_pproc(pproc){};
478  virtual int operator()(const QValueVector<QVariant> & parms, QString & err)
479  {
480  if (parms.size()!=arity)
481  {
482  err=QString("Number of provided parameters doesn't match function definition");
483  return 1;
484  };
485  PL1 p1=fromQVariant<PL1>(parms[0]);
486  (m_pobj->*m_pproc)(p1);
487  return 0;
488  };
489  virtual int argc()
490  {
491  return arity;
492  };
493 };
494 
495 template <class T, class P1, class P2>
497 {
498  typedef void (T::*memProcPtr)(P1,P2);
499  typedef typename LocVarType<P1>::Type PL1;
500  typedef typename LocVarType<P2>::Type PL2;
501  memProcPtr m_pproc;
502  T * m_pobj;
503  enum {arity=2};
504  memProc2(T * pobj, memProcPtr pproc):m_pproc(pproc),m_pobj(pobj){};
505  virtual int operator()(const QValueVector<QVariant> & parms, QString & err)
506  {
507  if (parms.size()!=arity)
508  {
509  err=QString("Number of provided parameters doesn't match function definition");
510  return 1;
511  };
512  PL1 p1=fromQVariant<PL1>(parms[0]);
513  PL2 p2=fromQVariant<PL2>(parms[1]);
514  (m_pobj->*m_pproc)(p1,p2);
515  return 0;
516  };
517  virtual int argc()
518  {
519  return arity;
520  };
521 };
522 
523 template <class T, class P1, class P2, class P3>
525 {
526  typedef void (T::*memProcPtr)(P1,P2,P3);
527  typedef typename LocVarType<P1>::Type PL1;
528  typedef typename LocVarType<P2>::Type PL2;
529  typedef typename LocVarType<P3>::Type PL3;
530  memProcPtr m_pproc;
531  T * m_pobj;
532  enum {arity=3};
533  memProc3(T * pobj, memProcPtr pproc):m_pproc(pproc),m_pobj(pobj){};
534  virtual int operator()(const QValueVector<QVariant> & parms, QString & err)
535  {
536  if (parms.size()!=arity)
537  {
538  err=QString("Number of provided parameters doesn't match function definition");
539  return 1;
540  };
541  PL1 p1=fromQVariant<PL1>(parms[0]);
542  PL2 p2=fromQVariant<PL2>(parms[1]);
543  PL3 p3=fromQVariant<PL3>(parms[2]);
544  (m_pobj->*m_pproc)(p1,p2,p3);
545  return 0;
546  };
547  virtual int argc()
548  {
549  return arity;
550  };
551 };
552 
553 template <class T, class P1, class P2, class P3, class P4>
555 {
556  typedef void (T::*memProcPtr)(P1,P2,P3,P4);
557  typedef typename LocVarType<P1>::Type PL1;
558  typedef typename LocVarType<P2>::Type PL2;
559  typedef typename LocVarType<P3>::Type PL3;
560  typedef typename LocVarType<P4>::Type PL4;
561  memProcPtr m_pproc;
562  T * m_pobj;
563  enum {arity=4};
564  memProc4(T * pobj, memProcPtr pproc):m_pproc(pproc),m_pobj(pobj){};
565  virtual int operator()(const QValueVector<QVariant> & parms, QString & err)
566  {
567  if (parms.size()!=arity)
568  {
569  err=QString("Number of provided parameters doesn't match function definition");
570  return 1;
571  };
572  PL1 p1=fromQVariant<PL1>(parms[0]);
573  PL2 p2=fromQVariant<PL2>(parms[1]);
574  PL3 p3=fromQVariant<PL3>(parms[2]);
575  PL4 p4=fromQVariant<PL4>(parms[3]);
576  (m_pobj->*m_pproc)(p1,p2,p3,p4);
577  return 0;
578  };
579  virtual int argc()
580  {
581  return arity;
582  };
583 };
584 
585 template <class T, class P1, class P2, class P3, class P4, class P5>
587 {
588  typedef void (T::*memProcPtr)(P1,P2,P3,P4,P5);
589  typedef typename LocVarType<P1>::Type PL1;
590  typedef typename LocVarType<P2>::Type PL2;
591  typedef typename LocVarType<P3>::Type PL3;
592  typedef typename LocVarType<P4>::Type PL4;
593  typedef typename LocVarType<P5>::Type PL5;
594  memProcPtr m_pproc;
595  T * m_pobj;
596  enum {arity=5};
597  memProc5(T * pobj, memProcPtr pproc):m_pproc(pproc),m_pobj(pobj){};
598  virtual int operator()(const QValueVector<QVariant> & parms, QString & err)
599  {
600  if (parms.size()!=arity)
601  {
602  err=QString("Number of provided parameters doesn't match function definition");
603  return 1;
604  };
605  PL1 p1=fromQVariant<PL1>(parms[0]);
606  PL2 p2=fromQVariant<PL2>(parms[1]);
607  PL3 p3=fromQVariant<PL3>(parms[2]);
608  PL4 p4=fromQVariant<PL4>(parms[3]);
609  PL5 p5=fromQVariant<PL5>(parms[4]);
610  (m_pobj->*m_pproc)(p1,p2,p3,p4,p5);
611  return 0;
612  };
613  virtual int argc()
614  {
615  return arity;
616  };
617 };
618 
619 #endif
Definition: conv.h:231
Definition: conv.h:213
Definition: conv.h:336
Definition: conv.h:258
Definition: conv.h:524
Definition: conv.h:446
Definition: conv.h:171
Definition: conv.h:366
Definition: conv.h:237
Definition: conv.h:162
Definition: conv.h:219
Definition: conv.h:554
Definition: conv.h:177
Definition: conv.h:201
Definition: conv.h:282
Definition: conv.h:243
Definition: conv.h:432
Definition: conv.h:37
Definition: conv.h:470
Definition: conv.h:189
Definition: conv.h:399
Definition: conv.h:207
Definition: conv.h:308
Definition: conv.h:183
Definition: conv.h:225
Definition: conv.h:586
Definition: conv.h:496
Definition: conv.h:195
Definition: conv.h:249