field_pointer.h

00001 
00002 /***************************************************************************
00003  *  field_pointer.h - BlackBoard Interface Field Pointer
00004  *
00005  *  Created: Mon Oct 09 18:34:11 2006
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. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #ifndef __INTERFACE_FIELD_POINTER_H_
00025 #define __INTERFACE_FIELD_POINTER_H_
00026 
00027 #include <interface/interface.h>
00028 
00029 namespace fawkes {
00030 
00031 /** Direct pointer to an interface field.
00032  * This class allows for keeping a pointer to an interface value which is
00033  * valid for the whole lifetime of the interface.
00034  * @author Tim Niemueller
00035  */
00036 template <typename FieldType>
00037   class InterfaceFieldPointer
00038 {
00039  public:
00040   /** Constructor.
00041    * @param type value type of the field
00042    * @param name name of the field
00043    * @param value pointer to the value of the field
00044    */
00045   InterfaceFieldPointer(Interface::interface_fieldtype_t type,
00046                         const char *name,
00047                         FieldType *value)
00048   {
00049     __type       = type;
00050     __name       = name;
00051     __value      = value;
00052   }
00053 
00054   /** Get the type of the field.
00055    * @return type of the field
00056    */
00057   Interface::interface_fieldtype_t get_type() const
00058   {
00059     return __type;
00060   }
00061 
00062   /** Get name of the field.
00063    * @return name of the field.
00064    */
00065   const char * get_name() const
00066   {
00067     return __name;
00068   }
00069 
00070   /** Get current value of the field.
00071    * @return current vlaue of the field.
00072    */
00073   FieldType get_value() const
00074   {
00075     return *__value;
00076   }
00077 
00078   /** Set value of the field.
00079    * @param value new value to set for the field.
00080    */
00081   void set_value(FieldType value)
00082   {
00083     *__value = value;
00084   }
00085 
00086  private:
00087   Interface::interface_fieldtype_t  __type;
00088   const char                       *__name;
00089   volatile FieldType               *__value;
00090 };
00091 
00092 } // end namespace fawkes
00093 
00094 #endif

Generated on Tue Feb 22 13:31:26 2011 for Fawkes API by  doxygen 1.4.7