Rev 1048 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1048 | Rev 1049 | ||
|---|---|---|---|
| 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 |
|
70 | if (myEnumValues.find(myValue) != myEnumValues.end()) |
| 71 | { |
71 | { |
| 72 |
|
72 | return myEnumValues[myValue]; |
| 73 | { |
- | |
| 74 | return iter->first; |
- | |
| 75 | } |
- | |
| 76 | } |
73 | } |
| 77 | 74 | ||
| 78 | return ""; |
75 | return ""; |
| 79 | } |
76 | } |
| 80 | 77 | ||
| 81 | string getEnumsString() |
78 | string getEnumsString() |
| 82 | { |
79 | { |
| 83 | string enumString = ""; |
80 | string enumString = ""; |
| 84 | for (map<string, string>::iterator iter; iter != myEnumValues.end(); iter++) |
81 | for (map<string, string>::iterator iter; iter != myEnumValues.end(); iter++) |
| 85 | { |
82 | { |
| 86 | enumString += iter->first + "=" + iter->second + ","; |
83 | enumString += iter->first + "=" + iter->second + ","; |
| 87 | } |
84 | } |
| 88 | 85 | ||
| 89 | enumString = trim(enumString, ','); |
86 | enumString = trim(enumString, ','); |
| 90 | 87 | ||
| 91 | return enumString; |
88 | return enumString; |
| 92 | } |
89 | } |
| 93 | 90 | ||
| 94 | void addEnumValue(string id, string name) |
91 | void addEnumValue(string id, string name) |
| 95 | { |
92 | { |
| 96 | myEnumValues[id] = name; |
93 | myEnumValues[id] = name; |
| 97 | } |
94 | } |
| 98 | 95 | ||
| 99 | private: |
96 | private: |
| 100 | string myName; |
97 | string myName; |
| 101 | string myValue; |
98 | string myValue; |
| 102 | string myType; |
99 | string myType; |
| 103 | string myUnit; |
100 | string myUnit; |
| 104 | unsigned int myBitLength; |
101 | unsigned int myBitLength; |
| 105 | unsigned int myStartBit; |
102 | unsigned int myStartBit; |
| 106 | map<string, string> myEnumValues; |
103 | map<string, string> myEnumValues; |
| 107 | }; |
104 | }; |
| 108 | 105 | ||
| 109 | #endif /* _CANVARIABLE_H */ |
106 | #endif /* _CANVARIABLE_H */ |
| 110 | 107 | ||
| 111 | 108 | ||