Statistics
| Branch: | Revision:

root / include / ccommbuffer.h @ master

History | View | Annotate | Download (9.88 KB)

1 01873262 Georg Kunz
//=========================================================================
2
//  CCOMMBUFFER.H - part of
3
//
4
//                  OMNeT++/OMNEST
5
//           Discrete System Simulation in C++
6
//
7
//  Author: Andras Varga, 2003
8
//          Dept. of Electrical and Computer Systems Engineering,
9
//          Monash University, Melbourne, Australia
10
//
11
//=========================================================================
12
13
/*--------------------------------------------------------------*
14
  Copyright (C) 2003-2008 Andras Varga
15
  Copyright (C) 2006-2008 OpenSim Ltd.
16

17
  This file is distributed WITHOUT ANY WARRANTY. See the file
18
  `license' for details on this and other legal matters.
19
*--------------------------------------------------------------*/
20
21
#ifndef __CCOMMBUFFER_H
22
#define __CCOMMBUFFER_H
23
24
#include "cobject.h"
25
#include "simtime.h"
26
#include "platdep/intxtypes.h"
27
28
NAMESPACE_BEGIN
29
30
// forward declaration:
31
class cCommBuffer;
32
class cOwnedObject;
33
class opp_string;
34
35
36
/**
37
 * Buffer for the communications layer of parallel simulation.
38
 * This is an abstract class which has different implementations
39
 * for specific communication mechanisms.
40
 * For example, the MPI implementation, cMPICommBuffer encapsulates
41
 * MPI_Pack() and MPI_Unpack().
42
 *
43
 * @see cOwnedObject::parsimPack(), cOwnedObject::parsimUnpack()
44
 *
45
 * @ingroup ParsimBrief
46
 * @ingroup Parsim
47
 */
