Main Page   Class Hierarchy   File List  

openFields.cpp

00001 /*
00002   Open Field impleentation file: openFields.cpp
00003 
00004 */
00005 #include "openFields.h"
00006 #include <cstdio> // for sprintf
00007 #include "ocString.h"
00008 /*
00009 class basicField
00010 properties:
00011   bool       m_bIsNull;
00012   bool       m_bIsEditable;
00013   string     m_strTable;
00014   string     m_strName;
00015   string     m_strFormatMask;
00016   string     m_strServerMask;
00017   string     m_strFormatted;
00018   fieldTypes m_fieldType;
00019   int        m_iSize;
00020 */
00021 basicField::basicField()
00022 :m_bIsNull(false),m_bIsEditable(false),m_strTable(""),
00023 m_strName(""),m_strFormatMask(""),m_strServerMask(""),
00024 m_strFormatted(""),m_fieldType(shortType),m_iSize(0)
00025 {
00026   ;
00027 }
00028 basicField::basicField
00029 ( bool isNull, bool isEditable,  string name, string table )
00030 :m_bIsNull(isNull),m_bIsEditable(isEditable),m_strTable(table),
00031 m_strName(name),m_strFormatMask(""),m_strServerMask(""),
00032 m_strFormatted(""),m_fieldType(shortType),m_iSize(0)
00033 {
00034   ;
00035 }
00036 
00037 
00038 basicField::~basicField()
00039 {
00040   ;
00041 }
00042     // assignment
00043 basicField & basicField::operator = ( basicField & input )
00044 {
00045   m_bIsNull=input.m_bIsNull;
00046   m_bIsEditable=input.m_bIsEditable;
00047   m_strTable=input.m_strTable;
00048   m_strName=input.m_strName;
00049   m_strFormatMask=input.m_strFormatMask;
00050   m_strServerMask = input.m_strServerMask;
00051   m_fieldType=input.m_fieldType;
00052   m_iSize = input.m_iSize;
00053   return *this;
00054 }
00055   // Sets
00056 basicField & basicField::setNull( bool bNull )
00057 {
00058   m_bIsNull=bNull;
00059   return *this;
00060 }
00061 basicField & basicField::setIsEditable( bool bEditable )
00062 {
00063   m_bIsEditable=bEditable;
00064   return *this;
00065 }
00066 basicField & basicField::setName( string strName )
00067 {
00068   m_strName=strName;
00069   return *this;
00070 }
00071 basicField & basicField::setTable( string strTable )
00072 {
00073   m_strTable=strTable;
00074   return *this;
00075 }
00076 basicField & basicField::setFormatMask( string strFormatMask )
00077 {
00078   m_strFormatMask=strFormatMask;
00079   return *this;
00080 }
00081 basicField & basicField::setSvrFormatMask( string strFormatMask )
00082 {
00083   m_strServerMask=strFormatMask;
00084   return *this;
00085 }
00086 basicField & basicField::setSize( int iSize )
00087 {
00088   m_iSize = iSize;
00089   return *this;
00090 }
00091   // Gets
00092 bool basicField::isNull( void )
00093 {
00094   return m_bIsNull;
00095 }
00096 bool basicField::isEditable( void )
00097 {
00098   return m_bIsEditable;
00099 }
00100 int  basicField::getSize( void )
00101 {
00102   return m_iSize;
00103 }
00104 string & basicField::getName( void )
00105 {
00106   return m_strName;
00107 }
00108 string & basicField::getTable( void )
00109 {
00110   return m_strTable;
00111 }
00112 fieldTypes basicField::getType( void )
00113 {
00114   return m_fieldType;
00115 }
00116 
00117 string & basicField::format()
00118 {
00119   return m_strFormatMask;
00120 }
00121 string & basicField::svrFormat()
00122 {
00123   return m_strServerMask;
00124 }
00125 
00126 
00127 // shortType
00128 /*
00129 class shortField:
00130 properties:
00131   bool       m_bIsNull;
00132   bool       m_bIsEditable;
00133   string     m_strTable;
00134   string     m_strName;
00135   string     m_strFormatMask;
00136   fieldTypes m_fieldType;
00137   short m_field;
00138 */
00139 
00140 // construction / destruction
00141 shortField::shortField
00142 ( short value, bool isNull, bool isEditable,  string name, string table )
00143 :basicField(isNull, isEditable, name, table),m_field(value)
00144 {
00145   m_strFormatMask = "%d";
00146   m_strServerMask = "%d";
00147 }
00148 shortField:: ~shortField(){;}
00149 
00150 // assignment
00151 shortField & shortField::operator = ( shortField & input )
00152 {
00153   basicField::operator = (input);
00154   m_field = input.get();
00155   return *this;
00156 }
00157 
00158 // access
00159 short & shortField::get( void )
00160 {
00161   return m_field;
00162 }
00163 void shortField::set( short input )
00164 {
00165   m_field = input;
00166   m_bIsNull = false;
00167 }
00168 
00169 // formatting
00170 string & shortField::format()
00171 {
00172   // temporary buffer big enough to hold formatted value
00173   char temp[64];
00174   // use old c formatting function
00175   sprintf( temp, m_strFormatMask.c_str(), m_field);
00176   m_strFormatted = temp;
00177   return  m_strFormatted;
00178 }
00179 string & shortField::svrFormat()
00180 {
00181   // temporary buffer big enough to hold formatted value
00182   char temp[64];
00183   // use old c formatting function
00184   sprintf( temp, m_strServerMask.c_str(), m_field);
00185   m_strFormatted = temp;
00186   return  m_strFormatted;
00187 }
00188 
00189 // longType
00190 /*
00191 class longField:
00192 
00193 properties:
00194   bool       m_bIsNull;
00195   bool       m_bIsEditable;
00196   string     m_strTable;
00197   string     m_strName;
00198   string     m_strFormatMask;
00199   fieldTypes m_fieldType;
00200   long       m_field;
00201 
00202 */
00203 
00204 // construction / destruction
00205 longField::longField
00206 ( long value, bool isNull, bool isEditable, string name, string table )
00207 :basicField(isNull, isEditable, name, table),m_field(value)
00208 {
00209   m_strFormatMask = "%ld";
00210   m_strServerMask = "%ld";
00211   m_fieldType = longType;
00212 }
00213 
00214 longField::~longField(){;}
00215 
00216 
00217 // assignment
00218 longField & longField::operator = ( longField & input )
00219 {
00220   basicField::operator = (input);
00221   m_field = input.get();
00222   return *this;
00223 }
00224 
00225 // access
00226 long & longField::get( void )
00227 {
00228   return m_field;
00229 }
00230 void longField::set( long input )
00231 {
00232   m_field = input;
00233   m_bIsNull = false;
00234 }
00235 
00236 // formatting
00237 string & longField::format()
00238 {
00239   if( m_bIsNull )
00240   {
00241     m_strFormatted="";
00242   }
00243   else
00244   {
00245     // temporary buffer big enough to hold formatted value
00246     char temp[64];
00247     // use old c formatting function
00248     sprintf( temp, m_strFormatMask.c_str(), m_field);
00249     m_strFormatted = temp;
00250   }
00251   return  m_strFormatted;
00252 }
00253 string & longField::svrFormat()
00254 {
00255   if( m_bIsNull )
00256   {
00257     m_strFormatted="NULL";
00258   }
00259   else
00260   {
00261     // temporary buffer big enough to hold formatted value
00262     char temp[64];
00263     // use old c formatting function
00264     sprintf( temp, m_strServerMask.c_str(), m_field);
00265     m_strFormatted = temp;
00266   }
00267   return  m_strFormatted;
00268 }
00269 
00270 // longlongType
00271 /*
00272 class longlongField:
00273 
00274 properties:
00275   bool       m_bIsNull;
00276   bool       m_bIsEditable;
00277   string     m_strTable;
00278   string     m_strName;
00279   string     m_strFormatMask;
00280   fieldTypes m_fieldType;
00281   long       m_field;
00282 
00283 */
00284 
00285 // construction / destruction
00286 longlongField::longlongField
00287 ( long long value, bool isNull, bool isEditable, string name, string table )
00288 :basicField(isNull, isEditable, name, table),m_field(value)
00289 {
00290   m_strFormatMask = "%lld";
00291   m_strServerMask = "%lld";
00292   m_fieldType = longlongType;
00293 }
00294 
00295 longlongField::~longlongField(){;}
00296 
00297 
00298 // assignment
00299 longlongField & longlongField::operator = ( longlongField & input )
00300 {
00301   basicField::operator = (input);
00302   m_field = input.get();
00303   return *this;
00304 }
00305 
00306 // access
00307 long long & longlongField::get( void )
00308 {
00309   return m_field;
00310 }
00311 void longlongField::set( long long input )
00312 {
00313   m_field = input;
00314   m_bIsNull = false;
00315 }
00316 
00317 // formatting
00318 string & longlongField::format()
00319 {
00320   if( m_bIsNull )
00321   {
00322     m_strFormatted="";
00323   }
00324   else
00325   {
00326     // temporary buffer big enough to hold formatted value
00327     char temp[64];
00328     // use old c formatting function
00329     sprintf( temp, m_strFormatMask.c_str(), m_field);
00330     m_strFormatted = temp;
00331   }
00332   return  m_strFormatted;
00333 }
00334 string & longlongField::svrFormat()
00335 {
00336   if( m_bIsNull )
00337   {
00338     m_strFormatted="NULL";
00339   }
00340   else
00341   {
00342     // temporary buffer big enough to hold formatted value
00343     char temp[64];
00344     // use old c formatting function
00345     sprintf( temp, m_strServerMask.c_str(), m_field);
00346     m_strFormatted = temp;
00347   }
00348   return  m_strFormatted;
00349 }
00350 
00351 
00352 
00353 
00354 
00355 
00356 // doubleType
00357 /*
00358 
00359 class doubleField:
00360 properties:
00361   bool       m_bIsNull;
00362   bool       m_bIsEditable;
00363   string     m_strTable;
00364   string     m_strName;
00365   string     m_strFormatMask;
00366   fieldTypes m_fieldType;
00367   double  m_field;
00368 
00369 */
00370 
00371 // construction / destruction
00372 doubleField::doubleField( double value, bool isNull, bool isEditable, string 
00373 name, string table )
00374 :basicField(isNull, isEditable, name, table),m_field(value)
00375 {
00376   m_strFormatMask = "%g";
00377   m_strServerMask = "%f";
00378   m_fieldType = doubleType;
00379 }
00380 doubleField::~doubleField(){;}
00381 
00382 // assignment
00383 doubleField & doubleField::operator = ( doubleField & input )
00384 {
00385   basicField::operator = (input);
00386   m_field = input.get();
00387   return *this;
00388 }
00389 
00390 // access
00391 double & doubleField::get( void )
00392 {
00393   return m_field;
00394 }
00395 void doubleField::set( double input )
00396 {
00397   m_field = input;
00398   m_bIsNull = false;
00399 }
00400 
00401 // formatting
00402 string & doubleField::format()
00403 {
00404   if( m_bIsNull )
00405   {
00406     m_strFormatted="";
00407   }
00408   else
00409   {
00410     // temporary buffer big enough to hold formatted value
00411     char temp[64];
00412     // use old c formatting function
00413     sprintf( temp, m_strFormatMask.c_str(), m_field);
00414     m_strFormatted = temp;
00415   }
00416   return  m_strFormatted;
00417 }
00418 string & doubleField::svrFormat()
00419 {
00420   if( m_bIsNull )
00421   {
00422     m_strFormatted="NULL";
00423   }
00424   else
00425   {
00426     // temporary buffer big enough to hold formatted value
00427     char temp[64];
00428     // use old c formatting function
00429     sprintf( temp, m_strServerMask.c_str(), m_field);
00430     m_strFormatted = temp;
00431   }
00432   return  m_strFormatted;
00433 }
00434 
00435 // floatType
00436 /*
00437   class floatField:
00438 
00439   float  m_field;
00440 
00441 */
00442 
00443   // construction / destruction
00444 floatField::floatField( float value, bool isNull, bool isEditable,  string 
00445 name, string table )
00446 :basicField(isNull, isEditable, name, table),m_field(value)
00447 {
00448   m_strFormatMask = "%f";
00449   m_strServerMask = "%g";
00450   m_fieldType = floatType;
00451 }
00452 
00453 floatField::~floatField(){;}
00454 
00455 // assignment
00456 floatField & floatField::operator = ( floatField & input )
00457 {
00458   basicField::operator = (input);
00459   m_field = input.get();
00460   return *this;
00461 }
00462 
00463 // access
00464 float & floatField::get( void )
00465 {
00466   return m_field;
00467 }
00468 
00469 void floatField::set( float input )
00470 {
00471   m_field = input;
00472   m_bIsNull = false;
00473 }
00474 
00475 // formatting
00476 string & floatField::format()
00477 {
00478   if( m_bIsNull )
00479   {
00480     m_strFormatted="";
00481   }
00482   else
00483   {
00484     // temporary buffer big enough to hold formatted value
00485     char temp[64];
00486     // use old c formatting function
00487     sprintf( temp, m_strFormatMask.c_str(), m_field);
00488     m_strFormatted = temp;
00489   }
00490   return  m_strFormatted;
00491 }
00492 string & floatField::svrFormat()
00493 {
00494   if( m_bIsNull )
00495   {
00496     m_strFormatted="NULL";
00497   }
00498   else
00499   {
00500     // temporary buffer big enough to hold formatted value
00501     char temp[64];
00502     // use old c formatting function
00503     sprintf( temp, m_strServerMask.c_str(), m_field);
00504     m_strFormatted = temp;
00505   }
00506   return  m_strFormatted;
00507 }
00508 
00509 // stringType
00510 /*
00511   class stringField:
00512   string   m_field;
00513 */
00514 
00515   // construction / destruction
00516 stringField::stringField( string value, bool isNull, bool isEditable, string
00517 name, string table )
00518 :basicField(isNull, isEditable, name, table),m_field(value)
00519 {
00520   m_strFormatMask = "%s";
00521   m_strServerMask = "'%s'";
00522   m_fieldType = stringType;
00523 }
00524 
00525 stringField::~stringField(){;}
00526 
00527 // assignment
00528 stringField & stringField::operator = ( stringField & input )
00529 {
00530   basicField::operator = (input);
00531   m_field = input.get();
00532   return *this;
00533 }
00534 
00535 // access
00536 string & stringField::get( void )
00537 {
00538   return m_field;
00539 }
00540 void stringField::set( string input )
00541 {
00542   m_field = input;
00543   m_bIsNull = false;
00544 }
00545 
00546 // formatting
00547 string & stringField::format()
00548 {
00549   if( m_bIsNull )
00550   {
00551     m_strFormatted="";
00552   }
00553   else
00554   {
00555     // temporary buffer big enough to hold formatted value
00556     char * temp = new char[ m_field.size() + m_strFormatMask.size() + 1 ];
00557     // use old c formatting function
00558     sprintf( temp, m_strFormatMask.c_str(), m_field.c_str() );
00559     m_strFormatted = temp;
00560     delete [] temp;
00561   }
00562   return  m_strFormatted;
00563 }
00564 string & stringField::svrFormat()
00565 {
00566   if( m_bIsNull )
00567   {
00568     m_strFormatted="NULL";
00569   }
00570   else
00571   {
00572     int fieldLen = m_field.size();
00573     string strTemp("");
00574     // double all single ticks in the string
00575     for( int i=0; i<fieldLen; i++ )
00576     {
00577       char ch = m_field[i];
00578       strTemp += ch;
00579       if( ch == '\'' )
00580       {
00581         strTemp += "'";
00582       }
00583     }
00584     fieldLen = strTemp.size();
00585     // temporary buffer big enough to hold formatted value
00586     char * temp = new char[ fieldLen + m_strFormatMask.size() + 1 ];
00587     // use old c formatting function
00588     sprintf( temp, m_strServerMask.c_str(), strTemp.c_str() );
00589     m_strFormatted = temp;
00590     delete [] temp;
00591   }
00592   return  m_strFormatted;
00593 }
00594 /*
00595 class currencyField:
00596 
00597  currency  m_field;
00598 
00599 */
00600 
00601 // construction / destruction
00602 currencyField::currencyField( currency value, bool isNull, bool isEditable,
00603 string name, string table )
00604 :basicField(isNull, isEditable, name, table),m_field(value)
00605 {
00606   m_strFormatMask = "%.2f";
00607   m_strServerMask = "%.2f";
00608   m_fieldType = currencyType;
00609 }
00610 
00611 currencyField::~currencyField(){;}
00612 
00613 // assignment
00614 currencyField & currencyField::operator = ( currencyField & input )
00615 {
00616   basicField::operator = (input);
00617   m_field.amount = input.get().amount;
00618   return *this;
00619 }
00620 // Gets
00621 currency & currencyField::get( void )
00622 {
00623   return m_field;
00624 }
00625 void currencyField::set( currency input)
00626 {
00627   m_field.amount = input.amount;
00628   m_bIsNull = false;
00629 }
00630 // formatting
00631 string & currencyField::format()
00632 {
00633   if( m_bIsNull )
00634   {
00635     m_strFormatted="";
00636   }
00637   else
00638   {
00639     // temporary buffer big enough to hold formatted value
00640     char temp[64];
00641     // use old c formatting function
00642     sprintf( temp, m_strFormatMask.c_str(), m_field);
00643     m_strFormatted = temp;
00644   }
00645   return  m_strFormatted;
00646 }
00647 string & currencyField::svrFormat()
00648 {
00649   if( m_bIsNull )
00650   {
00651     m_strFormatted="NULL";
00652   }
00653   else
00654   {
00655     // temporary buffer big enough to hold formatted value
00656     char temp[64];
00657     // use old c formatting function
00658     sprintf( temp, m_strServerMask.c_str(), m_field);
00659     m_strFormatted = temp;
00660   }
00661   return  m_strFormatted;
00662 }
00663 
00664 /*
00665   class dateTimeField:
00666 
00667   tm  m_field;
00668     int tm_sec;    Seconds. [0-60] (1 leap second)
00669     int tm_min;    Minutes. [0-59]
00670     int tm_hour;   Hours. [0-23]
00671     int tm_mday;   Day.  [1-31]
00672     int tm_mon;    Month. [0-11]
00673     int tm_year;   Year - 1900.
00674     int tm_wday;   Day of week. [0-6]
00675     int tm_yday;   Days in year.[0-365]
00676     int tm_isdst;  DST.  [-1/0/1]
00677 */
00678 
00679 // construction / destruction
00680 dateTimeField::dateTimeField( tm value, bool isNull, bool isEditable,
00681             string name, string table )
00682 :basicField(isNull, isEditable, name, table),m_field(value)
00683 {
00684   m_strFormatMask = "%m/%d/%Y %H:%M:%S";
00685   m_strServerMask = "%m/%d/%Y %H:%M:%S";
00686   m_fieldType = dateTimeType;
00687 }
00688 dateTimeField::~dateTimeField(){;}
00689 
00690 // assignment
00691 dateTimeField & dateTimeField::operator = ( dateTimeField & input )
00692 {
00693   basicField::operator = (input);
00694   m_field = input.get();
00695   return *this;
00696 }
00697 
00698 // access
00699 tm & dateTimeField::get( void )
00700 {
00701   return m_field;
00702 }
00703 void dateTimeField::set( tm input )
00704 {
00705   m_field = input;
00706   m_bIsNull = false;
00707 }
00708 
00709 // formatting
00710 string & dateTimeField::format()
00711 {
00712   if( m_bIsNull )
00713   {
00714     m_strFormatted="";
00715   }
00716   else
00717   {
00718     // temporary buffer big enough to hold formatted value
00719     char temp[64];
00720     // use old c formatting function
00721     strftime( temp, sizeof(temp), m_strFormatMask.c_str(), &m_field );
00722     m_strFormatted = temp;
00723   }
00724   return  m_strFormatted;
00725 }
00726 string & dateTimeField::svrFormat()
00727 {
00728   if( m_bIsNull )
00729   {
00730     m_strFormatted="NULL";
00731   }
00732   else
00733   {
00734     // temporary buffer big enough to hold formatted value
00735     char temp[64];
00736     // use old c formatting function
00737     strftime( temp, sizeof(temp), m_strServerMask.c_str(), &m_field );
00738     m_strFormatted = "'";
00739     m_strFormatted += temp;
00740     m_strFormatted += "'";
00741   }
00742   return  m_strFormatted;
00743 }
00744 /*
00745 class boolField
00746 */
00747 boolField::boolField
00748 ( bool value, bool isNull, bool isEditable,
00749   string name, string table )
00750 :basicField(isNull, isEditable, name, table),m_field(value)
00751 {
00752   m_strFormatMask = "Yes|No";
00753   m_strServerMask = "true|false";
00754   m_fieldType = boolType;
00755 }
00756 boolField::~boolField(){;}
00757 
00758 // assignment
00759 boolField & boolField::operator = ( boolField & input )
00760 {
00761   basicField::operator = (input);
00762   m_field = input.get();
00763   return *this;
00764 }
00765 // access
00766 bool & boolField::get( void )
00767 {
00768   return m_field;
00769 }
00770 void boolField::set( bool input )
00771 {
00772   m_field = input;
00773   m_bIsNull = false;
00774 }
00775 // formatting
00776 string & boolField::format()
00777 {
00778   if( m_bIsNull )
00779   {
00780     m_strFormatted="";
00781   }
00782   else
00783   {
00784     // temporary buffer big enough to hold formatted value
00785     string strTrue, strFalse;
00786     string::size_type idx = m_strFormatMask.find('|');
00787     if( idx != string::npos ) // found |
00788     {
00789       strTrue = m_strFormatMask.substr(0, idx);
00790       strFalse = m_strFormatMask.substr(idx+1);
00791       m_strFormatted = m_field?strTrue:strFalse;
00792     }
00793   }
00794   return  m_strFormatted;
00795 }
00796 string & boolField::svrFormat()
00797 {
00798   if( m_bIsNull )
00799   {
00800     m_strFormatted="NULL";
00801   }
00802   else
00803   {
00804     // temporary buffer big enough to hold formatted value
00805     string strTrue, strFalse;
00806     string::size_type idx = m_strServerMask.find('|');
00807     if( idx != string::npos ) // found |
00808     {
00809       strTrue = m_strServerMask.substr(0, idx);
00810       strFalse = m_strServerMask.substr(idx+1);
00811       m_strFormatted = m_field?strTrue:strFalse;
00812     }
00813   }
00814   return  m_strFormatted;
00815 }
00816 
00817 

Generated on Tue Jan 20 09:06:56 2004 for OpenTools by doxygen1.2.18