Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

buffered_string.cpp

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2005 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00029 #include "precomp.h"
00030 #include "buffered_string.h"
00031 #include "buffered_string_buffer.h"
00032 
00034 // CL_BufferedString Construction:
00035 
00036 CL_BufferedString::CL_BufferedString()
00037 : string_buffer(0), index(0), str(0), str_len(0)
00038 {
00039 }
00040 
00041 CL_BufferedString::CL_BufferedString(CL_BufferedStringBuffer *string_buffer, int index)
00042 : string_buffer(string_buffer), index(index), str(0), str_len(0)
00043 {
00044 }
00045 
00046 CL_BufferedString::CL_BufferedString(const char *str, int str_len)
00047 : string_buffer(0), index(0), str(str), str_len(str_len)
00048 {
00049 }
00050 
00051 CL_BufferedString::CL_BufferedString(const CL_BufferedString &copy)
00052 : string_buffer(copy.string_buffer), index(copy.index), str(copy.str), str_len(copy.str_len)
00053 {
00054 }
00055 
00056 CL_BufferedString::~CL_BufferedString()
00057 {
00058 }
00059 
00061 // CL_BufferedString Attributes:
00062 
00063 int CL_BufferedString::length() const
00064 {
00065         if (string_buffer)
00066                 return string_buffer->get_length(index);
00067         else
00068                 return str_len;
00069 }
00070 
00071 const char *CL_BufferedString::data() const
00072 {
00073         if (string_buffer)
00074                 return string_buffer->get_data(index);
00075         else
00076                 return str;
00077 }
00078 
00079 const char *CL_BufferedString::c_str() const
00080 {
00081         if (string_buffer)
00082                 return string_buffer->get_data(index);
00083         else
00084                 return str;
00085 }
00086 
00087 std::string CL_BufferedString::to_string() const
00088 {
00089         if (string_buffer)
00090                 return std::string(
00091                         string_buffer->get_data(index),
00092                         string_buffer->get_length(index));
00093         else
00094                 return std::string(str, str_len);
00095 }
00096 
00097 CL_BufferedString::operator const char *() const
00098 {
00099         return c_str();
00100 }
00101 
00102 CL_BufferedString::operator CL_StringA() const
00103 {
00104         return to_string();
00105 }
00106 
00108 // CL_BufferedString Operations:
00109 
00110 CL_BufferedString &CL_BufferedString::operator =(const CL_BufferedString &copy)
00111 {
00112         string_buffer = copy.string_buffer;
00113         index = copy.index;
00114         str = copy.str;
00115         str_len = copy.str_len;
00116         return *this;
00117 }
00118         
00119 bool CL_BufferedString::operator <(const CL_BufferedString &str) const
00120 {
00121         int len_a = length();
00122         int len_b = str.length();
00123         int len_min = (len_a < len_b) ? len_a : len_b;
00124         const unsigned char *data_a = (const unsigned char *) data();
00125         const unsigned char *data_b = (const unsigned char *) str.data();
00126         
00127         for (int i=0; i<len_min; i++)
00128         {
00129                 if (data_a[i] != data_b[i])
00130                         return data_a[i] < data_b[i];
00131         }
00132         return len_a < len_b;
00133 }
00134         
00135 bool CL_BufferedString::operator <(const char *str) const
00136 {
00137         CL_BufferedString s(str, (int) strlen(str));
00138         return *this < s;
00139 }
00140 
00141 bool CL_BufferedString::operator <(const CL_StringA &str) const
00142 {
00143         CL_BufferedString s(str.data(), (int) str.length());
00144         return *this < s;
00145 }
00146 
00147 bool CL_BufferedString::operator >(const CL_BufferedString &str) const
00148 {
00149         int len_a = length();
00150         int len_b = str.length();
00151         int len_min = (len_a < len_b) ? len_a : len_b;
00152         const unsigned char *data_a = (const unsigned char *) data();
00153         const unsigned char *data_b = (const unsigned char *) str.data();
00154         
00155         for (int i=0; i<len_min; i++)
00156         {
00157                 if (data_a[i] != data_b[i])
00158                         return data_a[i] > data_b[i];
00159         }
00160         return len_a > len_b;
00161 }
00162 
00163 bool CL_BufferedString::operator >(const char *str) const
00164 {
00165         CL_BufferedString s(str, (int) strlen(str));
00166         return *this > s;
00167 }
00168 
00169 bool CL_BufferedString::operator >(const CL_StringA &str) const
00170 {
00171         CL_BufferedString s(str.data(), (int) str.length());
00172         return *this > s;
00173 }
00174 
00175 bool CL_BufferedString::operator ==(const CL_BufferedString &str) const
00176 {
00177         int len_a = length();
00178         int len_b = str.length();
00179         const unsigned char *data_a = (const unsigned char *) data();
00180         const unsigned char *data_b = (const unsigned char *) str.data();
00181         
00182         if (len_a != len_b)
00183                 return false;
00184         
00185         for (int i=0; i<len_a; i++)
00186         {
00187                 if (data_a[i] != data_b[i])
00188                         return false;
00189         }
00190         return true;
00191 }
00192         
00193 bool CL_BufferedString::operator ==(const char *str) const
00194 {
00195         CL_BufferedString s(str, (int) strlen(str));
00196         return *this == s;
00197 }
00198 
00199 bool CL_BufferedString::operator ==(const CL_StringA &str) const
00200 {
00201         CL_BufferedString s(str.data(), (int) str.length());
00202         return *this == s;
00203 }
00204 
00205 bool CL_BufferedString::operator !=(const CL_BufferedString &str) const
00206 {
00207         return !(*this == str);
00208 }
00209         
00210 bool CL_BufferedString::operator !=(const char *str) const
00211 {
00212         CL_BufferedString s(str, (int) strlen(str));
00213         return !(*this == s);
00214 }
00215         
00216 bool CL_BufferedString::operator !=(const CL_StringA &str) const
00217 {
00218         CL_BufferedString s(str.data(), (int) str.length());
00219         return !(*this == s);
00220 }
00221 
00223 // CL_BufferedString Implementation:

Generated on Sat Feb 19 22:51:15 2005 for npcore by  doxygen 1.4.1