From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/mt/mstream.h | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/mt/mstream.h (limited to 'src/mt/mstream.h') diff --git a/src/mt/mstream.h b/src/mt/mstream.h new file mode 100644 index 0000000..4f5aeaf --- /dev/null +++ b/src/mt/mstream.h @@ -0,0 +1,103 @@ +/************************************************************************* + * + * 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 -- cgit v1.2.3