Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * iface_field_wrapper.h - Wrapper for a Fawkes interface field for XABSL 00004 * 00005 * Created: Thu Aug 07 18:50:52 2008 00006 * Copyright 2006-2008 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #ifndef __PLUGINS_XABSL_IFACE_FIELD_WRAPPER_H_ 00024 #define __PLUGINS_XABSL_IFACE_FIELD_WRAPPER_H_ 00025 00026 #include <interface/field_pointer.h> 00027 #include <XabslEngine/XabslSymbols.h> 00028 00029 /** Interface field wrapper for Xabsl. 00030 * This wraps a field of an iterface in a Xabsl function provider such that 00031 * the field can be used as input and/or output symbol in Xabsl. 00032 * This class does an implicit conversion of types. For instance in a 00033 * BlackBoard interface floats are stored, while Xabsl requires doubles. With 00034 * an explicit casting conversion code is generated by the compiler to make it 00035 * work. 00036 * @author Tim Niemueller. 00037 */ 00038 template <typename XabslType, typename FieldType> 00039 class XabslInterfaceFieldWrapper : public xabsl::FunctionProvider 00040 { 00041 public: 00042 /** Constructor. 00043 * @param type value type of the field 00044 * @param name name of the field 00045 * @param value pointer to the value of the field 00046 */ 00047 XabslInterfaceFieldWrapper(fawkes::Interface::interface_fieldtype_t type, 00048 const char *name, FieldType *value) 00049 { 00050 __pointer = new fawkes::InterfaceFieldPointer<FieldType>(type, name, value); 00051 } 00052 00053 /** Destructor. */ 00054 ~XabslInterfaceFieldWrapper() 00055 { 00056 delete __pointer; 00057 } 00058 00059 /** Get name of the field. 00060 * @return name of the field. 00061 */ 00062 const char * get_name() const 00063 { 00064 return __pointer->get_name(); 00065 } 00066 00067 /** Get type of the field. 00068 * @return type of the field. 00069 */ 00070 fawkes::Interface::interface_fieldtype_t get_type() const 00071 { 00072 return __pointer->get_type(); 00073 } 00074 00075 /** Get current value. 00076 * @return current value in the Xabsl type 00077 */ 00078 XabslType get_value() const 00079 { 00080 return (XabslType)__pointer->get_value(); 00081 } 00082 00083 /** Set new value. 00084 * @param new_value new value, converted to field type 00085 */ 00086 void set_value(XabslType new_value) 00087 { 00088 __pointer->set_value((FieldType)new_value); 00089 } 00090 00091 private: 00092 fawkes::InterfaceFieldPointer<FieldType> *__pointer; 00093 }; 00094 00095 #endif