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  */
38 template <typename XabslType, typename FieldType>
39 class XabslInterfaceFieldWrapper : public xabsl::FunctionProvider
40 {
41 public:
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 
94 private:
96 };
97 
98 #endif
fawkes::interface_fieldtype_t
interface_fieldtype_t
Interface field type.
Definition: types.h:36
fawkes::InterfaceFieldPointer
Direct pointer to an interface field.
Definition: field_pointer.h:39
XabslInterfaceFieldWrapper::get_value
XabslType get_value() const
Get current value.
Definition: iface_field_wrapper.h:80
XabslInterfaceFieldWrapper::get_name
const char * get_name() const
Get name of the field.
Definition: iface_field_wrapper.h:62
XabslInterfaceFieldWrapper
Interface field wrapper for Xabsl.
Definition: iface_field_wrapper.h:40
XabslInterfaceFieldWrapper::XabslInterfaceFieldWrapper
XabslInterfaceFieldWrapper(fawkes::interface_fieldtype_t type, const char *name, FieldType *value)
Constructor.
Definition: iface_field_wrapper.h:47
XabslInterfaceFieldWrapper::get_type
fawkes::interface_fieldtype_t get_type() const
Get type of the field.
Definition: iface_field_wrapper.h:71
XabslInterfaceFieldWrapper::set_value
void set_value(XabslType new_value)
Set new value.
Definition: iface_field_wrapper.h:89
XabslInterfaceFieldWrapper::~XabslInterfaceFieldWrapper
~XabslInterfaceFieldWrapper()
Destructor.
Definition: iface_field_wrapper.h:53