Project

General

Profile

Statistics
| Branch: | Revision:

root / src / scave / fields.cc @ a3be1d55

History | View | Annotate | Download (7.33 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  FIELDS.CC - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//  Author: Tamas Borbely
7
//
8
//==========================================================================
9
10
/*--------------------------------------------------------------*
11
  Copyright (C) 2006-2008 OpenSim Ltd.
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16
17
#include <algorithm>
18
#include <stdio.h>
19
#include <stdlib.h>
20
#include <string.h>
21
#include <assert.h>
22
#include "commonutil.h"
23
#include "stringutil.h"
24
#include "fields.h"
25
26
USING_NAMESPACE
27
28
using namespace std;
29
30
/*----------------------------------------
31
 *            ResultItemAttribute
32
 *----------------------------------------*/
33
const char * const ResultItemAttribute::TYPE  = "type";
34
const char * const ResultItemAttribute::ENUM = "enum";
35
36
StringVector ResultItemAttribute::getAttributeNames()
37
{
38
    StringVector names = StringVector();
39
    names.push_back(TYPE);
40
    names.push_back(ENUM);
41
    return names;
42
}
43
44
bool ResultItemAttribute::isAttributeName(const string name)
45
{
46
    return name == TYPE || name == ENUM;
47
}
48
49
/*----------------------------------------
50
 *              RunAttribute
51
 *----------------------------------------*/
52
53
//TODO: table to be kept consistent with ConfigVarDescription table in sectionbasedconfig.cc; use common source?
54
const char * const RunAttribute::INIFILE     = "inifile";
55
const char * const RunAttribute::CONFIGNAME  = "configname";
56
const char * const RunAttribute::RUNNUMBER   = "runnumber";
57
const char * const RunAttribute::NETWORK     = "network";
58
const char * const RunAttribute::EXPERIMENT  = "experiment";
59
const char * const RunAttribute::MEASUREMENT = "measurement";
60
const char * const RunAttribute::REPLICATION = "replication";
61
const char * const RunAttribute::DATETIME    = "datetime";
62
const char * const RunAttribute::PROCESSID   = "processid";
63
const char * const RunAttribute::RESULTDIR   = "resultdir";
64
const char * const RunAttribute::REPETITION  = "repetition";
65
const char * const RunAttribute::SEEDSET     = "seedset";
66
const char * const RunAttribute::ITERATIONVARS = "iterationvars";
67
const char * const RunAttribute::ITERATIONVARS2 = "iterationvars2";
68
69
StringVector RunAttribute::getAttributeNames()
70
{
71
    StringVector names = StringVector();
72
    names.push_back(INIFILE);
73
    names.push_back(CONFIGNAME);
74
    names.push_back(RUNNUMBER);
75
    names.push_back(NETWORK);
76
    names.push_back(EXPERIMENT);
77
    names.push_back(MEASUREMENT);
78
    names.push_back(REPLICATION);
79
    names.push_back(DATETIME);
80
    names.push_back(PROCESSID);
81
    names.push_back(RESULTDIR);
82
    names.push_back(REPETITION);
83
    names.push_back(SEEDSET);
84
    names.push_back(ITERATIONVARS);
85
    names.push_back(ITERATIONVARS2);
86
    return names;
87
}
88
89
bool RunAttribute::isAttributeName(const string name)
90
{
91
    return name == INIFILE || name == CONFIGNAME || name == RUNNUMBER || name == NETWORK ||
92
           name == EXPERIMENT || name == MEASUREMENT || name == REPLICATION ||
93
           name == DATETIME || name == PROCESSID || name == RESULTDIR ||
94
           name == REPETITION || name == SEEDSET || name == ITERATIONVARS ||
95
           name == ITERATIONVARS2;
96
}
97
98
/*----------------------------------------
99
 *              ResultItemField
100
 *----------------------------------------*/
101
const char * const ResultItemField::FILE   = "file";
102
const char * const ResultItemField::RUN    = "run";
103
const char * const ResultItemField::MODULE = "module";
104
const char * const ResultItemField::NAME   = "name";
105
106
ResultItemField::ResultItemField(const string fieldName)
107
{
108
    this->id = getFieldID(fieldName);
109
    this->name = fieldName;
110
}
111
112
int ResultItemField::getFieldID(const string fieldName)
113
{
114
    if (fieldName == ResultItemField::FILE) return ResultItemField::FILE_ID;
115
    else if (fieldName == ResultItemField::RUN) return ResultItemField::RUN_ID;
116
    else if (fieldName == ResultItemField::MODULE) return ResultItemField::MODULE_ID;
117
    else if (fieldName == ResultItemField::NAME) return ResultItemField::NAME_ID;
118
    else if (ResultItemAttribute::isAttributeName(fieldName)) return ResultItemField::ATTR_ID;
119
    else if (fieldName.find_first_of('.') != string::npos) return ResultItemField::RUN_PARAM_ID;
120
    else return ResultItemField::RUN_ATTR_ID;
121
}
122
123
124
/*----------------------------------------
125
 *              ResultItemFields
126
 *----------------------------------------*/
127
128
StringVector ResultItemFields::getFieldNames()
129
{
130
    StringVector names = StringVector();
131
    names.push_back(ResultItemField::FILE);
132
    names.push_back(ResultItemField::RUN);
133
    names.push_back(ResultItemField::MODULE);
134
    names.push_back(ResultItemField::NAME);
135
    StringVector attrNames = ResultItemAttribute::getAttributeNames();
136
    names.insert(names.end(), attrNames.begin(), attrNames.end());
137
    attrNames = RunAttribute::getAttributeNames();
138
    names.insert(names.end(), attrNames.begin(), attrNames.end());
139
    return names;
140
}
141
142
ResultItemFields::ResultItemFields(ResultItemField field)
143
{
144
    this->fields.push_back(field);
145
}
146
147
ResultItemFields::ResultItemFields(const string fieldName)
148
{
149
    this->fields.push_back(ResultItemField(fieldName));
150
}
151
152
ResultItemFields::ResultItemFields(const StringVector &fieldNames)
153
{
154
    for (StringVector::const_iterator fieldName = fieldNames.begin(); fieldName != fieldNames.end(); ++fieldName)
155
        this->fields.push_back(ResultItemField(*fieldName));
156
}
157
158
bool ResultItemFields::hasField(ResultItemField field) const
159
{
160
    return hasField(field.getName());
161
}
162
163
bool ResultItemFields::hasField(const string fieldName) const
164
{
165
    for (vector<ResultItemField>::const_iterator field = fields.begin(); field != fields.end(); ++field)
166
        if (field->getName() == fieldName)
167
            return true;
168
    return false;
169
}
170
171
ResultItemFields ResultItemFields::complement() const
172
{
173
    StringVector complementFields;
174
    StringVector fieldNames = getFieldNames();
175
    for (StringVector::const_iterator fieldName = fieldNames.begin(); fieldName != fieldNames.end(); ++fieldName)
176
        if (!hasField(*fieldName))
177
            complementFields.push_back(*fieldName);
178
    return ResultItemFields(complementFields);
179
}
180
181
bool ResultItemFields::equal(ID id1, ID id2, ResultFileManager *manager) const
182
{
183
    if (id1==-1 || id2==-1 || id1 == id2) return id1==id2;
184
    const ResultItem& d1 = manager->getItem(id1);
185
    const ResultItem& d2 = manager->getItem(id2);
186
    return equal(d1, d2);
187
}
188
189
bool ResultItemFields::equal(const ResultItem& d1, const ResultItem& d2) const
190
{
191
    for (vector<ResultItemField>::const_iterator field = fields.begin(); field != fields.end(); ++field)
192
        if (!field->equal(d1, d2))
193
            return false;
194
    return true;
195
}
196
197
bool ResultItemFields::less(ID id1, ID id2, ResultFileManager *manager) const
198
{
199
    if (id1==-1 || id2==-1) return id2!=-1; // -1 is the smallest
200
    if (id1 == id2) return false;
201
    const ResultItem& d1 = manager->getItem(id1);
202
    const ResultItem& d2 = manager->getItem(id2);
203
    return less(d1, d2);
204
}
205
206
bool ResultItemFields::less(const ResultItem &d1, const ResultItem &d2) const
207
{
208
    for (vector<ResultItemField>::const_iterator field = fields.begin(); field != fields.end(); ++field)
209
    {
210
        int cmp = field->compare(d1, d2);
211
        if (cmp)
212
            return cmp < 0;
213
    }
214
    return false; // ==
215
}