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

string.hh

00001 /*
00002 *  Name:      string.hh
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   UESQLC base SQL type string
00005 *  Date:      $Date: 2003/10/06 13:21:35 $
00006 *  Revision:  $Revision: 1.1 $
00007 *
00008 *  Copyright (C) 2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #ifndef _UESQL_STRING__
00027 #define _UESQL_STRING__
00028 
00029 #include <mpcl/text/string.hh>
00030 #include "type.hh"
00031 
00032 
00034 namespace uesqlc
00035 {
00036 
00038   class TString                :
00039     public IType               ,
00040     public mpcl::text::TString
00041   {
00042 
00043     public:
00044 
00046       typedef
00047         mpcl::text::TString::size_type
00048         size_type;
00049 
00050 
00051     public:
00052       
00053       //
00054       //  C O N S T R U C T O R S
00055       //
00056       
00057       explicit TString (void)  :
00058         IType               () ,
00059         mpcl::text::TString () {}
00060 
00062       TString (const TString& rkySTRING) :
00063         IType               ()           ,
00064         mpcl::text::TString (rkySTRING)
00065       {
00066         setNull (rkySTRING.isNull());
00067       }
00068 
00069       TString ( const TString& rkySTRING      ,
00070                 size_type      zOFFSET        ,
00071                 size_type      zLENGTH = npos )           :
00072         IType               ()                            ,
00073         mpcl::text::TString (rkySTRING, zOFFSET, zLENGTH)
00074       {
00075         setNull (rkySTRING.isNull());
00076       }
00077 
00078       TString (const mpcl::text::TString& rkySOURCE) :
00079         IType               ()                       ,
00080         mpcl::text::TString (rkySOURCE)
00081       {
00082         setNull (false);
00083       }
00084 
00090       TString (const char* pkcVALUE, size_type zLENGTH) :
00091         IType               ()                          ,
00092         mpcl::text::TString ()
00093       {
00094         if ( pkcVALUE )
00095         {
00096           setNull (false);
00097           assign (pkcVALUE, zLENGTH);
00098         }
00099       }
00100       
00106       TString (const char* pkcVALUE) :
00107         IType               ()       ,
00108         mpcl::text::TString ()
00109       {
00110         if ( pkcVALUE )
00111         {
00112           setNull (false);
00113           assign (pkcVALUE);
00114         }
00115       }
00116       
00117       TString (size_type zTIMES, char cSOURCE) :
00118         IType               ()                 ,
00119         mpcl::text::TString (zTIMES, cSOURCE)
00120       {
00121         setNull (false);
00122       }
00123       
00124       template<typename InputIterator>
00125       TString (InputIterator tBEGIN_ITER, InputIterator tEND_ITER) :
00126         IType               ()                                     ,
00127         mpcl::text::TString (tBEGIN_ITER, tEND_ITER)
00128       {
00129         setNull (false);
00130       }
00131 
00132       TString& operator = (const TString& rkySTRING)
00133       {
00134         mpcl::text::TString::operator = (rkySTRING);
00135         setNull (rkySTRING.isNull());
00136         return *this;
00137       }
00138 
00139       TString& operator = (const mpcl::text::TString& rkySOURCE)
00140       {
00141         mpcl::text::TString::operator = (rkySOURCE);
00142         setNull (false);
00143         return *this;
00144       }
00145 
00146       TString& operator = (const char* pkcVALUE)
00147       {
00148         if ( !pkcVALUE )
00149         {
00150           throw mpcl::TConstraintException ("null string", __FILE__, __LINE__);
00151         }
00152         mpcl::text::TString::operator = (pkcVALUE);
00153         setNull (false);
00154         return *this;
00155       }
00156 
00157       TString& operator = (char cSOURCE)
00158       {
00159         mpcl::text::TString::operator = (cSOURCE);
00160         setNull (false);
00161         return *this;
00162       }
00163 
00170       void set (const char* pkcVALUE)
00171       {
00172         if ( !pkcVALUE )
00173         {
00174           erase();
00175           setNull (true);
00176         }
00177         else
00178         {
00179           assign (pkcVALUE);
00180           setNull (false);
00181         }
00182       }
00183 
00188       void set (const std::string& rkyVALUE)
00189       {
00190         assign (rkyVALUE);
00191         setNull (false);
00192       }
00193 
00194 
00195     public:
00196 
00197       //
00198       //  S E L E C T O R S
00199       //
00200 
00205       mpcl::text::TString get (void) const
00206       {
00207 
00208         mpcl::text::TString   yResult;
00209         mpcl::text::TString   yEscaped (*this);
00210 
00211         if ( isNull() )
00212         {
00213           yResult = "null";
00214         }
00215         else
00216         {
00217           yEscaped.replaceAll ("'", "''");
00218           yEscaped.replaceAll ("\\", "\\\\");
00219           yResult = '\'';
00220           yResult.append (yEscaped);
00221           yResult.append (1, '\'');
00222         }
00223         return yResult;
00224 
00225       }  // get()
00226 
00227   };  // class TString
00228 
00229 }  // namespace uesqlc
00230 
00231 
00232 #endif  // not _UESQL_STRING__

Generated on Mon Oct 13 02:40:10 2003 for UESQLC by doxygen1.2.18