Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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#pragma once
14#include <config.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
34namespace tcpip
35{
36
38{
39
40public:
41 typedef std::vector<unsigned char> StorageType;
42
43private:
45 StorageType::const_iterator iter_;
46
47 // sortation of bytes forwards or backwards?
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
63public:
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();
78 void resetPos();
80 std::string hexDump() const;
81
82 virtual unsigned char readChar();
83 virtual void writeChar(unsigned char);
84
85 virtual int readByte();
86 virtual void writeByte(int);
87// virtual void writeByte(unsigned char);
88
89 virtual int readUnsignedByte();
90 virtual void writeUnsignedByte(int);
91
92 virtual std::string readString();
93 virtual void writeString(const std::string& s);
94
95 virtual std::vector<std::string> readStringList();
96 virtual void writeStringList(const std::vector<std::string> &s);
97
98 virtual std::vector<double> readDoubleList();
99 virtual void writeDoubleList(const std::vector<double> &s);
100
101 virtual int readShort();
102 virtual void writeShort(int);
103
104 virtual int readInt();
105 virtual void writeInt(int);
106
107 virtual float readFloat();
108 virtual void writeFloat( float );
109
110 virtual double readDouble();
111 virtual void writeDouble( double );
112
113 virtual void writePacket(unsigned char* packet, int length);
114 virtual void writePacket(const std::vector<unsigned char> &packet);
115
116 virtual void writeStorage(tcpip::Storage& store);
117
118 // Some enabled functions of the underlying std::list
119 StorageType::size_type size() const { return store.size(); }
120
121 StorageType::const_iterator begin() const { return store.begin(); }
122 StorageType::const_iterator end() const { return store.end(); }
123
125 Storage& operator=(const Storage&) = delete;
126
127};
128
129} // namespace tcpip
130
131#endif // BUILD_TCPIP
virtual void writePacket(unsigned char *packet, int length)
Definition storage.cpp:372
std::vector< unsigned char > StorageType
Definition storage.h:41
bool bigEndian_
Definition storage.h:48
StorageType::const_iterator begin() const
Definition storage.h:121
virtual void writeFloat(float)
Definition storage.cpp:346
virtual int readShort()
Definition storage.cpp:280
virtual unsigned char readChar()
Definition storage.cpp:102
virtual std::string readString()
Definition storage.cpp:180
virtual void writeString(const std::string &s)
Definition storage.cpp:197
virtual float readFloat()
Definition storage.cpp:336
virtual unsigned int position() const
Definition storage.cpp:76
virtual void writeInt(int)
Definition storage.cpp:321
void resetPos()
Definition storage.cpp:92
StorageType::const_iterator end() const
Definition storage.h:122
virtual void writeDouble(double)
Definition storage.cpp:354
StorageType store
Definition storage.h:44
virtual int readUnsignedByte()
Definition storage.cpp:155
virtual void writeStringList(const std::vector< std::string > &s)
Definition storage.cpp:247
virtual void writeChar(unsigned char)
Definition storage.cpp:116
StorageType::const_iterator iter_
Definition storage.h:45
virtual void writeUnsignedByte(int)
Definition storage.cpp:165
StorageType::size_type size() const
Definition storage.h:119
virtual ~Storage()
Definition storage.cpp:64
virtual bool valid_pos()
Definition storage.cpp:69
virtual void writeDoubleList(const std::vector< double > &s)
Definition storage.cpp:262
unsigned char readCharUnsafe()
Read a byte without validity check.
Definition storage.cpp:410
std::string hexDump() const
Dump storage content as series of hex values.
Definition storage.cpp:448
void writeByEndianess(const unsigned char *begin, unsigned int size)
Write size elements of array begin according to endianess.
Definition storage.cpp:419
Storage()
Standard Constructor.
Definition storage.cpp:32
virtual void writeByte(int)
Definition storage.cpp:140
virtual void writeStorage(tcpip::Storage &store)
Definition storage.cpp:388
virtual int readByte()
Definition storage.cpp:128
void readByEndianess(unsigned char *array, int size)
Read size elements into array according to endianess.
Definition storage.cpp:431
virtual std::vector< std::string > readStringList()
Definition storage.cpp:211
virtual void writeShort(int)
Definition storage.cpp:290
void checkReadSafe(unsigned int num) const
Check if the next num bytes can be read safely.
Definition storage.cpp:397
void init()
Used in constructors to initialize local variables.
Definition storage.cpp:52
virtual double readDouble()
Definition storage.cpp:362
Storage & operator=(const Storage &)=delete
Invalidated assignment operator.
virtual int readInt()
Definition storage.cpp:311
virtual std::vector< double > readDoubleList()
Definition storage.cpp:229