sprint 1-alpha
|
00001 /****************************************************************************** 00002 * sprint::iostream 00003 * 00004 * Copyright (C) 2003-2004 Paolo Medici and LostOnesLandTeam 00005 * Copyright (C) 2005-2011 Paolo Medici <www.pmx.it> 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 * 00021 *******************************************************************************/ 00022 00026 #ifndef _SPRINT_IO_STREAM_H 00027 #define _SPRINT_IO_STREAM_H 00028 00029 #ifndef DISABLE_IO_STREAMS 00030 00031 #include <cstring> 00032 #include <sprint/buffer_cast.h> 00033 00034 namespace sprint { 00035 template<class _Ostream, class R> 00036 inline void _out_stream(_Ostream & d, const R & obj) 00037 { 00038 sprint::buffer_cast buf(obj); 00039 d.write ( buf.c_str(), ::strlen( buf.c_str()) ); 00040 } 00041 } 00042 00043 #ifdef _GLIBCXX_STRING 00044 # define IMPLEMENT_OUTSTREAM_OPERATOR_STRING(Type) inline Type & operator << ( Type & d, const std::string & str) {d.write(str.c_str(), str.size());return d;} 00045 #else 00046 # define IMPLEMENT_OUTSTREAM_OPERATOR_STRING(Type) 00047 #endif 00048 00049 #define IMPLEMENT_OUTSTREAM_OPERATOR_CONST_CHAR(Type) inline Type & operator << ( Type & d, const char * str) { d.write(str, ::strlen(str) ); return d; } 00050 #define IMPLEMENT_OUTSTREAM_OPERATOR_CHAR(Type) inline Type & operator << ( Type & d, char c) { d.write(&c, 1 ); return d; } 00051 #ifdef _MSC_VER 00052 # define IMPLEMENT_OUTSTREAM_OPERATOR_GENERIC(Type) inline Type & operator << ( Type & d, int obj) { sprint::_out_stream(d,obj); return d; } \ 00053 inline Type & operator << ( Type & d, unsigned int obj) { sprint::_out_stream(d,obj); return d; } \ 00054 inline Type & operator << ( Type & d, long obj) { sprint::_out_stream(d,obj); return d; } \ 00055 inline Type & operator << ( Type & d, unsigned long obj) { sprint::_out_stream(d,obj); return d; } 00056 #else 00057 # define IMPLEMENT_OUTSTREAM_OPERATOR_GENERIC(Type) template<class R> Type & operator << (Type & d, const R & obj) { sprint::_out_stream(d,obj); return d; } 00058 #endif 00059 00060 #define IMPLEMENT_OUTSTREAM_OPERATOR(Type) \ 00061 IMPLEMENT_OUTSTREAM_OPERATOR_STRING(Type) \ 00062 IMPLEMENT_OUTSTREAM_OPERATOR_CONST_CHAR(Type) \ 00063 IMPLEMENT_OUTSTREAM_OPERATOR_CHAR(Type) \ 00064 IMPLEMENT_OUTSTREAM_OPERATOR_GENERIC(Type) 00065 00066 #else 00067 00068 # define IMPLEMENT_OUTSTREAM_OPERATOR(Type) 00069 00070 #endif 00071 00072 #endif