Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/foreign/tcpip/storage.h
169678 views
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 <[email protected]> **
10
** \author Bjoern Hendriks <[email protected]> **
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
34
namespace tcpip
35
{
36
37
class Storage
38
{
39
40
public:
41
typedef std::vector<unsigned char> StorageType;
42
43
private:
44
StorageType store;
45
StorageType::const_iterator iter_;
46
47
// sortation of bytes forwards or backwards?
48
bool bigEndian_;
49
50
/// Used in constructors to initialize local variables
51
void init();
52
53
/// Check if the next \p num bytes can be read safely
54
void checkReadSafe(unsigned int num) const;
55
/// Read a byte \em without validity check
56
unsigned char readCharUnsafe();
57
/// Write \p size elements of array \p begin according to endianess
58
void writeByEndianess(const unsigned char * begin, unsigned int size);
59
/// Read \p size elements into \p array according to endianess
60
void readByEndianess(unsigned char * array, int size);
61
62
63
public:
64
65
/// Standard Constructor
66
Storage();
67
68
/// Constructor, that fills the storage with an char array. If length is -1, the whole array is handed over
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();
79
/// Dump storage content as series of hex values
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
124
/// @brief Invalidated assignment operator.
125
Storage& operator=(const Storage&) = delete;
126
127
};
128
129
} // namespace tcpip
130
131
#endif // BUILD_TCPIP
132
133