Fawkes API Fawkes Development Version
iface_field_wrapper.h
1
2/***************************************************************************
3 * iface_field_wrapper.h - Wrapper for a Fawkes interface field for XABSL
4 *
5 * Created: Thu Aug 07 18:50:52 2008
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.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL file in the doc directory.
21 */
22
23#ifndef _PLUGINS_XABSL_IFACE_FIELD_WRAPPER_H_
24#define _PLUGINS_XABSL_IFACE_FIELD_WRAPPER_H_
25
26#include <XabslEngine/XabslSymbols.h>
27#include <interface/field_pointer.h>
28
29/** Interface field wrapper for Xabsl.
30 * This wraps a field of an iterface in a Xabsl function provider such that
31 * the field can be used as input and/or output symbol in Xabsl.
32 * This class does an implicit conversion of types. For instance in a
33 * BlackBoard interface floats are stored, while Xabsl requires doubles. With
34 * an explicit casting conversion code is generated by the compiler to make it
35 * work.
36 * @author Tim Niemueller.
37 */
38template <typename XabslType, typename FieldType>
39class XabslInterfaceFieldWrapper : public xabsl::FunctionProvider
40{
41public:
42 /** Constructor.
43 * @param type value type of the field
44 * @param name name of the field
45 * @param value pointer to the value of the field
46 */
47 XabslInterfaceFieldWrapper(fawkes::interface_fieldtype_t type, const char *name, FieldType *value)
48 {
49 pointer_ = new fawkes::InterfaceFieldPointer<FieldType>(type, name, value);
50 }
51
52 /** Destructor. */
54 {
55 delete pointer_;
56 }
57
58 /** Get name of the field.
59 * @return name of the field.
60 */
61 const char *
62 get_name() const
63 {
64 return pointer_->get_name();
65 }
66
67 /** Get type of the field.
68 * @return type of the field.
69 */
71 get_type() const
72 {
73 return pointer_->get_type();
74 }
75
76 /** Get current value.
77 * @return current value in the Xabsl type
78 */
79 XabslType
80 get_value() const
81 {
82 return (XabslType)pointer_->get_value();
83 }
84
85 /** Set new value.
86 * @param new_value new value, converted to field type
87 */
88 void
89 set_value(XabslType new_value)
90 {
91 pointer_->set_value((FieldType)new_value);
92 }
93
94private:
96};
97
98#endif
Interface field wrapper for Xabsl.
void set_value(XabslType new_value)
Set new value.
fawkes::interface_fieldtype_t get_type() const
Get type of the field.
const char * get_name() const
Get name of the field.
XabslInterfaceFieldWrapper(fawkes::interface_fieldtype_t type, const char *name, FieldType *value)
Constructor.
XabslType get_value() const
Get current value.
Direct pointer to an interface field.
Definition: field_pointer.h:39
interface_fieldtype_t
Interface field type.
Definition: types.h:36