OpenZWave Library  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
36 class TiXmlElement;
37 
38 namespace OpenZWave
39 {
40  class Msg;
41  class Node;
42 
45  class ValueList: public Value
46  {
47  public:
50  struct Item
51  {
52  string m_label;
54  };
55 
56  ValueList( uint32 const _homeId, uint8 const _nodeId, ValueID::ValueGenre const _genre, uint8 const _commandClassId, uint8 const _instance, uint8 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 );
57  ValueList();
58  virtual ~ValueList(){}
59 
60  bool SetByLabel( string const& _label );
61  bool SetByValue( int32 const _value );
62 
63  void OnValueRefreshed( int32 const _valueIdx );
64 
65  // From Value
66  virtual string const GetAsString() const { return GetItem()->m_label; }
67  virtual bool SetFromString( string const& _value ) { return SetByLabel( _value ); }
68  virtual void ReadXML( uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const* _valueElement );
69  virtual void WriteXML( TiXmlElement* _valueElement );
70 
71  Item const* GetItem() const;
72 
73  int32 const GetItemIdxByLabel( string const& _label );
74  int32 const GetItemIdxByValue( int32 const _value );
75 
76  bool GetItemLabels( vector<string>* o_items );
77  bool GetItemValues( vector<int32>* o_values );
78 
79  uint8 const GetSize()const{ return m_size; }
80 
81  private:
82  vector<Item> m_items;
83  int32 m_valueIdx; // the current index in the m_items vector
84  int32 m_valueIdxCheck; // the previous index in the m_items vector (used for double-checking spurious value reads)
85  int32 m_newValueIdx; // a new value to be set on the appropriate device
86  uint8 m_size;
87  };
88 
89 } // namespace OpenZWave
90 
91 #endif
92 
93 
94 
An item (element) in the list of values.
Definition: ValueList.h:50
string m_label
Definition: ValueList.h:52
int32 m_value
Definition: ValueList.h:53
Item const * GetItem() const
Definition: ValueList.cpp:379
uint8 const GetSize() const
Definition: ValueList.h:79
int32 const GetItemIdxByLabel(string const &_label)
Definition: ValueList.cpp:296
bool SetByLabel(string const &_label)
Definition: ValueList.cpp:244
virtual ~ValueList()
Definition: ValueList.h:58
void OnValueRefreshed()
Definition: Value.cpp:412
virtual void WriteXML(TiXmlElement *_valueElement)
Definition: ValueList.cpp:192
signed int int32
Definition: Defs.h:79
ValueList()
Definition: ValueList.cpp:73
unsigned int uint32
Definition: Defs.h:80
bool SetByValue(int32 const _value)
Definition: ValueList.cpp:222
virtual bool SetFromString(string const &_value)
Definition: ValueList.h:67
virtual void ReadXML(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, TiXmlElement const *_valueElement)
Definition: ValueList.cpp:89
virtual string const GetAsString() const
Definition: ValueList.h:66
Base class for values associated with a node.
Definition: Value.h:47
bool GetItemLabels(vector< string > *o_items)
Definition: ValueList.cpp:336
int32 const GetItemIdxByValue(int32 const _value)
Definition: ValueList.cpp:316
ValueGenre
Definition: ValueID.h:71
List of values sent to/received from a node.
Definition: ValueList.h:45
unsigned char uint8
Definition: Defs.h:74
bool GetItemValues(vector< int32 > *o_values)
Definition: ValueList.cpp:358