Fawkes API Fawkes Development Version
field_pointer.h
1
2/***************************************************************************
3 * field_pointer.h - BlackBoard Interface Field Pointer
4 *
5 * Created: Mon Oct 09 18:34:11 2006
6 * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#ifndef _INTERFACE_FIELD_POINTER_H_
25#define _INTERFACE_FIELD_POINTER_H_
26
27#include <interface/interface.h>
28#include <interface/types.h>
29
30namespace fawkes {
31
32/** Direct pointer to an interface field.
33 * This class allows for keeping a pointer to an interface value which is
34 * valid for the whole lifetime of the interface.
35 * @author Tim Niemueller
36 */
37template <typename FieldType>
39{
40public:
41 /** Constructor.
42 * @param type value type of the field
43 * @param name name of the field
44 * @param value pointer to the value of the field
45 */
46 InterfaceFieldPointer(interface_fieldtype_t type, const char *name, FieldType *value)
47 {
48 type_ = type;
49 name_ = name;
50 value_ = value;
51 }
52
53 /** Get the type of the field.
54 * @return type of the field
55 */
57 get_type() const
58 {
59 return type_;
60 }
61
62 /** Get name of the field.
63 * @return name of the field.
64 */
65 const char *
66 get_name() const
67 {
68 return name_;
69 }
70
71 /** Get current value of the field.
72 * @return current vlaue of the field.
73 */
74 FieldType
75 get_value() const
76 {
77 return *value_;
78 }
79
80 /** Set value of the field.
81 * @param value new value to set for the field.
82 */
83 void
84 set_value(FieldType value)
85 {
86 *value_ = value;
87 }
88
89private:
91 const char * name_;
92 volatile FieldType * value_;
93};
94
95} // end namespace fawkes
96
97#endif
Direct pointer to an interface field.
Definition: field_pointer.h:39
interface_fieldtype_t get_type() const
Get the type of the field.
Definition: field_pointer.h:57
FieldType get_value() const
Get current value of the field.
Definition: field_pointer.h:75
void set_value(FieldType value)
Set value of the field.
Definition: field_pointer.h:84
const char * get_name() const
Get name of the field.
Definition: field_pointer.h:66
InterfaceFieldPointer(interface_fieldtype_t type, const char *name, FieldType *value)
Constructor.
Definition: field_pointer.h:46
Fawkes library namespace.
interface_fieldtype_t
Interface field type.
Definition: types.h:36