Statistics
| Branch: | Revision:

napa-baselibs / monl / mon_parameter.h @ 17af7b70

History | View | Annotate | Download (3.15 KB)

1 956892f0 ArpadBakay
/***************************************************************************
2
 *   Copyright (C) 2009 by Robert Birke
3
 *   robert.birke@polito.it
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9

10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14

15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
18
 ***********************************************************************/
19
20
#ifndef _MON_PARAMETER_H_
21
#define _MON_PARAMETER_H_
22
23
#include <string>
24
#include "mon.h"
25
#include "errors.h"
26
27
#define DEFAULT_DEFAULT_VALUE 0
28
29
class MeasurePlugin;
30
31
/* This class describes the basic MonParameterValue */
32
class MonParameter {
33
34
public:
35
        /* Constructor */
36
        MonParameter(std::string n,std::string d, MonParameterValue dv = 0): name(n), desc(d), dval(dv) {}
37
38
        /* The name of the measure e.g. window size*/
39
        const std::string name;
40
41
        /* Short description of the measure */
42
        const std::string desc;
43
44
        /* Default value */
45
        const MonParameterValue dval;
46
47
        /* Parameter handler */
48
        MonParameterType ph;
49
50
        /* Validation function */
51
        virtual int validator (MonParameterValue) {return EOK;};
52
};
53
54
/* A MonParameterValue with minimal value check v must be >= min */
55
56
class MinParameter : public MonParameter {
57
        /* the minimum acceptable value */
58
        MonParameterValue min;
59
public:
60
        /* Constructor */
61
        MinParameter(std::string n,std::string d, MonParameterValue m, MonParameterValue dv = DEFAULT_DEFAULT_VALUE):MonParameter(n,d,dv),min(m) {}
62
63
        /* Validation function */
64
        virtual int validator (MonParameterValue p) {
65
                if (p >= min)
66
                        return EOK;
67
        return -EINVAL;
68
        };
69
};
70
71
/* A MonParameterValue with maximum value check: v must be <= max */
72
73
class MaxParameter : public MonParameter {
74
        /* the maximum acceptable value */
75
        MonParameterValue max;
76
public:
77
        /* Constructor */
78
        MaxParameter(std::string n,std::string d, MonParameterValue M, MonParameterValue dv = DEFAULT_DEFAULT_VALUE):MonParameter(n,d,dv),max(M) {}
79
80
        /* Validation function */
81
        virtual int validator (MonParameterValue p) {
82
                if (p <= max)
83
                        return EOK;
84
        return -EINVAL;
85
        };
86
};
87
88
89
/* A MonParameterValue with interval value check: v must be >= min and <= max*/
90
91
class MinMaxParameter : public MonParameter {
92
        /* the minimum acceptable value */
93
        MonParameterValue min;
94
        /* the maximum acceptable value */
95
        MonParameterValue max;
96
public:
97
        /* Constructor */
98
        MinMaxParameter(std::string n,std::string d, MonParameterValue m, MonParameterValue M, MonParameterValue dv = DEFAULT_DEFAULT_VALUE):MonParameter(n,d,dv),min(m),max(M) {}
99
100
        /* Validation function */
101
        virtual int validator (MonParameterValue p) {
102
                if (p <= max && p >= min)
103
                        return EOK;
104
        return -EINVAL;
105
        };
106
};
107
#endif /* _MON_PARAMETER_HH_ */