added: uptime winix function prints how many sessions there are

changed: functions for text/numbers conversions
         int Toi(const std::string & str,  int base = 10);
         int Toi(const std::wstring & str, int base = 10);
         int Toi(const char * str,         int base = 10);
         int Toi(const wchar_t * str,      int base = 10);

         long Tol(const std::string & str,  int base = 10);
         long Tol(const std::wstring & str, int base = 10);
         long Tol(const char * str,         int base = 10);
         long Tol(const wchar_t * str,      int base = 10);

         template<class CharType>
         bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);

         template<class CharType>
         bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);

         template<class CharType>
         bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);

         template<class CharType>
         bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);

         const wchar_t * Toa(unsigned int value,  int base = 10);
         const wchar_t * Toa(unsigned long value, int base = 10);
         const wchar_t * Toa(int value,  int base = 10);
         const wchar_t * Toa(long value, int base = 10);

         void Toa(int  value, std::string & res,  int base = 10, bool clear = true);
         void Toa(long value, std::string & res,  int base = 10, bool clear = true);
         void Toa(int  value, std::wstring & res, int base = 10, bool clear = true);
         void Toa(long value, std::wstring & res, int base = 10, bool clear = true);

added:   HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
         this is a special stream for automatically escaping html tags
	     



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-11-25 01:34:46 +00:00
parent 518281e101
commit 933c8841ff
53 changed files with 1925 additions and 1098 deletions

View File

@@ -14,6 +14,13 @@
#include "misc.h"
/*
a special class representing a stream buffer
similar to std::ostringstream
StringType can be either std::string or std::wstring
this class doesn't use UTF-8 in any kind
*/
template<class StringType>
class TextStream
{
@@ -25,6 +32,8 @@ public:
void Clear();
bool Empty() const;
size_t Size() const;
void Reserve(size_t len);
const StringType & Str() const;
const CharType * CStr() const;
@@ -45,8 +54,10 @@ public:
TextStream & operator<<(double);
TextStream & operator<<(const void *);// printing a pointer
TextStream & Write(const CharType * buf, size_t len);
TextStream & write(const CharType * buf, size_t len); // for compatibility with standard library (Ezc uses it)
TextStream & Write(const char * buf, size_t len);
TextStream & Write(const wchar_t * buf, size_t len);
TextStream & write(const char * buf, size_t len); // for compatibility with standard library (Ezc uses it)
TextStream & write(const wchar_t * buf, size_t len);
protected:
@@ -74,6 +85,13 @@ size_t TextStream<StringType>::Size() const
return buffer.size();
}
template<class StringType>
void TextStream<StringType>::Reserve(size_t len)
{
buffer.reserve(len);
}
template<class StringType>
const StringType & TextStream<StringType>::Str() const
{
@@ -166,9 +184,10 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(int v)
{
char buf[50];
wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
sprintf(buf, "%d", v);
Toa(v, buf, len);
AssignString(buf, buffer, false);
return *this;
@@ -178,9 +197,10 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(long v)
{
char buf[50];
wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
sprintf(buf, "%ld", v);
Toa(v, buf, len);
AssignString(buf, buffer, false);
return *this;
@@ -190,9 +210,10 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(unsigned int v)
{
char buf[50];
wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
sprintf(buf, "%u", v);
Toa(v, buf, len);
AssignString(buf, buffer, false);
return *this;
@@ -202,9 +223,10 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(unsigned long v)
{
char buf[50];
wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
sprintf(buf, "%lu", v);
Toa(v, buf, len);
AssignString(buf, buffer, false);
return *this;
@@ -226,9 +248,13 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const void * v)
{
char buf[50];
wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
sprintf(buf, "%p", v);
buf[0] = '0';
buf[1] = 'x';
Toa(reinterpret_cast<unsigned long>(v), buf+2, len-2, 16);
AssignString(buf, buffer, false);
return *this;
@@ -236,24 +262,35 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::Write(const TextStream<StringType>::CharType * buf, size_t len)
TextStream<StringType> & TextStream<StringType>::Write(const char * buf, size_t len)
{
if( buffer.capacity() < buffer.size() + len )
buffer.reserve(buffer.size() + len + 256); // !! add some constant
for(size_t i=0 ; i<len ; ++i)
buffer += buf[i];
AssignString(buf, len, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::write(const TextStream<StringType>::CharType * buf, size_t len)
TextStream<StringType> & TextStream<StringType>::write(const char * buf, size_t len)
{
return Write(buf, len);
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::Write(const wchar_t * buf, size_t len)
{
AssignString(buf, len, buffer, false);
return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::write(const wchar_t * buf, size_t len)
{
return Write(buf, len);
}
#endif