SUMO - Simulation of Urban MObility
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  ** \author Bjoern Hendriks <hendriks@ibr.cs.tu-bs.de>                 **
00011  **                                                                    **
00012  ************************************************************************/
00013 #ifndef __SHAWN_APPS_TCPIP_STORAGE_H
00014 #define __SHAWN_APPS_TCPIP_STORAGE_H
00015 
00016 #ifdef SHAWN
00017      #include <shawn_config.h>
00018      #include "_apps_enable_cmake.h"
00019      #ifdef ENABLE_TCPIP
00020             #define BUILD_TCPIP
00021      #endif
00022 #else
00023      #define BUILD_TCPIP
00024 #endif
00025 
00026 
00027 #ifdef BUILD_TCPIP
00028 
00029 #include <vector>
00030 #include <string>
00031 #include <stdexcept>
00032 #include <iostream>
00033 
00034 namespace tcpip
00035 {
00036 
00037 class Storage
00038 {
00039 
00040 public:
00041     typedef std::vector<unsigned char> StorageType;
00042 
00043 private:
00044     StorageType store;
00045     StorageType::const_iterator iter_;
00046 
00047     // sortation of bytes forwards or backwards?
00048     bool bigEndian_;
00049 
00051     void init();
00052 
00054     void checkReadSafe(unsigned int num) const throw(std::invalid_argument);
00056     unsigned char readCharUnsafe();
00058     void writeByEndianess(const unsigned char * begin, unsigned int size);
00060     void readByEndianess(unsigned char * array, int size);
00061 
00062 
00063 public:
00064 
00066     Storage();
00067 
00069     Storage(const unsigned char[], int length=-1);
00070 
00071     // Destructor
00072     virtual ~Storage();
00073 
00074     virtual bool valid_pos();
00075     virtual unsigned int position() const;
00076 
00077     void reset();
00079     std::string hexDump() const;
00080 
00081     virtual unsigned char readChar() throw(std::invalid_argument);
00082     virtual void writeChar(unsigned char) throw();
00083 
00084     virtual int readByte() throw(std::invalid_argument);
00085     virtual void writeByte(int) throw(std::invalid_argument);
00086 //  virtual void writeByte(unsigned char) throw();
00087 
00088     virtual int readUnsignedByte() throw(std::invalid_argument);
00089     virtual void writeUnsignedByte(int) throw(std::invalid_argument);
00090 
00091     virtual std::string readString() throw(std::invalid_argument);
00092     virtual void writeString(const std::string& s) throw();
00093 
00094     virtual std::vector<std::string> readStringList() throw(std::invalid_argument);
00095     virtual void writeStringList(const std::vector<std::string> &s) throw();
00096 
00097     virtual int readShort() throw(std::invalid_argument);
00098     virtual void writeShort(int) throw(std::invalid_argument);
00099 
00100     virtual int readInt() throw(std::invalid_argument);
00101     virtual void writeInt(int) throw();
00102 
00103     virtual float readFloat() throw(std::invalid_argument);
00104     virtual void writeFloat( float ) throw();
00105 
00106     virtual double readDouble() throw(std::invalid_argument);
00107     virtual void writeDouble( double ) throw();
00108 
00109     virtual void writePacket(unsigned char* packet, int length);
00110     virtual void writePacket(const std::vector<unsigned char> &packet);
00111 
00112     virtual void writeStorage(tcpip::Storage& store);
00113 
00114     // Some enabled functions of the underlying std::list
00115     StorageType::size_type size() const { return store.size(); }
00116 
00117     StorageType::const_iterator begin() const { return store.begin(); }
00118     StorageType::const_iterator end() const { return store.end(); }
00119 
00120 };
00121 
00122 } // namespace tcpip
00123 
00124 #endif // BUILD_TCPIP
00125 
00126 #endif
00127 /*-----------------------------------------------------------------------
00128  * Source  $Source: $
00129  * Version $Revision: 620 $
00130  * Date    $Date: 2011-07-08 17:39:10 +0200 (Fr, 08. Jul 2011) $
00131  *-----------------------------------------------------------------------
00132  * $Log: $
00133  *-----------------------------------------------------------------------*/
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines