sprint 1-alpha
|
00001 /****************************************************************************** 00002 * sprint::xstreamio 00003 * 00004 * Copyright (C) 2005-2011 Paolo Medici <www.pmx.it> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 * 00020 *******************************************************************************/ 00021 00022 #ifndef _XSTREAM_IO_H 00023 #define _XSTREAM_IO_H 00024 00028 #include <string> 00029 #include <cstring> 00030 #include <sprint/container/buffer.h> 00031 00032 namespace sprint { 00033 00034 namespace io { 00035 00037 inline xstream & operator << (xstream & out, const const_buffer & c) { out.write(c.data(), c.lenght() ); return out; } 00038 00040 inline xstream & operator << (xstream & out, char c) { out.write(&c, 1); return out; } 00041 00043 inline xstream & operator << (xstream & out, const char *str) { out.write(str, strlen(str)); return out; } 00044 00046 inline xstream & operator << (xstream & out, const std::string & str) { out.write(str.data(), str.length() ); return out; } 00047 00048 00049 inline xstream & fill (xstream & out, int len, char c) { 00050 for(int i=0;i<len;++i) 00051 out.write(&c, 1); 00052 return out; 00053 } 00054 /* 00055 struct fill { 00056 char filltype; 00057 int len; 00058 00059 fill(int l, char f) : filltype(f) { } 00060 }; 00061 00062 inline xstream & operator << (xstream & out, const fill & f) { 00063 for(int i=0;i<f.len;++i) 00064 out.write(&f.filltype, 1); 00065 return out; 00066 } 00067 */ 00068 struct right { 00069 int width; 00070 char fill; 00071 const const_buffer & buf; 00072 public: 00073 00074 right(int l, char f, const const_buffer & b) : width(l - b.lenght() ), fill(f), buf(b) {} 00075 00076 }; 00077 00078 00079 inline xstream & operator << (xstream & out, const right & r) 00080 { fill(out, r.width, r.fill); out.write(r.buf.data(), r.buf.lenght() ); return out; } 00081 } 00082 00083 } 00084 00085 #endif