48
class SIM_API cCommBuffer : public cObject
49
{
50
  public:
51
    /**
52
     * Virtual destructor
53
     */
54
    virtual ~cCommBuffer() {}
55
56
    /** @name Buffer management */
57
    //@{
58
    /**
59
     * Returns true if all data in buffer was used up during unpacking.
60
     * Returns false if there was underflow (too much data unpacked)
61
     * or still there are unpacked data in the buffer.
62
     */
63
    virtual bool isBufferEmpty() const = 0;
64
65
    /**
66
     * Utility function. To be called after unpacking a communication buffer,
67
     * it checks whether the buffer is empty. If it is not (i.e. an underflow
68
     * or overflow occurred), an exception is thrown.
69
     */
70
    virtual void assertBufferEmpty() = 0;
71
    //@}
72
73
    /** @name Pack basic types */
74
    //@{
75
    /**
76
     * Packs a character.
77
     */
78
    virtual void pack(char d) = 0;
79
    /**
80
     * Packs an unsigned character.
81
     */
82
    virtual void pack(unsigned char d) = 0;
83
    /**
84
     * Packs a bool.
85
     */
86
    virtual void pack(bool d) = 0;
87
    /**
88
     * Packs a short int.
89
     */
90
    virtual void pack(short d) = 0;
91
    /**
92
     * Packs an unsigned short int.
93
     */
94
    virtual void pack(unsigned short d) = 0;
95
    /**
96
     * Packs an int.
97
     */
98
    virtual void pack(int d) = 0;
99
    /**
100
     * Packs an unsigned int.
101
     */
102
    virtual void pack(unsigned int d) = 0;
103
    /**
104
     * Packs a long int.
105
     */
106
    virtual void pack(long d) = 0;
107
    /**
108
     * Packs an unsigned long int.
109
     */
110
    virtual void pack(unsigned long d) = 0;
111
    /**
112
     * Packs a long long (on MSVC, __int64).
113
     */
114
    virtual void pack(opp_long_long d) = 0;
115
    /**
116
     * Packs an unsigned long long (on MSVC, __int64).
117
     */
118
    virtual void pack(opp_unsigned_long_long d) = 0;
119
    /**
120
     * Packs a float.
121
     */
122
    virtual void pack(float d) = 0;
123
    /**
124
     * Packs a double.
125
     */
126
    virtual void pack(double d) = 0;
127
    /**
128
     * Packs a long double.
129
     */
130
    virtual void pack(long double d) = 0;
131
    /**
132
     * Packs a string.
133
     */
134
    virtual void pack(const char *d) = 0;
135
    /**
136
     * Packs a string.
137
     */
138
    virtual void pack(const opp_string& d) = 0;
139
    /**
140
     * Packs a SimTime.
141
     */
142
    virtual void pack(SimTime d) = 0;
143
    //@}
144
145
    /** @name Pack arrays of basic types */
146
    //@{
147
    /**
148
     * Packs an array of chars.
149
     */
150
    virtual void pack(const char *d,  int size) = 0;
151
    /**
152
     * Packs an array of unsigned chars.
153
     */
154
    virtual void pack(const unsigned char *d,  int size) = 0;
155
    /**
156
     * Packs an array of bools.
157
     */
158
    virtual void pack(const bool *d, int size) = 0;
159
    /**
160
     * Packs an array of shorts.
161
     */
162
    virtual void pack(const short *d, int size) = 0;
163
    /**
164
     * Packs an array of unsigned shorts.
165
     */
166
    virtual void pack(const unsigned short *d, int size) = 0;
167
    /**
168
     * Packs an array of ints.
169
     */
170
    virtual void pack(const int *d, int size) = 0;
171
    /**
172
     * Packs an array of unsigned ints.
173
     */
174
    virtual void pack(const unsigned int *d, int size) = 0;
175
    /**
176
     * Packs an array of longs.
177
     */
178
    virtual void pack(const long *d, int size) = 0;
179
    /**
180
     * Packs an array of unsigned longs.
181
     */
182
    virtual void pack(const unsigned long *d, int size) = 0;
183
    /**
184
     * Packs an array of long long's (on MSVC, __int64).
185
     */
186
    virtual void pack(const opp_long_long *d, int size) = 0;
187
    /**
188
     * Packs an array of unsigned long long's (on MSVC, __int64).
189
     */
190
    virtual void pack(const opp_unsigned_long_long *d, int size) = 0;
191
    /**
192
     * Packs an array of floats.
193
     */
194
    virtual void pack(const float *d, int size) = 0;
195
    /**
196
     * Packs an array of doubles.
197
     */
198
    virtual void pack(const double *d, int size) = 0;
199
    /**
200
     * Packs an array of long doubles.
201
     */
202
    virtual void pack(const long double *d, int size) = 0;
203
    /**
204
     * Packs an array of strings.
205
     */
206
    void pack(char **d, int size)  {pack((const char **)d,size);}
207
    /**
208
     * Packs an array of strings.
209
     */
210
    virtual void pack(const char **d, int size) = 0;
211
    /**
212
     * Packs an array of opp_strings.
213
     */
214
    virtual void pack(const opp_string *d, int size) = 0;
215
    /**
216
     * Packs an array of SimTimes.
217
     */
218
    virtual void pack(const SimTime *d, int size) = 0;
219
    //@}
220
221
    /** @name Unpack basic types */
222
    //@{
223
    /**
224
     * Unpacks a char.
225
     */
226
    virtual void unpack(char& d) = 0;
227
    /**
228
     * Unpacks an unsigned char.
229
     */
230
    virtual void unpack(unsigned char& d) = 0;
231
    /**
232
     * Unpacks a bool.
233
     */
234
    virtual void unpack(bool& d) = 0;
235
    /**
236
     * Unpacks a short.
237
     */
238
    virtual void unpack(short& d) = 0;
239
    /**
240
     * Unpacks an unsigned short.
241
     */
242
    virtual void unpack(unsigned short& d) = 0;
243
    /**
244
     * Unpacks an int.
245
     */
246
    virtual void unpack(int& d) = 0;
247
    /**
248
     * Unpacks an unsigned int.
249
     */
250
    virtual void unpack(unsigned int& d) = 0;
251
    /**
252
     * Unpacks a long.
253
     */
254
    virtual void unpack(long& d) = 0;
255
    /**
256
     * Unpacks an unsigned long.
257
     */
258
    virtual void unpack(unsigned long& d) = 0;
259
    /**
260
     * Unpacks a long long (on MSVC, __int64).
261
     */
262
    virtual void unpack(opp_long_long& d) = 0;
263
    /**
264
     * Unpacks an unsigned long long (on MSVC, __int64).
265
     */
266
    virtual void unpack(opp_unsigned_long_long& d) = 0;
267
    /**
268
     * Unpacks a float.
269
     */
270
    virtual void unpack(float& d) = 0;
271
    /**
272
     * Unpacks a double.
273
     */
274
    virtual void unpack(double& d) = 0;
275
    /**
276
     * Unpacks a long double.
277
     */
278
    virtual void unpack(long double& d) = 0;
279
    /**
280
     * Unpacks a string -- storage will be allocated for it via new char[].
281
     */
282
    void unpack(char *&d)  {unpack((const char *&)d);}
283
    /**
284
     * Unpacks a string -- storage will be allocated for it via new char[].
285
     */
286
    virtual void unpack(const char *&d) = 0;
287
    /**
288
     * Unpacks an opp_string.
289
     */
290
    virtual void unpack(opp_string& d) = 0;
291
    /**
292
     * Unpacks a SimTime.
293
     */
294
    virtual void unpack(SimTime& d) = 0;
295
    //@}
296
297
    /** @name Unpack arrays of basic types */
298
    //@{
299
    /**
300
     * Unpacks an array of chars.
301
     */
302
    virtual void unpack(char *d, int size) = 0;
303
    /**
304
     * Unpacks an array of unsigned chars.
305
     */
306
    virtual void unpack(unsigned char *d, int size) = 0;
307
    /**
308
     * Unpacks an array of bools.
309
     */
310
    virtual void unpack(bool *d, int size) = 0;
311
    /**
312
     * Unpacks an array of shorts.
313
     */
314
    virtual void unpack(short *d, int size) = 0;
315
    /**
316
     * Unpacks an array of unsigned shorts.
317
     */
318
    virtual void unpack(unsigned short *d, int size) = 0;
319
    /**
320
     * Unpacks an array of ints.
321
     */
322
    virtual void unpack(int *d, int size) = 0;
323
    /**
324
     * Unpacks an array of unsigned ints.
325
     */
326
    virtual void unpack(unsigned int *d, int size) = 0;
327
    /**
328
     * Unpacks an array of longs.
329
     */
330
    virtual void unpack(long *d, int size) = 0;
331
    /**
332
     * Unpacks an array of unsigned longs.
333
     */
334
    virtual void unpack(unsigned long *d, int size) = 0;
335
    /**
336
     * Unpacks an array of long long's (on MSVC, __int64).
337
     */
338
    virtual void unpack(opp_long_long *d, int size) = 0;
339
    /**
340
     * Unpacks an array of unsigned long long's (on MSVC, __int64).
341
     */
342
    virtual void unpack(opp_unsigned_long_long *d, int size) = 0;
343
    /**
344
     * Unpacks an array of floats.
345
     */
346
    virtual void unpack(float *d, int size) = 0;
347
    /**
348
     * Unpacks an array of doubles.
349
     */
350
    virtual void unpack(double *d, int size) = 0;
351
    /**
352
     * Unpacks an array of long doubles.
353
     */
354
    virtual void unpack(long double *d, int size) = 0;
355
    /**
356
     * Unpacks an array of strings -- storage for strings will be allocated via new char[].
357
     */
358
    void unpack(char **d, int size)  {unpack((const char **)d,size);}
359
    /**
360
     * Unpacks an array of strings -- storage for strings will be allocated via new char[].
361
     */
362
    virtual void unpack(const char **d, int size) = 0;
363
    /**
364
     * Unpacks an array of opp_strings.
365
     */
366
    virtual void unpack(opp_string *d, int size) = 0;
367
    /**
368
     * Unpacks an array of SimTime.
369
     */
370
    virtual void unpack(SimTime *d, int size) = 0;
371
    //@}
372
373
    /** @name Utility functions */
374
    //@{
375
    /**
376
     * Stores and returns the given flag.
377
     */
378
    bool packFlag(bool flag)  {pack(flag); return flag;}
379
380
    /**
381
     * Unpacks and returns a bool flag stored by packFlag().
382
     */
383
    bool checkFlag() {bool flag; unpack(flag); return flag;}
384
385
    /**
386
     * Packs an object.
387
     */
388
    virtual void packObject(cObject *obj);
389
390
    /**
391
     * Unpacks and returns an object.
392
     */
393
    virtual cObject *unpackObject();
394
    //@}
395
};
396
397
NAMESPACE_END
398
399
#endif