Subversion Repositories HomeAutomation

Rev

Rev 1049 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1049 Rev 1050
1
/***************************************************************************
1
/***************************************************************************
2
 *   Copyright (C) December 5, 2008 by Mattias Runge                             *
2
 *   Copyright (C) December 5, 2008 by Mattias Runge                             *
3
 *   mattias@runge.se                                                      *
3
 *   mattias@runge.se                                                      *
4
 *   canvariable.h                                            *
4
 *   canvariable.h                                            *
5
 *                                                                         *
5
 *                                                                         *
6
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   This program is free software; you can redistribute it and/or modify  *
7
 *   it under the terms of the GNU General Public License as published by  *
7
 *   it under the terms of the GNU General Public License as published by  *
8
 *   the Free Software Foundation; either version 2 of the License, or     *
8
 *   the Free Software Foundation; either version 2 of the License, or     *
9
 *   (at your option) any later version.                                   *
9
 *   (at your option) any later version.                                   *
10
 *                                                                         *
10
 *                                                                         *
11
 *   This program is distributed in the hope that it will be useful,       *
11
 *   This program is distributed in the hope that it will be useful,       *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU General Public License for more details.                          *
14
 *   GNU General Public License for more details.                          *
15
 *                                                                         *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU General Public License     *
16
 *   You should have received a copy of the GNU General Public License     *
17
 *   along with this program; if not, write to the                         *
17
 *   along with this program; if not, write to the                         *
18
 *   Free Software Foundation, Inc.,                                       *
18
 *   Free Software Foundation, Inc.,                                       *
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
20
 ***************************************************************************/
20
 ***************************************************************************/
21
 
21
 
22
#ifndef _CANVARIABLE_H
22
#ifndef _CANVARIABLE_H
23
#define _CANVARIABLE_H
23
#define _CANVARIABLE_H
24
 
24
 
25
using namespace std;
25
using namespace std;
26
 
26
 
27
#include <string>
27
#include <string>
28
#include <map>
28
#include <map>
29
 
29
 
30
#include "../Tools/tools.h"
30
#include "../Tools/tools.h"
31
 
31
 
32
class CanVariable
32
class CanVariable
33
{
33
{
34
public:
34
public:
35
    CanVariable() {};
35
    CanVariable() {};
36
    CanVariable(string name, string value)
36
    CanVariable(string name, string value)
37
    {
37
    {
38
        setName(name);
38
        setName(name);
39
        setValue(value);
39
        setValue(value);
40
    };
40
    };
41
    CanVariable(string name, string value, string type, string unit)
41
    CanVariable(string name, string value, string type, string unit)
42
    {
42
    {
43
        setName(name);
43
        setName(name);
44
        setValue(value);
44
        setValue(value);
45
        setType(type);
45
        setType(type);
46
        setUnit(unit);
46
        setUnit(unit);
47
    };
47
    };
48
    ~CanVariable() {};
48
    ~CanVariable() {};
49
 
49
 
50
    string getName() { return myName; };
50
    string getName() { return myName; };
51
    void setName(string name) { myName = name; };
51
    void setName(string name) { myName = name; };
52
 
52
 
53
    string getValue() { return myValue; };
53
    string getValue() { return myValue; };
54
    void setValue(string value) { myValue = value; };
54
    void setValue(string value) { myValue = value; };
55
 
55
 
56
    string getType() { return myType; };
56
    string getType() { return myType; };
57
    void setType(string type) { myType = type; };
57
    void setType(string type) { myType = type; };
58
 
58
 
59
    string getUnit() { return myUnit; };
59
    string getUnit() { return myUnit; };
60
    void setUnit(string unit) { myUnit = unit; };
60
    void setUnit(string unit) { myUnit = unit; };
61
 
61
 
62
    unsigned int getBitLength() { return myBitLength; };
62
    unsigned int getBitLength() { return myBitLength; };
63
    void setBitLength(int bitLength) { myBitLength = bitLength; };
63
    void setBitLength(int bitLength) { myBitLength = bitLength; };
64
 
64
 
65
    unsigned int getStartBit() { return myStartBit; };
65
    unsigned int getStartBit() { return myStartBit; };
66
    void setStartBit(int startBit) { myStartBit = startBit; };
66
    void setStartBit(int startBit) { myStartBit = startBit; };
67
 
67
 
68
    string getEnumIdValue()
68
    string getEnumIdValue()
69
    {
69
    {
70
        if (myEnumValues.find(myValue) != myEnumValues.end())
70
        for (map<string, string>::iterator iter = myEnumValues.begin(); iter != myEnumValues.end(); iter++)
71
        {
71
        {
72
            return myEnumValues[myValue];
72
            if (iter->second == myValue)
-
 
73
            {
-
 
74
                return iter->first;
-
 
75
            }
73
        }
76
        }
74
 
77
 
75
        return "";
78
        return "";
76
    }
79
    }
77
 
80
 
78
    string getEnumsString()
81
    string getEnumsString()
79
    {
82
    {
80
        string enumString = "";
83
        string enumString = "";
81
        for (map<string, string>::iterator iter; iter != myEnumValues.end(); iter++)
84
        for (map<string, string>::iterator iter = myEnumValues.begin(); iter != myEnumValues.end(); iter++)
82
        {
85
        {
83
            enumString += iter->first + "=" + iter->second + ",";
86
            enumString += iter->first + "=" + iter->second + ",";
84
        }
87
        }
85
 
88
 
86
        enumString = trim(enumString, ',');
89
        enumString = trim(enumString, ',');
87
 
90
 
88
        return enumString;
91
        return enumString;
89
    }
92
    }
90
 
93
 
91
    void addEnumValue(string id, string name)
94
    void addEnumValue(string id, string name)
92
    {
95
    {
93
        myEnumValues[id] = name;
96
        myEnumValues[id] = name;
94
    }
97
    }
95
 
98
 
96
private:
99
private:
97
    string myName;
100
    string myName;
98
    string myValue;
101
    string myValue;
99
    string myType;
102
    string myType;
100
    string myUnit;
103
    string myUnit;
101
    unsigned int myBitLength;
104
    unsigned int myBitLength;
102
    unsigned int myStartBit;
105
    unsigned int myStartBit;
103
    map<string, string> myEnumValues;
106
    map<string, string> myEnumValues;
104
};
107
};
105
 
108
 
106
#endif  /* _CANVARIABLE_H */
109
#endif  /* _CANVARIABLE_H */
107
 
110
 
108
 
111