Subversion Repositories HomeAutomation

Rev

Rev 1046 | Rev 1049 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

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