Project

General

Profile

Statistics
| Branch: | Revision:

root / src / sim / cconfigoption.cc @ fbe00e73

History | View | Annotate | Download (2.14 KB)

1
//=========================================================================
2
//  CCONFIGOPTION.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) 2003-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 "cconfigoption.h"
21

    
22
USING_NAMESPACE
23

    
24

    
25
cConfigOption::cConfigOption(const char *name, bool isPerObject, bool isGlobal, Type type, const char *unit,
26
                       const char *defaultValue, const char *description) :
27
    cNoncopyableOwnedObject(name, false)
28
{
29
    isPerObject_ = isPerObject;
30
    isGlobal_ = isGlobal;
31
    type_ = type;
32
    unit_ = unit ? unit : "";
33
    if (type_==CFG_BOOL && defaultValue)
34
        defaultValue = (defaultValue[0]=='0' || defaultValue[0]=='f') ? "false" : "true";
35
    defaultValue_ = defaultValue ? defaultValue : "";
36
    description_ = description ? description : "";
37
}
38

    
39
std::string cConfigOption::info() const
40
{
41
    std::stringstream out;
42
    out << (isPerObject_ ? "per-object " : "");
43
    out << (isGlobal_ ? "global" : "per-run");
44
    out << ", type=" << getTypeName(type_);
45
    if (!unit_.empty()) out << ", unit=\"" << unit_ << "\"";
46
    if (!defaultValue_.empty()) out << ", default=\"" << defaultValue_ << "\"";
47
    if (!description_.empty()) out << ", hint: " << description_;
48
    return out.str();
49
}
50

    
51
const char *cConfigOption::getTypeName(Type type)
52
{
53
    switch (type)
54
    {
55
        case CFG_BOOL:      return "bool";
56
        case CFG_INT:       return "int";
57
        case CFG_DOUBLE:    return "double";
58
        case CFG_STRING:    return "string";
59
        case CFG_FILENAME:  return "filename";
60
        case CFG_FILENAMES: return "filenames";
61
        case CFG_PATH:      return "path";
62
        case CFG_CUSTOM:    return "custom";
63
        default:            return "???";
64
    }
65
}