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 <interface/field_pointer.h>
27 #include <XabslEngine/XabslSymbols.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::interface_fieldtype_t type,
48  const char *name, FieldType *value)
49  {
50  __pointer = new fawkes::InterfaceFieldPointer<FieldType>(type, name, value);
51  }
52 
53  /** Destructor. */
55  {
56  delete __pointer;
57  }
58 
59  /** Get name of the field.
60  * @return name of the field.
61  */
62  const char * get_name() const
63  {
64  return __pointer->get_name();
65  }
66 
67  /** Get type of the field.
68  * @return type of the field.
69  */
70  fawkes::Interface::interface_fieldtype_t get_type() const
71  {
72  return __pointer->get_type();
73  }
74 
75  /** Get current value.
76  * @return current value in the Xabsl type
77  */
78  XabslType get_value() const
79  {
80  return (XabslType)__pointer->get_value();
81  }
82 
83  /** Set new value.
84  * @param new_value new value, converted to field type
85  */
86  void set_value(XabslType new_value)
87  {
88  __pointer->set_value((FieldType)new_value);
89  }
90 
91  private:
93 };
94 
95 #endif
Interface field wrapper for Xabsl.
~XabslInterfaceFieldWrapper()
Destructor.
XabslInterfaceFieldWrapper(fawkes::Interface::interface_fieldtype_t type, const char *name, FieldType *value)
Constructor.
const char * get_name() const
Get name of the field.
void set_value(XabslType new_value)
Set new value.
XabslType get_value() const
Get current value.
Direct pointer to an interface field.
Definition: field_pointer.h:37
fawkes::Interface::interface_fieldtype_t get_type() const
Get type of the field.