Eclipse SUMO - Simulation of Urban MObility
storage.h
Go to the documentation of this file.
1 /************************************************************************
2  ** This file is part of the network simulator Shawn. **
3  ** Copyright (C) 2004-2007 by the SwarmNet (www.swarmnet.de) project **
4  ** Shawn is free software; you can redistribute it and/or modify it **
5  ** under the terms of the BSD License. Refer to the shawn-licence.txt **
6  ** file in the root of the Shawn source tree for further details. **
7  ************************************************************************
8  ** **
9  ** \author Axel Wegener <wegener@itm.uni-luebeck.de> **
10  ** \author Bjoern Hendriks <hendriks@ibr.cs.tu-bs.de> **
11  ** **
12  ************************************************************************/
13 #ifndef __SHAWN_APPS_TCPIP_STORAGE_H
14 #define __SHAWN_APPS_TCPIP_STORAGE_H
15 
16 #ifdef SHAWN
17  #include <shawn_config.h>
18  #include "_apps_enable_cmake.h"
19  #ifdef ENABLE_TCPIP
20  #define BUILD_TCPIP
21  #endif
22 #else
23  #define BUILD_TCPIP
24 #endif
25 
26 
27 #ifdef BUILD_TCPIP
28 
29 #include <vector>
30 #include <string>
31 #include <stdexcept>
32 #include <iostream>
33 
34 namespace tcpip
35 {
36 
37 class Storage
38 {
39 
40 public:
41  typedef std::vector<unsigned char> StorageType;
42 
43 private:
45  StorageType::const_iterator iter_;
46 
47  // sortation of bytes forwards or backwards?
48  bool bigEndian_;
49 
51  void init();
52 
54  void checkReadSafe(unsigned int num) const;
56  unsigned char readCharUnsafe();
58  void writeByEndianess(const unsigned char * begin, unsigned int size);
60  void readByEndianess(unsigned char * array, int size);
61 
62 
63 public:
64 
66  Storage();
67 
69  Storage(const unsigned char[], int length=-1);
70 
71  // Destructor
72  virtual ~Storage();
73 
74  virtual bool valid_pos();
75  virtual unsigned int position() const;
76 
77  void reset();
79  std::string hexDump() const;
80 
81  virtual unsigned char readChar();
82  virtual void writeChar(unsigned char);
83 
84  virtual int readByte();
85  virtual void writeByte(int);
86 // virtual void writeByte(unsigned char);
87 
88  virtual int readUnsignedByte();
89  virtual void writeUnsignedByte(int);
90 
91  virtual std::string readString();
92  virtual void writeString(const std::string& s);
93 
94  virtual std::vector<std::string> readStringList();
95  virtual void writeStringList(const std::vector<std::string> &s);
96 
97  virtual std::vector<double> readDoubleList();
98  virtual void writeDoubleList(const std::vector<double> &s);
99 
100  virtual int readShort();
101  virtual void writeShort(int);
102 
103  virtual int readInt();
104  virtual void writeInt(int);
105 
106  virtual float readFloat();
107  virtual void writeFloat( float );
108 
109  virtual double readDouble();
110  virtual void writeDouble( double );
111 
112  virtual void writePacket(unsigned char* packet, int length);
113  virtual void writePacket(const std::vector<unsigned char> &packet);
114 
115  virtual void writeStorage(tcpip::Storage& store);
116 
117  // Some enabled functions of the underlying std::list
118  StorageType::size_type size() const { return store.size(); }
119 
120  StorageType::const_iterator begin() const { return store.begin(); }
121  StorageType::const_iterator end() const { return store.end(); }
122 
123 };
124 
125 } // namespace tcpip
126 
127 #endif // BUILD_TCPIP
128 
129 #endif
130 /*-----------------------------------------------------------------------
131  * Source $Source: $
132  * Version $Revision: 620 $
133  * Date $Date: 2011-07-08 17:39:10 +0200 (Fri, 08 Jul 2011) $
134  *-----------------------------------------------------------------------
135  * $Log: $
136  *-----------------------------------------------------------------------*/
tcpip::Storage::hexDump
std::string hexDump() const
Dump storage content as series of hex values.
tcpip::Storage::readDouble
virtual double readDouble()
tcpip::Storage::~Storage
virtual ~Storage()
tcpip
Definition: socket.cpp:61
tcpip::Storage::init
void init()
Used in constructors to initialize local variables.
tcpip::Storage::writeUnsignedByte
virtual void writeUnsignedByte(int)
tcpip::Storage::readStringList
virtual std::vector< std::string > readStringList()
tcpip::Storage::valid_pos
virtual bool valid_pos()
tcpip::Storage::writePacket
virtual void writePacket(unsigned char *packet, int length)
tcpip::Storage::end
StorageType::const_iterator end() const
Definition: storage.h:120
tcpip::Storage::readByEndianess
void readByEndianess(unsigned char *array, int size)
Read size elements into array according to endianess.
tcpip::Storage::readChar
virtual unsigned char readChar()
tcpip::Storage::StorageType
std::vector< unsigned char > StorageType
Definition: storage.h:40
tcpip::Storage::writeByEndianess
void writeByEndianess(const unsigned char *begin, unsigned int size)
Write size elements of array begin according to endianess.
tcpip::Storage::writeByte
virtual void writeByte(int)
tcpip::Storage::readUnsignedByte
virtual int readUnsignedByte()
tcpip::Storage::writeInt
virtual void writeInt(int)
tcpip::Storage::writeChar
virtual void writeChar(unsigned char)
tcpip::Storage::position
virtual unsigned int position() const
tcpip::Storage::readString
virtual std::string readString()
tcpip::Storage::readInt
virtual int readInt()
tcpip::Storage::Storage
Storage()
Standard Constructor.
tcpip::Storage::writeStorage
virtual void writeStorage(tcpip::Storage &store)
tcpip::Storage::writeStringList
virtual void writeStringList(const std::vector< std::string > &s)
tcpip::Storage::store
StorageType store
Definition: storage.h:43
tcpip::Storage::bigEndian_
bool bigEndian_
Definition: storage.h:47
tcpip::Storage::writeFloat
virtual void writeFloat(float)
tcpip::Storage::reset
void reset()
tcpip::Storage::readCharUnsafe
unsigned char readCharUnsafe()
Read a byte without validity check.
tcpip::Storage::writeShort
virtual void writeShort(int)
tcpip::Storage::writeString
virtual void writeString(const std::string &s)
tcpip::Storage::begin
StorageType::const_iterator begin() const
Definition: storage.h:119
tcpip::Storage::checkReadSafe
void checkReadSafe(unsigned int num) const
Check if the next num bytes can be read safely.
tcpip::Storage::writeDoubleList
virtual void writeDoubleList(const std::vector< double > &s)
tcpip::Storage::size
StorageType::size_type size() const
Definition: storage.h:117
tcpip::Storage::readByte
virtual int readByte()
tcpip::Storage::writeDouble
virtual void writeDouble(double)
tcpip::Storage::iter_
StorageType::const_iterator iter_
Definition: storage.h:44
tcpip::Storage::readFloat
virtual float readFloat()
tcpip::Storage::readShort
virtual int readShort()
tcpip::Storage::readDoubleList
virtual std::vector< double > readDoubleList()
tcpip::Storage
Definition: storage.h:36