00001 /* 00002 * Copyright (C) Sergey P. Derevyago, 2008-2009. 00003 * 00004 * Permission to copy, use, modify, sell and distribute this software is granted 00005 * provided this copyright notice appears in all copies. 00006 * This software is provided "as is" without express or implied warranty, and 00007 * with no claim as to its suitability for any purpose. 00008 * 00009 */ 00010 00015 #ifndef __DERS__TEXT_BUF_HPP__ 00016 #define __DERS__TEXT_BUF_HPP__ 00017 00018 #include <ders/config.hpp> 00019 #include <ders/text.hpp> 00020 00021 namespace ders { // ::ders 00022 00026 class text_buf { 00027 sh_text txt; 00028 00029 text_buf(const text_buf&); 00030 text_buf& operator=(const text_buf&); 00031 00032 public: 00033 explicit text_buf(mem_pool& mp, int rsv=1024); 00034 explicit text_buf(sh_text sht, int rsv=1024); 00035 00036 text_buf& operator+(const ch_rng& r); 00037 text_buf& operator+(char byte); 00038 00039 text_buf& operator+(bool val); 00040 text_buf& operator+(int val); 00041 text_buf& operator+(unsigned val); 00042 text_buf& operator+(long val); 00043 text_buf& operator+(unsigned long val); 00044 00045 text_buf& operator+(const char* str); 00046 text_buf& operator+(void* ptr); 00047 00048 operator const sh_text&() const { return txt; } 00049 operator ch_rng() const { return ch_rng(txt); } 00050 00051 int size() const { return txt->size(); } 00052 }; 00053 00054 inline text_buf::text_buf(mem_pool& mp, int rsv) : txt(nt(mp)) 00055 { txt->reserve(rsv); } 00056 00057 inline text_buf::text_buf(sh_text sht, int rsv) : txt(nt(sht.pool(), sht)) 00058 { txt->reserve(rsv); } 00059 00060 inline text_buf& text_buf::operator+(const ch_rng& r) 00061 { 00062 txt->append(r); 00063 return *this; 00064 } 00065 00066 inline text_buf& text_buf::operator+(char byte) 00067 { 00068 txt->append(byte); 00069 return *this; 00070 } 00071 00072 inline text_buf& text_buf::operator+(bool val) 00073 { return *this+(val? "true" : "false"); } 00074 00075 inline text_buf& text_buf::operator+(const char* str) 00076 { return *this+ch_rng(str); } 00077 00078 } // namespace ::ders 00079 00080 #endif // __DERS__TEXT_BUF_HPP__ 00081