Statistics
| Branch: | Revision:

root / src / envir / matchablefield.cc @ 68da4f12

History | View | Annotate | Download (2.06 KB)

1
//==========================================================================
2
//  MATCHABLEFIELD.CC - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//==========================================================================
9

    
10
/*--------------------------------------------------------------*
11
  Copyright (C) 1992-2008 Andras Varga
12
  Copyright (C) 2006-2008 OpenSim Ltd.
13

14
  This file is distributed WITHOUT ANY WARRANTY. See the file
15
  `license' for details on this and other legal matters.
16
*--------------------------------------------------------------*/
17

    
18
#include "commonutil.h"
19
#include "matchablefield.h"
20
#include "cclassdescriptor.h"
21

    
22
USING_NAMESPACE
23

    
24
MatchableFieldAdapter::MatchableFieldAdapter(cObject *object, int fieldIndex)
25
{
26
    setField(object, fieldIndex);
27
}
28

    
29
void MatchableFieldAdapter::setField(cObject *object, int fieldIndex)
30
{
31
    Assert(object);
32
    this->object = object;
33
    this->fieldIndex = fieldIndex;
34
    this->classDescriptor = object->getDescriptor();
35
}
36

    
37
void MatchableFieldAdapter::setField(cObject *object, const char *fieldName)
38
{
39
    Assert(object);
40
    this->object = object;
41
    this->fieldIndex = -1;
42
    this->classDescriptor = object->getDescriptor();
43

    
44
    for (int i = 0; i < classDescriptor->getFieldCount(object); i++)
45
        if (!strcmp(fieldName, classDescriptor->getFieldName(object, i)))
46
            this->fieldIndex = i;
47

    
48
    Assert(fieldIndex != -1);
49
}
50

    
51
const char *MatchableFieldAdapter::getDefaultAttribute() const
52
{
53
    Assert(object && classDescriptor);
54
    return classDescriptor->getFieldName(object, fieldIndex);
55
}
56

    
57
const char *MatchableFieldAdapter::getAttribute(const char *name) const
58
{
59
    Assert(object && classDescriptor);
60

    
61
    if (!strcmp("name", name))
62
        return classDescriptor->getFieldName(object, fieldIndex);
63
    else if (!strcmp("type", name))
64
        return classDescriptor->getFieldTypeString(object, fieldIndex);
65
    else if (!strcmp("declaredOn", name))
66
        return classDescriptor->getFieldDeclaredOn(object, fieldIndex);
67
    else
68
        return NULL;
69
}