author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Fri, 07 Sep 2007 08:34:46 +0200 | |
changeset 1461 | d3f2aacbc1d7 |
parent 1313 | 02b29b3d74de |
child 1463 | 0df6c4ff3c9e |
permissions | -rw-r--r-- |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
2 |
/* |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
3 |
* Copyright (c) 2005,2006,2007 INRIA |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
4 |
* |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
8 |
* |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
13 |
* |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
17 |
* |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
18 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
19 |
*/ |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
#ifndef BUFFER_H |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
21 |
#define BUFFER_H |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
22 |
|
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
23 |
#include <stdint.h> |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
24 |
#include <vector> |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
25 |
|
16
99e833adbb46
change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
9
diff
changeset
|
26 |
namespace ns3 { |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
|
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
28 |
/** |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
29 |
* \brief automatically resized byte buffer |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
30 |
* |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
31 |
* This represents a buffer of bytes. Its size is |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
32 |
* automatically adjusted to hold any data prepended |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
33 |
* or appended by the user. Its implementation is optimized |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
34 |
* to ensure that the number of buffer resizes is minimized, |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
35 |
* by creating new Buffers of the maximum size ever used. |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
36 |
* The correct maximum size is learned at runtime during use by |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
37 |
* recording the maximum size of each packet. |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
38 |
*/ |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
39 |
class Buffer { |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
40 |
public: |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
41 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
42 |
* \brief iterator in a Buffer instance |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
43 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
44 |
class Iterator { |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
45 |
public: |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
46 |
Iterator (); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
47 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
48 |
* go forward by one byte |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
49 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
50 |
void Next (void); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
51 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
52 |
* go backward by one byte |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
53 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
54 |
void Prev (void); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
55 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
56 |
* \param delta number of bytes to go forward |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
57 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
58 |
void Next (uint32_t delta); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
59 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
60 |
* \param delta number of bytes to go backward |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
61 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
62 |
void Prev (uint32_t delta); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
63 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
64 |
* \param o the second iterator |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
65 |
* \return number of bytes included between the two iterators |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
66 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
67 |
* This method works only if the two iterators point |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
68 |
* to the same underlying buffer. Debug builds ensure |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
69 |
* this with an assert. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
70 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
71 |
uint32_t GetDistanceFrom (Iterator const &o) const; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
72 |
|
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
73 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
74 |
* \return true if this iterator points to the end of the byte array. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
75 |
* false otherwise. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
76 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
77 |
bool IsEnd (void) const; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
78 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
79 |
* \return true if this iterator points to the start of the byte array. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
80 |
* false otherwise. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
81 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
82 |
bool IsStart (void) const; |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
83 |
|
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
84 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
85 |
* \param data data to write in buffer |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
86 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
87 |
* Write the data in buffer and avance the iterator position |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
88 |
* by one byte. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
89 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
90 |
void WriteU8 (uint8_t data); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
91 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
92 |
* \param data data to write in buffer |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
93 |
* \param len number of times data must be written in buffer |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
94 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
95 |
* Write the data in buffer len times and avance the iterator position |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
96 |
* by len byte. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
97 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
98 |
void WriteU8 (uint8_t data, uint32_t len); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
99 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
100 |
* \param data data to write in buffer |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
101 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
102 |
* Write the data in buffer and avance the iterator position |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
103 |
* by two bytes. The format of the data written in the byte |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
104 |
* buffer is non-portable. We only ensure that readU16 will |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
105 |
* return exactly what we wrote with writeU16 if the program |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
106 |
* is run on the same machine. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
107 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
108 |
void WriteU16 (uint16_t data); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
109 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
110 |
* \param data data to write in buffer |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
111 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
112 |
* Write the data in buffer and avance the iterator position |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
113 |
* by four bytes. The format of the data written in the byte |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
114 |
* buffer is non-portable. We only ensure that readU32 will |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
115 |
* return exactly what we wrote with writeU32 if the program |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
116 |
* is run on the same machine. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
117 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
118 |
void WriteU32 (uint32_t data); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
119 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
120 |
* \param data data to write in buffer |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
121 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
122 |
* Write the data in buffer and avance the iterator position |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
123 |
* by eight bytes. The format of the data written in the byte |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
124 |
* buffer is non-portable. We only ensure that readU64 will |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
125 |
* return exactly what we wrote with writeU64 if the program |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
126 |
* is run on the same machine. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
127 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
128 |
void WriteU64 (uint64_t data); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
129 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
130 |
* \param data data to write in buffer |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
131 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
132 |
* Write the data in buffer and avance the iterator position |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
133 |
* by two bytes. The data is written in network order and the |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
134 |
* input data is expected to be in host order. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
135 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
136 |
void WriteHtonU16 (uint16_t data); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
137 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
138 |
* \param data data to write in buffer |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
139 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
140 |
* Write the data in buffer and avance the iterator position |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
141 |
* by four bytes. The data is written in network order and the |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
142 |
* input data is expected to be in host order. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
143 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
144 |
void WriteHtonU32 (uint32_t data); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
145 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
146 |
* \param data data to write in buffer |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
147 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
148 |
* Write the data in buffer and avance the iterator position |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
149 |
* by eight bytes. The data is written in network order and the |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
150 |
* input data is expected to be in host order. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
151 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
152 |
void WriteHtonU64 (uint64_t data); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
153 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
154 |
* \param buffer a byte buffer to copy in the internal buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
155 |
* \param size number of bytes to copy. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
156 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
157 |
* Write the data in buffer and avance the iterator position |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
158 |
* by size bytes. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
159 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
160 |
void Write (uint8_t const*buffer, uint32_t size); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
161 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
162 |
* \param start the start of the data to copy |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
163 |
* \param end the end of the data to copy |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
164 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
165 |
* Write the data delimited by start and end in internal buffer |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
166 |
* and avance the iterator position by the number of bytes |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
167 |
* copied. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
168 |
* The input interators _must_ not point to the same Buffer as |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
169 |
* we do to avoid overlapping copies. This is enforced |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
170 |
* in debug builds by asserts. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
171 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
172 |
void Write (Iterator start, Iterator end); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
173 |
|
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
174 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
175 |
* \return the byte read in the buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
176 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
177 |
* Read data and advance the Iterator by the number of bytes |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
178 |
* read. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
179 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
180 |
uint8_t ReadU8 (void); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
181 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
182 |
* \return the two bytes read in the buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
183 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
184 |
* Read data and advance the Iterator by the number of bytes |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
185 |
* read. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
186 |
* The data is read in the format written by writeU16. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
187 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
188 |
uint16_t ReadU16 (void); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
189 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
190 |
* \return the four bytes read in the buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
191 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
192 |
* Read data and advance the Iterator by the number of bytes |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
193 |
* read. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
194 |
* The data is read in the format written by writeU32. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
195 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
196 |
uint32_t ReadU32 (void); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
197 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
198 |
* \return the eight bytes read in the buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
199 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
200 |
* Read data and advance the Iterator by the number of bytes |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
201 |
* read. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
202 |
* The data is read in the format written by writeU64. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
203 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
204 |
uint64_t ReadU64 (void); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
205 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
206 |
* \return the two bytes read in the buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
207 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
208 |
* Read data and advance the Iterator by the number of bytes |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
209 |
* read. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
210 |
* The data is read in network format and return in host format. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
211 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
212 |
uint16_t ReadNtohU16 (void); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
213 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
214 |
* \return the four bytes read in the buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
215 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
216 |
* Read data and advance the Iterator by the number of bytes |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
217 |
* read. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
218 |
* The data is read in network format and return in host format. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
219 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
220 |
uint32_t ReadNtohU32 (void); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
221 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
222 |
* \return the eight bytes read in the buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
223 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
224 |
* Read data and advance the Iterator by the number of bytes |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
225 |
* read. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
226 |
* The data is read in network format and return in host format. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
227 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
228 |
uint64_t ReadNtohU64 (void); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
229 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
230 |
* \param buffer buffer to copy data into |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
231 |
* \param size number of bytes to copy |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
232 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
233 |
* Copy size bytes of data from the internal buffer to the |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
234 |
* input buffer and avance the Iterator by the number of |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
235 |
* bytes read. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
236 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
237 |
void Read (uint8_t *buffer, uint16_t size); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
238 |
private: |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
239 |
friend class Buffer; |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
240 |
Iterator (Buffer const*buffer, uint32_t m_current); |
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
241 |
uint32_t GetIndex (uint32_t n); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
242 |
uint32_t m_zeroStart; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
243 |
uint32_t m_zeroEnd; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
244 |
uint32_t m_dataEnd; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
245 |
uint32_t m_current; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
246 |
uint8_t *m_data; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
247 |
}; |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
248 |
|
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
249 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
250 |
* \return the number of bytes stored in this buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
251 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
252 |
uint32_t GetSize (void) const; |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
253 |
|
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
254 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
255 |
* \return a pointer to the start of the internal |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
256 |
* byte buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
257 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
258 |
* The returned pointer points to an area of |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
259 |
* memory which is ns3::Buffer::GetSize () bytes big. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
260 |
* Please, try to never ever use this method. It is really |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
261 |
* evil and is present only for a few specific uses. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
262 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
263 |
uint8_t const*PeekData (void) const; |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
264 |
|
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
265 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
266 |
* \param start size to reserve |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
267 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
268 |
* Add bytes at the start of the Buffer. The |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
269 |
* content of these bytes is undefined but debugging |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
270 |
* builds initialize them to 0x33. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
271 |
* Any call to this method invalidates any Iterator |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
272 |
* pointing to this Buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
273 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
274 |
void AddAtStart (uint32_t start); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
275 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
276 |
* \param end size to reserve |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
277 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
278 |
* Add bytes at the end of the Buffer. The |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
279 |
* content of these bytes is undefined but debugging |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
280 |
* builds initialize them to 0x33. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
281 |
* Any call to this method invalidates any Iterator |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
282 |
* pointing to this Buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
283 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
284 |
void AddAtEnd (uint32_t end); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
285 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
286 |
* \param start size to remove |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
287 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
288 |
* Remove bytes at the start of the Buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
289 |
* Any call to this method invalidates any Iterator |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
290 |
* pointing to this Buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
291 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
292 |
void RemoveAtStart (uint32_t start); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
293 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
294 |
* \param end size to remove |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
295 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
296 |
* Remove bytes at the end of the Buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
297 |
* Any call to this method invalidates any Iterator |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
298 |
* pointing to this Buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
299 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
300 |
void RemoveAtEnd (uint32_t end); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
301 |
|
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
302 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
303 |
* \param start offset from start of packet |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
304 |
* \param length |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
305 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
306 |
* \return a fragment of size length starting at offset |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
307 |
* start. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
308 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
309 |
Buffer CreateFragment (uint32_t start, uint32_t length) const; |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
310 |
|
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
311 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
312 |
* \return an Iterator which points to the |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
313 |
* start of this Buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
314 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
315 |
Buffer::Iterator Begin (void) const; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
316 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
317 |
* \return an Iterator which points to the |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
318 |
* end of this Buffer. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
319 |
*/ |
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
320 |
Buffer::Iterator End (void) const; |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
321 |
|
1137
620b9f96c9e6
add Buffer::CreateFullCopy and make TransformInto private
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
957
diff
changeset
|
322 |
Buffer CreateFullCopy (void) const; |
823
467609e92a6b
add more asserts, make TransformIntoRealBuffer public for Packet class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
780
diff
changeset
|
323 |
|
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
324 |
Buffer (Buffer const &o); |
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
325 |
Buffer &operator = (Buffer const &o); |
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
326 |
Buffer (); |
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
327 |
Buffer (uint32_t dataSize); |
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
328 |
~Buffer (); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
329 |
private: |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
330 |
struct BufferData { |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
331 |
uint32_t m_count; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
332 |
uint32_t m_size; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
333 |
uint32_t m_initialStart; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
334 |
uint32_t m_dirtyStart; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
335 |
uint32_t m_dirtySize; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
336 |
uint8_t m_data[1]; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
337 |
}; |
957 | 338 |
class BufferDataList : public std::vector<struct Buffer::BufferData*> |
339 |
{ |
|
340 |
public: |
|
341 |
~BufferDataList (); |
|
342 |
}; |
|
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
343 |
|
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
344 |
uint8_t *GetStart (void) const; |
1137
620b9f96c9e6
add Buffer::CreateFullCopy and make TransformInto private
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
957
diff
changeset
|
345 |
void TransformIntoRealBuffer (void) const; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
346 |
static void Recycle (struct Buffer::BufferData *data); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
347 |
static struct Buffer::BufferData *Create (void); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
348 |
static struct Buffer::BufferData *Allocate (uint32_t size, uint32_t start); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
349 |
static void Deallocate (struct Buffer::BufferData *data); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
350 |
|
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
351 |
static BufferDataList m_freeList; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
352 |
static uint32_t m_maxTotalAddStart; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
353 |
static uint32_t m_maxTotalAddEnd; |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
354 |
|
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
355 |
struct BufferData *m_data; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
356 |
uint32_t m_zeroAreaSize; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
357 |
uint32_t m_start; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
134
diff
changeset
|
358 |
uint32_t m_size; |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
359 |
}; |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
360 |
|
1461
d3f2aacbc1d7
move inline code from header to .cc file prior to rework of Buffer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1313
diff
changeset
|
361 |
} // namespace ns3 |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
362 |
|
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
363 |
#endif /* BUFFER_H */ |