sample.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 #ifndef SAMPLE_H
31 #define SAMPLE_H
32 
33 // Adjust this to absolute path!
34 // Using <> makes that the g++ standard implementation of vector is chosen!
35 #include "../bfl_err.h"
36 #include "../wrappers/matrix/vector_wrapper.h"
37 #include "../wrappers/matrix/matrix_wrapper.h"
38 #include <iostream>
39 
40 namespace BFL
41 {
42  using namespace std;
43 
47  template <typename T> class Sample
48  {
49  protected:
51  T Value;
52 
53  public:
55 
59  Sample (unsigned int dimension = 0);
60 
62  virtual ~Sample();
63 
65  Sample ( const Sample<T> & my_sample );
66 
68  T& ValueGet ( ) ;
69 
71  const T& ValueGet ( ) const;
72 
73  // dimension get
74  unsigned int DimensionGet () const;
75 
76  // dimension set
77  void DimensionSet (unsigned int dim);
78 
80 
83  void ValueSet ( const T& value );
84 
86 
90  template <typename S> friend ostream & operator<< (ostream & stream,
91  Sample<S> & my_sample);
92 
93  template <typename S> friend istream & operator>> (istream & stream,
94  Sample<S> & my_sample);
96  Sample & operator= (const Sample & my_sample);
97 
98  };
99 
100 
101 
102 
103 
104 
105 
106 
107  // constructor
108  template <typename T> Sample<T>::Sample (unsigned int dimension)
109  {};
110 
111 
112  // destructor
113  template <typename T> Sample<T>::~Sample( )
114  {};
115 
116 
117  // copy constructor
118  template <typename T> Sample<T>::Sample ( const Sample & my_sample )
119  {
120  Value = my_sample.ValueGet();
121  }
122 
123 
124  // set value
125  template <typename T> void Sample<T>::ValueSet (const T& value)
126  {
127  Value = value;
128  }
129 
130 
131  // get value
132  template <typename T> T& Sample<T>::ValueGet ( )
133  {
134  return Value;
135  }
136 
137 
138  // get value
139  template <typename T> const T& Sample<T>::ValueGet ( ) const
140  {
141  return Value;
142  }
143 
144  // get dimension
145  template <typename T> unsigned int Sample<T>::DimensionGet ( ) const
146  {
147  return 0;
148  }
149 
150  // set dimension
151  template <typename T> void Sample<T>::DimensionSet (unsigned int dim)
152  {}
153 
154  // stream
155  template <typename S> ostream & operator<< (ostream & stream, Sample<S> & my_sample)
156  {
157  stream << my_sample.ValueGet() << endl;
158  return stream;
159  }
160 
161  template <typename S> istream & operator>> (istream & stream, Sample<S> & my_sample)
162  {
163  S value;
164  stream >> value;
165  my_sample.ValueSet(value);
166  return stream;
167  }
168 
169  // operator =
170  template <typename T> Sample<T> & Sample<T>::operator= ( const Sample<T> & my_sample)
171  {
172  Value = my_sample.ValueGet();
173  return *this;
174  }
175 
176 
177 
178 } // End namespace BFL
179 
180 #include "sample.cpp"
181 
182 #endif
ostream & operator<<(ostream &stream, Probability &prob)
Definition: bfl_toolkit.cpp:62
Sample(unsigned int dimension=0)
Constructor.
void ValueSet(const T &value)
Set the value of the Sample.
void DimensionSet(unsigned int dim)
T Value
The Sample Value.
Definition: sample.h:51
istream & operator>>(istream &stream, Probability &prob)
Definition: bfl_toolkit.cpp:68
T & ValueGet()
Get the value of the Sample.
virtual ~Sample()
Destructor.
Sample & operator=(const Sample &my_sample)
Operator =.
unsigned int DimensionGet() const


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 Jun 10 2019 12:47:59