ICS

QicsTable Documentation Set

QicsDataItem.h

Go to the documentation of this file.
00001 /*********************************************************************
00002 **
00003 ** Copyright (C) 2002-2006 Integrated Computer Solutions, Inc
00004 ** All rights reserved.
00005 **
00006 ** This file is part of the QicsTable Product.
00007 **
00008 **********************************************************************/
00009 
00010 #ifndef _QicsDataItem_H
00011 #define _QicsDataItem_H
00012 
00013 #include <QicsNamespace.h>
00014 
00015 #include <QString>
00016 #include <QDateTime>
00017 #include <QDataStream>
00018 
00022 #define QICS_DEFAULT_TRUE_STRING "True"
00023 
00027 #define QICS_DEFAULT_FALSE_STRING "False"
00028 
00032 typedef unsigned int QicsDataItemType;
00033 const QicsDataItemType QicsDataItem_UserDefined = 0;
00034 const QicsDataItemType QicsDataItem_Int     = 1;
00035 const QicsDataItemType QicsDataItem_Long    = 2;
00036 const QicsDataItemType QicsDataItem_LongLong    = 3;
00037 const QicsDataItemType QicsDataItem_Float   = 4;
00038 const QicsDataItemType QicsDataItem_Double  = 5;
00039 const QicsDataItemType QicsDataItem_String  = 6;
00040 const QicsDataItemType QicsDataItem_Date    = 7;
00041 const QicsDataItemType QicsDataItem_Time    = 8;
00042 const QicsDataItemType QicsDataItem_DateTime    = 9;
00043 const QicsDataItemType QicsDataItem_Bool    = 10;
00044 
00046 
00049 
00050 
00051 // This is used in QicsDataItem::registerType() and must be declared
00052 // first.
00053 
00054 class QicsDataItem;
00060 typedef QicsDataItem * (*QicsDataItemParser)(const QString &);
00065 typedef QicsDataItem * (*QicsDataItemDecoder)(QDataStream &);
00066 
00075 typedef QicsDataItem * (*QicsDataItemDecoderWithType)(QDataStream &,
00076                               const QString &);
00077 
00079 
00100 class QICS_EXPORT QicsDataItem: public Qics {
00101     
00102 public:
00103 
00108     virtual QicsDataItem *create(void) const = 0;
00109 
00114     virtual QicsDataItem *clone(void) const = 0;
00115 
00116     virtual ~QicsDataItem() {}
00121     virtual bool setString(const QString &qs) = 0;
00122 
00127     virtual const QString string(void) const = 0;
00128         
00133     virtual QicsDataItemType type(void) const = 0;
00134 
00138     virtual QString typeString(void) const = 0;
00139 
00147     inline virtual QString format(const char *) const
00148     { return string(); }
00149 
00156     virtual int compareTo(const QicsDataItem &x) const;
00160     virtual void encode(QDataStream &ds) const = 0;
00164     static QicsDataItem *fromString(const QString &str);
00168     static QicsDataItem *decode(QDataStream &ds);
00182     static void registerType(const QString type_name,
00183                  QicsDataItemParser parser,
00184                  QicsDataItemDecoder decoder);
00185 
00201     static void registerTypeI(const QString type_name,
00202                   QicsDataItemParser parser,
00203                   QicsDataItemDecoderWithType decoder);
00204 
00219     static void registerParser(QicsDataItemParser parser);
00220 };
00221 
00225 typedef int (*DataItemComparator)(const QicsDataItem *, const QicsDataItem *); 
00226 
00228 
00235 class QICS_EXPORT QicsDataBool: public QicsDataItem {
00236 public:
00237             
00241     QicsDataBool() 
00242     { 
00243     myData = false; 
00244     setTrueString ( QString(QICS_DEFAULT_TRUE_STRING)  );
00245     setFalseString( QString(QICS_DEFAULT_FALSE_STRING) );
00246     }
00247 
00251     QicsDataBool(bool v, QString ts = QICS_DEFAULT_TRUE_STRING, QString fs = QICS_DEFAULT_FALSE_STRING ) 
00252     { 
00253     myData = v;
00254     setTrueString ( QString(ts) );
00255     setFalseString( QString(fs) );
00256     }
00257 
00261     QicsDataBool(const QicsDataBool &db);
00262 
00263     inline QicsDataItem *create(void) const { return new QicsDataBool(); }
00264     inline QicsDataItem *clone(void) const { return new QicsDataBool(*this); }
00265 
00269     inline virtual QicsDataItemType type(void) const
00270     { return (QicsDataItem_Bool); }
00271 
00275     inline static QString typeName(void)
00276     { return QString("bool"); }
00277 
00281     inline virtual QString typeString(void) const
00282     { return QicsDataBool::typeName(); }
00283 
00288     inline virtual QicsDataBool& operator=(const bool& b)
00289     { myData = b; return *this;}
00290         
00291     inline virtual const QString string(void) const 
00292     { 
00293     if ( myData ) return QString( trueString() );
00294     else return QString(falseString());
00295     }
00296     
00297     inline virtual bool setString(const QString &qs)
00298     {
00299     bool ok = false;
00300     if ( qs == trueString()  ) { myData = true;  ok = true; }
00301     else
00302         if ( qs == falseString() ) { myData = false; ok = true; }
00303     return ok;
00304     }
00305 
00309     inline bool data(void) const { return myData; }
00310 
00314     inline void setData(bool b) { myData = b;}
00315         
00316     inline virtual QString format(const char *fmt_string) const
00317     { QString str; return str.sprintf(fmt_string, (const char *) string().toAscii() ); }
00318 
00319     int compareTo(const QicsDataItem &x) const;
00320     inline void encode(QDataStream &ds) const 
00321     { ds << typeString(); ds << myData; }
00326     static QicsDataItem *fromString(const QString &str);
00330     static QicsDataItem *decode(QDataStream &ds)
00331     { bool val; ds >> val; return new QicsDataBool(val); }
00335     inline QString trueString() const { return myTrueString; }
00336 
00340     inline QString falseString() const { return myFalseString; }
00341 
00345     bool setTrueString(const QString &qs) 
00346     { 
00347     if (!qs.isEmpty()) 
00348         { myTrueString = qs; return true;}
00349     return false;
00350     }
00351 
00355     bool setFalseString(const QString &qs) 
00356     { 
00357     if (!qs.isEmpty()) 
00358         { myFalseString = qs; return true;}
00359     return false;
00360     }
00361 
00362 protected:
00367     bool myData;
00368 
00373     QString myTrueString;
00374 
00379     QString myFalseString;
00380 };
00381 
00383 
00391 class QICS_EXPORT QicsDataInt: public QicsDataItem {
00392 public:
00393             
00397     QicsDataInt() { myData = 0; }
00398 
00402     QicsDataInt(int i) { myData = i;}
00403 
00407     QicsDataInt(const QicsDataInt &di);
00408 
00409     inline QicsDataItem *create(void) const { return new QicsDataInt(); }
00410     inline QicsDataItem *clone(void) const { return new QicsDataInt(*this); }
00411 
00415     inline virtual QicsDataItemType type(void) const
00416     { return (QicsDataItem_Int); }
00417 
00421     inline static QString typeName(void)
00422     { return QString("int"); }
00423 
00427     inline virtual QString typeString(void) const
00428     { return QicsDataInt::typeName(); }
00429 
00434     inline virtual QicsDataInt& operator=(const int& i)
00435     { myData = i; return *this;}
00436         
00437     inline virtual const QString string(void) const { return QString("%1").arg(myData); }
00438     inline virtual bool setString(const QString &qs) 
00439     {bool ok; myData = qs.toInt(&ok); return ok;}
00440 
00444     inline int data(void) const { return myData; }
00445 
00449     inline void setData(int i) { myData = i;}
00450         
00451     inline virtual QString format(const char *fmt_string) const
00452     { QString str; return str.sprintf(fmt_string, myData); }
00453 
00454     int compareTo(const QicsDataItem &x) const;
00455     inline void encode(QDataStream &ds) const 
00456     { ds << typeString(); ds << myData; }
00461     static QicsDataItem *fromString(const QString &str);
00465     static QicsDataItem *decode(QDataStream &ds)
00466     { int val; ds >> val; return new QicsDataInt(val); }
00467 protected:
00472     int myData;     
00473 };
00474 
00476 
00483 class QICS_EXPORT QicsDataLong: public QicsDataItem {
00484 public:
00485             
00489     QicsDataLong() { myData = 0; }
00490 
00494     QicsDataLong(long i) { myData = i;}
00495 
00499     QicsDataLong(const QicsDataLong &dl);
00500 
00501     inline QicsDataItem *create(void) const { return new QicsDataLong(); }
00502     inline QicsDataItem *clone(void) const { return new QicsDataLong(*this); }
00503 
00507     inline virtual QicsDataItemType type(void) const
00508     { return (QicsDataItem_Long); }
00509 
00513     inline static QString typeName(void)
00514     { return QString("long"); }
00515 
00519     inline virtual QString typeString(void) const
00520     { return QicsDataLong::typeName(); }
00521 
00526     inline virtual QicsDataLong& operator=(const long& i)
00527     { myData = i; return *this;}
00528         
00529     inline virtual const QString string(void) const { return QString("%1").arg(myData); }
00530     inline virtual bool setString(const QString &qs) 
00531     {bool ok; myData = qs.toLong(&ok); return ok;}
00532 
00536     inline long data(void) const { return myData; }
00537 
00541     inline void setData(long i) { myData = i;}
00542         
00543     inline virtual QString format(const char *fmt_string) const
00544     { QString str; return str.sprintf(fmt_string, myData); }
00545 
00546     int compareTo(const QicsDataItem &x) const;
00547     inline void encode(QDataStream &ds) const 
00548         { ds << typeString(); ds << qlonglong(myData); }
00553     static QicsDataItem *fromString(const QString &str);
00557     static QicsDataItem *decode(QDataStream &ds)
00558     { qlonglong val; ds >> val; return new QicsDataLong((long)val); }
00559 
00560 protected:
00565     long myData;
00566 };
00567 
00569 
00577 class QICS_EXPORT QicsDataLongLong: public QicsDataItem {
00578 public:
00579             
00583     QicsDataLongLong() { myData = 0; }
00584 
00588     QicsDataLongLong(qlonglong i) { myData = i;}
00589 
00593     QicsDataLongLong(const QicsDataLongLong &dl);
00594 
00595     inline QicsDataItem *create(void) const { return new QicsDataLongLong(); }
00596     inline QicsDataItem *clone(void) const { return new QicsDataLongLong(*this); }
00597 
00601     inline virtual QicsDataItemType type(void) const
00602     { return (QicsDataItem_LongLong); }
00603 
00607     inline static QString typeName(void)
00608     { return QString("int64"); }
00609 
00613     inline virtual QString typeString(void) const
00614     { return QicsDataLongLong::typeName(); }
00615 
00620     inline virtual QicsDataLongLong& operator=(const qlonglong& i)
00621     { myData = i; return *this;}
00622         
00623     inline virtual const QString string(void) const { return QString("%1").arg(myData); }
00624     inline virtual bool setString(const QString &qs) ;
00625 
00629     inline qlonglong data(void) const { return myData; }
00630 
00634     inline void setData(qlonglong i) { myData = i;}
00635         
00636     inline virtual QString format(const char *fmt_string) const
00637     { QString str; return str.sprintf(fmt_string, myData); }
00638 
00639     int compareTo(const QicsDataItem &x) const;
00640 
00641     inline void encode(QDataStream &ds) const 
00642     { ds << typeString(); ds << myData; }
00643 
00648     static QicsDataItem *fromString(const QString &str);
00649 
00653     static QicsDataItem *decode(QDataStream &ds)
00654     { qlonglong val; ds >> val; return new QicsDataLongLong(val); }
00655 
00656 protected:
00661     qlonglong myData;
00662 };
00664 
00671 class QICS_EXPORT QicsDataFloat: public QicsDataItem {
00672 public:
00673             
00677     QicsDataFloat() { myData = 0.0; }
00678 
00682     QicsDataFloat(float f) { myData = f;}
00683 
00687     QicsDataFloat(const QicsDataFloat &df);
00688 
00689     inline QicsDataItem *create(void) const { return new QicsDataFloat(); }
00690     inline QicsDataItem *clone(void) const { return new QicsDataFloat(*this); }
00691 
00695     inline virtual QicsDataItemType type(void) const
00696     { return (QicsDataItem_Float); }
00697 
00701     inline static QString typeName(void)
00702     { return QString("float"); }
00703 
00707     inline virtual QString typeString(void) const
00708     { return QicsDataFloat::typeName(); }
00709 
00714     inline virtual QicsDataFloat& operator=(const float& f)
00715     { myData = f; return *this;}
00716         
00717     inline virtual const QString string(void) const { return QString("%1").arg(myData); }
00718     inline virtual bool setString(const QString &qs) 
00719     {bool ok; myData = qs.toFloat(&ok); return ok;}
00720 
00724     inline float data(void) const { return myData; }
00725 
00729     inline void setData(float f) { myData = f;}
00730         
00731     inline virtual QString format(const char *fmt_string) const
00732     { QString str; return str.sprintf(fmt_string, myData); }
00733 
00734     int compareTo(const QicsDataItem &x) const;
00735     inline void encode(QDataStream &ds) const 
00736     { ds << typeString(); ds << myData; }
00741     static QicsDataItem *fromString(const QString &str);
00745     static QicsDataItem *decode(QDataStream &ds)
00746     { float val; ds >> val; return new QicsDataFloat(val); }
00747 protected:
00752     float myData;     
00753 };
00754 
00756 
00763 class QICS_EXPORT QicsDataDouble: public QicsDataItem {
00764 public:
00765             
00769     QicsDataDouble() { myData = 0.0; }
00770 
00774     QicsDataDouble(double d) { myData = d;}
00775 
00779     QicsDataDouble(const QicsDataDouble &dd);
00780 
00781     inline QicsDataItem *create(void) const { return new QicsDataDouble(); }
00782     inline QicsDataItem *clone(void) const { return new QicsDataDouble(*this); }
00783 
00787     inline static QString typeName(void)
00788     { return QString("double"); }
00789 
00793     inline virtual QString typeString(void) const
00794     { return QicsDataDouble::typeName(); }
00795 
00799     inline virtual QicsDataItemType type(void) const
00800     { return (QicsDataItem_Double); }
00801 
00806     inline virtual QicsDataDouble& operator=(const double& d)
00807     { myData = d; return *this;}
00808         
00809     inline virtual const QString string(void) const { return QString("%1").arg(myData); }
00810     inline virtual bool setString(const QString &qs) 
00811     {bool ok; myData = qs.toDouble(&ok); return ok;}
00812 
00816     inline double data(void) const { return myData; }
00817 
00821     inline void setData(double d) { myData = d;}
00822         
00823     inline virtual QString format(const char *fmt_string) const
00824     { QString str; return str.sprintf(fmt_string, myData); }
00825 
00826     int compareTo(const QicsDataItem &x) const;
00827     inline void encode(QDataStream &ds) const 
00828     { ds << typeString(); ds << myData; }
00833     static QicsDataItem *fromString(const QString &str);
00837     static QicsDataItem *decode(QDataStream &ds)
00838     { double val; ds >> val; return new QicsDataDouble(val); }
00839 protected:
00845     double myData;     
00846 };
00847 
00849 
00857 class QICS_EXPORT QicsDataString: public QicsDataItem {
00858 public:
00859 
00864     QicsDataString() { myData = QString(); }
00865 
00869     QicsDataString(const QString &qs);
00870     QicsDataString(const char* s);
00871 
00872     virtual ~QicsDataString() {}
00873 
00877     QicsDataString(const QicsDataString &ds);
00878 
00879     inline QicsDataItem *create(void) const { return new QicsDataString(); }
00880     inline QicsDataItem *clone(void) const { return new QicsDataString(*this); }
00881 
00885     inline static QString typeName(void)
00886     { return QString("qstring"); }
00887 
00891     inline virtual QString typeString(void) const
00892     { return QicsDataString::typeName(); }
00893 
00897     inline virtual QicsDataItemType type(void) const
00898     { return (QicsDataItem_String); }
00899 
00904     QicsDataString& operator=(const QicsDataString& qs); 
00905         
00906     inline virtual bool setString(const QString &qs) 
00907     { myData = qs; return true;}
00908 
00912     inline bool setData(const char *s)
00913     { myData = s; return true;}
00914 
00918     inline bool setData(const QString &qs)
00919     { myData = qs; return true;}
00920 
00924     inline QString data(void) const { return myData;} 
00925         
00926     inline virtual const QString string(void) const { return myData; } 
00927 
00928     inline virtual QString format(const char *fmt_string) const
00929     { QString str; return str.sprintf(fmt_string, (const char *) myData.toAscii()); }
00930 
00931     int compareTo(const QicsDataItem &x) const;
00932     inline void encode(QDataStream &ds) const 
00933     { ds << typeString(); ds << myData; }
00934 
00938     static QicsDataItem *decode(QDataStream &ds)
00939     { QString val; ds >> val; return new QicsDataString(val); }
00940 protected: 
00945     QString myData;
00946 };
00947 
00949 
00956 class QICS_EXPORT QicsDataDate: public QicsDataItem
00957 {
00958 public:
00959 
00963     QicsDataDate(Qt::DateFormat format = Qt::TextDate);
00968     QicsDataDate(const QDate &date, Qt::DateFormat format = Qt::TextDate);
00973     QicsDataDate(int y, int m, int d, Qt::DateFormat format = Qt::TextDate);
00974 
00978     QicsDataDate(const QicsDataDate &dd);
00979 
00980     inline QicsDataItem *create(void) const { return new QicsDataDate(); }
00981     inline QicsDataItem *clone(void) const { return new QicsDataDate(*this); }
00982 
00986     inline static QString typeName(void)
00987     { return QString("qdate"); }
00988 
00992     inline virtual QString typeString(void) const
00993     { return QicsDataDate::typeName(); }
00994 
00998     inline virtual QicsDataItemType type(void) const
00999     { return (QicsDataItem_Date); }
01000 
01005     virtual QicsDataDate& operator=(const QDate &d);
01006         
01007     inline virtual const QString string(void) const
01008     { return myData.toString(); }
01009     virtual bool setString(const QString &qs);
01010 
01014     inline QDate data(void) const { return myData; }
01015 
01019     inline void setData(const QDate &date)
01020     { myData = date; }
01021 
01022     virtual QString format(const char *fmt_string) const;
01023 
01027     inline virtual Qt::DateFormat defaultDateFormat(void) const
01028     { return myDefaultFormat;}
01029 
01033     inline virtual void setDefaultDateFormat(Qt::DateFormat f)
01034     { myDefaultFormat = f; }
01035 
01036     int compareTo(const QicsDataItem &x) const;
01037     inline void encode(QDataStream &ds) const 
01038     { ds << typeString(); ds << myData; }
01043     static QicsDataItem *fromString(const QString &str);
01047     static QicsDataItem *decode(QDataStream &ds)
01048     { QDate val; ds >> val; return new QicsDataDate(val); }
01049 protected:
01054     QDate myData;
01059     Qt::DateFormat myDefaultFormat;
01060 };
01061 
01063 
01070 class QICS_EXPORT QicsDataTime: public QicsDataItem
01071 {
01072 public:
01073 
01077     QicsDataTime(Qt::DateFormat format = Qt::TextDate);
01082     QicsDataTime(const QTime &time, Qt::DateFormat format = Qt::TextDate);
01087     QicsDataTime(int hour, int minute, int second, int msec,
01088          Qt::DateFormat format);
01089 
01093     QicsDataTime(const QicsDataTime &dt);
01094 
01095     inline QicsDataItem *create(void) const { return new QicsDataTime(); }
01096     inline QicsDataItem *clone(void) const { return new QicsDataTime(*this); }
01097 
01101     inline static QString typeName(void)
01102     { return QString("qtime"); }
01103 
01107     inline virtual QString typeString(void) const
01108     { return QicsDataTime::typeName(); }
01109 
01113     inline virtual QicsDataItemType type(void) const
01114     { return (QicsDataItem_Time); }
01115 
01120     virtual QicsDataTime& operator=(const QTime &t);
01121         
01122     inline virtual const QString string(void) const { return myData.toString(); }
01123     virtual bool setString(const QString &qs);
01124 
01128     inline QTime data(void) const { return myData; }
01129 
01133     void setData(const QTime &time);
01134 
01135     virtual QString format(const char *fmt_string) const;
01136 
01140     inline virtual Qt::DateFormat defaultDateFormat(void) const
01141     { return myDefaultFormat;}
01142 
01146     inline virtual void setDefaultDateFormat(Qt::DateFormat f)
01147     { myDefaultFormat = f; }
01148 
01149     int compareTo(const QicsDataItem &x) const;
01150     inline void encode(QDataStream &ds) const 
01151     { ds << typeString(); ds << myData; }
01156     static QicsDataItem *fromString(const QString &str);
01160     static QicsDataItem *decode(QDataStream &ds)
01161     { QTime val; ds >> val; return new QicsDataTime(val); }
01162 protected:
01167     QTime myData;
01172     Qt::DateFormat myDefaultFormat;
01173 };
01174 
01176 
01183 class QICS_EXPORT QicsDataDateTime: public QicsDataItem
01184 {
01185 public:
01186 
01190     QicsDataDateTime(Qt::DateFormat format = Qt::TextDate);
01195     QicsDataDateTime(const QDateTime &dt, Qt::DateFormat format = Qt::TextDate);
01200     QicsDataDateTime(const QDate &date, const QTime &time,
01201              Qt::DateFormat format = Qt::TextDate);
01202 
01206     QicsDataDateTime(const QicsDataDateTime &ddt);
01207 
01208     inline QicsDataItem *create(void) const { return new QicsDataDateTime(); }
01209     inline QicsDataItem *clone(void) const { return new QicsDataDateTime(*this); }
01210 
01211     inline virtual QicsDataItemType type(void) const
01212     { return (QicsDataItem_DateTime); }
01213 
01217     inline static QString typeName(void)
01218     { return QString("qdatetime"); }
01219 
01223     inline virtual QString typeString(void) const
01224     { return QicsDataDateTime::typeName(); }
01225 
01230     virtual QicsDataDateTime& operator=(const QDateTime &dt);
01231         
01232     inline virtual const QString string(void) const { return myData.toString(); }
01233     
01238     inline virtual const QString string(const char *fmt_string) const 
01239     { 
01240     return myData.toString(fmt_string); 
01241     }
01242     virtual bool setString(const QString &qs);
01243 
01247     inline QDateTime data(void) const { return myData; }
01248 
01252     void setData(const QDateTime &dt);
01253 
01254     virtual QString format(const char *fmt_string) const;
01255 
01259     inline virtual Qt::DateFormat defaultDateFormat(void) const
01260     { return myDefaultFormat;}
01261 
01265     inline virtual void setDefaultDateFormat(Qt::DateFormat f)
01266     { myDefaultFormat = f; }
01267 
01268     int compareTo(const QicsDataItem &x) const;
01269     inline void encode(QDataStream &ds) const 
01270     { ds << typeString(); ds << myData; }
01275     static QicsDataItem *fromString(const QString &str);
01279     static QicsDataItem *decode(QDataStream &ds)
01280     { QDateTime val; ds >> val; return new QicsDataDateTime(val); }
01281 protected:
01286     QDateTime myData;
01291     Qt::DateFormat myDefaultFormat;
01292 };
01293 
01294 #endif /*_QicsDataItem_H --- Do not add anything past this line */
01295  

All trademarks and copyrights on this page are properties of their respective owners.
The rest is copyright 1999-2006 Integrated Computer Solutions, Inc.