bpp-core  2.2.0
Number.h
Go to the documentation of this file.
1 //
2 // File: Number.h
3 // Created by: Julien Dutheil
4 // Created on: Thu Nov 13 16:29:03 2003
5 //
6 
7 
8 /*
9 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
10 
11 This software is a computer program whose purpose is to provide utilitary
12 classes. This file belongs to the Bio++ Project.
13 
14 This software is governed by the CeCILL license under French law and
15 abiding by the rules of distribution of free software. You can use,
16 modify and/ or redistribute the software under the terms of the CeCILL
17 license as circulated by CEA, CNRS and INRIA at the following URL
18 "http://www.cecill.info".
19 
20 As a counterpart to the access to the source code and rights to copy,
21 modify and redistribute granted by the license, users are provided only
22 with a limited warranty and the software's author, the holder of the
23 economic rights, and the successive licensors have only limited
24 liability.
25 
26 In this respect, the user's attention is drawn to the risks associated
27 with loading, using, modifying and/or developing or reproducing the
28 software by the user in light of its specific status of free software,
29 that may mean that it is complicated to manipulate, and that also
30 therefore means that it is reserved for developers and experienced
31 professionals having in-depth computer knowledge. Users are therefore
32 encouraged to load and test the software's suitability as regards their
33 requirements in conditions enabling the security of their systems and/or
34 data to be ensured and, more generally, to use and operate it in the
35 same conditions as regards security.
36 
37 The fact that you are presently reading this means that you have had
38 knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef _NUMBER_H_
42 #define _NUMBER_H_
43 
44 #include "../Clonable.h"
45 
46 #include <string>
47 
48 namespace bpp
49 {
55 class BppNumberI: public Clonable
56 {
57  public:
58 
60 
61  virtual ~BppNumberI() {}
62 
63  public:
64 
65  virtual BppNumberI* clone() const = 0;
66 
67  public:
68 
69  virtual std::string toString() const = 0;
70 
71 };
72 
73 
74 class BppNotANumber: public virtual BppNumberI
75 {
76  public:
77 
79 
80  virtual ~BppNotANumber() {}
81 
82  public:
83 
84  virtual BppNotANumber* clone() const { return new BppNotANumber(); }
85 
86  public:
87 
88  virtual std::string toString() const { return "NaN"; }
89 
90 };
91 
92 
98 template<class T> class Number: public virtual BppNumberI
99 {
100  protected:
103 
104  public:
105 
111  Number(const T& value = 0): value_(value) {}
112 
113  virtual ~Number() {}
114 
115  Number<T> & operator=(const T & t)
116  {
117  value_ = t;
118  return *this;
119  }
120 
121  public:
122 
128  Number<T>* clone() const { return new Number<T>(value_); }
131  public:
132 
138  T getValue() const { return value_; }
139 
140  std::string toString() const { return TextTools::toString(value_); }
141 };
142 
146 class BppDouble: public virtual Number<double>
147 {
148  public:
149 
155  BppDouble(double value = 0): Number<double>(value) {}
156 
157  virtual ~BppDouble() {}
158 
159  public:
160 
166  BppDouble* clone() const { return new BppDouble(*this); }
169 };
170 
174 class BppInteger: public virtual Number<int>
175 {
176  public:
177 
183  BppInteger(int value = 0): Number<int>(value) {}
184 
185  virtual ~BppInteger() {}
186 
187  public:
188 
194  BppInteger* clone() const { return new BppInteger(*this); }
197 };
198 
202 class BppUnsignedInteger: public virtual Number<unsigned int>
203 {
204  public:
205 
211  BppUnsignedInteger(unsigned int value = 0): Number<unsigned int>(value) {}
212 
213  virtual ~BppUnsignedInteger() {}
214 
215  public:
216 
222  BppUnsignedInteger* clone() const { return new BppUnsignedInteger(*this); }
225 };
226 
227 } //end of namespace bpp.
228 
229 #endif //_NUMBER_H_
230 
std::string toString() const
Definition: Number.h:140
T getValue() const
Get the value of this number.
Definition: Number.h:138
BppInteger(int value=0)
Build a new BppInteger number object with a specific value.
Definition: Number.h:183
This class allows to perform a correspondence analysis.
virtual std::string toString() const
Definition: Number.h:88
The Number interface.
Definition: Number.h:55
An object wrapper for double values.
Definition: Number.h:146
static std::string toString(T t)
General template method to convert to a string.
Definition: TextTools.h:189
An object wrapper for integer values.
Definition: Number.h:174
Number< T > & operator=(const T &t)
Definition: Number.h:115
T value_
The value of this parameter.
Definition: Number.h:102
virtual ~BppNotANumber()
Definition: Number.h:80
virtual ~BppNumberI()
Definition: Number.h:61
virtual BppNotANumber * clone() const
Create a copy of this object and send a pointer to it.
Definition: Number.h:84
BppDouble * clone() const
Create a copy of this object and send a pointer to it.
Definition: Number.h:166
BppUnsignedInteger * clone() const
Create a copy of this object and send a pointer to it.
Definition: Number.h:222
virtual BppNumberI * clone() const =0
Create a copy of this object and send a pointer to it.
BppUnsignedInteger(unsigned int value=0)
Build a new BppUnsignedInteger number object with a specific value.
Definition: Number.h:211
virtual ~BppDouble()
Definition: Number.h:157
The Clonable interface (allow an object to be cloned).
Definition: Clonable.h:99
The Number object template class.
Definition: Number.h:98
BppDouble(double value=0)
Build a new BppDouble number object with a specific value.
Definition: Number.h:155
virtual ~Number()
Definition: Number.h:113
BppInteger * clone() const
Create a copy of this object and send a pointer to it.
Definition: Number.h:194
virtual std::string toString() const =0
Number< T > * clone() const
Create a copy of this object and send a pointer to it.
Definition: Number.h:128
An object wrapper for unsigned integer values.
Definition: Number.h:202
virtual ~BppUnsignedInteger()
Definition: Number.h:213
Number(const T &value=0)
Build a new Number object with a specific value.
Definition: Number.h:111
virtual ~BppInteger()
Definition: Number.h:185