Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

FBwNumField.h

Go to the documentation of this file.
00001 
00005 //---------------------------------------------------------------------------
00006 
00007 #ifndef FBwNumFieldH
00008 #define FBwNumFieldH
00009 
00010 //---------------------------------------------------------------------------
00011 
00013 namespace fbwrap
00014 {
00015 
00016 // What are we using from standard libraries
00017 using std::string;
00018 
00020 class FBwNumField : public FBwField
00021 {
00022 protected:
00023     float factor;
00024     struct
00025     {
00026         bool showmon    :1;
00027         bool showgroup  :1;
00028         bool showsign   :1;
00029         bool showparen  :1;
00030         bool blanknull  :1;
00031         bool fillzero   :1;
00032     } format;
00033     string GetFormat() const
00034     {
00035         return dspformat;
00036     }
00037     string GetFormatedValue(double val) const;
00038 public:
00039     virtual void SetFormatFlag();
00041 
00045     FBwNumField(string pname,FBwFieldKind pKind);
00047     FBwNumField(const FBwNumField &f,FBwFieldKind pKind);
00049     virtual void SetScale(short scal);
00051 
00055     void ShowSign(bool show)
00056     {
00057         format.showsign=show;
00058         SetFormatFlag();
00059     }
00061     void ShowParen(bool show)
00062     {
00063         format.showparen=show;
00064         SetFormatFlag();
00065     }
00067     void ShowMon(bool show)
00068     {
00069         format.showmon=show;
00070         SetFormatFlag();
00071     }
00073     void ShowGroup(bool show)
00074     {
00075         format.showgroup=show;
00076         SetFormatFlag();
00077     }
00079     virtual ~FBwNumField()
00080     {}
00081 };
00082 
00084 class FBwFloatField : public FBwNumField
00085 {
00086     float  value,svalue;
00087 protected:
00088     virtual void *GetPtr()
00089     {
00090         return &svalue;
00091     }
00092     virtual int ByteSize()
00093     {
00094         return sizeof(svalue);
00095     }
00096 public:
00098 
00101     FBwFloatField(string pName);
00103     FBwFloatField(const FBwFloatField &f);
00105     virtual short AsShort() const
00106     {
00107         return (short)(value);
00108     }
00110     virtual long AsInteger() const
00111     {
00112         return (long) (value);
00113     }
00115     virtual long long int AsLongInteger() const
00116     {
00117         return (long long int) (value);
00118     }
00120     virtual double AsDouble() const
00121     {
00122         return (double)value;
00123     }
00124     virtual void SetAsShort(short pvalue)
00125     {
00126         value = (float)(pvalue);
00127         ClearNull();
00128     }
00129     virtual void SetAsInteger(long pvalue)
00130     {
00131         value = (float)pvalue;
00132         ClearNull();
00133     }
00134     virtual void SetAsString(const string &pvalue);
00135     virtual void SetAsLongInteger(long long int pvalue)
00136     {
00137         value = (float)pvalue;
00138         ClearNull();
00139     }
00140     virtual void SetAsDouble(double pvalue)
00141     {
00142         value = (float)pvalue;
00143         ClearNull();
00144     }
00145     virtual void BindPtr(char  **p)
00146     {
00147         *p=(char *)&svalue;
00148     }
00149     virtual void ConvertStoV()
00150     {
00151         if( IsNull() )
00152             value = 0;
00153         value=svalue*factor;
00154     }
00155     virtual void ConvertVtoS()
00156     {
00157         svalue=value/factor;
00158     }
00159     virtual string AsString() const;
00160     virtual std::ostream &DisplayText(std::ostream &o) const;
00161     FBwField *Clone() const
00162     {
00163         return new FBwFloatField(*this);
00164     }
00165     virtual void bCopy(const FBwField *f)
00166     {
00167         value = f->AsDouble();
00168     }
00169     virtual ~FBwFloatField()
00170     {}
00171 };
00173 class FBwDoubleField : public FBwNumField
00174 {
00175     double  value;
00176     double svalue;
00177 protected:
00178     virtual void *GetPtr()
00179     {
00180         return &svalue;
00181     }
00182     virtual int ByteSize()
00183     {
00184         return sizeof(svalue);
00185     }
00186 public:
00187     FBwDoubleField(string pName);
00188     FBwDoubleField(const FBwDoubleField &f);
00189     virtual short AsShort() const
00190     {
00191         return (short)(value);
00192     }
00193     virtual long AsInteger() const
00194     {
00195         return (long) (value);
00196     }
00197     virtual long long int AsLongInteger() const
00198     {
00199         return (long long int) (value);
00200     }
00201     virtual double AsDouble() const
00202     {
00203         return (double)(value);
00204     }
00205     virtual void SetAsShort(short pvalue)
00206     {
00207         value = (double)pvalue;
00208         ClearNull();
00209     }
00210     virtual void SetAsInteger(long pvalue)
00211     {
00212         value = (double)pvalue;
00213         ClearNull();
00214     }
00215     virtual void SetAsLongInteger(long long int pvalue)
00216     {
00217         value = (double)pvalue;
00218         ClearNull();
00219     }
00220     virtual void SetAsDouble(double pvalue)
00221     {
00222         value = (double)pvalue;
00223         ClearNull();
00224     }
00225     virtual void SetAsString(const string &pvalue);
00226     virtual void BindPtr(char  **p)
00227     {
00228         *p=(char *)&svalue;
00229     }
00230     virtual void ConvertStoV()
00231     {
00232         if( IsNull() )
00233             value = 0;
00234         value=svalue*factor;
00235     }
00236     virtual void ConvertVtoS()
00237     {
00238         svalue=value/factor;
00239     }
00240     virtual string AsString() const;
00241     virtual std::ostream &DisplayText(std::ostream &o) const;
00242     FBwField *Clone() const
00243     {
00244         return new FBwDoubleField(*this);
00245     }
00246     virtual void bCopy(const FBwField *f)
00247     {
00248         value = f->AsDouble();
00249     }
00250     virtual ~FBwDoubleField()
00251     {}
00252 };
00253 
00255 class FBwExact32 : public FBwNumField
00256 {
00257     int value;
00258     int svalue;
00259 protected:
00260     virtual void *GetPtr()
00261     {
00262         return &svalue;
00263     }
00264     virtual int ByteSize()
00265     {
00266         return sizeof(svalue);
00267     }
00268 public:
00269     FBwExact32(string pName);
00270     FBwExact32(const FBwExact32 &f);
00271     virtual void SetFormatFlag();
00272     virtual short AsShort() const
00273     {
00274         return (short)(value);
00275     }
00276     virtual long AsInteger() const
00277     {
00278         return (long) (value);
00279     }
00280     virtual long long int AsLongInteger() const
00281     {
00282         return (long long int) (value);
00283     }
00284     virtual double AsDouble() const
00285     {
00286         double val=value;
00287         return (double)(val/factor);
00288     }
00289     virtual float AsFloat() const
00290     {
00291         double val=value;
00292         return (float)(val/factor);
00293     }
00294     virtual void SetAsShort(short pvalue)
00295     {
00296         value = (int)pvalue;
00297         ClearNull();
00298     }
00299     virtual void SetAsInteger(long pvalue)
00300     {
00301         value = (int)pvalue;
00302         ClearNull();
00303     }
00304     virtual void SetAsLongInteger(long long int pvalue)
00305     {
00306         value = (int)pvalue;
00307         ClearNull();
00308     }
00309     virtual void SetAsDouble(double pvalue)
00310     {
00311         value = (int)(pvalue*factor);
00312         ClearNull();
00313     }
00314     virtual void SetAsString(const string &pvalue);
00315     virtual void BindPtr(char  **p)
00316     {
00317         *p=(char *)&svalue;
00318     }
00319     virtual void ConvertStoV()
00320     {
00321         if( IsNull() )
00322             value = 0;
00323         value=svalue;
00324     }
00325     virtual void ConvertVtoS()
00326     {
00327         svalue=value;
00328     }
00329     virtual string AsString() const;
00330     virtual std::ostream &DisplayText(std::ostream &o) const;
00331     FBwField *Clone() const
00332     {
00333         return new FBwExact32(*this);
00334     }
00335     virtual void bCopy(const FBwField *f)
00336     {
00337         // can loose precision here 
00338         SetAsDouble(f->AsDouble());
00339     }
00340     virtual ~FBwExact32()
00341     {}
00342 };
00343 //-------------------------------------------------------------------------
00344 }
00345 #endif

Generated on Fri Jan 31 08:30:02 2003 for fbwrap by doxygen1.2.17