Project

General

Profile

Statistics
| Branch: | Revision:

root / src / sim / cstlwatch.cc @ 3e29b8a0

History | View | Annotate | Download (4.56 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  CSTLWATCH.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//
7
//  WATCH_VECTOR, WATCH_MAP etc macros
8
//
9
//==========================================================================
10
11
/*--------------------------------------------------------------*
12
  Copyright (C) 1992-2008 Andras Varga
13
  Copyright (C) 2006-2008 OpenSim Ltd.
14

15
  This file is distributed WITHOUT ANY WARRANTY. See the file
16
  `license' for details on this and other legal matters.
17
*--------------------------------------------------------------*/
18
19
#include <stdio.h>
20
#include "cstlwatch.h"
21
#include "cclassdescriptor.h"
22
#include "globals.h"
23
24
USING_NAMESPACE
25
26
//
27
// Internal
28
//
29
class SIM_API cStdVectorWatcherDescriptor : public cClassDescriptor //noncopyable
30
{
31
  public:
32
    cStdVectorWatcherDescriptor();
33
    virtual ~cStdVectorWatcherDescriptor();
34
35
    virtual const char *getProperty(const char *propertyname) const;
36
    virtual int getFieldCount(void *object) const;
37
    virtual const char *getFieldName(void *object, int field) const;
38
    virtual unsigned int getFieldTypeFlags(void *object, int field) const;
39
    virtual const char *getFieldTypeString(void *object, int field) const;
40
    virtual const char *getFieldProperty(void *object, int field, const char *propertyname) const;
41
    virtual int getArraySize(void *object, int field) const;
42
43
    virtual std::string getFieldAsString(void *object, int field, int i) const;
44
    virtual bool setFieldAsString(void *object, int field, int i, const char *value) const;
45
46
    virtual const char *getFieldStructName(void *object, int field) const;
47
    virtual void *getFieldStructPointer(void *object, int field, int i) const;
48
};
49
50
Register_ClassDescriptor(cStdVectorWatcherDescriptor);
51
52
cStdVectorWatcherDescriptor::cStdVectorWatcherDescriptor() :
53
cClassDescriptor("cStdVectorWatcher", "cStdVectorWatcherBase")
54
{
55
}
56
57
cStdVectorWatcherDescriptor::~cStdVectorWatcherDescriptor()
58
{
59
}
60
61
const char *cStdVectorWatcherDescriptor::getProperty(const char *propertyname) const
62
{
63
    return NULL;
64
}
65
66
int cStdVectorWatcherDescriptor::getFieldCount(void *) const
67
{
68
    return 1;
69
}
70
71
unsigned int cStdVectorWatcherDescriptor::getFieldTypeFlags(void *, int field) const
72
{
73
    switch (field) {
74
        case 0: return FD_ISARRAY; // as far as we're concerned. We don't know about FD_ISCOMPOUND, FD_ISPOINTER, FD_ISCOBJECT / FD_ISCOWNEDOBJECT
75
        default: return FD_NONE;
76
    }
77
}
78
79
const char *cStdVectorWatcherDescriptor::getFieldName(void *object, int field) const
80
{
81
    cStdVectorWatcherBase *pp = (cStdVectorWatcherBase *)object;
82
    switch (field) {
83
        case 0: return pp->getName();
84
        default: return NULL;
85
    }
86
}
87
88
const char *cStdVectorWatcherDescriptor::getFieldTypeString(void *object, int field) const
89
{
90
    cStdVectorWatcherBase *pp = (cStdVectorWatcherBase *)object;
91
    switch (field) {
92
        case 0: return pp->getElemTypeName();
93
        default: return NULL;
94
    }
95
}
96
97
const char *cStdVectorWatcherDescriptor::getFieldProperty(void *object, int field, const char *propertyname) const
98
{
99
    return NULL;
100
}
101
102
int cStdVectorWatcherDescriptor::getArraySize(void *object, int field) const
103
{
104
    cStdVectorWatcherBase *pp = (cStdVectorWatcherBase *)object;
105
    switch (field) {
106
        case 0: return pp->size();
107
        default: return 0;
108
    }
109
}
110
111
std::string cStdVectorWatcherDescriptor::getFieldAsString(void *object, int field, int i) const
112
{
113
    cStdVectorWatcherBase *pp = (cStdVectorWatcherBase *)object;
114
    switch (field) {
115
        case 0: return pp->at(i);
116
        default: return "";
117
    }
118
}
119
120
bool cStdVectorWatcherDescriptor::setFieldAsString(void *object, int field, int i, const char *value) const
121
{
122
    return false; // not supported
123
}
124
125
const char *cStdVectorWatcherDescriptor::getFieldStructName(void *object, int field) const
126
{
127
    return NULL;
128
}
129
130
void *cStdVectorWatcherDescriptor::getFieldStructPointer(void *object, int field, int i) const
131
{
132
    return NULL;
133
}
134
135
136
//--------------------------------
137
138
std::string cStdVectorWatcherBase::info() const
139
{
140
    if (size()==0)
141
        return std::string("empty");
142
    std::stringstream out;
143
    out << "size=" << size();
144
    return out.str();
145
}
146
147
std::string cStdVectorWatcherBase::detailedInfo() const
148
{
149
    std::stringstream out;
150
    int n = size()<=3 ? size() : 3;
151
    for (int i=0; i<n; i++)
152
        out << getFullName() << "[" << i << "] = " << at(i) << "\n";
153
    if (size()>3)
154
        out << "...\n";
155
    return out.str();
156
}
157
158
cClassDescriptor *cStdVectorWatcherBase::getDescriptor()
159
{
160
    return cClassDescriptor::getDescriptorFor("cStdVectorWatcher");
161
}