ByteOrderDataInStream.h

00001 /**********************************************************************
00002  * $Id: ByteOrderDataInStream.h 1820 2006-09-06 16:54:23Z mloskot $
00003  *
00004  * GEOS - Geometry Engine Open Source
00005  * http://geos.refractions.net
00006  *
00007  * Copyright (C) 2005-2006 Refractions Research Inc.
00008  * Copyright (C) 2001-2002 Vivid Solutions Inc.
00009  *
00010  * This is free software; you can redistribute and/or modify it under
00011  * the terms of the GNU Lesser General Public Licence as published
00012  * by the Free Software Foundation. 
00013  * See the COPYING file for more information.
00014  *
00015  **********************************************************************/
00016 
00017 #ifndef GEOS_IO_BYTEORDERDATAINSTREAM_H
00018 #define GEOS_IO_BYTEORDERDATAINSTREAM_H
00019 
00020 //#include <geos/platform.h>
00021 //#include <geos/io/ParseException.h>
00022 //#include <geos/io/ByteOrderValues.h>
00023 #include <geos/inline.h>
00024 
00025 #include <iosfwd> // ostream, istream (if we remove inlines)
00026 
00027 namespace geos {
00028 namespace io {
00029 
00030 /*
00031  * \class ByteOrderDataInStream io.h geos.h
00032  * 
00033  * Allows reading an stream of primitive datatypes from an underlying
00034  * istream, with the representation being in either common byte ordering.
00035  *
00036  */
00037 class ByteOrderDataInStream {
00038 
00039 public:
00040 
00041         ByteOrderDataInStream(std::istream *s=NULL);
00042 
00043         ~ByteOrderDataInStream();
00044 
00049         void setInStream(std::istream *s);
00050 
00051         void setOrder(int order);
00052 
00053         unsigned char readByte(); // throws ParseException
00054 
00055         int readInt(); // throws ParseException
00056 
00057         long readLong(); // throws ParseException
00058 
00059         double readDouble(); // throws ParseException
00060 
00061 private:
00062         int byteOrder;
00063         std::istream *stream;
00064 
00065         // buffers to hold primitive datatypes
00066         unsigned char buf[8];
00067 
00068 };
00069 
00070 } // namespace io
00071 } // namespace geos
00072 
00073 #ifdef GEOS_INLINE
00074 #include <geos/io/ByteOrderDataInStream.inl>
00075 #endif
00076 
00077 #endif // #ifndef GEOS_IO_BYTEORDERDATAINSTREAM_H
00078 
00079 /**********************************************************************
00080  * $Log$
00081  * Revision 1.2  2006/03/28 11:26:13  strk
00082  * ByteOrderDataInStream inlines moved to .inl file, updated
00083  * implementation files includes.
00084  *
00085  * Revision 1.1  2006/03/20 18:18:14  strk
00086  * io.h header split
00087  *
00088  **********************************************************************/

Generated on Fri Mar 27 04:52:35 2009 for GEOS by  doxygen 1.5.4