weightedsample.h
Go to the documentation of this file.
1 // $Id$
2 // Copyright (C) 2002 Klaas Gadeyne <first dot last at gmail dot com>
3  /***************************************************************************
4  * This library is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public *
6  * License as published by the Free Software Foundation; *
7  * version 2 of the License. *
8  * *
9  * As a special exception, you may use this file as part of a free *
10  * software library without restriction. Specifically, if other files *
11  * instantiate templates or use macros or inline functions from this *
12  * file, or you compile this file and link it with other files to *
13  * produce an executable, this file does not by itself cause the *
14  * resulting executable to be covered by the GNU General Public *
15  * License. This exception does not however invalidate any other *
16  * reasons why the executable file might be covered by the GNU General *
17  * Public License. *
18  * *
19  * This library is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22  * Lesser General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public *
25  * License along with this library; if not, write to the Free Software *
26  * Foundation, Inc., 59 Temple Place, *
27  * Suite 330, Boston, MA 02111-1307 USA *
28  * *
29  ***************************************************************************/
30 //
31 
32 #ifndef WEIGHTEDSAMPLE_H
33 #define WEIGHTEDSAMPLE_H
34 
35 #include "sample.h"
36 #include <assert.h>
37 
38 
39 namespace BFL
40 {
41 
48  template <typename T> class WeightedSample: virtual public Sample<T>
49  {
50  protected:
52  double Weight;
53 
54  public:
56 
60  WeightedSample (int dimension = 0 );
62  virtual ~WeightedSample();
64  WeightedSample ( const WeightedSample<T> & my_weighted_sample );
65 
67 
69  double WeightGet ( ) const;
70 
72 
75  void WeightSet ( double weight );
76 
78 
82  template <typename S> friend ostream & operator<< (ostream & stream,
83  WeightedSample<S> & mws);
84 
86  WeightedSample<T> & operator= (const WeightedSample<T> & my_sample);
87 
89  WeightedSample<T> & operator= (const Sample<T> & my_sample);
90  };
91 
92 
93  template <typename T> WeightedSample<T>::WeightedSample(int dimension)
94  : Sample<T>(dimension){}
95 
96  template <typename T> WeightedSample<T>::~WeightedSample(){}
97 
98  template <typename T> WeightedSample<T>::WeightedSample (const WeightedSample<T> & mws)
99  : Sample<T>(mws)
100  {
101  Weight = mws.Weight;
102  }
103 
104  template <typename T> double WeightedSample<T>::WeightGet ( ) const
105  {
106  return Weight;
107  }
108 
109  template <typename T> void WeightedSample<T>::WeightSet ( double weight )
110  {
111  assert(weight >= 0);
112 
113  Weight = weight;
114  }
115 
116  template <typename S> ostream & operator<< (ostream & stream,
117  WeightedSample<S> & mws)
118  {
119  stream << "WeightedSample Value = " << (Sample<S> &) mws
120  << "Weight = " << mws.Weight << endl;
121  return stream;
122  }
123 
124  template <typename T> WeightedSample<T> & WeightedSample<T>::operator= (const WeightedSample<T> & my_sample)
125  {
126  // TODO: Does this automatically calls the = operator in the
127  // baseclass? NO!!!
128  Sample<T> * op1; const Sample<T> * op2;
129  op1 = this; op2 = & my_sample;
130  *op1 = *op2;
131  this->Weight = my_sample.WeightGet();
132  return *this;
133  }
134 
135  // Turn sample into weighted one (weight = 1)
136  template <typename T> WeightedSample<T> & WeightedSample<T>::operator= (const Sample<T> & my_sample)
137  {
138  //: Does this automatically calls the = operator in the baseclass?
139  Sample<T> * op1; const Sample<T> * op2;
140  op1 = this; op2 = & my_sample;
141  *op1 = *op2;
142  this->Weight = 1;
143  return *this;
144  }
145 
146 } // End namespace BFL
147 
148 #endif
void WeightSet(double weight)
Set the weight.
virtual ~WeightedSample()
Destructor.
double Weight
The weight.
WeightedSample(int dimension=0)
Constructor.
double WeightGet() const
Get the weight.
friend ostream & operator<<(ostream &stream, WeightedSample< S > &mws)
Print a weighted sample.
WeightedSample< T > & operator=(const WeightedSample< T > &my_sample)
Operator =.
double Weight
The weight.
Definition: asirfilter.h:52
ostream & operator<<(ostream &stream, WeightedSample< S > &mws)


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 Mon Feb 28 2022 21:56:33