Project

General

Profile

Statistics
| Branch: | Revision:

root / src / nedxml / example.msg @ 79bb12dc

History | View | Annotate | Download (2.21 KB)

1 01873262 Georg Kunz
//
2
// An example for message subclassing.
3
//
4
// This file has to be processed by opp_msgc which generates C++ classes you
5
// can use from your models, as well as "reflection" classes that allow Tkenv
6
// to inspect these data stuctures.
7
//
8
// Check doc/msgsubclassing.txt for more information.
9
//
10
11
// put generated classes into a (nested) namespace
12
namespace exam::ple;
13
14
// includes necessary to compile the generated C++ header file
15
cplusplus {{
16
#include "basicpacket.h"
17
#include "payloadpacket.h"
18
#include "mystring.h"
19
}};
20
21
// announce types that come from included C++ code
22
struct IPAddress;
23
class BasicPacket;
24
class PayloadPacket;
25
class noncobject mystring;
26
27
// imports are not yet supported :-(
28
// import "othermsgs.msg";
29
30
// create an enum
31
enum ProtocolTypes
32
{
33
    IP = 1;
34
    TCP = 2;
35
};
36
37
// add new values to ProtocolTypes
38
enum MoreProtocolTypes extends ProtocolTypes
39
{
40
    CLNP = 3;
41
    TP4 = 4;
42
};
43
44
// empty message object
45
message BlankMsg {
46
    // garbage
47
};
48
49
// message object
50
message FooPacket extends BasicPacket
51
{
52
    char type='x';
53
    // not supported: IPAddress *x;
54
    short version=2;
55
    int protocolId enum(ProtocolTypes);
56
    bool hasPayload;
57
    long length;
58
    unsigned long route[4];
59
    string host[];
60
    IPAddress src;
61
    IPAddress dest;
62
    PayloadPacket twoPayloads[2];
63
    PayloadPacket payload[];
64
};
65
66
// demonstrate subclassing
67
message BarPacket extends FooPacket
68
{
69
    @customize(true);
70
    int hopcount;
71
    double delay;
72
    abstract int myvar;
73
};
74
75
// class without base class (NOT derived from cOwnedObject!)
76
class SomeClass
77
{
78
    int src;
79
};
80
81
class MyClass
82
{
83
    @customize(true);
84
    abstract char type;
85
    abstract short version;
86
};
87
88
// class not derived from cOwnedObject
89
class MyDerivedClass extends MyClass
90
{
91
    char bla='x';
92
    short blabla=2;
93
};
94
95
// class derived from cOwnedObject
96
class MyCObjectClass extends cOwnedObject
97
{
98
    char type='x';
99
    short version=2;
100
    mystring vendor;
101
};
102
103
// plain C struct (public members, no getter/setter methods, etc)
104
struct MyStruct
105
{
106
    char array[10];
107
    short version = 5;
108
};
109
110
// inheritance with structs
111
struct MyDerivedStruct extends MyStruct
112
{
113
    unsigned char code;
114
    short prot enum(ProtocolTypes);
115
    MyStruct substruct;  // also as embedded data member
116
};
117