You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(622) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(303) |
Feb
(64) |
Mar
(5) |
Apr
(63) |
May
(82) |
Jun
(53) |
Jul
(50) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Christian P. <cp...@us...> - 2005-07-08 08:17:54
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21106/src/IO Modified Files: TextStream.cpp Log Message: - Fixed IO::TextStream Index: TextStream.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/TextStream.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- TextStream.cpp 6 Jul 2005 13:01:05 -0000 1.2 +++ TextStream.cpp 8 Jul 2005 08:17:45 -0000 1.3 @@ -112,7 +112,7 @@ // create the new converter ... if(_converter) { - Unicode::Converter* newConverter = new Unicode::Converter(cp); + Unicode::Converter* newConverter = new Unicode::Converter(newCodePage.get()); delete _converter; _converter = newConverter; } @@ -142,7 +142,8 @@ // create the new number formater ... if(_numFormater) { - Unicode::NumberFormat* newNumFormater = createNumFormater(_numFormat, loc); + Unicode::NumberFormat* newNumFormater = createNumFormater(_numFormat, + newLocale.get()); delete _numFormater; _numFormater = newNumFormater; } @@ -205,15 +206,15 @@ return _padPos; } -void TextStream::setPadChar(Unicode::Char ch) throw() +void TextStream::setPadChar(const Unicode::String& str) throw() { if(_numFormater) - _numFormater->setPadChar(ch); + _numFormater->setPadChar(str); - _padChar = ch; + _padChar = str; } -Unicode::Char TextStream::padChar() const throw() +const Unicode::String& TextStream::padChar() const throw() { return _padChar; } @@ -316,10 +317,11 @@ return *this; } -void writePadString(TextStream& strm, Unicode::Char padChar, size_t count) +void writePadString(TextStream& strm, const Unicode::String& padChar, size_t count) { Unicode::String fillStr(count); - fillStr.insert(0, count, padChar); + while(fillStr.size() < count) + fillStr.append(padChar); strm.write(fillStr); } |
From: Christian P. <cp...@us...> - 2005-07-08 08:17:54
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21106/include/pclasses/IO Modified Files: TextStream.h Log Message: - Fixed IO::TextStream Index: TextStream.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/TextStream.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- TextStream.h 6 Jul 2005 13:01:05 -0000 1.2 +++ TextStream.h 8 Jul 2005 08:17:45 -0000 1.3 @@ -82,8 +82,8 @@ PadPosition padPosition() const throw(); //! Set padding character - void setPadChar(Unicode::Char ch) throw(); - Unicode::Char padChar() const throw(); + void setPadChar(const Unicode::String& str) throw(); + const Unicode::String& padChar() const throw(); TextStream& operator<<(Int8 val); TextStream& operator<<(UInt8 val); @@ -149,7 +149,7 @@ NumberFormat _numFormat; unsigned int _width; PadPosition _padPos; - Unicode::Char _padChar; + Unicode::String _padChar; char* _locale; char* _codePage; Unicode::Converter* _converter; |
From: Christian P. <cp...@us...> - 2005-07-08 08:16:53
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20670/include/pclasses/Util Modified Files: StringTool.h Log Message: - Fixed StringTool Index: StringTool.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Util/StringTool.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- StringTool.h 27 May 2005 14:02:17 -0000 1.9 +++ StringTool.h 8 Jul 2005 08:16:43 -0000 1.10 @@ -6,7 +6,7 @@ #include <pclasses/Export.h> #include <pclasses/Phoenix.h> -#include <pclasses/Util/LexT.h> +#include <pclasses/LexT.h> namespace P { @@ -19,7 +19,7 @@ */ namespace StringTool { - using ::P::Util::LexT; + using P::LexT; /** Convenience typedef for use with translateEntities(). */ |
From: Christian P. <cp...@us...> - 2005-07-08 08:15:52
|
Update of /cvsroot/pclasses/pclasses2/src/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19784/src/Unicode Modified Files: NumberFormat.cpp String.cpp Converter.cpp Makefile.am Added Files: DateTimeFormat.cpp Log Message: - Added Unicode::DateTimeFormat - Added String::realSize() to determine String's internal char count - Fixed Unicode::Converter - Changed Unicode::NumberFormat text-attributes from Char to String Index: Converter.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/Converter.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Converter.cpp 6 Jul 2005 12:59:10 -0000 1.2 +++ Converter.cpp 8 Jul 2005 08:15:42 -0000 1.3 @@ -119,7 +119,7 @@ if(str.empty()) return std::string(); - return fromUnicodeChars((UConverter*)_private, str.data(), str.size()); + return fromUnicodeChars((UConverter*)_private, str.data(), str.realSize()); } std::string Converter::fromUnicode(Char ch) throw(UnicodeError) Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/Makefile.am,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- Makefile.am 6 Jul 2005 12:59:10 -0000 1.14 +++ Makefile.am 8 Jul 2005 08:15:42 -0000 1.15 @@ -6,7 +6,7 @@ CPPFLAGS = -DPUNICODE_BUILD $(ICU_CFLAGS) libpclasses_unicode_la_SOURCES = Char.cpp String.cpp Converter.cpp \ - NumberFormat.cpp UnicodeError.cpp + NumberFormat.cpp DateTimeFormat.cpp UnicodeError.cpp libpclasses_unicode_la_LDFLAGS = -no-undefined Index: String.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/String.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- String.cpp 1 Jul 2005 13:55:10 -0000 1.13 +++ String.cpp 8 Jul 2005 08:15:42 -0000 1.14 @@ -161,6 +161,14 @@ return 0; } +size_t String::realSize() const throw() +{ + if(!_data.null()) + return _data->length; + + return 0; +} + size_t String::capacity() const throw() { if(!_data.null()) --- NEW FILE: DateTimeFormat.cpp --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/ScopedArrayPtr.h" #include "pclasses/Unicode/DateTimeFormat.h" #include <cstring> #include <unicode/udat.h> namespace P { namespace Unicode { UDateFormatStyle DateTimeFormatStyle2UDateFormatStyle(DateTimeFormat::Style style) { UDateFormatStyle ret; switch(style) { case DateTimeFormat::Full: ret = UDAT_FULL; break; case DateTimeFormat::Long: ret = UDAT_LONG; break; case DateTimeFormat::Medium: ret = UDAT_MEDIUM; break; case DateTimeFormat::Short: default: ret = UDAT_SHORT; break; } return ret; } DateTimeFormat::Style UDateFormatStyle2DateTimeFormatStyle(UDateFormatStyle style) { DateTimeFormat::Style ret; switch(style) { case UDAT_FULL: ret = DateTimeFormat::Full; break; case UDAT_LONG: ret = DateTimeFormat::Long; break; case UDAT_MEDIUM: ret = DateTimeFormat::Medium; break; case UDAT_SHORT: default: ret = DateTimeFormat::Short; break; } return ret; } // we use this DateTimeFormatImpl class for lazy creation of the ICU // UDateFormater's. Cause the ICU API does not directly support formatting // of only Date or Time values we may use up to three different UDateFormaters - // one for each formatable value... struct DateTimeFormatImpl { UDateFormatStyle _dateStyle, _dateTimeDateStyle; UDateFormatStyle _timeStyle, _dateTimeTimeStyle; mutable UDateFormat* _dateFormater; mutable UDateFormat* _timeFormater; mutable UDateFormat* _dateTimeFormater; char* _locale; DateTimeFormatImpl(UDateFormatStyle dateStyle, UDateFormatStyle timeStyle, const char* locale) { _dateTimeDateStyle = _dateStyle = dateStyle; _dateTimeTimeStyle = _timeStyle = timeStyle; _dateFormater = 0; _timeFormater = 0; _dateTimeFormater = 0; if(locale) { _locale = new char[std::strlen(locale)+1]; std::strcpy(_locale, locale); } else { _locale = 0; } } ~DateTimeFormatImpl() { if(_locale) delete[] _locale; if(_dateFormater) udat_close(_dateFormater); if(_timeFormater) udat_close(_timeFormater); if(_dateTimeFormater) udat_close(_dateTimeFormater); } String format(const Date& date) const { if(!_dateFormater) _dateFormater = createFormater(_dateStyle, UDAT_NONE, _locale); return format(_dateFormater, 0.0f); } String format(const Time& time) const { if(!_timeFormater) _timeFormater = createFormater(UDAT_NONE, _timeStyle, _locale); return format(_timeFormater, 0.0f); } String format(const DateTime& dt) const { if(!_dateTimeFormater) _dateTimeFormater = createFormater(_dateTimeDateStyle, _dateTimeTimeStyle, _locale); return format(_dateTimeFormater, 0.0f); } static UDateFormat* createFormater(UDateFormatStyle dateStyle, UDateFormatStyle timeStyle, const char* locale) { UErrorCode errorCode = U_ZERO_ERROR; UDateFormat* formater = udat_open(timeStyle, dateStyle, locale, NULL, 0, NULL, 0, &errorCode); if(U_FAILURE(errorCode)) throw UnicodeError(errorCode, "Could not init date formater for given locale", P_SOURCEINFO); return formater; } static String format(UDateFormat* formater, UDate val) { UErrorCode errorCode = U_ZERO_ERROR; size_t strLen = udat_format(formater, val, NULL, 0, NULL, &errorCode); ScopedArrayPtr<uchar16_t> ret(new uchar16_t[strLen + 1]); errorCode = U_ZERO_ERROR; udat_format(formater, val, ret.get(), strLen + 1, NULL, &errorCode); if(U_FAILURE(errorCode)) throw UnicodeError(errorCode, "Could not convert number to string", P_SOURCEINFO); String retStr; retStr.acquire(ret.release(), strLen + 1, strLen); return retStr; } }; DateTimeFormat::DateTimeFormat(Style dateStyle, Style timeStyle, const char* locale) throw(OutOfMemory, UnicodeError) { _private = (void*)new DateTimeFormatImpl( DateTimeFormatStyle2UDateFormatStyle(dateStyle), DateTimeFormatStyle2UDateFormatStyle(timeStyle), locale); } DateTimeFormat::~DateTimeFormat() throw() { delete (DateTimeFormatImpl*)_private; } void DateTimeFormat::setDateTimeStyle(Style dateStyle, Style timeStyle) throw() { DateTimeFormatImpl* impl = (DateTimeFormatImpl*)_private; if(impl->_dateTimeFormater) { delete impl->_dateTimeFormater; impl->_dateTimeFormater = 0; } impl->_dateTimeDateStyle = DateTimeFormatStyle2UDateFormatStyle(dateStyle); impl->_dateTimeTimeStyle = DateTimeFormatStyle2UDateFormatStyle(timeStyle); } std::pair<DateTimeFormat::Style, DateTimeFormat::Style> DateTimeFormat::dateTimeStyle() const throw() { DateTimeFormatImpl* impl = (DateTimeFormatImpl*)_private; return std::make_pair( UDateFormatStyle2DateTimeFormatStyle(impl->_dateTimeDateStyle), UDateFormatStyle2DateTimeFormatStyle(impl->_dateTimeTimeStyle)); } void DateTimeFormat::setDateStyle(Style dateStyle) throw() { DateTimeFormatImpl* impl = (DateTimeFormatImpl*)_private; if(impl->_dateFormater) { delete impl->_dateFormater; impl->_dateFormater = 0; } impl->_dateStyle = DateTimeFormatStyle2UDateFormatStyle(dateStyle); } DateTimeFormat::Style DateTimeFormat::dateStyle() const throw() { DateTimeFormatImpl* impl = (DateTimeFormatImpl*)_private; return UDateFormatStyle2DateTimeFormatStyle(impl->_dateStyle); } void DateTimeFormat::setTimeStyle(Style timeStyle) throw() { DateTimeFormatImpl* impl = (DateTimeFormatImpl*)_private; if(impl->_timeFormater) { delete impl->_timeFormater; impl->_timeFormater = 0; } impl->_timeStyle = DateTimeFormatStyle2UDateFormatStyle(timeStyle); } DateTimeFormat::Style DateTimeFormat::timeStyle() const throw() { DateTimeFormatImpl* impl = (DateTimeFormatImpl*)_private; return UDateFormatStyle2DateTimeFormatStyle(impl->_timeStyle); } String DateTimeFormat::format(const Date& date) const throw(OutOfMemory, UnicodeError) { return ((DateTimeFormatImpl*)_private)->format(date); } String DateTimeFormat::format(const Time& time) const throw(OutOfMemory, UnicodeError) { return ((DateTimeFormatImpl*)_private)->format(time); } String DateTimeFormat::format(const DateTime& dt) const throw(OutOfMemory, UnicodeError) { return ((DateTimeFormatImpl*)_private)->format(dt); } } // !namespace Unicode } // !namespace P Index: NumberFormat.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/NumberFormat.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- NumberFormat.cpp 6 Jul 2005 12:59:10 -0000 1.1 +++ NumberFormat.cpp 8 Jul 2005 08:15:42 -0000 1.2 @@ -62,6 +62,7 @@ } NumberFormat::NumberFormat(Style s, const char* locale) + throw(OutOfMemory, UnicodeError) { UErrorCode error = U_ZERO_ERROR; _private = (void*)unum_open(Style2UNumberFormatStyle(s), NULL, 0, locale, NULL, &error); @@ -75,7 +76,7 @@ unum_close((UNumberFormat*)_private); } -void NumberFormat::setWidth(unsigned int width) +void NumberFormat::setWidth(unsigned int width) throw() { unum_setAttribute((UNumberFormat*)_private, UNUM_FORMAT_WIDTH, width); } @@ -109,7 +110,7 @@ return ret; } -void NumberFormat::setPadPosition(PadPosition p) +void NumberFormat::setPadPosition(PadPosition p) throw() { unum_setAttribute((UNumberFormat*)_private, UNUM_PADDING_POSITION, PadPosition2UNumberFormatPadPosition(p)); @@ -145,87 +146,82 @@ (UNumberFormatPadPosition)unum_getAttribute((UNumberFormat*)_private, UNUM_PADDING_POSITION)); } -void NumberFormatSetTextAttr(UNumberFormat* format, UNumberFormatTextAttribute attr, Unicode::Char ch) +void NumberFormatSetTextAttr(UNumberFormat* format, UNumberFormatTextAttribute attr, const String& str) { - uchar16_t tmp[2]; - size_t offset = 0; - - U16_APPEND_UNSAFE(tmp, offset, (uint32_t)ch); - UErrorCode errorCode = U_ZERO_ERROR; - unum_setTextAttribute(format, attr, tmp, offset, &errorCode); + unum_setTextAttribute(format, attr, str.data(), str.realSize(), &errorCode); if(U_FAILURE(errorCode)) - throw UnicodeError(errorCode, "Could not set padding character", P_SOURCEINFO); + throw UnicodeError(errorCode, "Could not set text attribute", P_SOURCEINFO); } -Char NumberFormatGetTextAttr(UNumberFormat* format, UNumberFormatTextAttribute attr) +String NumberFormatGetTextAttr(UNumberFormat* format, UNumberFormatTextAttribute attr) { - uchar16_t tmp[3]; - size_t len; - UErrorCode errorCode = U_ZERO_ERROR; - len = unum_getTextAttribute(format, attr, tmp, sizeof(tmp), &errorCode); - if(U_FAILURE(errorCode)) - throw UnicodeError(errorCode, "Could not set padding character", P_SOURCEINFO); + size_t strLen = unum_getTextAttribute(format, attr, NULL, 0, &errorCode); - size_t offset = 0; - uint32_t ch; + ScopedArrayPtr<uchar16_t> ret(new uchar16_t[strLen + 1]); + errorCode = U_ZERO_ERROR; - U16_GET_UNSAFE(tmp, offset, ch); - return Char(ch); + unum_getTextAttribute(format, attr, ret.get(), strLen + 1, &errorCode); + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not get text attribute", P_SOURCEINFO); + + String retStr; + retStr.acquire(ret.release(), strLen + 1, strLen); + return retStr; } -void NumberFormat::setPadChar(Char ch) +void NumberFormat::setPadChar(const String& str) throw(UnicodeError) { - NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_PADDING_CHARACTER, ch); + NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_PADDING_CHARACTER, str); } -Char NumberFormat::padChar() const throw() +String NumberFormat::padChar() const throw(OutOfMemory, UnicodeError) { return NumberFormatGetTextAttr((UNumberFormat*)_private, UNUM_PADDING_CHARACTER); } -void NumberFormat::setPositivePrefix(Char ch) +void NumberFormat::setPositivePrefix(const String& str) throw(UnicodeError) { - NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_POSITIVE_PREFIX, ch); + NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_POSITIVE_PREFIX, str); } -Char NumberFormat::positivePrefix() +String NumberFormat::positivePrefix() const throw(OutOfMemory, UnicodeError) { return NumberFormatGetTextAttr((UNumberFormat*)_private, UNUM_POSITIVE_PREFIX); } -void NumberFormat::setPositiveSuffix(Char ch) +void NumberFormat::setPositiveSuffix(const String& str) throw(UnicodeError) { - NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_POSITIVE_SUFFIX, ch); + NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_POSITIVE_SUFFIX, str); } -Char NumberFormat::positiveSuffix() +String NumberFormat::positiveSuffix() const throw(OutOfMemory, UnicodeError) { return NumberFormatGetTextAttr((UNumberFormat*)_private, UNUM_POSITIVE_SUFFIX); } -void NumberFormat::setNegativePrefix(Char ch) +void NumberFormat::setNegativePrefix(const String& str) throw(UnicodeError) { - NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_NEGATIVE_PREFIX, ch); + NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_NEGATIVE_PREFIX, str); } -Char NumberFormat::negativePrefix() +String NumberFormat::negativePrefix() const throw(OutOfMemory, UnicodeError) { return NumberFormatGetTextAttr((UNumberFormat*)_private, UNUM_NEGATIVE_PREFIX); } -void NumberFormat::setNegativeSuffix(Char ch) +void NumberFormat::setNegativeSuffix(const String& str) throw(UnicodeError) { - NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_NEGATIVE_SUFFIX, ch); + NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_NEGATIVE_SUFFIX, str); } -Char NumberFormat::negativeSuffix() +String NumberFormat::negativeSuffix() const throw(OutOfMemory, UnicodeError) { return NumberFormatGetTextAttr((UNumberFormat*)_private, UNUM_NEGATIVE_SUFFIX); } -String NumberFormat::format(Int32 val) throw(UnicodeError) +String NumberFormat::format(Int32 val) throw(OutOfMemory, UnicodeError) { UErrorCode errorCode = U_ZERO_ERROR; size_t strLen = unum_format((UNumberFormat*)_private, val, NULL, 0, NULL, &errorCode); @@ -242,7 +238,7 @@ return retStr; } -String NumberFormat::format(Int64 val) throw(UnicodeError) +String NumberFormat::format(Int64 val) throw(OutOfMemory, UnicodeError) { UErrorCode errorCode = U_ZERO_ERROR; size_t strLen = unum_formatInt64((UNumberFormat*)_private, val, NULL, 0, NULL, &errorCode); @@ -259,7 +255,7 @@ return retStr; } -String NumberFormat::format(double val) throw(UnicodeError) +String NumberFormat::format(double val) throw(OutOfMemory, UnicodeError) { UErrorCode errorCode = U_ZERO_ERROR; size_t strLen = unum_formatDouble((UNumberFormat*)_private, val, NULL, 0, NULL, &errorCode); |
From: Christian P. <cp...@us...> - 2005-07-08 08:15:51
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19784/include/pclasses/Unicode Modified Files: NumberFormat.h String.h Added Files: DateTimeFormat.h Log Message: - Added Unicode::DateTimeFormat - Added String::realSize() to determine String's internal char count - Fixed Unicode::Converter - Changed Unicode::NumberFormat text-attributes from Char to String --- NEW FILE: DateTimeFormat.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_Unicode_DateTimeFormat_h #define P_Unicode_DateTimeFormat_h #include <pclasses/Export.h> #include <pclasses/Exception.h> #include <pclasses/DateTime.h> #include <pclasses/Unicode/UnicodeError.h> #include <pclasses/Unicode/String.h> #include <memory> namespace P { namespace Unicode { class PUNICODE_EXPORT DateTimeFormat { public: enum Style { Full, Long, Medium, Short }; typedef std::pair<Style, Style> StylePair; DateTimeFormat(Style dateStyle, Style timeStyle, const char* locale) throw(OutOfMemory, UnicodeError); ~DateTimeFormat() throw(); void setDateTimeStyle(Style dateStyle, Style timeStyle) throw(); StylePair dateTimeStyle() const throw(); void setDateStyle(Style dateStyle) throw(); Style dateStyle() const throw(); void setTimeStyle(Style timeStyle) throw(); Style timeStyle() const throw(); String format(const Date& date) const throw(OutOfMemory, UnicodeError); String format(const Time& time) const throw(OutOfMemory, UnicodeError); String format(const DateTime& dt) const throw(OutOfMemory, UnicodeError); private: void* _private; }; } // !namespace Unicode } // !namespace P #endif Index: String.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/String.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- String.h 1 Jul 2005 13:55:10 -0000 1.9 +++ String.h 8 Jul 2005 08:15:42 -0000 1.10 @@ -84,7 +84,9 @@ //! Test if the String is empty bool empty() const throw(); + size_t size() const throw(); + size_t realSize() const throw(); size_t capacity() const throw(); void reserve(size_t sz); Index: NumberFormat.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/NumberFormat.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- NumberFormat.h 6 Jul 2005 12:59:09 -0000 1.1 +++ NumberFormat.h 8 Jul 2005 08:15:42 -0000 1.2 @@ -22,9 +22,11 @@ #define P_Unicode_NumberFormat_h #include <pclasses/Export.h> +#include <pclasses/Exception.h> #include <pclasses/Unicode/UnicodeError.h> #include <pclasses/Unicode/Char.h> #include <pclasses/Unicode/String.h> +#include <memory> namespace P { @@ -41,10 +43,12 @@ Ordinal }; - NumberFormat(Style s, const char* locale); + NumberFormat(Style s, const char* locale) + throw(OutOfMemory, UnicodeError); + ~NumberFormat() throw(); - void setWidth(unsigned int width); + void setWidth(unsigned int width) throw(); unsigned int width() const throw(); enum PadPosition { @@ -54,27 +58,27 @@ AfterSuffix }; - void setPadPosition(PadPosition p); + void setPadPosition(PadPosition p) throw(); PadPosition padPosition() const throw(); - void setPadChar(Char ch); - Char padChar() const throw(); + void setPadChar(const String& str) throw(UnicodeError); + String padChar() const throw(OutOfMemory, UnicodeError); - void setPositivePrefix(Char ch); - Char positivePrefix(); + void setPositivePrefix(const String& str) throw(UnicodeError); + String positivePrefix() const throw(OutOfMemory, UnicodeError); - void setPositiveSuffix(Char ch); - Char positiveSuffix(); + void setPositiveSuffix(const String& str) throw(UnicodeError); + String positiveSuffix() const throw(OutOfMemory, UnicodeError); - void setNegativePrefix(Char ch); - Char negativePrefix(); + void setNegativePrefix(const String& str) throw(UnicodeError); + String negativePrefix() const throw(OutOfMemory, UnicodeError); - void setNegativeSuffix(Char ch); - Char negativeSuffix(); + void setNegativeSuffix(const String& str) throw(UnicodeError); + String negativeSuffix() const throw(OutOfMemory, UnicodeError); - String format(Int32 val) throw(UnicodeError); - String format(Int64 val) throw(UnicodeError); - String format(double val) throw(UnicodeError); + String format(Int32 val) throw(OutOfMemory, UnicodeError); + String format(Int64 val) throw(OutOfMemory, UnicodeError); + String format(double val) throw(OutOfMemory, UnicodeError); private: void* _private; |
From: Christian P. <cp...@us...> - 2005-07-06 13:01:45
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27612/src/IO Modified Files: TextStream.cpp Log Message: - More work on TextStream Index: TextStream.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/TextStream.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- TextStream.cpp 4 Jul 2005 23:36:14 -0000 1.1 +++ TextStream.cpp 6 Jul 2005 13:01:05 -0000 1.2 @@ -18,6 +18,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "pclasses/ScopedArrayPtr.h" #include "pclasses/IO/TextStream.h" #include "pclasses/IO/IODeviceStreamBuffer.h" @@ -28,133 +29,334 @@ TextStream::TextStream(IO::IODevice& dev, size_t outBufferSize, size_t inBufferSize) : StreamBase(dev, outBufferSize, inBufferSize), - _fmt(Dec), _width(0), _prec(0), _fillCh(' '), - _converter(0) + _numFormat(Unicode::NumberFormat::Decimal), + _width(0), _padPos(Before), _padChar(' '), + _locale(0), _codePage(0), + _converter(0), _numFormater(0) { } TextStream::TextStream(IO::StreamBuffer& buffer) throw() : StreamBase(buffer), - _fmt(Dec), _width(0), _prec(0), _fillCh(' '), - _converter(0) + _numFormat(Unicode::NumberFormat::Decimal), + _width(0), _padPos(Before), _padChar(' '), + _locale(0), _codePage(0), + _converter(0), _numFormater(0) { } TextStream::~TextStream() throw() { + if(_locale) + delete[] _locale; + + if(_codePage) + delete[] _codePage; + + if(_converter) + delete _converter; + + if(_numFormater) + delete _numFormater; } -void TextStream::setFormat(Format fmt) throw() +Unicode::NumberFormat::PadPosition + PadPosition2NumberFormatPadPosition(TextStream::PadPosition pos) { - _fmt = fmt; + Unicode::NumberFormat::PadPosition numFmtPadPos; + + switch(pos) + { + case TextStream::BeforePrefix: + numFmtPadPos = Unicode::NumberFormat::BeforePrefix; + break; + + case TextStream::AfterPrefix: + numFmtPadPos = Unicode::NumberFormat::AfterPrefix; + break; + + case TextStream::BeforeSuffix: + numFmtPadPos = Unicode::NumberFormat::BeforeSuffix; + break; + + case TextStream::AfterSuffix: + default: + numFmtPadPos = Unicode::NumberFormat::AfterSuffix; + break; + } + + return numFmtPadPos; +} + + +Unicode::NumberFormat* TextStream::createNumFormater( + NumberFormat fmt, const char* locale) throw(Unicode::UnicodeError) +{ + Unicode::NumberFormat* ret = new Unicode::NumberFormat(fmt, locale); + ret->setWidth(_width); + ret->setPadChar(_padChar); + ret->setPadPosition(PadPosition2NumberFormatPadPosition(_padPos)); + return ret; +} + +void TextStream::setCodePage(const char* cp) throw(Unicode::UnicodeError) +{ + // copy the given codepage ... + ScopedArrayPtr<char> newCodePage; + if(cp) + { + newCodePage = new char[std::strlen(cp)+1]; + strcpy(newCodePage.get(), cp); + } + + // create the new converter ... + if(_converter) + { + Unicode::Converter* newConverter = new Unicode::Converter(cp); + delete _converter; + _converter = newConverter; + } + + // delete the old codepage ... + if(_codePage) + delete[] _codePage; + + _codePage = newCodePage.release(); +} + +const char* TextStream::codePage() const throw() +{ + return _codePage; +} + +void TextStream::setLocale(const char* loc) throw(Unicode::UnicodeError) +{ + // copy the given locale ... + ScopedArrayPtr<char> newLocale; + if(loc) + { + newLocale = new char[std::strlen(loc)+1]; + strcpy(newLocale.get(), loc); + } + + // create the new number formater ... + if(_numFormater) + { + Unicode::NumberFormat* newNumFormater = createNumFormater(_numFormat, loc); + delete _numFormater; + _numFormater = newNumFormater; + } + + // delete the old locale ... + if(_locale) + delete[] _locale; + + _locale = newLocale.release(); +} + +const char* TextStream::locale() const throw() +{ + return _locale; +} + +void TextStream::setNumberFormat(NumberFormat fmt) throw(Unicode::UnicodeError) +{ + if(_numFormat != fmt) + { + if(_numFormater) + { + Unicode::NumberFormat* newNumFormater = createNumFormater(fmt, _locale); + delete _numFormater; + _numFormater = newNumFormater; + } + + _numFormat = fmt; + } +} + +TextStream::NumberFormat TextStream::numberFormat() const throw() +{ + return _numFormat; } void TextStream::setWidth(unsigned int width) throw() { + if(_numFormater) + _numFormater->setWidth(width); + _width = width; } -void TextStream::setPrecision(unsigned int prec) throw() +unsigned int TextStream::width() const throw() { - _prec = prec; + return _width; } -void TextStream::setFill(Unicode::Char ch) throw() +void TextStream::setPadPosition(PadPosition pos) throw() { - _fillCh = ch; + if(_numFormater) + _numFormater->setPadPosition(PadPosition2NumberFormatPadPosition(pos)); + + _padPos = pos; } -void TextStream::setCodepage(const char* cp) +TextStream::PadPosition TextStream::padPosition() const throw() { - if(_converter) - delete _converter; + return _padPos; +} - _converter = new Unicode::Converter(cp); +void TextStream::setPadChar(Unicode::Char ch) throw() +{ + if(_numFormater) + _numFormater->setPadChar(ch); + + _padChar = ch; +} + +Unicode::Char TextStream::padChar() const throw() +{ + return _padChar; } TextStream& TextStream::operator<<(Int8 val) { - return *this; + if(!_numFormater) + _numFormater = createNumFormater(_numFormat, _locale); + + return write(_numFormater->format(Int32(val))); } TextStream& TextStream::operator<<(UInt8 val) { - return *this; + if(!_numFormater) + _numFormater = createNumFormater(_numFormat, _locale); + + return write(_numFormater->format(Int32(val))); } TextStream& TextStream::operator<<(Int16 val) { - return *this; + if(!_numFormater) + _numFormater = createNumFormater(_numFormat, _locale); + + return write(_numFormater->format(Int32(val))); } TextStream& TextStream::operator<<(UInt16 val) { - return *this; + if(!_numFormater) + _numFormater = createNumFormater(_numFormat, _locale); + + return write(_numFormater->format(Int32(val))); } TextStream& TextStream::operator<<(Int32 val) { - return *this; + if(!_numFormater) + _numFormater = createNumFormater(_numFormat, _locale); + + return write(_numFormater->format(val)); } TextStream& TextStream::operator<<(UInt32 val) { - return *this; + if(!_numFormater) + _numFormater = createNumFormater(_numFormat, _locale); + + return write(_numFormater->format(Int64(val))); } #ifdef PCLASSES_HAVE_64BIT_INT TextStream& TextStream::operator<<(Int64 val) { - return *this; + if(!_numFormater) + _numFormater = createNumFormater(_numFormat, _locale); + + return write(_numFormater->format(val)); } TextStream& TextStream::operator<<(UInt64 val) { + //@fixme return *this; } #endif TextStream& TextStream::operator<<(float val) { - return *this; + if(!_numFormater) + _numFormater = createNumFormater(_numFormat, _locale); + + return write(_numFormater->format((double)val)); } TextStream& TextStream::operator<<(double val) { - return *this; + if(!_numFormater) + _numFormater = createNumFormater(_numFormat, _locale); + + return write(_numFormater->format(val)); } #ifdef PCLASSES_HAVE_LONG_DOUBLE TextStream& TextStream::operator<<(long double val) { + //@fixme return *this; } #endif TextStream& TextStream::operator<<(const Unicode::Char& ch) { + if(!_converter) + _converter = new Unicode::Converter(_codePage); + + std::string cpStr = _converter->fromUnicode(ch); + writeRaw(cpStr.c_str(), cpStr.size()); return *this; } +void writePadString(TextStream& strm, Unicode::Char padChar, size_t count) +{ + Unicode::String fillStr(count); + fillStr.insert(0, count, padChar); + strm.write(fillStr); +} + TextStream& TextStream::operator<<(const Unicode::String& str) { + bool smaller = (str.size() < _width); + + if(smaller && (_padPos == BeforePrefix || _padPos == AfterPrefix)) + writePadString(*this, _padChar, _width - str.size()); + + write(str); + + if(smaller && (_padPos == AfterSuffix || _padPos == BeforeSuffix)) + writePadString(*this, _padChar, _width - str.size()); + + return *this; +} + +TextStream& TextStream::write(const Unicode::String& str) +{ if(!_converter) - _converter = new Unicode::Converter(0); + _converter = new Unicode::Converter(_codePage); std::string cpStr = _converter->fromUnicode(str); - (*this) << cpStr; + writeRaw(cpStr.c_str(), cpStr.size()); return *this; } TextStream& TextStream::operator<<(const char* str) { - writeRaw(str, std::strlen(str)); + (*this) << Unicode::String(str); return *this; } TextStream& TextStream::operator<<(const std::string& str) { - writeRaw(str.c_str(), str.size()); + (*this) << Unicode::String(str); return *this; } @@ -169,25 +371,43 @@ #ifdef PCLASSES_WITH_CR_LINEFEED strm << Unicode::Char::cr(); #endif - strm << Unicode::Char::nl(); + strm << Unicode::Char::lf(); return strm; } -TextStream& dec(TextStream& strm) +TextStream& decimal(TextStream& strm) { - strm.setFormat(TextStream::Dec); + strm.setNumberFormat(Unicode::NumberFormat::Decimal); return strm; } -TextStream& hex(TextStream& strm) +TextStream& currency(TextStream& strm) { - strm.setFormat(TextStream::Hex); + strm.setNumberFormat(Unicode::NumberFormat::Currency); return strm; } -TextStream& oct(TextStream& strm) +TextStream& percent(TextStream& strm) { - strm.setFormat(TextStream::Oct); + strm.setNumberFormat(Unicode::NumberFormat::Percent); + return strm; +} + +TextStream& scientific(TextStream& strm) +{ + strm.setNumberFormat(Unicode::NumberFormat::Scientific); + return strm; +} + +TextStream& spellout(TextStream& strm) +{ + strm.setNumberFormat(Unicode::NumberFormat::Spellout); + return strm; +} + +TextStream& ordinal(TextStream& strm) +{ + strm.setNumberFormat(Unicode::NumberFormat::Ordinal); return strm; } |
From: Christian P. <cp...@us...> - 2005-07-06 13:01:31
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27612/include/pclasses/IO Modified Files: TextStream.h Log Message: - More work on TextStream Index: TextStream.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/TextStream.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- TextStream.h 4 Jul 2005 23:36:13 -0000 1.1 +++ TextStream.h 6 Jul 2005 13:01:05 -0000 1.2 @@ -28,6 +28,7 @@ #include <pclasses/IO/StreamBuffer.h> #include <pclasses/Unicode/String.h> #include <pclasses/Unicode/Converter.h> +#include <pclasses/Unicode/NumberFormat.h> namespace P { @@ -35,6 +36,8 @@ class PIO_EXPORT TextStream: public StreamBase { public: + typedef Unicode::NumberFormat::Style NumberFormat; + TextStream(IODevice& dev, size_t outBufferSize = 1024, size_t inBufferSize = 1024); @@ -42,26 +45,45 @@ ~TextStream() throw(); - //! Number format - enum Format { - Hex, /*!< Print numbers in hexadecimal format */ - Dec, /*!< Print numbers in decimal format */ - Oct /*!< Print numbers in octal fomat */ - }; + //! Set the codepage + /*! + Sets the codepage for the output- and input-conversion. + */ + void setCodePage(const char* cp) throw(Unicode::UnicodeError); + const char* codePage() const throw(); + + //! Set the locale + /*! + Sets the locale for formatting numbers, date and time + values. + */ + void setLocale(const char* loc) throw(Unicode::UnicodeError); + const char* locale() const throw(); //! Set number-format - void setFormat(Format fmt) throw(); + void setNumberFormat(NumberFormat fmt) throw(Unicode::UnicodeError); + NumberFormat numberFormat() const throw(); - //! Set width of numbers + //! Set width of output fields void setWidth(unsigned int width) throw(); + unsigned int width() const throw(); - //! Set floating-point precision - void setPrecision(unsigned int prec) throw(); + enum PadPosition { + BeforePrefix, + AfterPrefix, + BeforeSuffix, + AfterSuffix, + Before = BeforePrefix, + After = AfterSuffix + }; - //! Set fill-character - void setFill(Unicode::Char ch) throw(); + //! Set padding position + void setPadPosition(PadPosition pos) throw(); + PadPosition padPosition() const throw(); - void setCodepage(const char* cp); + //! Set padding character + void setPadChar(Unicode::Char ch) throw(); + Unicode::Char padChar() const throw(); TextStream& operator<<(Int8 val); TextStream& operator<<(UInt8 val); @@ -92,6 +114,8 @@ TextStream& operator<<(const char* str); TextStream& operator<<(const std::string& str); + TextStream& write(const Unicode::String& str); + TextStream& operator>>(Int8& val); TextStream& operator>>(UInt8& val); @@ -119,16 +143,32 @@ TextStream& operator>>(std::string& str); private: - Format _fmt; - unsigned int _width, _prec; - Unicode::Char _fillCh; - Unicode::Converter* _converter; + Unicode::NumberFormat* createNumFormater(NumberFormat fmt, + const char* locale) throw(Unicode::UnicodeError); + + NumberFormat _numFormat; + unsigned int _width; + PadPosition _padPos; + Unicode::Char _padChar; + char* _locale; + char* _codePage; + Unicode::Converter* _converter; + Unicode::NumberFormat* _numFormater; }; -PUNICODE_EXPORT TextStream& endl(TextStream& strm); -PUNICODE_EXPORT TextStream& dec(TextStream& strm); +PIO_EXPORT TextStream& endl(TextStream& strm); + +PIO_EXPORT TextStream& decimal(TextStream& strm); +PIO_EXPORT TextStream& currency(TextStream& strm); +PIO_EXPORT TextStream& percent(TextStream& strm); +PIO_EXPORT TextStream& scientific(TextStream& strm); +PIO_EXPORT TextStream& spellout(TextStream& strm); +PIO_EXPORT TextStream& ordinal(TextStream& strm); + + +/*PUNICODE_EXPORT TextStream& dec(TextStream& strm); PUNICODE_EXPORT TextStream& hex(TextStream& strm); -PUNICODE_EXPORT TextStream& oct(TextStream& strm); +PUNICODE_EXPORT TextStream& oct(TextStream& strm);*/ } // !namespace IO |
From: Christian P. <cp...@us...> - 2005-07-06 12:59:20
|
Update of /cvsroot/pclasses/pclasses2/src/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25949/src/Unicode Modified Files: Converter.cpp Char.cpp Makefile.am Added Files: NumberFormat.cpp Log Message: - Renamed Unicode::Char::nl() to Unicode::Char::lf() - Added some documentation and methods to Unicode::Converter - Added Unicode::NumberFormat Index: Converter.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/Converter.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Converter.cpp 24 May 2005 02:32:59 -0000 1.1 +++ Converter.cpp 6 Jul 2005 12:59:10 -0000 1.2 @@ -40,6 +40,33 @@ ucnv_close((UConverter*)_private); } +std::string Converter::name() const throw(UnicodeError) +{ + UErrorCode errorCode = U_ZERO_ERROR; + + std::string ret = ucnv_getName((UConverter*)_private, &errorCode); + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not get converter name", P_SOURCEINFO); + + return ret; +} + +String Converter::displayName(const char* locale) const throw(UnicodeError) +{ + UErrorCode errorCode = U_ZERO_ERROR; + size_t neededSize = ucnv_getDisplayName((UConverter*)_private, locale, 0, 0, &errorCode); + + ScopedArrayPtr<uchar16_t> displayName(new uchar16_t[neededSize + 1]); + + ucnv_getDisplayName((UConverter*)_private, locale, displayName.get(), neededSize + 1, &errorCode); + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not get converter displayname", P_SOURCEINFO); + + String ret; + ret.acquire(displayName.release(), neededSize + 1, neededSize); + return ret; +} + String Converter::toUnicode(const std::string& str) throw(UnicodeError) { return toUnicode(str.c_str(), str.size()); @@ -69,19 +96,15 @@ return retStr; } -std::string Converter::fromUnicode(const String& str) throw(UnicodeError) +std::string fromUnicodeChars(UConverter* conv, const uchar16_t* str, size_t srcLen) { - if(str.empty()) - return std::string(); - UErrorCode errorCode = U_ZERO_ERROR; - size_t srcLen = str.size(); - size_t strSize = UCNV_GET_MAX_BYTES_FOR_STRING(srcLen, ucnv_getMaxCharSize((UConverter*)_private)) + 1; + size_t strSize = UCNV_GET_MAX_BYTES_FOR_STRING(srcLen, ucnv_getMaxCharSize(conv) + 1); ScopedArrayPtr<char> ret(new char[strSize]); - ucnv_fromUChars((UConverter*)_private, ret.get(), strSize, - str.data(), srcLen, &errorCode); + ucnv_fromUChars(conv, ret.get(), strSize, + str, srcLen, &errorCode); if(U_FAILURE(errorCode)) throw UnicodeError(errorCode, "Could not convert string from unicode", P_SOURCEINFO); @@ -91,6 +114,67 @@ return retStr; } +std::string Converter::fromUnicode(const String& str) throw(UnicodeError) +{ + if(str.empty()) + return std::string(); + + return fromUnicodeChars((UConverter*)_private, str.data(), str.size()); +} + +std::string Converter::fromUnicode(Char ch) throw(UnicodeError) +{ + uchar16_t tmp[2]; + size_t offset = 0; + + U16_APPEND_UNSAFE(tmp, offset, (uint32_t)ch); + return fromUnicodeChars((UConverter*)_private, tmp, offset); +} + +Converter::StringVector Converter::availableNames() throw(UnicodeError) +{ + int count = ucnv_countAvailable(); + + StringVector ret; + ret.reserve(count); + + for(int i = 0; i < count; ++i) + ret.at(i) = ucnv_getAvailableName(i); + + return ret; +} + +Converter::StringVector Converter::aliasNames(const std::string& name) throw(UnicodeError) +{ + UErrorCode errorCode = U_ZERO_ERROR; + + int count = ucnv_countAliases(name.c_str(), &errorCode); + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not get count of alias names", P_SOURCEINFO); + + StringVector ret; + ret.reserve(count); + + for(int i = 0; i < count; ++i) + { + const char* alias = ucnv_getAlias(name.c_str(), i, &errorCode); + + if(U_FAILURE(errorCode)) + throw UnicodeError(errorCode, "Could not get alias name", P_SOURCEINFO); + + if(errorCode == U_AMBIGUOUS_ALIAS_WARNING) + { + errorCode = U_ZERO_ERROR; + continue; + } + + ret.at(i) = alias; + } + + return ret; +} + + } // !namespace Unicode } // !namespace P Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/Makefile.am,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- Makefile.am 4 Jul 2005 23:36:15 -0000 1.13 +++ Makefile.am 6 Jul 2005 12:59:10 -0000 1.14 @@ -6,7 +6,7 @@ CPPFLAGS = -DPUNICODE_BUILD $(ICU_CFLAGS) libpclasses_unicode_la_SOURCES = Char.cpp String.cpp Converter.cpp \ - UnicodeError.cpp + NumberFormat.cpp UnicodeError.cpp libpclasses_unicode_la_LDFLAGS = -no-undefined Index: Char.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/Char.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Char.cpp 24 May 2005 02:32:59 -0000 1.8 +++ Char.cpp 6 Jul 2005 12:59:10 -0000 1.9 @@ -178,15 +178,15 @@ return _eof; } -const Char& Char::nl() throw() +const Char& Char::lf() throw() { - static Char _nl('\n'); + static Char _nl(0x000A); return _nl; } const Char& Char::cr() throw() { - static Char _cr('\r'); + static Char _cr(0x000D); return _cr; } --- NEW FILE: NumberFormat.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/ScopedArrayPtr.h" #include "pclasses/Unicode/NumberFormat.h" #include <unicode/unum.h> /* #include <unicode/uloc.h> #include <unicode/umisc.h> #include <unicode/parseerr.h>*/ namespace P { namespace Unicode { UNumberFormatStyle Style2UNumberFormatStyle(NumberFormat::Style s) { UNumberFormatStyle ret = UNUM_DEFAULT; switch(s) { case NumberFormat::Decimal: ret = UNUM_DECIMAL; break; case NumberFormat::Currency: ret = UNUM_CURRENCY; break; case NumberFormat::Percent: ret = UNUM_PERCENT; break; case NumberFormat::Scientific: ret = UNUM_SCIENTIFIC; break; case NumberFormat::Spellout: ret = UNUM_SPELLOUT; break; case NumberFormat::Ordinal: ret = UNUM_ORDINAL; break; default: break; } return ret; } NumberFormat::NumberFormat(Style s, const char* locale) { UErrorCode error = U_ZERO_ERROR; _private = (void*)unum_open(Style2UNumberFormatStyle(s), NULL, 0, locale, NULL, &error); if(U_FAILURE(error)) throw UnicodeError(error, "Could not init number formater for given locale", P_SOURCEINFO); } NumberFormat::~NumberFormat() throw() { unum_close((UNumberFormat*)_private); } void NumberFormat::setWidth(unsigned int width) { unum_setAttribute((UNumberFormat*)_private, UNUM_FORMAT_WIDTH, width); } unsigned int NumberFormat::width() const throw() { return unum_getAttribute((UNumberFormat*)_private, UNUM_FORMAT_WIDTH); } UNumberFormatPadPosition PadPosition2UNumberFormatPadPosition(NumberFormat::PadPosition pos) { UNumberFormatPadPosition ret; switch(pos) { case NumberFormat::BeforePrefix: ret = UNUM_PAD_BEFORE_PREFIX; break; case NumberFormat::AfterPrefix: ret = UNUM_PAD_AFTER_PREFIX; break; case NumberFormat::BeforeSuffix: ret = UNUM_PAD_BEFORE_SUFFIX; break; case NumberFormat::AfterSuffix: default: ret = UNUM_PAD_AFTER_SUFFIX; break; } return ret; } void NumberFormat::setPadPosition(PadPosition p) { unum_setAttribute((UNumberFormat*)_private, UNUM_PADDING_POSITION, PadPosition2UNumberFormatPadPosition(p)); } NumberFormat::PadPosition UNumberFormatPadPosition2PadPosition(UNumberFormatPadPosition pos) { NumberFormat::PadPosition ret; switch(pos) { case UNUM_PAD_BEFORE_PREFIX: ret = NumberFormat::BeforePrefix; break; case UNUM_PAD_AFTER_PREFIX: ret = NumberFormat::AfterPrefix; break; case UNUM_PAD_BEFORE_SUFFIX: ret = NumberFormat::BeforeSuffix; break; case UNUM_PAD_AFTER_SUFFIX: ret = NumberFormat::AfterSuffix; break; } return ret; } NumberFormat::PadPosition NumberFormat::padPosition() const throw() { return UNumberFormatPadPosition2PadPosition( (UNumberFormatPadPosition)unum_getAttribute((UNumberFormat*)_private, UNUM_PADDING_POSITION)); } void NumberFormatSetTextAttr(UNumberFormat* format, UNumberFormatTextAttribute attr, Unicode::Char ch) { uchar16_t tmp[2]; size_t offset = 0; U16_APPEND_UNSAFE(tmp, offset, (uint32_t)ch); UErrorCode errorCode = U_ZERO_ERROR; unum_setTextAttribute(format, attr, tmp, offset, &errorCode); if(U_FAILURE(errorCode)) throw UnicodeError(errorCode, "Could not set padding character", P_SOURCEINFO); } Char NumberFormatGetTextAttr(UNumberFormat* format, UNumberFormatTextAttribute attr) { uchar16_t tmp[3]; size_t len; UErrorCode errorCode = U_ZERO_ERROR; len = unum_getTextAttribute(format, attr, tmp, sizeof(tmp), &errorCode); if(U_FAILURE(errorCode)) throw UnicodeError(errorCode, "Could not set padding character", P_SOURCEINFO); size_t offset = 0; uint32_t ch; U16_GET_UNSAFE(tmp, offset, ch); return Char(ch); } void NumberFormat::setPadChar(Char ch) { NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_PADDING_CHARACTER, ch); } Char NumberFormat::padChar() const throw() { return NumberFormatGetTextAttr((UNumberFormat*)_private, UNUM_PADDING_CHARACTER); } void NumberFormat::setPositivePrefix(Char ch) { NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_POSITIVE_PREFIX, ch); } Char NumberFormat::positivePrefix() { return NumberFormatGetTextAttr((UNumberFormat*)_private, UNUM_POSITIVE_PREFIX); } void NumberFormat::setPositiveSuffix(Char ch) { NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_POSITIVE_SUFFIX, ch); } Char NumberFormat::positiveSuffix() { return NumberFormatGetTextAttr((UNumberFormat*)_private, UNUM_POSITIVE_SUFFIX); } void NumberFormat::setNegativePrefix(Char ch) { NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_NEGATIVE_PREFIX, ch); } Char NumberFormat::negativePrefix() { return NumberFormatGetTextAttr((UNumberFormat*)_private, UNUM_NEGATIVE_PREFIX); } void NumberFormat::setNegativeSuffix(Char ch) { NumberFormatSetTextAttr((UNumberFormat*)_private, UNUM_NEGATIVE_SUFFIX, ch); } Char NumberFormat::negativeSuffix() { return NumberFormatGetTextAttr((UNumberFormat*)_private, UNUM_NEGATIVE_SUFFIX); } String NumberFormat::format(Int32 val) throw(UnicodeError) { UErrorCode errorCode = U_ZERO_ERROR; size_t strLen = unum_format((UNumberFormat*)_private, val, NULL, 0, NULL, &errorCode); ScopedArrayPtr<uchar16_t> ret(new uchar16_t[strLen + 1]); errorCode = U_ZERO_ERROR; unum_format((UNumberFormat*)_private, val, ret.get(), strLen + 1, NULL, &errorCode); if(U_FAILURE(errorCode)) throw UnicodeError(errorCode, "Could not convert number to string", P_SOURCEINFO); String retStr; retStr.acquire(ret.release(), strLen + 1, strLen); return retStr; } String NumberFormat::format(Int64 val) throw(UnicodeError) { UErrorCode errorCode = U_ZERO_ERROR; size_t strLen = unum_formatInt64((UNumberFormat*)_private, val, NULL, 0, NULL, &errorCode); ScopedArrayPtr<uchar16_t> ret(new uchar16_t[strLen + 1]); errorCode = U_ZERO_ERROR; unum_formatInt64((UNumberFormat*)_private, val, ret.get(), strLen + 1, NULL, &errorCode); if(U_FAILURE(errorCode)) throw UnicodeError(errorCode, "Could not convert number to string", P_SOURCEINFO); String retStr; retStr.acquire(ret.release(), strLen + 1, strLen); return retStr; } String NumberFormat::format(double val) throw(UnicodeError) { UErrorCode errorCode = U_ZERO_ERROR; size_t strLen = unum_formatDouble((UNumberFormat*)_private, val, NULL, 0, NULL, &errorCode); ScopedArrayPtr<uchar16_t> ret(new uchar16_t[strLen + 1]); errorCode = U_ZERO_ERROR; unum_formatDouble((UNumberFormat*)_private, val, ret.get(), strLen + 1, NULL, &errorCode); if(U_FAILURE(errorCode)) throw UnicodeError(errorCode, "Could not convert number to string", P_SOURCEINFO); String retStr; retStr.acquire(ret.release(), strLen + 1, strLen); return retStr; } } // !namespace Unicode } // !namespace P |
From: Christian P. <cp...@us...> - 2005-07-06 12:59:20
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25949/include/pclasses/Unicode Modified Files: Converter.h Char.h Makefile.am Added Files: NumberFormat.h Log Message: - Renamed Unicode::Char::nl() to Unicode::Char::lf() - Added some documentation and methods to Unicode::Converter - Added Unicode::NumberFormat Index: Char.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/Char.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Char.h 24 May 2005 02:32:59 -0000 1.7 +++ Char.h 6 Jul 2005 12:59:09 -0000 1.8 @@ -80,7 +80,7 @@ bool operator>=(const Char& ch) const throw(); static const Char& eof() throw(); - static const Char& nl() throw(); + static const Char& lf() throw(); static const Char& cr() throw(); private: Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/Makefile.am,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Makefile.am 4 Jul 2005 23:36:14 -0000 1.6 +++ Makefile.am 6 Jul 2005 12:59:09 -0000 1.7 @@ -2,4 +2,5 @@ INCLUDES = METASOURCES = AUTO -pclasses_unicode_include_HEADERS = Char.h String.h Converter.h UnicodeError.h +pclasses_unicode_include_HEADERS = Char.h String.h Converter.h UnicodeError.h \ + NumberFormat.h Index: Converter.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/Converter.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Converter.h 24 May 2005 02:32:59 -0000 1.1 +++ Converter.h 6 Jul 2005 12:59:09 -0000 1.2 @@ -26,22 +26,77 @@ #include <pclasses/Unicode/UnicodeError.h> #include <string> +#include <vector> namespace P { namespace Unicode { +//! UNICODE Charset converter +/*! + The converter class is used to convert UNICODE strings + to and from different charsets. + + This class is utilizes the ICU character conversion library, + for more information see http://icu.sourceforge.net. + + @todo add streaming conversion methods ... +*/ class PUNICODE_EXPORT Converter { public: + typedef std::vector<std::string> StringVector; + + //! Creates a Converter object with the name specified as a C string + /*! + The actual name will be resolved with the alias file using a + case-insensitive string comparison that ignores the delimiters + '-', '_', and ' ' (dash, underscore, and space). E.g., the names + "UTF8", "utf-8", and "Utf 8" are all equivalent. If NULL is passed + for the converter name, it will create one with the systems default + converter name. + + Options are appended to the converter name string, with a ',' between + the name and the first option and also between adjacent options. + + \param name Name of the uconv table, may have options appended + \throw UnicodeError + */ Converter(const char* name) throw(UnicodeError); ~Converter() throw(); + //! Returns the internal, canonical name of the converter + std::string name() const throw(UnicodeError); + + //! Returns the display name of the converter + /*! + Returns the display name of the converter based on the locale passed + that was passid in. + If the locale contains no display name, the internal ASCII name will + be filled in. + \param locale the locale the name should be localised for + \throw UnicodeError + */ + String displayName(const char* locale) const throw(UnicodeError); + + //! Converts a string in the converters charset to UNICODE String toUnicode(const std::string& str) throw(UnicodeError); + + //! Converts a string in the converters charset to UNICODE String toUnicode(const char* str, size_t count = String::npos) throw(UnicodeError); + //! Converts a UNICODE string to the converters charset std::string fromUnicode(const String& str) throw(UnicodeError); + //! Converts a UNICODE character to the converters charset + std::string fromUnicode(Char ch) throw(UnicodeError); + + //! Returns the canonical names of all known converters + static StringVector availableNames() throw(UnicodeError); + + //! Returns the aliases for a given converter or alias name + static StringVector aliasNames(const std::string& name) throw(UnicodeError); + private: void* _private; }; --- NEW FILE: NumberFormat.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_Unicode_NumberFormat_h #define P_Unicode_NumberFormat_h #include <pclasses/Export.h> #include <pclasses/Unicode/UnicodeError.h> #include <pclasses/Unicode/Char.h> #include <pclasses/Unicode/String.h> namespace P { namespace Unicode { class PUNICODE_EXPORT NumberFormat { public: enum Style { Decimal, Currency, Percent, Scientific, Spellout, Ordinal }; NumberFormat(Style s, const char* locale); ~NumberFormat() throw(); void setWidth(unsigned int width); unsigned int width() const throw(); enum PadPosition { BeforePrefix, AfterPrefix, BeforeSuffix, AfterSuffix }; void setPadPosition(PadPosition p); PadPosition padPosition() const throw(); void setPadChar(Char ch); Char padChar() const throw(); void setPositivePrefix(Char ch); Char positivePrefix(); void setPositiveSuffix(Char ch); Char positiveSuffix(); void setNegativePrefix(Char ch); Char negativePrefix(); void setNegativeSuffix(Char ch); Char negativeSuffix(); String format(Int32 val) throw(UnicodeError); String format(Int64 val) throw(UnicodeError); String format(double val) throw(UnicodeError); private: void* _private; }; } // !namespace Unicode } // !namespace P #endif |
From: Christian P. <cp...@us...> - 2005-07-04 23:36:24
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1650/src/IO Modified Files: Makefile.am Added Files: DataStream.cpp IODeviceStreamBuffer.cpp StreamBase.cpp StreamBuffer.cpp TextStream.cpp Log Message: - Added StreamBuffer, StreamBase - std::streams are not suitable for our needs - Added IODeviceStreamBuffer - buffers Streams and writes them to an IODevice - Added DataStream - portable data streaming - Added TextStream - unicode text streaming with on the fly codepage conversion Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/Makefile.am,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- Makefile.am 29 May 2005 17:48:31 -0000 1.12 +++ Makefile.am 4 Jul 2005 23:36:14 -0000 1.13 @@ -6,7 +6,8 @@ libpclasses_io_la_SOURCES = IOError.cpp IODevice.cpp IOStream.cpp \ IOFilter.cpp URL.cpp ZLib.cpp ZLibIOFilter.cpp BZip2.cpp BZip2IOFilter.cpp \ - IORequest.cpp IOHandler.cpp IOManager.cpp IOListener.cpp + IORequest.cpp IOHandler.cpp IOManager.cpp IOListener.cpp StreamBuffer.cpp \ + IODeviceStreamBuffer.cpp StreamBase.cpp DataStream.cpp TextStream.cpp libpclasses_io_la_LDFLAGS = -no-nundefined --- NEW FILE: TextStream.cpp --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/IO/TextStream.h" #include "pclasses/IO/IODeviceStreamBuffer.h" namespace P { namespace IO { TextStream::TextStream(IO::IODevice& dev, size_t outBufferSize, size_t inBufferSize) : StreamBase(dev, outBufferSize, inBufferSize), _fmt(Dec), _width(0), _prec(0), _fillCh(' '), _converter(0) { } TextStream::TextStream(IO::StreamBuffer& buffer) throw() : StreamBase(buffer), _fmt(Dec), _width(0), _prec(0), _fillCh(' '), _converter(0) { } TextStream::~TextStream() throw() { } void TextStream::setFormat(Format fmt) throw() { _fmt = fmt; } void TextStream::setWidth(unsigned int width) throw() { _width = width; } void TextStream::setPrecision(unsigned int prec) throw() { _prec = prec; } void TextStream::setFill(Unicode::Char ch) throw() { _fillCh = ch; } void TextStream::setCodepage(const char* cp) { if(_converter) delete _converter; _converter = new Unicode::Converter(cp); } TextStream& TextStream::operator<<(Int8 val) { return *this; } TextStream& TextStream::operator<<(UInt8 val) { return *this; } TextStream& TextStream::operator<<(Int16 val) { return *this; } TextStream& TextStream::operator<<(UInt16 val) { return *this; } TextStream& TextStream::operator<<(Int32 val) { return *this; } TextStream& TextStream::operator<<(UInt32 val) { return *this; } #ifdef PCLASSES_HAVE_64BIT_INT TextStream& TextStream::operator<<(Int64 val) { return *this; } TextStream& TextStream::operator<<(UInt64 val) { return *this; } #endif TextStream& TextStream::operator<<(float val) { return *this; } TextStream& TextStream::operator<<(double val) { return *this; } #ifdef PCLASSES_HAVE_LONG_DOUBLE TextStream& TextStream::operator<<(long double val) { return *this; } #endif TextStream& TextStream::operator<<(const Unicode::Char& ch) { return *this; } TextStream& TextStream::operator<<(const Unicode::String& str) { if(!_converter) _converter = new Unicode::Converter(0); std::string cpStr = _converter->fromUnicode(str); (*this) << cpStr; return *this; } TextStream& TextStream::operator<<(const char* str) { writeRaw(str, std::strlen(str)); return *this; } TextStream& TextStream::operator<<(const std::string& str) { writeRaw(str.c_str(), str.size()); return *this; } TextStream& TextStream::operator<<(TextStream& (*__pfn)(TextStream& strm)) { (*__pfn)(*this); return *this; } TextStream& endl(TextStream& strm) { #ifdef PCLASSES_WITH_CR_LINEFEED strm << Unicode::Char::cr(); #endif strm << Unicode::Char::nl(); return strm; } TextStream& dec(TextStream& strm) { strm.setFormat(TextStream::Dec); return strm; } TextStream& hex(TextStream& strm) { strm.setFormat(TextStream::Hex); return strm; } TextStream& oct(TextStream& strm) { strm.setFormat(TextStream::Oct); return strm; } } // !namespace Unicode } // !namespace P --- NEW FILE: DataStream.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/config.h" #include "pclasses/ScopedArrayPtr.h" #include "pclasses/IO/DataStream.h" #include "pclasses/IO/IODeviceStreamBuffer.h" #include <cstring> #ifdef WIN32 # define IEEE_FLOATING_POINT 1 #else #ifdef STDC_HEADERS # include <float.h> #endif #if (__STDC_IEC_559__ || (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \ && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)) # define IEEE_FLOATING_POINT 1 #else # define IEEE_FLOATING_POINT 0 #endif #endif namespace P { namespace IO { DataStream::DataStream(IODevice& dev, size_t outBufferSize, size_t inBufferSize) : StreamBase(dev, outBufferSize, inBufferSize), _byteOrder(BigEndian) { } DataStream::DataStream(StreamBuffer& buffer) throw() : StreamBase(buffer), _byteOrder(BigEndian) { } DataStream::~DataStream() throw() { } void DataStream::setByteOrder(ByteOrder b) throw() { _byteOrder = b; } DataStream::ByteOrder DataStream::byteOrder() const throw() { return _byteOrder; } template <class Type> Type byteOrderedVal(DataStream::ByteOrder byteOrder, Type val) { switch(byteOrder) { case DataStream::BigEndian: return val.bigEndian(); case DataStream::LittleEndian: return val.littleEndian(); case DataStream::Native: default: break; } return val; } template <class Type> IntType<Type> nativeOrderedVal(DataStream::ByteOrder fromByteOrder, Type val) { IntType<Type> ret; switch(fromByteOrder) { case DataStream::BigEndian: ret.setBigEndian(val); break; case DataStream::LittleEndian: ret.setLittleEndian(val); break; case DataStream::Native: default: ret = val; break; } return ret; } DataStream& DataStream::operator<<(Int8 val) { writeRaw((const char*)&val, sizeof(int8_t)); return *this; } DataStream& DataStream::operator<<(UInt8 val) { writeRaw((const char*)&val, sizeof(uint8_t)); return *this; } DataStream& DataStream::operator<<(Int16 val) { int16_t tmp = byteOrderedVal(_byteOrder, val); writeRaw((const char*)&tmp, sizeof(int16_t)); return *this; } DataStream& DataStream::operator<<(UInt16 val) { uint16_t tmp = byteOrderedVal(_byteOrder, val); writeRaw((const char*)&tmp, sizeof(uint16_t)); return *this; } DataStream& DataStream::operator<<(Int32 val) { int32_t tmp = byteOrderedVal(_byteOrder, val); writeRaw((const char*)&tmp, sizeof(int32_t)); return *this; } DataStream& DataStream::operator<<(UInt32 val) { uint32_t tmp = byteOrderedVal(_byteOrder, val); writeRaw((const char*)&tmp, sizeof(uint32_t)); return *this; } #ifdef PCLASSES_HAVE_64BIT_INT DataStream& DataStream::operator<<(Int64 val) { int64_t tmp = byteOrderedVal(_byteOrder, val); writeRaw((const char*)&tmp, sizeof(int64_t)); return *this; } DataStream& DataStream::operator<<(UInt64 val) { uint64_t tmp = byteOrderedVal(_byteOrder, val); writeRaw((const char*)&tmp, sizeof(uint64_t)); return *this; } #endif DataStream& DataStream::operator<<(float val) { #ifdef IEEE_FLOATING_POINT writeRaw((const char*)&val, sizeof(float)); #else #error "please fix me - architecture seems not IEE754" #endif return *this; } DataStream& DataStream::operator<<(double val) { #ifdef IEEE_FLOATING_POINT writeRaw((const char*)&val, sizeof(double)); #else #error "please fix me - architecture seems not IEE754" #endif return *this; } #ifdef PCLASSES_HAVE_LONG_DOUBLE DataStream& DataStream::operator<<(long double val) { #ifdef IEEE_FLOATING_POINT writeRaw((const char*)&val, sizeof(long double)); #else #error "please fix me - architecture seems not IEE754" #endif return *this; } #endif DataStream& DataStream::operator<<(const char* str) { write(str, std::strlen(str)); return *this; } DataStream& DataStream::operator<<(const std::string& str) { write(str.c_str(), str.size()); return *this; } DataStream& DataStream::operator>>(Int8& val) { readRaw((char*)&val, sizeof(int8_t)); return *this; } DataStream& DataStream::operator>>(UInt8& val) { readRaw((char*)&val, sizeof(uint8_t)); return *this; } DataStream& DataStream::operator>>(Int16& val) { int16_t tmp; readRaw((char*)&tmp, sizeof(int16_t)); val = nativeOrderedVal(_byteOrder, tmp); return *this; } DataStream& DataStream::operator>>(UInt16& val) { uint16_t tmp; readRaw((char*)&tmp, sizeof(uint16_t)); val = nativeOrderedVal(_byteOrder, tmp); return *this; } DataStream& DataStream::operator>>(Int32& val) { int32_t tmp; readRaw((char*)&tmp, sizeof(int32_t)); val = nativeOrderedVal(_byteOrder, tmp); return *this; } DataStream& DataStream::operator>>(UInt32& val) { uint32_t tmp; readRaw((char*)&tmp, sizeof(uint32_t)); val = nativeOrderedVal(_byteOrder, tmp); return *this; } #ifndef PCLASSES_HAVE_64BIT_INT DataStream& DataStream::operator>>(Int64& val) { int64_t tmp; readRaw((char*)&tmp, sizeof(int64_t)); val = nativeOrderedVal(_byteOrder, tmp); return *this; } DataStream& DataStream::operator>>(UInt64& val) { uint64_t tmp; readRaw((char*)&tmp, sizeof(uint64_t)); val = nativeOrderedVal(_byteOrder, tmp); return *this; } #endif DataStream& DataStream::operator>>(float& val) { #ifdef IEEE_FLOATING_POINT readRaw((char*)&val, sizeof(float)); #else #error "please fix me - architecture seems not IEE754" #endif return *this; } DataStream& DataStream::operator>>(double& val) { #ifdef IEEE_FLOATING_POINT readRaw((char*)&val, sizeof(double)); #else #error "please fix me - architecture seems not IEE754" #endif return *this; } #ifdef PCLASSES_HAVE_LONG_DOUBLE DataStream& DataStream::operator>>(long double& val) { #ifdef IEEE_FLOATING_POINT readRaw((char*)&val, sizeof(long double)); #else #error "please fix me - architecture seems not IEE754" #endif return *this; } #endif DataStream& DataStream::operator>>(std::string& str) { char* ret; size_t retLen; read(ret, retLen); str.assign(ret, retLen); delete[] ret; return *this; } DataStream& DataStream::write(const char* str, size_t count) throw(IOError) { DataStream::operator<<(UInt32(count)); writeRaw(str, count); DataStream::operator<<(UInt8(0)); return *this; } DataStream& DataStream::read(char*& str, size_t& count) throw(IOError) { UInt32 len; DataStream::operator>>(len); if(!eof()) { ScopedArrayPtr<char> ret(new char[len + 1]); len = readRaw(ret.get(), len + 1); str = ret.release(); str[len + 1] = 0; count = len; } else { str = new char[1]; str[0] = 0; count = 0; } return *this; } } // !namespace IO } // !namespace P --- NEW FILE: IODeviceStreamBuffer.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/ScopedArrayPtr.h" #include "pclasses/IO/IODeviceStreamBuffer.h" namespace P { namespace IO { IODeviceStreamBuffer::IODeviceStreamBuffer(IODevice& dev, size_t outBufferSize, size_t inBufferSize) : _device(dev), _outBuffer(outBufferSize), _inBuffer(inBufferSize) { } IODeviceStreamBuffer::~IODeviceStreamBuffer() throw() { } IODevice& IODeviceStreamBuffer::device() const throw() { return _device; } bool IODeviceStreamBuffer::eof() const throw() { return (_inBuffer.empty() && _device.eof()); } // this methods ensures that at minimum <minCount> bytes are flushed from // the output queue to the device .... void flushBuffer(IODevice& device, CircularQueue<char>& buffer, size_t minCount = (size_t)-1) { size_t bufferSize = buffer.size(); if(minCount == (size_t)-1) minCount = bufferSize; ScopedArrayPtr<char> tmp(new char[bufferSize]); buffer.get(tmp.get(), bufferSize); size_t written = 0, totalWritten = 0; while(totalWritten < minCount) { written = device.write(tmp.get() + totalWritten, bufferSize - totalWritten); totalWritten += written; buffer.pop(written); // wait until we can write more data ... if(totalWritten < minCount && !device.isBlocking()) device.wait(IODevice::WaitOutput, (unsigned int)-1); } } // this method ensures that at mimum <minCount> bytes are flushed from // the given buffer to the device ... size_t writeRawBuffer(IODevice& device, const char* buffer, size_t count, size_t minCount) { size_t written = 0, totalWritten = 0; while(totalWritten < minCount) { written = device.write(buffer + totalWritten, count - totalWritten); totalWritten += written; // wait until we can write more data ... if(totalWritten < minCount && !device.isBlocking()) device.wait(IODevice::WaitOutput, (unsigned int)-1); } return totalWritten; } void IODeviceStreamBuffer::sync() throw(IOError) { flushBuffer(_device, _outBuffer); } void IODeviceStreamBuffer::write(const char* buffer, size_t count) throw(IOError) { size_t capacity = _outBuffer.capacity(); // the bytes will never fit into our output buffer ... if(count > capacity) { // flush the hole output buffer ... flushBuffer(_device, _outBuffer); // write as many as we can .. but minimum that our output buffer can hold // the rest of it ... size_t written = writeRawBuffer(_device, buffer, count, count - capacity); // buffer unwritten bytes ... _outBuffer.push(buffer + written, count - written); } else { size_t size = _outBuffer.size(); // flush bytes from the output buffer until the bytes fit ... if(size + count > capacity) { size_t flushBytes = (size + count) - capacity; flushBuffer(_device, _outBuffer, flushBytes); } // buffer the bytes ... _outBuffer.push(buffer, count); } } size_t IODeviceStreamBuffer::read(char* buffer, size_t count) throw(IOError) { return 0; //@todo } } // !namespace IO } // !namespace P --- NEW FILE: StreamBuffer.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/IO/StreamBuffer.h" namespace P { namespace IO { StreamBuffer::StreamBuffer() { } StreamBuffer::~StreamBuffer() throw() { } } // !namespace IO } // !namespace P --- NEW FILE: StreamBase.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/IO/StreamBase.h" #include "pclasses/IO/StreamBuffer.h" #include "pclasses/IO/IODeviceStreamBuffer.h" namespace P { namespace IO { StreamBase::StreamBase(IODevice& dev, size_t outBufferSize, size_t inBufferSize) : _ownBuffer(true), _buffer(new IODeviceStreamBuffer(dev, outBufferSize, inBufferSize)) { } StreamBase::StreamBase(StreamBuffer& buffer) throw() : _ownBuffer(false), _buffer(&buffer) { } StreamBase::~StreamBase() throw() { try { _buffer->sync(); } catch(...) { } if(_ownBuffer) { delete _buffer; _buffer = 0; } } StreamBuffer& StreamBase::buffer() const throw() { return *_buffer; } bool StreamBase::eof() const throw() { return _buffer->eof(); } void StreamBase::sync() throw(IOError) { _buffer->sync(); } void StreamBase::writeRaw(const char* buffer, size_t count) throw(IOError) { _buffer->write(buffer, count); } size_t StreamBase::readRaw(char* buffer, size_t count) throw(IOError) { return _buffer->read(buffer, count); } } // !namespace IO } // !namespace P |
From: Christian P. <cp...@us...> - 2005-07-04 23:36:23
|
Update of /cvsroot/pclasses/pclasses2/src/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1650/src/Unicode Modified Files: Makefile.am Removed Files: TextStream.cpp Log Message: - Added StreamBuffer, StreamBase - std::streams are not suitable for our needs - Added IODeviceStreamBuffer - buffers Streams and writes them to an IODevice - Added DataStream - portable data streaming - Added TextStream - unicode text streaming with on the fly codepage conversion Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/Makefile.am,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- Makefile.am 3 Jul 2005 23:46:29 -0000 1.12 +++ Makefile.am 4 Jul 2005 23:36:15 -0000 1.13 @@ -6,7 +6,7 @@ CPPFLAGS = -DPUNICODE_BUILD $(ICU_CFLAGS) libpclasses_unicode_la_SOURCES = Char.cpp String.cpp Converter.cpp \ - UnicodeError.cpp TextStream.cpp + UnicodeError.cpp libpclasses_unicode_la_LDFLAGS = -no-undefined --- TextStream.cpp DELETED --- |
From: Christian P. <cp...@us...> - 2005-07-04 23:36:23
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1650/include/pclasses/Unicode Modified Files: Makefile.am Removed Files: TextStream.h Log Message: - Added StreamBuffer, StreamBase - std::streams are not suitable for our needs - Added IODeviceStreamBuffer - buffers Streams and writes them to an IODevice - Added DataStream - portable data streaming - Added TextStream - unicode text streaming with on the fly codepage conversion Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Makefile.am 24 May 2005 02:32:59 -0000 1.5 +++ Makefile.am 4 Jul 2005 23:36:14 -0000 1.6 @@ -2,5 +2,4 @@ INCLUDES = METASOURCES = AUTO -pclasses_unicode_include_HEADERS = Char.h String.h Converter.h UnicodeError.h \ - TextStream.h +pclasses_unicode_include_HEADERS = Char.h String.h Converter.h UnicodeError.h --- TextStream.h DELETED --- |
From: Christian P. <cp...@us...> - 2005-07-04 23:36:23
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1650/include/pclasses/IO Modified Files: Makefile.am Added Files: StreamBase.h DataStream.h IODeviceStreamBuffer.h StreamBuffer.h TextStream.h Log Message: - Added StreamBuffer, StreamBase - std::streams are not suitable for our needs - Added IODeviceStreamBuffer - buffers Streams and writes them to an IODevice - Added DataStream - portable data streaming - Added TextStream - unicode text streaming with on the fly codepage conversion Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/Makefile.am,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Makefile.am 29 May 2005 17:48:31 -0000 1.9 +++ Makefile.am 4 Jul 2005 23:36:13 -0000 1.10 @@ -4,4 +4,5 @@ METASOURCES = AUTO pclasses_io_include_HEADERS = IOError.h IODevice.h IOStream.h IOFilter.h \ URL.h ZLib.h ZLibIOFilter.h BZip2.h BZip2IOFilter.h IORequest.h \ - IOHandler.h IOManager.h IOListener.h + IOHandler.h IOManager.h IOListener.h StreamBuffer.h IODeviceStreamBuffer.h \ + StreamBase.h DataStream.h TextStream.h --- NEW FILE: IODeviceStreamBuffer.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_IODeviceStreamBuffer_h #define P_IO_IODeviceStreamBuffer_h #include <pclasses/Export.h> #include <pclasses/CircularQueue.h> #include <pclasses/IO/IODevice.h> #include <pclasses/IO/IOError.h> #include <pclasses/IO/StreamBuffer.h> namespace P { namespace IO { class PIO_EXPORT IODeviceStreamBuffer: public StreamBuffer { public: IODeviceStreamBuffer(IODevice& dev, size_t outBufferSize = 1024, size_t inBufferSize = 1024); ~IODeviceStreamBuffer() throw(); IODevice& device() const throw(); bool eof() const throw(); void sync() throw(IOError); void write(const char* buffer, size_t count) throw(IOError); size_t read(char* buffer, size_t count) throw(IOError); private: IODevice& _device; CircularQueue<char> _outBuffer; CircularQueue<char> _inBuffer; }; } // !namespace IO } // !namespace P #endif --- NEW FILE: StreamBase.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_StreamBase_h #define P_IO_StreamBase_h #include <pclasses/Export.h> #include <pclasses/IO/IOError.h> #include <pclasses/IO/IODevice.h> #include <pclasses/IO/StreamBuffer.h> namespace P { namespace IO { class PIO_EXPORT StreamBase { public: StreamBase(IODevice& dev, size_t outBufferSize = 1024, size_t inBufferSize = 1024); StreamBase(StreamBuffer& buffer) throw(); ~StreamBase() throw(); StreamBuffer& buffer() const throw(); bool eof() const throw(); void sync() throw(IOError); void writeRaw(const char* buffer, size_t count) throw(IOError); size_t readRaw(char* buffer, size_t count) throw(IOError); private: bool _ownBuffer; StreamBuffer* _buffer; }; } // !namespace IO } // !namespace P #endif --- NEW FILE: DataStream.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_DataStream_h #define P_IO_DataStream_h #include <pclasses/Export.h> #include <pclasses/IntTypes.h> #include <pclasses/IO/IODevice.h> #include <pclasses/IO/StreamBase.h> #include <pclasses/IO/StreamBuffer.h> #include <string> namespace P { namespace IO { class PIO_EXPORT DataStream: public StreamBase { public: DataStream(IODevice& dev, size_t outBufferSize = 1024, size_t inBufferSize = 1024); DataStream(StreamBuffer& buffer) throw(); ~DataStream() throw(); enum ByteOrder { BigEndian, LittleEndian, Native }; void setByteOrder(ByteOrder b) throw(); ByteOrder byteOrder() const throw(); DataStream& operator<<(Int8 val); DataStream& operator<<(UInt8 val); DataStream& operator<<(Int16 val); DataStream& operator<<(UInt16 val); DataStream& operator<<(Int32 val); DataStream& operator<<(UInt32 val); #ifdef PCLASSES_HAVE_64BIT_INT DataStream& operator<<(Int64 val); DataStream& operator<<(UInt64 val); #endif DataStream& operator<<(float val); DataStream& operator<<(double val); #ifdef PCLASSES_HAVE_LONG_DOUBLE DataStream& operator<<(long double val); #endif DataStream& operator<<(const char* str); DataStream& operator<<(const std::string& str); DataStream& operator>>(Int8& val); DataStream& operator>>(UInt8& val); DataStream& operator>>(Int16& val); DataStream& operator>>(UInt16& val); DataStream& operator>>(Int32& val); DataStream& operator>>(UInt32& val); #ifdef PCLASSES_HAVE_64BIT_INT DataStream& operator>>(Int64& val); DataStream& operator>>(UInt64& val); #endif DataStream& operator>>(float& val); DataStream& operator>>(double& val); #ifdef PCLASSES_HAVE_LONG_DOUBLE DataStream& operator>>(long double& val); #endif DataStream& operator>>(std::string& str); DataStream& write(const char* str, size_t count) throw(IOError); DataStream& read(char*& str, size_t& count) throw(IOError); private: ByteOrder _byteOrder; }; } // !namespace IO } // !namespace P #endif --- NEW FILE: StreamBuffer.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_StreamBuffer_h #define P_IO_StreamBuffer_h #include <pclasses/Export.h> #include <pclasses/IO/IOError.h> namespace P { namespace IO { class PIO_EXPORT StreamBuffer { public: StreamBuffer(); virtual ~StreamBuffer() throw(); virtual bool eof() const throw() = 0; virtual void sync() throw(IOError) = 0; virtual void write(const char* buffer, size_t count) throw(IOError) = 0; virtual size_t read(char* buffer, size_t count) throw(IOError) = 0; }; } // !namespace IO } // !namespace P #endif --- NEW FILE: TextStream.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_TextStream_h #define P_IO_TextStream_h #include <pclasses/Export.h> #include <pclasses/IntTypes.h> #include <pclasses/IO/IODevice.h> #include <pclasses/IO/StreamBase.h> #include <pclasses/IO/StreamBuffer.h> #include <pclasses/Unicode/String.h> #include <pclasses/Unicode/Converter.h> namespace P { namespace IO { class PIO_EXPORT TextStream: public StreamBase { public: TextStream(IODevice& dev, size_t outBufferSize = 1024, size_t inBufferSize = 1024); TextStream(StreamBuffer& buffer) throw(); ~TextStream() throw(); //! Number format enum Format { Hex, /*!< Print numbers in hexadecimal format */ Dec, /*!< Print numbers in decimal format */ Oct /*!< Print numbers in octal fomat */ }; //! Set number-format void setFormat(Format fmt) throw(); //! Set width of numbers void setWidth(unsigned int width) throw(); //! Set floating-point precision void setPrecision(unsigned int prec) throw(); //! Set fill-character void setFill(Unicode::Char ch) throw(); void setCodepage(const char* cp); TextStream& operator<<(Int8 val); TextStream& operator<<(UInt8 val); TextStream& operator<<(Int16 val); TextStream& operator<<(UInt16 val); TextStream& operator<<(Int32 val); TextStream& operator<<(UInt32 val); #ifdef PCLASSES_HAVE_64BIT_INT TextStream& operator<<(Int64 val); TextStream& operator<<(UInt64 val); #endif TextStream& operator<<(float val); TextStream& operator<<(double val); #ifdef PCLASSES_HAVE_LONG_DOUBLE TextStream& operator<<(long double val); #endif TextStream& operator<<(TextStream& (*pfn)(TextStream& strm)); TextStream& operator<<(const Unicode::Char& ch); TextStream& operator<<(const Unicode::String& str); TextStream& operator<<(const char* str); TextStream& operator<<(const std::string& str); TextStream& operator>>(Int8& val); TextStream& operator>>(UInt8& val); TextStream& operator>>(Int16& val); TextStream& operator>>(UInt16& val); TextStream& operator>>(Int32& val); TextStream& operator>>(UInt32& val); #ifdef PCLASSES_HAVE_64BIT_INT TextStream& operator>>(Int64& val); TextStream& operator>>(UInt64& val); #endif TextStream& operator>>(float& val); TextStream& operator>>(double& val); #ifdef PCLASSES_HAVE_LONG_DOUBLE TextStream& operator>>(long double& val); #endif TextStream& operator>>(Unicode::Char& ch); TextStream& operator>>(Unicode::String& str); TextStream& operator>>(std::string& str); private: Format _fmt; unsigned int _width, _prec; Unicode::Char _fillCh; Unicode::Converter* _converter; }; PUNICODE_EXPORT TextStream& endl(TextStream& strm); PUNICODE_EXPORT TextStream& dec(TextStream& strm); PUNICODE_EXPORT TextStream& hex(TextStream& strm); PUNICODE_EXPORT TextStream& oct(TextStream& strm); } // !namespace IO } // !namespace P #endif |
From: Christian P. <cp...@us...> - 2005-07-04 06:06:38
|
Update of /cvsroot/pclasses/pclasses2/src/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4563/src/App Modified Files: LogManager.cpp Log Message: - Added LogManager::initConfig() Index: LogManager.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/App/LogManager.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- LogManager.cpp 1 Jul 2005 12:07:00 -0000 1.5 +++ LogManager.cpp 4 Jul 2005 06:06:26 -0000 1.6 @@ -19,6 +19,9 @@ ***************************************************************************/ #include "pclasses/Phoenix.h" +#include "pclasses/Trace.h" +#include "pclasses/IO/URL.h" +#include "pclasses/App/Config.h" #include "pclasses/App/LogTarget.h" #include "pclasses/App/LogChannel.h" #include "pclasses/App/LogManager.h" @@ -33,6 +36,8 @@ LogManager::~LogManager() throw() { + P_TRACE(LogManager) << "cleaning up ..."; + System::CriticalSection::ScopedLock lck(_channelsMtx); // delete our LogChannels ... @@ -58,6 +63,93 @@ } } +void LogManager::initFromConfig(Config* cfg) +{ + try + { + ConfigSection& logCfgSection = cfg->root().section("Logging", false); + + StringList<std::string> logTargets = + logCfgSection.value("Targets", false); + + LogManager& logMgr = LogManager::instance(); + + StringList<std::string>::const_iterator si = logTargets.begin(); + while(si != logTargets.end()) + { + P_TRACE(LogManager) << "initFromConfig(): initializing LogTarget '" << *si << "'"; + + try + { + ConfigSection& logTargetSection = logCfgSection.section(*si); + + std::string logTargetType = logTargetSection.value("Type", false); + + IO::URL logTargetURL = logTargetSection.value("URL", false); + + std::string logTargetLevel = + logTargetSection.value("LogLevel", std::string("Warning"), false); + + P_TRACE(LogManager) << "initFromConfig(): Type=" << logTargetType + << ", URL=" << logTargetURL + << ", LogLevel=" << logTargetLevel; + + LogTarget* logTarget = logMgr.addTarget(*si, logTargetType); + if(!logTarget) + { + P_TRACE(LogManager) << "initFromConfig(): could not create LogTarget"; + ++si; + continue; + } + + try + { + logTarget->open(logTargetURL); + } + catch(...) + { + P_TRACE(LogManager) << "initFromConfig(): could not open target"; + ++si; + continue; + } + + StringList<std::string> logTargetChannels = + logTargetSection.value("Channels", false); + + StringList<std::string>::const_iterator ci = + logTargetChannels.begin(); + + while(ci != logTargetChannels.end()) + { + P_TRACE(LogManager) << "initFromConfig(): adding target to channel '" << *ci << "'"; + + LogChannel* logChannel = logMgr.channel(*ci); + if(!logChannel) + { + P_TRACE(LogManager) << "initFromConfig(): could not add target to channel '" + << *ci << "'"; + ++ci; + continue; + } + + logChannel->addTarget(logTarget); + ++ci; + } + } + catch(...) + { + P_TRACE(LogManager) << "initFromConfig(): config error, skipping target '" << *si << "'"; + } + + ++si; + } + } + catch(...) + { + P_TRACE(LogManager) << "initFromConfig(): config error, could not init logging"; + } +} + void LogManager::reload() throw() { System::CriticalSection::ScopedLock lck(_targetsMtx); @@ -131,7 +223,7 @@ // create the new target ... else { - target = LogTargetFactory::instance().create(type); + target = LogTargetFactory::instance().create("LogTarget_" + type); if(target) _targets.insert(std::make_pair(name, target)); } |
From: Christian P. <cp...@us...> - 2005-07-04 06:06:34
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4563/include/pclasses/App Modified Files: LogManager.h Log Message: - Added LogManager::initConfig() Index: LogManager.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/App/LogManager.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- LogManager.h 1 Jul 2005 12:06:59 -0000 1.3 +++ LogManager.h 4 Jul 2005 06:06:26 -0000 1.4 @@ -33,6 +33,8 @@ namespace App { +class Config; + //! Logging manager /*! The LogManager class provides a container for easy management of @@ -59,6 +61,9 @@ */ ~LogManager() throw(); + //! Initialize logging from configuration + void initFromConfig(Config* cfg); + //! Close and re-open all LogTargets void reload() throw(); |
From: Christian P. <cp...@us...> - 2005-07-03 23:46:37
|
Update of /cvsroot/pclasses/pclasses2/src/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17199/src/Unicode Modified Files: Makefile.am Log Message: - Added configure check for ICU - Removed configure check for libiconv Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/Makefile.am,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- Makefile.am 24 May 2005 02:32:59 -0000 1.11 +++ Makefile.am 3 Jul 2005 23:46:29 -0000 1.12 @@ -3,11 +3,11 @@ lib_LTLIBRARIES = libpclasses_unicode.la -CPPFLAGS = -DPUNICODE_BUILD +CPPFLAGS = -DPUNICODE_BUILD $(ICU_CFLAGS) libpclasses_unicode_la_SOURCES = Char.cpp String.cpp Converter.cpp \ UnicodeError.cpp TextStream.cpp libpclasses_unicode_la_LDFLAGS = -no-undefined -libpclasses_unicode_la_LIBADD = $(top_builddir)/src/libpclasses.la $(LIBICONV) -licuuc +libpclasses_unicode_la_LIBADD = $(top_builddir)/src/libpclasses.la $(ICU_LIBS) |
From: Christian P. <cp...@us...> - 2005-07-03 23:46:37
|
Update of /cvsroot/pclasses/pclasses2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17199 Modified Files: configure.in Log Message: - Added configure check for ICU - Removed configure check for libiconv Index: configure.in =================================================================== RCS file: /cvsroot/pclasses/pclasses2/configure.in,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- configure.in 2 Jul 2005 11:43:35 -0000 1.15 +++ configure.in 3 Jul 2005 23:46:29 -0000 1.16 @@ -233,10 +233,14 @@ AM_CONDITIONAL(WITH_WIN32_TIME, false) dnl -dnl check for libiconv .. needed by Unicode support +dnl check for ICU .. needed by Unicode support dnl -AM_ICONV +AC_CHECK_ICU + +dnl +dnl check for XML library ... +dnl AM_WITH_EXPAT |
From: Christian P. <cp...@us...> - 2005-07-03 23:46:37
|
Update of /cvsroot/pclasses/pclasses2/m4 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17199/m4 Added Files: icu.m4 Log Message: - Added configure check for ICU - Removed configure check for libiconv --- NEW FILE: icu.m4 --- AC_DEFUN([AC_CHECK_ICU],[ AC_PATH_PROG(icuconfig,icu-config) if test [ -z "$icuconfig" ] then AC_MSG_ERROR([icu-config executable not found]) else AC_MSG_CHECKING(for ICU) ICU_LIBS=`${icuconfig} --ldflags` ICU_CFLAGS=`${icuconfig} --cppflags` ICU_VERSION=`${icuconfig} --version` ICU_UNICODE_VERSION=`${icuconfig} --unicode-version` AC_MSG_RESULT([$ICU_VERSION Unicode $ICU_UNICODE_VERSION]) AC_SUBST(ICU_CFLAGS) AC_SUBST(ICU_LIBS) fi ]) |
From: Christian P. <cp...@us...> - 2005-07-03 23:45:11
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16104/include/pclasses Modified Files: CircularQueue.h Log Message: - Added methods to CircularQueue for efficient buffering/unbuffering of arrays Index: CircularQueue.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/CircularQueue.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- CircularQueue.h 3 Jun 2005 09:50:13 -0000 1.2 +++ CircularQueue.h 3 Jul 2005 23:45:03 -0000 1.3 @@ -23,6 +23,7 @@ #include <pclasses/BasicTypes.h> #include <pclasses/Algorithm.h> +#include <iostream> namespace P { @@ -114,17 +115,41 @@ inline bool full() const throw() { return ((_in + 1) % _size == _out); } + inline size_t size() const throw() + { + if(_in >= _out) + return (_in - _out); + return (_size - _out) + _in; + } + void push(const Type& val) { if(!full()) { - copy_construct(_buffer + (_in % _size), &val, 1); + //copy_construct(_buffer + (_in % _size), &val, 1); + copy_construct(_buffer + _in, &val, 1); _in = (_in + 1) % _size; return; } throw OverrunError("Queue overrun", P_SOURCEINFO); } + void push(const Type* buffer, size_t count) + { + size_t cap = capacity(); + if(cap - size() >= count) + { + //size_t withoutWrap = cap - _in; + size_t withoutWrap = _size - _in; + copy_construct(_buffer + _in, buffer, min(withoutWrap,count)); + if(count > withoutWrap) + copy_construct(_buffer, buffer + withoutWrap, count - withoutWrap); + _in = (_in + count) % _size; + return; + } + throw OverrunError("Queue overrun", P_SOURCEINFO); + } + //! Remove next item from queue /*! Removes the next item from queue. @@ -142,6 +167,35 @@ throw UnderrunError("Queue underrun", P_SOURCEINFO); } + void pop(size_t count) throw(UnderrunError) + { + if(size() >= count) + { + //size_t withoutWrap = capacity() - _out; + size_t withoutWrap = _size - _out; + destruct(_buffer + _out, min(withoutWrap,count)); + if(count > withoutWrap) + destruct(_buffer, count - withoutWrap); + _out = (_out + count) % _size; + return; + } + throw UnderrunError("Queue underrun", P_SOURCEINFO); + } + + void get(Type* buffer, size_t count) throw(UnderrunError) + { + if(size() >= count) + { + //size_t withoutWrap = capacity() - _out; + size_t withoutWrap = _size - _out; + copy(buffer, _buffer + _out, min(withoutWrap,count)); + if(count > withoutWrap) + copy(buffer + withoutWrap, _buffer, count - withoutWrap); + return; + } + throw UnderrunError("Queue underrun", P_SOURCEINFO); + } + //! Returns a reference to the front item /*! Returns a reference to the front item in the queue, which is the next item |
From: Christian P. <cp...@us...> - 2005-07-03 23:42:41
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14473/src/Net Modified Files: Socket.cpp Log Message: - Added virtual IODevice::setBlocking(), IODevice::isBlocking(), IODevice::wait() Index: Socket.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/Socket.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Socket.cpp 6 Jun 2005 12:09:31 -0000 1.10 +++ Socket.cpp 3 Jul 2005 23:42:33 -0000 1.11 @@ -484,6 +484,16 @@ P_SOURCEINFO); } +bool Socket::isBlocking() const throw() +{ + int ret; + ret = ::fcntl(handle(), F_GETFL); + if(ret == -1 || !(ret & O_NONBLOCK)) + return true; + + return false; +} + int Socket::handle() const throw() { return _handle; |
From: Christian P. <cp...@us...> - 2005-07-03 23:42:41
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14473/include/pclasses/Net Modified Files: Socket.h Log Message: - Added virtual IODevice::setBlocking(), IODevice::isBlocking(), IODevice::wait() Index: Socket.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/Socket.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Socket.h 6 Jun 2005 12:09:30 -0000 1.9 +++ Socket.h 3 Jul 2005 23:42:33 -0000 1.10 @@ -92,6 +92,8 @@ void setBlocking(bool enable) throw(IO::IOError); + bool isBlocking() const throw(); + int wait(int wait, unsigned int timeout) throw(IO::IOError); static int wait(Socket* s[], int wait[], int num, unsigned int timeout) |
From: Christian P. <cp...@us...> - 2005-07-03 23:42:41
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14473/src/IO Modified Files: IODevice.cpp Log Message: - Added virtual IODevice::setBlocking(), IODevice::isBlocking(), IODevice::wait() Index: IODevice.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/IODevice.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- IODevice.cpp 3 Jun 2005 09:55:44 -0000 1.10 +++ IODevice.cpp 3 Jul 2005 23:42:33 -0000 1.11 @@ -170,6 +170,21 @@ return _filter ? _filter->size() : _size(); } +void IODevice::setBlocking(bool val) throw(IOError) +{ + throw IOError(0, "Could not set device blocking mode", P_SOURCEINFO); +} + +bool IODevice::isBlocking() const throw() +{ + return true; +} + +int IODevice::wait(int wait, unsigned int timeout) throw(IOError) +{ + return wait; +} + void IODevice::setFilter(IOFilter* f) throw(LogicError) { // it took me 1 hour to find out why the Pipe test crashed ... |
From: Christian P. <cp...@us...> - 2005-07-03 23:42:41
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14473/include/pclasses/IO Modified Files: IODevice.h Log Message: - Added virtual IODevice::setBlocking(), IODevice::isBlocking(), IODevice::wait() Index: IODevice.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/IODevice.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- IODevice.h 3 Jun 2005 09:55:44 -0000 1.9 +++ IODevice.h 3 Jul 2005 23:42:32 -0000 1.10 @@ -193,6 +193,18 @@ //! Returns if the device has reached EOF bool eof() const throw(); + virtual void setBlocking(bool enable) throw(IOError); + + virtual bool isBlocking() const throw(); + + //! IODevice wait flags + enum WaitFlag { + WaitInput = 0x01, + WaitOutput = 0x02 + }; + + virtual int wait(int wait, unsigned int timeout) throw(IOError); + void setFilter(IOFilter* filter) throw(LogicError); IOFilter* filter() const throw(); |
From: Christian P. <cp...@us...> - 2005-07-03 23:40:42
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13625/include/pclasses Modified Files: ByteOrderTraits.h Log Message: - Added missing ByteOrderTraits Index: ByteOrderTraits.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/ByteOrderTraits.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ByteOrderTraits.h 20 Jan 2005 22:40:24 -0000 1.2 +++ ByteOrderTraits.h 3 Jul 2005 23:40:26 -0000 1.3 @@ -38,6 +38,33 @@ }; template <> +struct PCORE_EXPORT ByteOrderTraits<int8_t> { + static void setLittleEndian(int8_t& cpuVal, int8_t newValLE) throw(); + static int8_t littleEndian(int8_t cpuVal) throw(); + + static void setBigEndian(int8_t& cpuVal, int8_t newValBE) throw(); + static int8_t bigEndian(int8_t cpuVal) throw(); +}; + +template <> +struct PCORE_EXPORT ByteOrderTraits<uint8_t> { + static void setLittleEndian(uint8_t& cpuVal, uint8_t newValLE) throw(); + static uint8_t littleEndian(uint8_t cpuVal) throw(); + + static void setBigEndian(uint8_t& cpuVal, uint8_t newValBE) throw(); + static uint8_t bigEndian(uint8_t cpuVal) throw(); +}; + +template <> +struct PCORE_EXPORT ByteOrderTraits<int16_t> { + static void setLittleEndian(int16_t& cpuVal, int16_t newValLE) throw(); + static int16_t littleEndian(int16_t cpuVal) throw(); + + static void setBigEndian(int16_t& cpuVal, int16_t newValBE) throw(); + static int16_t bigEndian(int16_t cpuVal) throw(); +}; + +template <> struct PCORE_EXPORT ByteOrderTraits<uint16_t> { static void setLittleEndian(uint16_t& cpuVal, uint16_t newValLE) throw(); static uint16_t littleEndian(uint16_t cpuVal) throw(); @@ -47,6 +74,15 @@ }; template <> +struct PCORE_EXPORT ByteOrderTraits<int32_t> { + static void setLittleEndian(int32_t& cpuVal, int32_t newValLE) throw(); + static int32_t littleEndian(int32_t cpuVal) throw(); + + static void setBigEndian(int32_t& cpuVal, int32_t newValBE) throw(); + static int32_t bigEndian(int32_t cpuVal) throw(); +}; + +template <> struct PCORE_EXPORT ByteOrderTraits<uint32_t> { static void setLittleEndian(uint32_t& cpuVal, uint32_t newValLE) throw(); static uint32_t littleEndian(uint32_t cpuVal) throw(); @@ -57,6 +93,15 @@ #ifdef PCLASSES_HAVE_64BIT_INT template <> +struct PCORE_EXPORT ByteOrderTraits<int64_t> { + static void setLittleEndian(int64_t& cpuVal, int64_t newValLE) throw(); + static int64_t littleEndian(int64_t cpuVal) throw(); + + static void setBigEndian(int64_t& cpuVal, int64_t newValBE) throw(); + static int64_t bigEndian(int64_t cpuVal) throw(); +}; + +template <> struct PCORE_EXPORT ByteOrderTraits<uint64_t> { static void setLittleEndian(uint64_t& cpuVal, uint64_t newValLE) throw(); static uint64_t littleEndian(uint64_t cpuVal) throw(); |
From: Christian P. <cp...@us...> - 2005-07-03 23:40:35
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13625/src Modified Files: ByteOrderTraits.cpp Log Message: - Added missing ByteOrderTraits Index: ByteOrderTraits.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/ByteOrderTraits.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- ByteOrderTraits.cpp 22 Dec 2004 17:54:34 -0000 1.1.1.1 +++ ByteOrderTraits.cpp 3 Jul 2005 23:40:26 -0000 1.2 @@ -55,6 +55,88 @@ } #endif +void ByteOrderTraits<int8_t>:: + setLittleEndian(int8_t& cpuVal, int8_t newValLE) throw() +{ + cpuVal = newValLE; +} + +int8_t ByteOrderTraits<int8_t>::littleEndian(int8_t cpuVal) throw() +{ + return cpuVal; +} + +void ByteOrderTraits<int8_t>:: + setBigEndian(int8_t& cpuVal, int8_t newValBE) throw() +{ + cpuVal = newValBE; +} + +int8_t ByteOrderTraits<int8_t>::bigEndian(int8_t cpuVal) throw() +{ + return cpuVal; +} + +void ByteOrderTraits<uint8_t>:: + setLittleEndian(uint8_t& cpuVal, uint8_t newValLE) throw() +{ + cpuVal = newValLE; +} + +uint8_t ByteOrderTraits<uint8_t>::littleEndian(uint8_t cpuVal) throw() +{ + return cpuVal; +} + +void ByteOrderTraits<uint8_t>:: + setBigEndian(uint8_t& cpuVal, uint8_t newValBE) throw() +{ + cpuVal = newValBE; +} + +uint8_t ByteOrderTraits<uint8_t>::bigEndian(uint8_t cpuVal) throw() +{ + return cpuVal; +} + +void ByteOrderTraits<int16_t>:: + setLittleEndian(int16_t& cpuVal, int16_t newValLE) throw() +{ + #ifdef PCLASSES_WORDS_BIGENDIAN + cpuVal = (int16_t)swab16((uint16_t)newValLE); + #else + cpuVal = newValLE; + #endif +} + +int16_t ByteOrderTraits<int16_t>::littleEndian(int16_t cpuVal) throw() +{ + #ifdef PCLASSES_WORDS_BIGENDIAN + return (int16_t)swab16((uint16_t)cpuVal); + #else + return cpuVal; + #endif +} + +void ByteOrderTraits<int16_t>:: + setBigEndian(int16_t& cpuVal, int16_t newValBE) throw() +{ + #ifdef PCLASSES_WORDS_BIGENDIAN + cpuVal = newValBE; + #else + cpuVal = (int16_t)swab16((uint16_t)newValBE); + #endif +} + +int16_t ByteOrderTraits<int16_t>::bigEndian(int16_t cpuVal) throw() +{ + #ifdef PCLASSES_WORDS_BIGENDIAN + return cpuVal; + #else + return (int16_t)swab16((uint16_t)cpuVal); + #endif +} + void ByteOrderTraits<uint16_t>:: setLittleEndian(uint16_t& cpuVal, uint16_t newValLE) throw() { @@ -93,6 +175,44 @@ #endif } +void ByteOrderTraits<int32_t>:: + setLittleEndian(int32_t& cpuVal, int32_t newValLE) throw() +{ + #ifdef PCLASSES_WORDS_BIGENDIAN + cpuVal = (int32_t)swab32((uint32_t)newValLE); + #else + cpuVal = newValLE; + #endif +} + +int32_t ByteOrderTraits<int32_t>::littleEndian(int32_t cpuVal) throw() +{ + #ifdef PCLASSES_WORDS_BIGENDIAN + return (int32_t)swab32((uint32_t)cpuVal); + #else + return cpuVal; + #endif +} + +void ByteOrderTraits<int32_t>:: + setBigEndian(int32_t& cpuVal, int32_t newValBE) throw() +{ + #ifdef PCLASSES_WORDS_BIGENDIAN + cpuVal = newValBE; + #else + cpuVal = (int32_t)swab32((uint32_t)newValBE); + #endif +} + +int32_t ByteOrderTraits<int32_t>::bigEndian(int32_t cpuVal) throw() +{ + #ifdef PCLASSES_WORDS_BIGENDIAN + return cpuVal; + #else + return (int32_t)swab32((uint32_t)cpuVal); + #endif +} + void ByteOrderTraits<uint32_t>:: setLittleEndian(uint32_t& cpuVal, uint32_t newValLE) throw() { @@ -133,6 +253,44 @@ #ifdef PCLASSES_HAVE_64BIT_INT +void ByteOrderTraits<int64_t>:: + setLittleEndian(int64_t& cpuVal, int64_t newValLE) throw() +{ + #ifdef PCLASSES_WORDS_BIGENDIAN + cpuVal = (int64_t)swab64((uint64_t)newValLE); + #else + cpuVal = newValLE; + #endif +} + +int64_t ByteOrderTraits<int64_t>::littleEndian(int64_t cpuVal) throw() +{ + #ifdef PCLASSES_WORDS_BIGENDIAN + return (int64_t)swab64((uint64_t)cpuVal); + #else + return cpuVal; + #endif +} + +void ByteOrderTraits<int64_t>:: + setBigEndian(int64_t& cpuVal, int64_t newValBE) throw() +{ + #ifdef PCLASSES_WORDS_BIGENDIAN + cpuVal = newValBE; + #else + cpuVal = (int64_t)swab64((uint64_t)newValBE); + #endif +} + +int64_t ByteOrderTraits<int64_t>::bigEndian(int64_t cpuVal) throw() +{ + #ifdef PCLASSES_WORDS_BIGENDIAN + return cpuVal; + #else + return (int64_t)swab64((uint64_t)cpuVal); + #endif +} + void ByteOrderTraits<uint64_t>:: setLittleEndian(uint64_t& cpuVal, uint64_t newValLE) throw() { |