00001 #ifndef GSGL_DATA_STREAM_H 00002 #define GSGL_DATA_STREAM_H 00003 00004 // 00005 // $Id: stream.hpp 2 2008-03-01 20:58:50Z kulibali $ 00006 // 00007 // Copyright (c) 2008, The Periapsis Project. All rights reserved. 00008 // 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions are 00011 // met: 00012 // 00013 // * Redistributions of source code must retain the above copyright notice, 00014 // this list of conditions and the following disclaimer. 00015 // 00016 // * Redistributions in binary form must reproduce the above copyright 00017 // notice, this list of conditions and the following disclaimer in the 00018 // documentation and/or other materials provided with the distribution. 00019 // 00020 // * Neither the name of the The Periapsis Project nor the names of its 00021 // contributors may be used to endorse or promote products derived from 00022 // this software without specific prior written permission. 00023 // 00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00025 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 // 00036 00037 #include "data/data.hpp" 00038 #include "data/printable.hpp" 00039 #include "data/serializable.hpp" 00040 00041 namespace gsgl 00042 { 00043 00044 namespace io 00045 { 00046 00047 /// A text stream. 00048 class DATA_API text_stream 00049 { 00050 protected: 00051 text_stream(); 00052 public: 00053 virtual ~text_stream(); 00054 00055 virtual wchar_t peek() = 0; 00056 virtual wchar_t get() = 0; 00057 virtual void unget(wchar_t) = 0; 00058 virtual bool at_end() const = 0; 00059 00060 virtual gsgl::index_t read(wchar_t *, const gsgl::index_t num) = 0; 00061 virtual gsgl::index_t write(const wchar_t *, const gsgl::index_t num) = 0; 00062 00063 text_stream & operator<< (const wchar_t *); 00064 text_stream & operator<< (const wchar_t &); 00065 text_stream & operator<< (const int &); 00066 00067 text_stream & operator<< (const float &); 00068 text_stream & operator<< (const double &); 00069 text_stream & operator<< (const char *); 00070 00071 text_stream & operator>> (wchar_t &); 00072 text_stream & operator>> (int &); 00073 00074 text_stream & operator>> (float &); 00075 text_stream & operator>> (double &); 00076 00077 }; // class stream 00078 00079 00080 DATA_API text_stream & operator<< (text_stream &, const printable &); 00081 DATA_API text_stream & operator>> (text_stream &, printable &); 00082 00083 00084 /// A data stream. This is used for serializing data in binary format. 00085 /// \todo Implement endian check. 00086 class DATA_API data_stream 00087 { 00088 protected: 00089 data_stream(); 00090 00091 public: 00092 virtual ~data_stream(); 00093 00094 virtual bool at_end() const = 0; 00095 00096 virtual gsgl::index_t read(unsigned char *, const gsgl::index_t num) = 0; 00097 virtual gsgl::index_t write(const unsigned char *, const gsgl::index_t num) = 0; 00098 00099 data_stream & operator<< (const unsigned char &); 00100 data_stream & operator<< (const int &); 00101 data_stream & operator<< (const float &); 00102 data_stream & operator<< (const double &); 00103 00104 data_stream & operator>> (unsigned char &); 00105 data_stream & operator>> (int &); 00106 data_stream & operator>> (float &); 00107 data_stream & operator>> (double &); 00108 }; // class data_stream 00109 00110 00111 DATA_API data_stream & operator<< (data_stream &, const serializable &); 00112 DATA_API data_stream & operator>> (data_stream &, serializable &); 00113 00114 } // namespace io 00115 00116 } // namespace gsgl 00117 00118 #endif