/************************************************************************* * * HTCd - Copyright (C) 1998-2006 Henrik Rydberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU 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 General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef MSTREAMH #define MSTREAMH #include #include #include /////////////////////////////////////////////////////////// const char cvt_form_i[]="%d"; /////////////////////////////////////////////////////////// inline sref itoa(sref_t& buf,int i) { return sref(buf,sprintf(buf,cvt_form_i,i)); } sref ftoa(sref_t& buf,double f); /////////////////////////////////////////////////////////// struct mstream { virtual int appc(char c); virtual int appi(int i); virtual int appf(double f); virtual int apps(const sref& s); mstream& put(char c) { return appc(c),*this; } int write(const char* s,int n) { return apps(sref(s,n)); } }; inline mstream& operator<<(mstream& out,int i) { return out.appi(i),out; } inline mstream& operator<<(mstream& out,long l) { return out.appi(l),out; } inline mstream& operator<<(mstream& out,unsigned u) { return out.appi(u),out; } inline mstream& operator<<(mstream& out,unsigned long ul) { return out.appi(ul),out; } inline mstream& operator<<(mstream& out,double f) { return out.appf(f),out; } inline mstream& operator<<(mstream& out,const sref& s) { return out.apps(s),out; } inline mstream& operator<<(mstream& out,const char* s) { return out.apps(sref(s)),out; } /////////////////////////////////////////////////////////// struct cvt_stream : public mstream { int appi(int i); int appf(double f); }; /////////////////////////////////////////////////////////// struct fp_stream : public cvt_stream { FILE* fp; int appc(char c); int apps(const sref& s); fp_stream(FILE* f) : fp(f) {} int flush() { return fflush(fp); } }; /////////////////////////////////////////////////////////// struct fd_stream : public cvt_stream { int fd; int appc(char c); int apps(const sref& s); fd_stream(int f) : fd(f) {} }; /////////////////////////////////////////////////////////// struct pipe_stream : public cvt_stream { int fd,hup; int appc(char c); int apps(const sref& s); pipe_stream(int f) : fd(f),hup(0) {} int mwrite(const char* s,int n); }; /////////////////////////////////////////////////////////// #endif