OpenZWave Library 1.6.1914
ValueList.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2//
3// ValueList.h
4//
5// Represents a list of items
6//
7// Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
8//
9// SOFTWARE NOTICE AND LICENSE
10//
11// This file is part of OpenZWave.
12//
13// OpenZWave is free software: you can redistribute it and/or modify
14// it under the terms of the GNU Lesser General Public License as published
15// by the Free Software Foundation, either version 3 of the License,
16// or (at your option) any later version.
17//
18// OpenZWave is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU Lesser General Public License for more details.
22//
23// You should have received a copy of the GNU Lesser General Public License
24// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
25//
26//-----------------------------------------------------------------------------
27
28#ifndef _ValueList_H
29#define _ValueList_H
30
31#include <string>
32#include <vector>
33#include "Defs.h"
34#include "value_classes/Value.h"
35
36class TiXmlElement;
37
38namespace OpenZWave
39{
40 namespace Internal
41 {
42 namespace VC
43 {
44
48 class ValueList: public Value
49 {
50 public:
53 struct Item
54 {
55 string m_label;
57 };
58
59 ValueList(uint32 const _homeId, uint8 const _nodeId, ValueID::ValueGenre const _genre, uint8 const _commandClassId, uint8 const _instance, uint16 const _index, string const& _label, string const& _units, bool const _readOnly, bool const _writeOnly, vector<Item> const& _items, int32 const _valueIdx, uint8 const _pollIntensity, uint8 const _size = 4);
60 ValueList();
61 virtual ~ValueList()
62 {
63 }
64
65 bool SetByLabel(string const& _label);
66 bool SetByValue(int32 const _value);
67
68 void OnValueRefreshed(int32 const _valueIdx);
69
70 // From Value
71 virtual string const GetAsString() const
72 {
73 return GetItem()->m_label;
74 }
75 virtual bool SetFromString(string const& _value)
76 {
77 return SetByLabel(_value);
78 }
79 void SetTargetValue(int32 const _target, uint32 _duration = 0);
80
81 virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const* _valueElement);
82 virtual void WriteXML(TiXmlElement* _valueElement);
83
84 Item const* GetItem() const;
85
86 int32 GetItemIdxByLabel(string const& _label) const;
87 int32 GetItemIdxByValue(int32 const _value) const;
88
89 bool GetItemLabels(vector<string>* o_items);
90 bool GetItemValues(vector<int32>* o_values);
91
92 uint8 GetSize() const
93 {
94 return m_size;
95 }
96
97 private:
98 vector<Item> m_items;
99 int32 m_valueIdx; // the current index in the m_items vector
100 int32 m_valueIdxCheck; // the previous index in the m_items vector (used for double-checking spurious value reads)
101 uint8 m_size;
102 int32 m_targetValue; // the Target Value, if the CC support it
103
104 };
105 } // namespace VC
106 } // namespace Internal
107} // namespace OpenZWave
108
109#endif
110
unsigned short uint16
Definition: Defs.h:88
unsigned int uint32
Definition: Defs.h:91
signed int int32
Definition: Defs.h:90
unsigned char uint8
Definition: Defs.h:85
List of values sent to/received from a node.
Definition: ValueList.h:49
int32 GetItemIdxByValue(int32 const _value) const
Definition: ValueList.cpp:321
Item const * GetItem() const
Definition: ValueList.cpp:376
virtual void WriteXML(TiXmlElement *_valueElement)
Definition: ValueList.cpp:199
ValueList()
Definition: ValueList.cpp:64
void SetTargetValue(int32 const _target, uint32 _duration=0)
Definition: ValueList.cpp:263
uint8 GetSize() const
Definition: ValueList.h:92
bool SetByValue(int32 const _value)
Definition: ValueList.cpp:226
bool GetItemValues(vector< int32 > *o_values)
Definition: ValueList.cpp:357
bool SetByLabel(string const &_label)
Definition: ValueList.cpp:245
virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const *_valueElement)
Definition: ValueList.cpp:74
virtual string const GetAsString() const
Definition: ValueList.h:71
int32 GetItemIdxByLabel(string const &_label) const
Definition: ValueList.cpp:304
virtual bool SetFromString(string const &_value)
Definition: ValueList.h:75
virtual ~ValueList()
Definition: ValueList.h:61
bool GetItemLabels(vector< string > *o_items)
Definition: ValueList.cpp:338
Base class for values associated with a node.
Definition: Value.h:55
void OnValueRefreshed()
Definition: Value.cpp:351
ValueGenre
Definition: ValueID.h:85
Definition: Bitfield.cpp:31
An item (element) in the list of values.
Definition: ValueList.h:54
int32 m_value
Definition: ValueList.h:56
string m_label
Definition: ValueList.h:55