Position2DTrackInterface.cpp

00001
00002 /***************************************************************************
00003  *  Position2DTrackInterface.cpp - Fawkes BlackBoard Interface - Position2DTrackInterface
00004  *
00005  *  Templated created:   Thu Oct 12 10:49:19 2006
00006  *  Copyright  2009  Masrur Doostdar
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 #include <interfaces/Position2DTrackInterface.h>
00025
00026 #include <core/exceptions/software.h>
00027
00028 #include <cstring>
00029 #include <cstdlib>
00030
00031 namespace fawkes {
00032 
00033 /** @class Position2DTrackInterface <interfaces/Position2DTrackInterface.h>
00034  * Position2DTrackInterface Fawkes BlackBoard Interface.
00035  * 
00036       This interface provides access to a track of 2D positions.
00037     
00038  * @ingroup FawkesInterfaces
00039  */
00040
00041
00042 
00043 /** Constructor */
00044 Position2DTrackInterface::Position2DTrackInterface() : Interface()
00045 {
00046   data_size = sizeof(Position2DTrackInterface_data_t);
00047   data_ptr  = malloc(data_size);
00048   data      = (Position2DTrackInterface_data_t *)data_ptr;
00049   memset(data_ptr, 0, data_size);
00050   add_fieldinfo(IFT_FLOAT, "track_x_positions", 30, &data->track_x_positions);
00051   add_fieldinfo(IFT_FLOAT, "track_y_positions", 30, &data->track_y_positions);
00052   add_fieldinfo(IFT_INT, "track_timestamps", 30, &data->track_timestamps);
00053   add_fieldinfo(IFT_BOOL, "valid", 1, &data->valid);
00054   add_fieldinfo(IFT_UINT, "length", 1, &data->length);
00055   add_fieldinfo(IFT_UINT, "track_id", 1, &data->track_id);
00056   unsigned char tmp_hash[] = {0xda, 0x9e, 0x3f, 0x1e, 0x79, 0x8e, 0x9f, 0xd6, 0xec, 0xa6, 0x1f, 0xd2, 0x53, 0x7, 0x41, 0x2d};
00057   set_hash(tmp_hash);
00058 }
00059 
00060 /** Destructor */
00061 Position2DTrackInterface::~Position2DTrackInterface()
00062 {
00063   free(data_ptr);
00064 }
00065 /* Methods */
00066 /** Get track_x_positions value.
00067  * 
00068       X-Positions of the track. The first array-element is the oldest position of the track, 
00069       the last is the newest.
00070     
00071  * @return track_x_positions value
00072  */
00073 float *
00074 Position2DTrackInterface::track_x_positions() const
00075 {
00076   return data->track_x_positions;
00077 }
00078 
00079 /** Get track_x_positions value at given index.
00080  * 
00081       X-Positions of the track. The first array-element is the oldest position of the track, 
00082       the last is the newest.
00083     
00084  * @param index index of value
00085  * @return track_x_positions value
00086  * @exception Exception thrown if index is out of bounds
00087  */
00088 float
00089 Position2DTrackInterface::track_x_positions(unsigned int index) const
00090 {
00091   if (index > 30) {
00092     throw Exception("Index value %u out of bounds (0..30)", index);
00093   }
00094   return data->track_x_positions[index];
00095 }
00096 
00097 /** Get maximum length of track_x_positions value.
00098  * @return length of track_x_positions value, can be length of the array or number of 
00099  * maximum number of characters for a string
00100  */
00101 size_t
00102 Position2DTrackInterface::maxlenof_track_x_positions() const
00103 {
00104   return 30;
00105 }
00106 
00107 /** Set track_x_positions value.
00108  * 
00109       X-Positions of the track. The first array-element is the oldest position of the track, 
00110       the last is the newest.
00111     
00112  * @param new_track_x_positions new track_x_positions value
00113  */
00114 void
00115 Position2DTrackInterface::set_track_x_positions(const float * new_track_x_positions)
00116 {
00117   memcpy(data->track_x_positions, new_track_x_positions, sizeof(float) * 30);
00118 }
00119 
00120 /** Set track_x_positions value at given index.
00121  * 
00122       X-Positions of the track. The first array-element is the oldest position of the track, 
00123       the last is the newest.
00124     
00125  * @param new_track_x_positions new track_x_positions value
00126  * @param index index for of the value
00127  */
00128 void
00129 Position2DTrackInterface::set_track_x_positions(unsigned int index, const float new_track_x_positions)
00130 {
00131   if (index > 30) {
00132     throw Exception("Index value %u out of bounds (0..30)", index);
00133   }
00134   data->track_x_positions[index] = new_track_x_positions;
00135 }
00136 /** Get track_y_positions value.
00137  * 
00138       Y-Positions of the track. The first array-element is the oldest position of the track, 
00139       the last is the newest.
00140     
00141  * @return track_y_positions value
00142  */
00143 float *
00144 Position2DTrackInterface::track_y_positions() const
00145 {
00146   return data->track_y_positions;
00147 }
00148 
00149 /** Get track_y_positions value at given index.
00150  * 
00151       Y-Positions of the track. The first array-element is the oldest position of the track, 
00152       the last is the newest.
00153     
00154  * @param index index of value
00155  * @return track_y_positions value
00156  * @exception Exception thrown if index is out of bounds
00157  */
00158 float
00159 Position2DTrackInterface::track_y_positions(unsigned int index) const
00160 {
00161   if (index > 30) {
00162     throw Exception("Index value %u out of bounds (0..30)", index);
00163   }
00164   return data->track_y_positions[index];
00165 }
00166 
00167 /** Get maximum length of track_y_positions value.
00168  * @return length of track_y_positions value, can be length of the array or number of 
00169  * maximum number of characters for a string
00170  */
00171 size_t
00172 Position2DTrackInterface::maxlenof_track_y_positions() const
00173 {
00174   return 30;
00175 }
00176 
00177 /** Set track_y_positions value.
00178  * 
00179       Y-Positions of the track. The first array-element is the oldest position of the track, 
00180       the last is the newest.
00181     
00182  * @param new_track_y_positions new track_y_positions value
00183  */
00184 void
00185 Position2DTrackInterface::set_track_y_positions(const float * new_track_y_positions)
00186 {
00187   memcpy(data->track_y_positions, new_track_y_positions, sizeof(float) * 30);
00188 }
00189 
00190 /** Set track_y_positions value at given index.
00191  * 
00192       Y-Positions of the track. The first array-element is the oldest position of the track, 
00193       the last is the newest.
00194     
00195  * @param new_track_y_positions new track_y_positions value
00196  * @param index index for of the value
00197  */
00198 void
00199 Position2DTrackInterface::set_track_y_positions(unsigned int index, const float new_track_y_positions)
00200 {
00201   if (index > 30) {
00202     throw Exception("Index value %u out of bounds (0..30)", index);
00203   }
00204   data->track_y_positions[index] = new_track_y_positions;
00205 }
00206 /** Get track_timestamps value.
00207  * 
00208       Timestamps of the track. The first array-element is the oldest position of the track, 
00209       the last is the newest.
00210     
00211  * @return track_timestamps value
00212  */
00213 int *
00214 Position2DTrackInterface::track_timestamps() const
00215 {
00216   return data->track_timestamps;
00217 }
00218 
00219 /** Get track_timestamps value at given index.
00220  * 
00221       Timestamps of the track. The first array-element is the oldest position of the track, 
00222       the last is the newest.
00223     
00224  * @param index index of value
00225  * @return track_timestamps value
00226  * @exception Exception thrown if index is out of bounds
00227  */
00228 int
00229 Position2DTrackInterface::track_timestamps(unsigned int index) const
00230 {
00231   if (index > 30) {
00232     throw Exception("Index value %u out of bounds (0..30)", index);
00233   }
00234   return data->track_timestamps[index];
00235 }
00236 
00237 /** Get maximum length of track_timestamps value.
00238  * @return length of track_timestamps value, can be length of the array or number of 
00239  * maximum number of characters for a string
00240  */
00241 size_t
00242 Position2DTrackInterface::maxlenof_track_timestamps() const
00243 {
00244   return 30;
00245 }
00246 
00247 /** Set track_timestamps value.
00248  * 
00249       Timestamps of the track. The first array-element is the oldest position of the track, 
00250       the last is the newest.
00251     
00252  * @param new_track_timestamps new track_timestamps value
00253  */
00254 void
00255 Position2DTrackInterface::set_track_timestamps(const int * new_track_timestamps)
00256 {
00257   memcpy(data->track_timestamps, new_track_timestamps, sizeof(int) * 30);
00258 }
00259 
00260 /** Set track_timestamps value at given index.
00261  * 
00262       Timestamps of the track. The first array-element is the oldest position of the track, 
00263       the last is the newest.
00264     
00265  * @param new_track_timestamps new track_timestamps value
00266  * @param index index for of the value
00267  */
00268 void
00269 Position2DTrackInterface::set_track_timestamps(unsigned int index, const int new_track_timestamps)
00270 {
00271   if (index > 30) {
00272     throw Exception("Index value %u out of bounds (0..30)", index);
00273   }
00274   data->track_timestamps[index] = new_track_timestamps;
00275 }
00276 /** Get valid value.
00277  * True, if this track is valid.
00278  * @return valid value
00279  */
00280 bool
00281 Position2DTrackInterface::is_valid() const
00282 {
00283   return data->valid;
00284 }
00285 
00286 /** Get maximum length of valid value.
00287  * @return length of valid value, can be length of the array or number of 
00288  * maximum number of characters for a string
00289  */
00290 size_t
00291 Position2DTrackInterface::maxlenof_valid() const
00292 {
00293   return 1;
00294 }
00295 
00296 /** Set valid value.
00297  * True, if this track is valid.
00298  * @param new_valid new valid value
00299  */
00300 void
00301 Position2DTrackInterface::set_valid(const bool new_valid)
00302 {
00303   data->valid = new_valid;
00304 }
00305 
00306 /** Get length value.
00307  * Length of the Tracks (i.e. up to which index there are valid positions).
00308  * @return length value
00309  */
00310 unsigned int
00311 Position2DTrackInterface::length() const
00312 {
00313   return data->length;
00314 }
00315 
00316 /** Get maximum length of length value.
00317  * @return length of length value, can be length of the array or number of 
00318  * maximum number of characters for a string
00319  */
00320 size_t
00321 Position2DTrackInterface::maxlenof_length() const
00322 {
00323   return 1;
00324 }
00325 
00326 /** Set length value.
00327  * Length of the Tracks (i.e. up to which index there are valid positions).
00328  * @param new_length new length value
00329  */
00330 void
00331 Position2DTrackInterface::set_length(const unsigned int new_length)
00332 {
00333   data->length = new_length;
00334 }
00335 
00336 /** Get track_id value.
00337  * The ID of the Track.
00338  * @return track_id value
00339  */
00340 unsigned int
00341 Position2DTrackInterface::track_id() const
00342 {
00343   return data->track_id;
00344 }
00345 
00346 /** Get maximum length of track_id value.
00347  * @return length of track_id value, can be length of the array or number of 
00348  * maximum number of characters for a string
00349  */
00350 size_t
00351 Position2DTrackInterface::maxlenof_track_id() const
00352 {
00353   return 1;
00354 }
00355 
00356 /** Set track_id value.
00357  * The ID of the Track.
00358  * @param new_track_id new track_id value
00359  */
00360 void
00361 Position2DTrackInterface::set_track_id(const unsigned int new_track_id)
00362 {
00363   data->track_id = new_track_id;
00364 }
00365
00366 /* =========== message create =========== */
00367 Message *
00368 Position2DTrackInterface::create_message(const char *type) const
00369 {
00370   throw UnknownTypeException("The given type '%s' does not match any known "
00371                              "message type for this interface type.", type);
00372 }
00373
00374 
00375 /** Copy values from other interface.
00376  * @param other other interface to copy values from
00377  */
00378 void
00379 Position2DTrackInterface::copy_values(const Interface *other)
00380 {
00381   const Position2DTrackInterface *oi = dynamic_cast<const Position2DTrackInterface *>(other);
00382   if (oi == NULL) {
00383     throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00384                                 type(), other->type());
00385   }
00386   memcpy(data, oi->data, sizeof(Position2DTrackInterface_data_t));
00387 }
00388
00389 /* =========== messages =========== */
00390 /** Check if message is valid and can be enqueued.
00391  * @param message Message to check
00392  */
00393 bool
00394 Position2DTrackInterface::message_valid(const Message *message) const
00395 {
00396   return false;
00397 }
00398 
00399 /// @cond INTERNALS
00400 EXPORT_INTERFACE(Position2DTrackInterface)
00401 /// @endcond
00402 
00403
00404 } // end namespace fawkes