weightedsample.h
Go to the documentation of this file.
00001 // $Id: weightedsample.h 29830 2009-01-14 15:10:41Z kgadeyne $
00002 // Copyright (C) 2002 Klaas Gadeyne <first dot last at gmail dot com>
00003  /***************************************************************************
00004  *   This library is free software; you can redistribute it and/or         *
00005  *   modify it under the terms of the GNU General Public                   *
00006  *   License as published by the Free Software Foundation;                 *
00007  *   version 2 of the License.                                             *
00008  *                                                                         *
00009  *   As a special exception, you may use this file as part of a free       *
00010  *   software library without restriction.  Specifically, if other files   *
00011  *   instantiate templates or use macros or inline functions from this     *
00012  *   file, or you compile this file and link it with other files to        *
00013  *   produce an executable, this file does not by itself cause the         *
00014  *   resulting executable to be covered by the GNU General Public          *
00015  *   License.  This exception does not however invalidate any other        *
00016  *   reasons why the executable file might be covered by the GNU General   *
00017  *   Public License.                                                       *
00018  *                                                                         *
00019  *   This library is distributed in the hope that it will be useful,       *
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00022  *   Lesser General Public License for more details.                       *
00023  *                                                                         *
00024  *   You should have received a copy of the GNU General Public             *
00025  *   License along with this library; if not, write to the Free Software   *
00026  *   Foundation, Inc., 59 Temple Place,                                    *
00027  *   Suite 330, Boston, MA  02111-1307  USA                                *
00028  *                                                                         *
00029  ***************************************************************************/
00030 //
00031 
00032 #ifndef WEIGHTEDSAMPLE_H
00033 #define WEIGHTEDSAMPLE_H
00034 
00035 #include "sample.h"
00036 #include <assert.h>
00037 
00038 
00039 namespace BFL
00040 {
00041 
00048   template <typename T> class WeightedSample: virtual public Sample<T>
00049     {
00050     protected:
00052       double Weight;
00053 
00054     public:
00056 
00060       WeightedSample (int dimension = 0 );
00062       virtual ~WeightedSample();
00064       WeightedSample ( const WeightedSample<T> & my_weighted_sample );
00065 
00067 
00069       double WeightGet (  ) const;
00070 
00072 
00075       void WeightSet ( double weight );
00076 
00078 
00082       template <typename S> friend ostream & operator<< (ostream & stream,
00083                                                          WeightedSample<S> & mws);
00084 
00086       WeightedSample<T> & operator= (const WeightedSample<T> & my_sample);
00087 
00089       WeightedSample<T> & operator= (const Sample<T> & my_sample);
00090     };
00091 
00092 
00093   template <typename T> WeightedSample<T>::WeightedSample(int dimension)
00094     : Sample<T>(dimension){}
00095 
00096   template <typename T> WeightedSample<T>::~WeightedSample(){}
00097 
00098   template <typename T> WeightedSample<T>::WeightedSample (const WeightedSample<T> & mws)
00099     : Sample<T>(mws)
00100     {
00101       Weight = mws.Weight;
00102     }
00103 
00104   template <typename T> double WeightedSample<T>::WeightGet (  ) const
00105     {
00106       return Weight;
00107     }
00108 
00109   template <typename T> void WeightedSample<T>::WeightSet ( double weight )
00110     {
00111       assert(weight >= 0);
00112 
00113       Weight = weight;
00114     }
00115 
00116   template <typename S> ostream & operator<< (ostream & stream,
00117                                               WeightedSample<S> & mws)
00118     {
00119       stream << "WeightedSample Value = " << (Sample<S> &) mws
00120              << "Weight = " << mws.Weight << endl;
00121       return stream;
00122     }
00123 
00124   template <typename T> WeightedSample<T> & WeightedSample<T>::operator= (const WeightedSample<T> & my_sample)
00125     {
00126       // TODO: Does this automatically calls the = operator in the
00127       // baseclass?  NO!!!
00128       Sample<T> * op1; const Sample<T> * op2;
00129       op1 = this; op2 = & my_sample;
00130       *op1 = *op2;
00131       this->Weight = my_sample.WeightGet();
00132       return *this;
00133     }
00134 
00135   // Turn sample into weighted one (weight = 1)
00136   template <typename T> WeightedSample<T> & WeightedSample<T>::operator= (const Sample<T> & my_sample)
00137     {
00138       //: Does this automatically calls the = operator in the baseclass?
00139       Sample<T> * op1; const Sample<T> * op2;
00140       op1 = this; op2 = & my_sample;
00141       *op1 = *op2;
00142       this->Weight = 1;
00143       return *this;
00144     }
00145 
00146 } // End namespace BFL
00147 
00148 #endif


bfl
Author(s): Klaas Gadeyne, Wim Meeussen, Tinne Delaet and many others. See web page for a full contributor list. ROS package maintained by Wim Meeussen.
autogenerated on Fri Aug 28 2015 10:10:21