FUtils/FUStringBuilder.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2005-2006 Feeling Software Inc.
00003     MIT License: http://www.opensource.org/licenses/mit-license.php
00004 */
00005 /*
00006     Based on the FS Import classes:
00007     Copyright (C) 2005-2006 Feeling Software Inc
00008     Copyright (C) 2005-2006 Autodesk Media Entertainment
00009     MIT License: http://www.opensource.org/licenses/mit-license.php
00010 */
00011 
00018 #ifndef _FCU_STRING_BUILDER_
00019 #define _FCU_STRING_BUILDER_
00020 
00031 template <class Char, class SPrintF>
00032 class FUStringBuilderT
00033 {
00034 private:
00035     Char* buffer;
00036     size_t reserved;
00037     size_t size;
00038 
00039 public:
00041     typedef std::basic_string<Char> String;
00042 
00045     FUStringBuilderT(const String& sz);
00046 
00050     FUStringBuilderT(const Char* sz);
00051 
00055     FUStringBuilderT(Char ch, size_t count);
00056 
00060     FUStringBuilderT(size_t reserved);
00061 
00063     FUStringBuilderT();
00064 
00067     ~FUStringBuilderT();
00068 
00075     void reserve(size_t length);
00076 
00079     inline size_t length() { return size; }
00080 
00083     void clear();
00084 
00089     inline bool empty() { return size == 0; }
00090 
00093     void append(Char c);
00094 
00097     void append(const String& sz);
00098 
00102     void append(const Char* sz);
00103 
00106     void append(const FUStringBuilderT& b);
00107 
00111     void append(int32 i);
00112     void append(uint32 i); 
00113     void append(uint64 i); 
00115     inline void append(int i) { append((int32) i); } 
00116 #ifdef _W64
00117     inline void append(_W64 unsigned int i) { append((uint32) i); } 
00118 #else
00119     inline void append(unsigned int i) { append((uint32) i); } 
00120 #endif 
00121 
00128     void append(float f);
00129     void append(double f); 
00135     template<typename TYPE> inline FUStringBuilderT& operator+=(const TYPE& val) { append(val); return *this; }
00136 
00141     void appendLine(const Char* sz);
00142 
00147     void remove(int32 start);
00148 
00155     void remove(int32 start, int32 end);
00156 
00158     inline void pop_back() { if (size > 0) --size; }
00159 
00163     template<typename TYPE> inline void set(const TYPE& val) { clear(); append(val); }
00164     template<typename TYPE> inline FUStringBuilderT& operator=(const TYPE& val) { clear(); append(val); return *this; } 
00168     String ToString();
00169     operator String() { return ToString(); } 
00175     const Char* ToCharPtr();
00176     operator const Char*() { return ToCharPtr(); } 
00183     int32 index(Char c);
00184 
00190     int32 rindex(Char c);
00191 
00192 private:
00193     void enlarge(size_t minimum);
00194 };
00195 
00200 class SprintF
00201 {
00202 public:
00207     void PrintInt32(char* output, uint32 length, int32 i) { snprintf(output, length, "%i", i); } 
00208 
00213     void PrintUInt32(char* output, uint32 length, uint32 i) { snprintf(output, length, "%u", i); }
00214     void PrintUInt64(char* output, uint32 length, uint64 i) { snprintf(output, length, "%u", i); } 
00220     void PrintFloat(char* output, uint32 length, double f) { snprintf(output, length, "%f", f); }
00221 
00225     size_t StrLen(const char* in) { return strlen(in); }
00226 };
00227 
00232 class SFprintF
00233 {
00234 public:
00239     void PrintInt32(fchar* output, uint32 length, int32 i) { fsnprintf(output, length, FC("%i"), i); }
00240 
00245     void PrintUInt32(fchar* output, uint32 length, uint32 i) { fsnprintf(output, length, FC("%u"), i); }
00246 
00251     void PrintUInt64(fchar* output, uint32 length, uint64 i) { fsnprintf(output, length, FC("%u"), i); }
00252 
00257     void PrintFloat(fchar* output, uint32 length, double f) { fsnprintf(output, length, FC("%f"), f); }
00258 
00262     size_t StrLen(const fchar* in) { return fstrlen(in); }
00263 };
00264 
00265 typedef FUStringBuilderT<fchar, SFprintF> FUStringBuilder; 
00266 typedef FUStringBuilderT<char, SprintF> FUSStringBuilder;  
00271 FCOLLADA_EXPORT extern FUStringBuilder globalBuilder; 
00272 
00276 FCOLLADA_EXPORT extern FUSStringBuilder globalSBuilder;
00277 
00278 #include "FUtils/FUStringBuilder.hpp"
00279 
00280 #endif // _FCU_STRING_BUILDER_
00281 

Generated on Fri May 12 16:44:39 2006 for FCollada by  doxygen 1.4.6-NO