Project

General

Profile

Statistics
| Branch: | Revision:

root / src / envir / matchableobject.h @ e26d3d25

History | View | Annotate | Download (1.71 KB)

1
//==========================================================================
2
//  MATCHABLEOBJECT.H - 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
#ifndef __MATCHABLEOBJECT_H
19
#define __MATCHABLEOBJECT_H
20

    
21
#include "envirdefs.h"
22
#include "cobject.h"
23
#include "matchexpression.h"
24

    
25
NAMESPACE_BEGIN
26

    
27
class cClassDescriptor;
28

    
29

    
30
/**
31
 * Wrapper around a cObject to make it matchable with MatchExpression.
32
 * The default attribute is either getFullName() or getFullPath().
33
 */
34
class ENVIR_API MatchableObjectAdapter : public MatchExpression::Matchable
35
{
36
  public:
37
    enum DefaultAttribute {FULLNAME, FULLPATH, CLASSNAME};
38
  protected:
39
    DefaultAttribute attr;
40
    cObject *obj;
41
    mutable cClassDescriptor *desc;
42
    mutable std::string tmp;
43
  protected:
44
    static void splitIndex(char *fieldname, int& index);
45
    static bool findDescriptorField(cClassDescriptor *desc, cObject *obj, char *fieldname, int& fieldId, int& index);
46
  public:
47
    MatchableObjectAdapter(DefaultAttribute attr=FULLPATH, cObject *obj=NULL);
48
    void setObject(cObject *obj);
49
    void setDefaultAttribute(DefaultAttribute attr) {this->attr = attr;}
50
    virtual const char *getDefaultAttribute() const;
51
    virtual const char *getAttribute(const char *name) const;
52
};
53

    
54
NAMESPACE_END
55

    
56

    
57
#endif
58