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

const_string.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 /***********************************************************************
00006  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
00007  MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
00008  Others may also hold copyrights on code in this file.  See the CREDITS
00009  file in the top directory of the distribution for details.
00010 
00011  This file is part of MySQL++.
00012 
00013  MySQL++ is free software; you can redistribute it and/or modify it
00014  under the terms of the GNU Lesser General Public License as published
00015  by the Free Software Foundation; either version 2.1 of the License, or
00016  (at your option) any later version.
00017 
00018  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
00019  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00020  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00021  License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with MySQL++; if not, write to the Free Software
00025  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
00026  USA
00027 ***********************************************************************/
00028 
00029 #ifndef MYSQLPP_CONST_STRING_H
00030 #define MYSQLPP_CONST_STRING_H
00031 
00032 #include "defs.h"
00033 
00034 #include <stdexcept>
00035 #include <string>
00036 #include <iostream>
00037 
00038 namespace mysqlpp {
00039 
00049 class const_string
00050 {
00051 private:
00052         const char* str_data;
00053 
00054 public:
00057         typedef const char value_type;
00058 
00060         typedef unsigned int size_type;
00061 
00064         typedef const char& const_reference;
00065 
00067         typedef const char* const_iterator;
00068 
00071         typedef const_iterator iterator;
00072 
00073 #if !defined(DOXYGEN_IGNORE)
00074 // Doxygen will not generate documentation for this section.
00075         typedef int difference_type;
00076         typedef const_reference reference;
00077         typedef const char* const_pointer;
00078         typedef const_pointer pointer;
00079 #endif // !defined(DOXYGEN_IGNORE)
00080 
00082         const_string() :
00083         str_data("")
00084         {
00085         }
00086         
00088         const_string(const char* str) :
00089         str_data(str)
00090         {
00091         }
00092         
00094         const_string& operator=(const char* str)
00095         {
00096                 str_data = str;
00097                 return *this;
00098         }
00099 
00101         size_type size() const
00102         {
00103                 register int i = 0;
00104                 while (str_data[i])
00105                          i++;
00106                  return i;
00107         }
00108         
00111         const_iterator begin() const
00112         {
00113                 return str_data;
00114         }
00115         
00118         const_iterator end() const
00119         {
00120                 return str_data + size();
00121         }
00122         
00124         size_type length() const
00125         {
00126                 return size();
00127         }
00128         
00134         size_type max_size() const
00135         {
00136                 return size();
00137         }
00138         
00140         const_reference operator [](size_type pos) const
00141         {
00142                 return str_data[pos];
00143         }
00144         
00149         const_reference at(size_type pos) const
00150         {
00151                 if (pos >= size())
00152                         throw std::out_of_range("");
00153                 else
00154                         return str_data[pos];
00155         }
00156         
00159         const char* c_str() const
00160         {
00161                 return str_data;
00162         }
00163         
00165         const char* data() const
00166         {
00167                 return str_data;
00168         }
00169         
00177         int compare(const const_string& str) const
00178         {
00179                 const char* str1 = str_data;
00180                 const char* str2 = str.str_data;
00181                 while (*str1 == *str2 && (*str1 && *str2)) {
00182                         str1++;
00183                         str2++;
00184                 }
00185                 return *str1 - *str2;
00186         }
00187 };
00188 
00189 
00191 inline std::ostream& operator <<(std::ostream& o,
00192                 const const_string& str)
00193 {
00194         return o << str.c_str();
00195 }
00196 
00198 inline int compare(const const_string& lhs, const const_string& rhs)
00199 {
00200         return lhs.compare(rhs);
00201 }
00202 
00204 inline bool operator ==(const_string& lhs, const_string& rhs)
00205 {
00206         return compare(lhs, rhs) == 0;
00207 }
00208 
00210 inline bool operator !=(const_string& lhs, const_string& rhs)
00211 {
00212         return compare(lhs, rhs) != 0;
00213 }
00214 
00216 inline bool operator <(const_string& lhs, const_string& rhs)
00217 {
00218         return compare(lhs, rhs) < 0;
00219 }
00220 
00222 inline bool operator <=(const_string& lhs, const_string& rhs)
00223 {
00224         return compare(lhs, rhs) <= 0;
00225 }
00226 
00228 inline bool operator >(const_string& lhs, const_string& rhs)
00229 {
00230         return compare(lhs, rhs) > 0;
00231 }
00232 
00234 inline bool operator >=(const_string& lhs, const_string& rhs)
00235 {
00236         return compare(lhs, rhs) >= 0;
00237 }
00238 
00239 } // end namespace mysqlpp
00240 
00241 #endif

Generated on Thu May 26 09:39:58 2005 for MySQL++ by doxygen1.2.18