storage.h

Go to the documentation of this file.
00001 /************************************************************************
00002  ** This file is part of the network simulator Shawn.                  **
00003  ** Copyright (C) 2004-2007 by the SwarmNet (www.swarmnet.de) project  **
00004  ** Shawn is free software; you can redistribute it and/or modify it   **
00005  ** under the terms of the BSD License. Refer to the shawn-licence.txt **
00006  ** file in the root of the Shawn source tree for further details.     **
00007  ************************************************************************
00008  **                                                                    **
00009  ** \author Axel Wegener <wegener@itm.uni-luebeck.de>                  **
00010  **                                                                    **
00011  ************************************************************************/
00012 #ifndef __SHAWN_APPS_TCPIP_STORAGE_H
00013 #define __SHAWN_APPS_TCPIP_STORAGE_H
00014 
00015 #ifdef SHAWN
00016      #include <shawn_config.h>
00017      #include "_apps_enable_cmake.h"
00018      #ifdef ENABLE_TCPIP
00019             #define BUILD_TCPIP
00020      #endif
00021 #else
00022      #define BUILD_TCPIP
00023 #endif
00024 
00025 
00026 #ifdef BUILD_TCPIP
00027 
00028 #include <vector>
00029 #include <string>
00030 #include <stdexcept>
00031 
00032 namespace tcpip
00033 {
00034 
00035 class Storage
00036 {
00037 
00038 public:
00039     typedef std::vector<unsigned char> StorageType;
00040 
00041 private:
00042     StorageType store;
00043 
00044     unsigned int pos_;
00045     bool iterValid_;
00046 //  std::list<unsigned char>::const_iterator iter_;
00047     bool iterEndValid_;
00048 //  std::list<unsigned char>::const_iterator iterEnd_;
00049 
00050     StorageType::const_iterator iter_;
00051     StorageType::const_iterator iterEnd_;
00052 
00053     // sortation of bytes forwards or backwards?
00054     bool bigEndian_;
00055     
00057     void init();
00058 
00059 public:
00060 
00062     Storage();
00063 
00065     Storage(unsigned char[], int length=-1);
00066 
00067     // Destructor
00068     virtual ~Storage();
00069 
00070     virtual bool valid_pos();
00071     virtual unsigned int position() const;
00072 
00073     void reset();
00074 
00075     virtual unsigned char readChar() throw(std::invalid_argument);
00076     virtual void writeChar(unsigned char) throw();
00077 
00078     virtual int readByte() throw(std::invalid_argument);
00079     virtual void writeByte(int) throw(std::invalid_argument);
00080 //  virtual void writeByte(unsigned char) throw();
00081 
00082     virtual int readUnsignedByte() throw(std::invalid_argument);
00083     virtual void writeUnsignedByte(int) throw(std::invalid_argument);
00084 
00085     virtual std::string readString() throw(std::invalid_argument);
00086     virtual void writeString(std::string s) throw();
00087 
00088     virtual std::vector<std::string> readStringList() throw(std::invalid_argument);
00089     virtual void writeStringList(const std::vector<std::string> &s) throw();
00090 
00091     virtual int readShort() throw(std::invalid_argument);
00092     virtual void writeShort(int) throw(std::invalid_argument);
00093 
00094     virtual int readInt() throw(std::invalid_argument);
00095     virtual void writeInt(int) throw();
00096 
00097     virtual float readFloat() throw(std::invalid_argument);
00098     virtual void writeFloat( float ) throw();
00099 
00100     virtual double readDouble() throw(std::invalid_argument);
00101     virtual void writeDouble( double ) throw();
00102 
00103     virtual void writePacket(unsigned char* packet, int length);
00104 
00105     virtual void writeStorage(tcpip::Storage& store);
00106 
00107     // Some enabled functions of the underlying std::list
00108     size_t size() const { return store.size(); }
00109 
00110     StorageType::const_iterator begin() const { return store.begin(); }
00111     StorageType::const_iterator end() const { return store.end(); }
00112 
00113 };
00114 
00115 } // namespace tcpip
00116 
00117 #endif // BUILD_TCPIP
00118 
00119 #endif
00120 /*-----------------------------------------------------------------------
00121  * Source  $Source: $
00122  * Version $Revision: 342 $
00123  * Date    $Date: 2009-04-14 13:56:09 +0200 (Tue, 14 Apr 2009) $
00124  *-----------------------------------------------------------------------
00125  * $Log: $
00126  *-----------------------------------------------------------------------*/

Generated on Wed May 5 00:06:36 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6