string_reference.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 */
00028 
00031 
00032 #ifndef _cl_header_string_reference_
00033 #define _cl_header_string_reference_
00034 
00035 #if defined(_MSC_VER)
00036 #pragma once
00037 #endif
00038 
00039 #include "../api_core.h"
00040 #include "string_data.h"
00041 
00046 template<typename CharType, typename StdString>
00047 class CL_API_CORE CL_StringReference : public CL_StringData<CharType, CL_StringReference<CharType, StdString>, StdString>
00048 {
00049 public:
00050 
00051 #ifndef WIN32
00052         // Fix for GCC bug for not finding CL_StringDataTypes::size_type and so on .... grrrrrrr!
00053         // TODO: Remove this fix when GCC is a good compiler. As from 13 December 2007, SVN GCC does not work
00054         // See: http:/** gcc.gnu.org/bugzilla/show_bug.cgi?id=34453*/
00055 
00056         typedef unsigned int size_type;
00057         typedef CharType char_type;
00058         typedef CharType *iterator;
00059         typedef const CharType *const_iterator;
00060 
00061         // These could and maybe should be replaced with "this->function_name()"
00062         iterator begin() { return CL_StringData<CharType, CL_StringReference<CharType, StdString>, StdString>::begin(); }
00063 
00067         iterator end() { return CL_StringData<CharType, CL_StringReference<CharType, StdString>, StdString>::end(); }
00068 
00072         size_type size() const { return CL_StringData<CharType, CL_StringReference<CharType, StdString>, StdString>::size(); }
00073 
00077         size_type length() const { return CL_StringData<CharType, CL_StringReference<CharType, StdString>, StdString>::length(); }
00078 
00082         bool empty() const { return CL_StringData<CharType, CL_StringReference<CharType, StdString>, StdString>::empty(); }
00083         const CharType *data() const { return CL_StringData<CharType, CL_StringReference<CharType, StdString>, StdString>::data(); }
00084 
00088         CharType *data() { return CL_StringData<CharType, CL_StringReference<CharType, StdString>, StdString>::data(); }
00089 
00090 #endif
00091 
00092         CL_StringReference();
00093 
00097         CL_StringReference(const StdString &source);
00098 
00102         CL_StringReference(const CL_StringReference &source);
00103 
00109         CL_StringReference(const CL_StringData<CharType, CL_StringReference<CharType, StdString>, StdString> &source);
00110 
00114         CL_StringReference(const char *c_str);
00115 
00121         CL_StringReference(const char *c_str, size_type length, bool null_terminated);
00122 
00126         CL_StringReference(const wchar_t *wc_str);
00127 
00133         CL_StringReference(const wchar_t *wc_str, size_type length, bool null_terminated);
00134         ~CL_StringReference();
00135 
00136         const CharType *c_str() const;
00137 
00141         void set_length(size_type length);
00142 
00143         CL_StringReference<CharType, StdString> &operator =(const CL_StringReference<CharType, StdString> &source);
00144         CL_StringReference<CharType, StdString> &operator =(const CL_StringData<CharType, CL_StringReference<CharType, StdString>, StdString> &source);
00145         CL_StringReference<CharType, StdString> &operator =(const char *c_str);
00146         CL_StringReference<CharType, StdString> &operator =(const wchar_t *c_str);
00147 
00148 protected:
00149 
00151         void clear() const;
00152 
00157         void create_temp(const CharType *data, size_type length) const;
00158 
00159         mutable bool null_terminated;
00160         mutable bool temporary;
00161 };
00162 
00163 #endif
00164 

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