library of assembled shared sources

http://lass.cocamware.com

binary_o_stream.cpp

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 #include "io_common.h"
00044 #include "binary_o_stream.h"
00045 
00046 // static_cast from pointer to TintPtr gives warning on MSVC, yet both are identical in size [Bramz]
00047 // 
00048 #if LASS_COMPILER_TYPE == LASS_COMPILER_TYPE_MSVC
00049 #   pragma warning(disable: 4311) // 'reinterpret_cast' : 'reinterpret_cast' : pointer truncation from 'const void *' to 'lass::num::TintPtr'
00050 #endif
00051 
00052 namespace lass
00053 {
00054 namespace io
00055 {
00056 
00057 // --- public --------------------------------------------------------------------------------------
00058 
00059 BinaryOStream::BinaryOStream():
00060     BinaryStreamBase()
00061 {
00062 }
00063 
00064 
00065 
00066 BinaryOStream::~BinaryOStream()
00067 {
00068 }
00069 
00070 
00071 
00072 long BinaryOStream::tellp() const
00073 {
00074     return doTellp();
00075 }
00076 
00077 
00078 
00079 BinaryOStream& BinaryOStream::seekp(long position)
00080 {
00081     doSeekp(position, std::ios_base::beg);
00082     return *this;
00083 }
00084 
00085 
00086 
00087 BinaryOStream& BinaryOStream::seekp(long offset, std::ios_base::seekdir direction)
00088 {
00089     doSeekp(offset, direction);
00090     return *this;
00091 }
00092 
00093 
00094 
00095 void BinaryOStream::flush()
00096 {
00097     doFlush();
00098 }
00099 
00100 
00101 
00102 BinaryOStream& BinaryOStream::operator<<( char x )
00103 {
00104     return writeValue(x);
00105 }
00106 
00107 
00108 
00109 BinaryOStream& BinaryOStream::operator<<( num::Tint8 x )
00110 {
00111     return writeValue(x);
00112 }
00113 
00114 
00115 
00116 BinaryOStream& BinaryOStream::operator<<( num::Tuint8 x )
00117 {
00118     return writeValue(x);
00119 }
00120 
00121 
00122 
00123 BinaryOStream& BinaryOStream::operator<<( num::Tint16 x )
00124 {
00125     return writeValue(x);
00126 }
00127 
00128 
00129 
00130 BinaryOStream& BinaryOStream::operator<<( num::Tuint16 x )
00131 {
00132     return writeValue(x);
00133 }
00134 
00135 
00136 
00137 BinaryOStream& BinaryOStream::operator<<( num::Tint32 x )
00138 {
00139     return writeValue(x);
00140 }
00141 
00142 
00143 
00144 BinaryOStream& BinaryOStream::operator<<( num::Tuint32 x )
00145 {
00146     return writeValue(x);
00147 }
00148 
00149 
00150 
00151 BinaryOStream& BinaryOStream::operator<<( num::Tint64 x )
00152 {
00153     return writeValue(x);
00154 }
00155 
00156 
00157 
00158 BinaryOStream& BinaryOStream::operator<<( num::Tuint64 x )
00159 {
00160     return writeValue(x);
00161 }
00162 
00163 
00164 
00165 BinaryOStream& BinaryOStream::operator<<( num::Tfloat32 x )
00166 {
00167     return writeValue(x);
00168 }
00169 
00170 
00171 
00172 BinaryOStream& BinaryOStream::operator<<( num::Tfloat64 x )
00173 {
00174     return writeValue(x);
00175 }
00176 
00177 
00178 
00179 BinaryOStream& BinaryOStream::operator<<(bool x)
00180 {
00181     return *this << (x ? num::Tuint8(1) : num::Tuint8(0));
00182 }
00183 
00184 
00185 
00186 BinaryOStream& BinaryOStream::operator<<(const void* x)
00187 {
00188     LASS_META_ASSERT(sizeof(num::TintPtr) == sizeof(const void*), TintPtr_should_be_of_pointer_size);
00189     return *this << static_cast<num::Tint64>(reinterpret_cast<num::TintPtr>(x));
00190 }
00191 
00192 
00193 
00194 BinaryOStream& BinaryOStream::operator<<(const char* x)
00195 {
00196     return writeString(x, strlen(x));
00197 }
00198 
00199 
00200 
00201 BinaryOStream& BinaryOStream::operator<<(const std::string& x)
00202 {
00203     return writeString(x.data(), x.length());
00204 }
00205 
00206 
00207 
00208 /** write a buffer of bytes to the stream
00209  *  @param bytes pointer to buffer.
00210  *  @param numBytes length of buffer in bytes.
00211  */
00212 void BinaryOStream::write(const void* bytes, size_t numBytes)
00213 {
00214     doWrite(bytes, numBytes);
00215 }
00216 
00217 // --- private -------------------------------------------------------------------------------------
00218 
00219 template <typename T>
00220 BinaryOStream& BinaryOStream::writeValue(T x)
00221 {
00222     const T temp = num::fixEndianness(x, endianness());
00223     doWrite(&temp, sizeof(T));
00224     return *this;
00225 }
00226 
00227 
00228 
00229 BinaryOStream& BinaryOStream::writeString(const char* string, size_t length)
00230 {
00231     const num::Tuint64 n = static_cast<num::Tuint64>(length);
00232     LASS_ASSERT(length == static_cast<size_t>(n));
00233     *this << n;
00234     doWrite(string, length);
00235     return *this;
00236 }
00237 
00238 }
00239 
00240 }
00241 

Generated on Mon Nov 10 14:20:00 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo