string_data.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2009 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 may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 **    Harry Storbacka
00028 */
00029 
00032 
00033 #ifndef _cl_header_string_data_
00034 #define _cl_header_string_data_
00035 
00036 #if defined(_MSC_VER)
00037 #pragma once
00038 #endif
00039 
00040 #include "../api_core.h"
00041 
00046 class CL_API_CORE CL_StringDataTypes
00047 {
00048 public:
00049         typedef unsigned int size_type;
00050         static const size_type npos; // = 0xffffffff;
00051 };
00052 
00057 template<typename CharType, typename ReferenceClass, typename StdString>
00058 class CL_API_CORE CL_StringData : public CL_StringDataTypes
00059 {
00060 public:
00061         CL_StringData();
00062 
00067         CL_StringData(const CharType *ptr, size_type length);
00068 
00069         typedef CharType char_type;
00070         typedef CharType *iterator;
00071         typedef const CharType *const_iterator;
00072 
00076         iterator begin() { return (iterator) data_ptr; }
00077 
00081         iterator end() { return begin() + data_length; }
00082 
00086         const_iterator begin() const { return (const_iterator) data_ptr; }
00087 
00091         const_iterator end() const { return begin() + data_length; }
00092 
00093 //      reverse_iterator rbegin();
00094 //      reverse_iterator rend();
00095 //      const_reverse_iterator rbegin() const;
00096 //      const_reverse_iterator rend() const;
00097 
00098         const CharType &operator[](size_type n) const { return *(data_ptr + n); }
00099         CharType &operator[](size_type n) { return *(data_ptr + n); }
00100 
00101         const CharType *data() const { return data_ptr; }
00102 
00106         CharType *data() { return data_ptr; }
00107 
00111         operator StdString() const;
00112 
00116         operator ReferenceClass() const;
00117 
00121         size_type size() const { return data_length; }
00122 
00126         size_type length() const { return data_length; }
00127 
00131         bool empty() const { return data_length == 0; }
00132 
00139         size_type find(const CL_StringData &s, size_type pos = 0) const;
00140 
00148         size_type find(const CharType *s, size_type pos, size_type n) const;
00149 
00156         size_type find(const CharType *s, size_type pos = 0) const;
00157 
00164         size_type find(CharType c, size_type pos = 0) const;
00165 
00172         size_type rfind(const CL_StringData &s, size_type pos = npos) const;
00173 
00181         size_type rfind(const CharType *s, size_type pos, size_type n) const;
00182 
00189         size_type rfind(const CharType *s, size_type pos = npos) const;
00190 
00197         size_type rfind(CharType c, size_type pos = npos) const;
00198 
00205         size_type find_first_of(const CL_StringData &s, size_type pos = 0) const;
00206 
00214         size_type find_first_of(const CharType *s, size_type pos, size_type n) const;
00215 
00222         size_type find_first_of(const CharType *s, size_type pos = 0) const;
00223 
00230         size_type find_first_of(CharType c, size_type pos = 0) const;
00231 
00238         size_type find_first_not_of(const CL_StringData &s, size_type pos = 0) const;
00239 
00247         size_type find_first_not_of(const CharType *s, size_type pos, size_type n) const;
00248 
00255         size_type find_first_not_of(const CharType *s, size_type pos = 0) const;
00256 
00263         size_type find_first_not_of(CharType c, size_type pos = 0) const;
00264 
00271         size_type find_last_of(const CL_StringData &s, size_type pos = npos) const;
00272 
00280         size_type find_last_of(const CharType *s, size_type pos, size_type n) const;
00281 
00288         size_type find_last_of(const CharType *s, size_type pos = npos) const;
00289 
00296         size_type find_last_of(CharType c, size_type pos = npos) const;
00297 
00304         size_type find_last_not_of(const CL_StringData &s, size_type pos = npos) const;
00305 
00313         size_type find_last_not_of(const CharType *s, size_type pos, size_type n) const;
00314 
00321         size_type find_last_not_of(const CharType *s, size_type pos = npos) const;
00322 
00329         size_type find_last_not_of(CharType c, size_type pos = npos) const;
00330 
00337         ReferenceClass substr(size_type pos = 0, size_type n = npos) const;
00338 
00344         int compare(const CL_StringData &s) const;
00345 
00353         int compare(size_type pos, size_type n, const CL_StringData &s) const;
00354 
00364         int compare(size_type pos, size_type n, const CL_StringData &s, size_type pos1, size_type n1) const;
00365 
00371         int compare(const CharType *s) const;
00372 
00381         int compare(size_type pos, size_type n, const CharType *s, size_type len = npos) const;
00382 
00383 protected:
00384         mutable CharType *data_ptr;
00385         mutable size_type data_length;
00386 };
00387 
00388 template <typename CharType, typename ReferenceClass, typename StdString>
00389 CL_API_CORE bool operator==(const CL_StringData<CharType, ReferenceClass, StdString> &s1, const CL_StringData<CharType, ReferenceClass, StdString> &s2);
00390 
00391 template <typename CharType, typename ReferenceClass, typename StdString>
00392 CL_API_CORE bool operator==(const CharType *s1, const CL_StringData<CharType, ReferenceClass, StdString> &s2);
00393 
00394 template <typename CharType, typename ReferenceClass, typename StdString>
00395 CL_API_CORE bool operator==(const CL_StringData<CharType, ReferenceClass, StdString> &s1, const CharType *s2);
00396 
00397 template <typename CharType, typename ReferenceClass, typename StdString>
00398 CL_API_CORE bool operator!=(const CL_StringData<CharType, ReferenceClass, StdString> &s1, const CL_StringData<CharType, ReferenceClass, StdString> &s2);
00399 
00400 template <typename CharType, typename ReferenceClass, typename StdString>
00401 CL_API_CORE bool operator!=(const CharType *s1, const CL_StringData<CharType, ReferenceClass, StdString> &s2);
00402 
00403 template <typename CharType, typename ReferenceClass, typename StdString>
00404 CL_API_CORE bool operator!=(const CL_StringData<CharType, ReferenceClass, StdString> &s1, const CharType *s2);
00405 
00406 template <typename CharType, typename ReferenceClass, typename StdString>
00407 CL_API_CORE bool operator<(const CL_StringData<CharType, ReferenceClass, StdString> &s1, const CL_StringData<CharType, ReferenceClass, StdString> &s2);
00408 
00409 template <typename CharType, typename ReferenceClass, typename StdString>
00410 CL_API_CORE bool operator<(const CharType *s1, const CL_StringData<CharType, ReferenceClass, StdString> &s2);
00411 
00412 template <typename CharType, typename ReferenceClass, typename StdString>
00413 CL_API_CORE bool operator<(const CL_StringData<CharType, ReferenceClass, StdString> &s1, const CharType *s2);
00414 
00415 template <typename CharType, typename ReferenceClass, typename StdString>
00416 CL_API_CORE bool operator>(const CL_StringData<CharType, ReferenceClass, StdString> &s1, const CL_StringData<CharType, ReferenceClass, StdString> &s2);
00417 
00418 template <typename CharType, typename ReferenceClass, typename StdString>
00419 CL_API_CORE bool operator>(const CharType *s1, const CL_StringData<CharType, ReferenceClass, StdString> &s2);
00420 
00421 template <typename CharType, typename ReferenceClass, typename StdString>
00422 CL_API_CORE bool operator>(const CL_StringData<CharType, ReferenceClass, StdString> &s1, const CharType *s2);
00423 
00424 #endif
00425 

Generated on Thu Dec 3 02:39:32 2009 for ClanLib by  doxygen 1.4.6