- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# FUtils/FUStringBuilder.h

Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2005-2007 Feeling Software Inc.
    00003     Portions of the code are:
    00004     Copyright (C) 2005-2007 Sony Computer Entertainment America
    00005
    00006     MIT License: http://www.opensource.org/licenses/mit-license.php
    00007 */
    00008 /*
    00009     Based on the FS Import classes:
    00010     Copyright (C) 2005-2006 Feeling Software Inc
    00011     Copyright (C) 2005-2006 Autodesk Media Entertainment
    00012     MIT License: http://www.opensource.org/licenses/mit-license.php
    00013 */
    00014
    00021 #ifndef _FCU_STRING_BUILDER_
    00022 #define _FCU_STRING_BUILDER_
    00023
    00034 template <class Char>
    00035 class FCOLLADA_EXPORT FUStringBuilderT
    00036 {
    00037 private:
    00038     Char* buffer;
    00039     size_t reserved;
    00040     size_t size;
    00041
    00042 public:
    00044     typedef fm::stringT<Char> String;
    00045
    00048     FUStringBuilderT(const String& sz);
    00049
    00053     FUStringBuilderT(const Char* sz);
    00054
    00058     FUStringBuilderT(Char ch, size_t count);
    00059
    00063     FUStringBuilderT(size_t reserved);
    00064
    00066     FUStringBuilderT();
    00067
    00070     ~FUStringBuilderT();
    00071
    00078     void reserve(size_t length);
    00079
    00082     inline size_t length() { return size; }
    00083
    00086     void clear();
    00087
    00092     inline bool empty() const { return size == 0; }
    00093
    00096     void append(Char c);
    00097
    00100     void append(const String& sz);
    00101
    00105     void append(const Char* sz);
    00106
    00111     void append(const Char* sz, size_t len);
    00112
    00115     void append(const FUStringBuilderT& b);
    00116
    00120     void append(int32 i);
    00121     void append(uint32 i);
    00122     void append(uint64 i);
    00128     void appendHex(uint8 i);
    00129     template <class T> inline void appendHex(const T& i) { for (size_t j = 0; j < sizeof(T); ++j) appendHex(*(((uint8*)&i) + j)); }
    00131     inline void append(int i) { append((int32) i); }
    00132 #ifdef _W64
    00133     inline void append(_W64 unsigned int i) { append((uint32) i); }
    00134 #else
    00135     inline void append(unsigned int i) { append((uint32) i); }
    00136 #endif
    00137
    00144     void append(float f);
    00145     void append(double f);
    00149     void append(const FMVector2& v);
    00150     void append(const FMVector3& v);
    00151     void append(const FMVector4& v);
    00157     template<typename TYPE> inline FUStringBuilderT& operator+=(const TYPE& val) { append(val); return *this; }
    00158
    00163     void appendLine(const Char* sz);
    00164
    00169     void remove(int32 start);
    00170
    00177     void remove(int32 start, int32 end);
    00178
    00180     inline void pop_back() { if (size > 0) --size; }
    00181
    00185     template<typename TYPE> inline void set(const TYPE& val) { clear(); append(val); }
    00186     template<typename TYPE> inline FUStringBuilderT& operator=(const TYPE& val) { clear(); append(val); return *this; }
    00190     String ToString() const;
    00191
    00196     const Char* ToCharPtr() const;
    00197     inline operator const Char*() const { return ToCharPtr(); }
    00204     int32 index(Char c) const;
    00205
    00211     int32 rindex(Char c) const;
    00212
    00215     Char back() const { FUAssert(size > 0, return (Char) 0); return buffer[size-1]; }
    00216
    00217 private:
    00218     void enlarge(size_t minimum);
    00219 };
    00220
    00221 typedef FUStringBuilderT<fchar> FUStringBuilder;
    00222 typedef FUStringBuilderT<char> FUSStringBuilder;
    00224 #if defined(__APPLE__)
    00225 #include "FUtils/FUStringBuilder.hpp"
    00226 #endif // __APPLE__
    00227
    00228 #endif // _FCU_STRING_BUILDER_
    00229