Trade equipment common library. 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
36template <class T>
38{
39 typedef T Type;
40};
41
42template <>
43struct LocVarType<const QString &>
44{
45 typedef QString Type;
46};
47
48template <>
49struct LocVarType<QString &>
50{
51 typedef QString Type;
52};
53
54template <>
55struct LocVarType<const int &>
56{
57 typedef int Type;
58};
59
60template <>
61struct LocVarType<int &>
62{
63 typedef int Type;
64};
65
66template <>
67struct LocVarType<const QDateTime &>
68{
69 typedef QDateTime Type;
70};
71
72template <>
73struct LocVarType<QDateTime &>
74{
75 typedef QDateTime Type;
76};
77
78template <>
79struct LocVarType<const float &>
80{
81 typedef float Type;
82};
83
84template <>
85struct LocVarType<float &>
86{
87 typedef float Type;
88};
89
90template <>
91struct LocVarType<double &>
92{
93 typedef double Type;
94};
95
96template <>
97struct LocVarType<const double &>
98{
99 typedef double Type;
100};
101
102template <>
103struct LocVarType<const char *>
104{
105 typedef QCString Type;
106};
107
108template <class T>
109QString toString(T v)
110{
111 return QString("%1").arg(v);
112};
113
114template <>
115LIB_EXPORT QString toString<double>(double v);
116
117template <>
118LIB_EXPORT QString toString<QVariant>(QVariant v);
119
120template <>
121LIB_EXPORT QString toString<float>(float v);
122
123template <class T>
124T fromQVariant(const QVariant & s)
125{
126 return (T)s;
127};
128
129template <>
130LIB_EXPORT bool fromQVariant<bool>(const QVariant &);
131
132template <>
133LIB_EXPORT int fromQVariant<int>(const QVariant &);
134
135template <>
136LIB_EXPORT uint fromQVariant<uint>(const QVariant &);
137
138template <>
139LIB_EXPORT float fromQVariant<float>(const QVariant &);
140
141template <>
142LIB_EXPORT double fromQVariant<double>(const QVariant &);
143
144template <>
145LIB_EXPORT Q_LLONG fromQVariant<Q_LLONG>(const QVariant &);
146
147template <>
148LIB_EXPORT Q_ULLONG fromQVariant<Q_ULLONG>(const QVariant &);
149
150template <>
151LIB_EXPORT Q_ULONG fromQVariant<Q_ULONG>(const QVariant &);
152
153template <>
154LIB_EXPORT Q_LONG fromQVariant<Q_LONG>(const QVariant &);
155
156template <>
157LIB_EXPORT QString fromQVariant<QString>(const QVariant &);
158
159template <>
160LIB_EXPORT QCString fromQVariant<QCString>(const QVariant &);
161
162struct 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
170template <class T, class R>
172{
173 typedef R (T::*memFunPtr)();
174};
175
176template <class T>
178{
179 typedef void (T::*Type)();
180};
181
182template <class T>
184{
185 typedef void (T::*Type)() const;
186};
187
188template <class T, class R, class P1>
190{
191 typedef R (T::*memFunPtr)(P1);
192};
193
194template <class T, class R, class P1, class P2>
196{
197 typedef R (T::*memFunPtr)(P1,P2);
198};
199
200template <class T, class R, class P1, class P2, class P3>
202{
203 typedef R (T::*memFunPtr)(P1,P2,P3);
204};
205
206template <class T, class R, class P1, class P2, class P3, class P4>
208{
209 typedef R (T::*memFunPtr)(P1,P2,P3,P4);
210};
211
212template <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
218template <class T, class R>
220{
221 typedef R (T::*memFunPtr)() const;
222};
223
224template <class T, class R, class P1>
226{
227 typedef R (T::*memFunPtr)(P1) const;
228};
229
230template <class T, class R, class P1, class P2>
232{
233 typedef R (T::*memFunPtr)(P1,P2) const;
234};
235
236template <class T, class R, class P1, class P2, class P3>
238{
239 typedef R (T::*memFunPtr)(P1,P2,P3) const;
240};
241
242template <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
248template <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
257template <class T, class R, class Func=NonConstFunc0<T,R> >
258struct memFunc0 : memFunc
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
281template <class T, class R, class P1, class Func=NonConstFunc1<T,R,P1> >
282struct memFunc1 : memFunc
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
307template <class T, class R, class P1, class P2, class Func=NonConstFunc2<T,R,P1,P2> >
308struct memFunc2 : memFunc
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
335template <class T, class R, class P1, class P2, class P3, class Func=NonConstFunc3<T,R,P1,P2,P3> >
336struct memFunc3 : memFunc
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
365template <class T, class R, class P1, class P2, class P3, class P4, class Func=NonConstFunc4<T,R,P1,P2,P3,P4> >
366struct memFunc4 : memFunc
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
397template <class T, class R, class P1, class P2, class P3, class P4, class P5,
399struct memFunc5 : memFunc
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
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
445template <class T, class FT=NonConstProc0<T> >
446struct memProc0 : memProc
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
469template <class T, class P1>
470struct memProc1 : memProc
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
495template <class T, class P1, class P2>
496struct memProc2 : memProc
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
523template <class T, class P1, class P2, class P3>
524struct memProc3 : memProc
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
553template <class T, class P1, class P2, class P3, class P4>
554struct memProc4 : memProc
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
585template <class T, class P1, class P2, class P3, class P4, class P5>
586struct memProc5 : memProc
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:220
Definition conv.h:226
Definition conv.h:232
Definition conv.h:238
Definition conv.h:244
Definition conv.h:250
Definition conv.h:184
Definition conv.h:38
Definition conv.h:172
Definition conv.h:190
Definition conv.h:196
Definition conv.h:202
Definition conv.h:208
Definition conv.h:214
Definition conv.h:178
Definition conv.h:163
Definition conv.h:433