Project

General

Profile

Statistics
| Branch: | Revision:

root / src / sim / cparimpl.cc @ fbe00e73

History | View | Annotate | Download (3.61 KB)

1
//=========================================================================
2
//  CPARIMPL.CC - part of
3
//
4
//                  OMNeT++/OMNEST
5
//           Discrete System Simulation in C++
6
//
7
//  Author: Andras Varga
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 <sstream>
20
#include "cparimpl.h"
21
#include "cproperties.h"
22
#include "ccomponent.h"
23
#include "csimulation.h"
24

    
25
#ifdef WITH_PARSIM
26
#include "ccommbuffer.h"
27
#endif
28

    
29
USING_NAMESPACE
30

    
31
long cParImpl::total_parimpl_objs;
32
long cParImpl::live_parimpl_objs;
33
cDummyStringPool cParImpl::unitStringPool("cParImpl::unitStringPool");
34

    
35

    
36
cParImpl::cParImpl()
37
{
38
    unitp = NULL;
39
    total_parimpl_objs++;
40
    live_parimpl_objs++;
41
}
42

    
43
cParImpl::~cParImpl()
44
{
45
    unitStringPool.release(unitp);
46
    live_parimpl_objs--;
47
}
48

    
49
cParImpl& cParImpl::operator=(const cParImpl& other)
50
{
51
    bool shared = isShared();
52
    cNamedObject::operator=(other);
53
    setIsShared(shared); // preserve FL_ISSHARED flag
54
    setUnit(other.getUnit());
55
    return *this;
56
}
57

    
58
void cParImpl::parsimPack(cCommBuffer *buffer)
59
{
60
    //TBD
61
}
62

    
63
void cParImpl::parsimUnpack(cCommBuffer *buffer)
64
{
65
    //TBD
66
}
67

    
68
std::string cParImpl::info() const
69
{
70
    return str();
71
}
72

    
73
std::string cParImpl::detailedInfo() const
74
{
75
    std::stringstream out;
76
    out << cPar::getTypeName(getType()) << " " << getName();
77
    if (containsValue())
78
    {
79
        if (isSet())
80
            out << " = " << str();
81
        else
82
            out << " = default(" << str() << ")";
83
        out << " isExpression=" << (isExpression()?"true":"false");
84
    }
85
    else
86
    {
87
        out << " (unassigned)";
88
    }
89
    return out.str();
90
}
91

    
92
cParImpl *cParImpl::dup() const
93
{
94
    throw cRuntimeError(this, eCANTDUP);  // cannot instantiate an abstract class
95
}
96

    
97
const char *cParImpl::getUnit() const
98
{
99
    return unitp;
100
}
101

    
102
void cParImpl::setUnit(const char *s)
103
{
104
    unitStringPool.release(unitp);
105
    unitp = unitStringPool.get(s);
106
}
107

    
108
bool cParImpl::containsConstSubexpressions() const
109
{
110
    cExpression *expr = getExpression();
111
    return expr==NULL ? false : expr->containsConstSubexpressions();
112
}
113

    
114
void cParImpl::evaluateConstSubexpressions(cComponent *context)
115
{
116
    cExpression *expr = getExpression();
117
    if (expr)
118
        expr->evaluateConstSubexpressions(context);
119
}
120

    
121
int cParImpl::compare(const cParImpl *other) const
122
{
123
    int res = strcmp(getName(), other->getName());
124
    if (res!=0)
125
        return res;
126

    
127
    unsigned short flags2 = flags & ~FL_ISSHARED; // ignore "isShared" flag
128
    unsigned short otherflags2 = other->flags & ~FL_ISSHARED;
129
    if (flags2!=otherflags2)
130
        return flags2 < otherflags2 ? -1 : 1;
131

    
132
    if (getType()!=other->getType())
133
        return getType() < other->getType() ? -1 : 1;
134

    
135
    return opp_strcmp(unitp, other->unitp);
136
}
137

    
138
//----
139
#include "cboolparimpl.h"
140
#include "clongparimpl.h"
141
#include "cdoubleparimpl.h"
142
#include "cstringparimpl.h"
143
#include "cxmlparimpl.h"
144

    
145
cParImpl *cParImpl::createWithType(Type type)
146
{
147
    switch (type)
148
    {
149
        case cPar::BOOL:    return new cBoolParImpl();
150
        case cPar::DOUBLE:  return new cDoubleParImpl();
151
        case cPar::LONG:    return new cLongParImpl();
152
        case cPar::STRING:  return new cStringParImpl();
153
        case cPar::XML:     return new cXMLParImpl();
154
        default: throw cRuntimeError("cParImpl::createWithType(): no such type: %d", type);
155
    }
156
}
157