STK++ 0.9.13
STK_Integer.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff, Université Lille 1, Inria
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp:stkernel::base
27 * Purpose: Define the fundamental type Integer.
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 *
30 **/
31
36#ifndef STK_INTEGER_H
37#define STK_INTEGER_H
38
39#include <map>
40
41// for building
42#ifdef IS_RTKPP_LIB
43#include "Rtkpp/include/STK_RcppTraits.h"
44#endif
45
46namespace STK
47{
54template<>
55struct Arithmetic<Integer>: public std::numeric_limits<Integer>
56{
57#ifdef IS_RTKPP_LIB
58 enum
59 {
60 Rtype_ = hidden::RcppTraits<Integer>::Rtype_
61 };
62#endif
64 static const bool hasNA = true;
66 static inline Integer NA() throw() { return std::numeric_limits<Integer>::min();}
70 static inline bool isNA(Integer const& x) throw()
71 { return (x==std::numeric_limits<Integer>::min());}
74 static inline Integer min() throw() { return std::numeric_limits<Integer>::min() +1; }
78 static inline bool isInfinite(Integer const& x) throw() { return false; }
82 static inline bool isFinite(Integer const& x) throw() { return (!isNA(x));}
83};
84
88template<>
90{
92 static inline Base::IdType returnType() { return(Base::integer_);}
93};
94
95#ifdef IS_RTKPP_LIB
102template<>
103struct Arithmetic<const Integer>
104{
105 enum
106 {
107 Rtype_ = hidden::RcppTraits<const Integer>::Rtype_
108 };
110 static const bool hasNA = true;
112 static inline Integer NA() throw() { return std::numeric_limits<Integer>::min();}
116 static inline bool isNA(Integer const& x) throw()
117 { return (x==std::numeric_limits<Integer>::min());}
120 static inline Integer min() throw() { return std::numeric_limits<Integer>::min() +1; }
124 static inline bool isInfinite(Integer const& x) throw() { return false; }
128 static inline bool isFinite(Integer const& x) throw() { return (!isNA(x));}
129};
130
134template<>
135struct IdTypeImpl<const Integer>
136{
138 static inline Base::IdType returnType() { return(Base::integer_);}
139};
140
141#endif /* IS_RTKPP_LIB */
142
150{
151 Integer x;
153 is >> Proxy<Integer>(x);
154 return x;
155}
163inline Integer stringToInt( String const& str, std::map<String, Integer> const& mapping)
164{
165 std::map<String, Integer>::const_iterator it=mapping.find(str);
166 return (it == mapping.end()) ? Arithmetic<Integer>::NA() : it->second;
167}
168
175inline String intToString( Integer const& value, std::ios_base& (*f)(std::ios_base&) = std::dec)
176{
177 if (Arithmetic<Integer>::isNA(value)) return stringNa;
179 os << f << value;
180 return os.str();
181}
182
189inline String intToString( Integer const& value, std::map<Integer, String> const& mapping)
190{
191 std::map<Integer, String>::const_iterator it=mapping.find(value);
192 return (it == mapping.end()) ? stringNa : it->second;
193}
194
200template<>
202{ return stringToInt(s);}
203
209template<>
210inline String typeToString<Integer>( Integer const& t, std::ios_base& (*f)(std::ios_base&))
211{ return intToString(t, f);}
212
213} // namespace STK
214
215#endif /*STK_INTEGER_H*/
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
String intToString(Integer const &value, std::ios_base &(*f)(std::ios_base &)=std::dec)
Convert an Integer to a String.
Integer stringToInt(String const &str)
Convert a String to an Integer.
String typeToString< Integer >(Integer const &t, std::ios_base &(*f)(std::ios_base &))
specialization for Integer
Integer stringToType< Integer >(String const &s)
specialization for Integer
String stringNa
Representation of a Not Available value.
IdType
Id for the Type of a variable.
@ integer_
Qualitative type.
std::basic_string< Char > String
STK fundamental type of a String.
int Integer
STK fundamental type of integer values.
hidden::SliceVisitorSelector< Derived, hidden::MinVisitor, Arrays::by_col_ >::type_result min(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual minimal value of the ...
std::basic_ostringstream< Char > ostringstream
ostringstream (ostringstream) for Char
Definition STK_Stream.h:65
std::basic_istringstream< Char > istringstream
istringstream for Char
Definition STK_Stream.h:63
The namespace STK is the main domain space of the Statistical ToolKit project.
static bool isFinite(Integer const &x)
Definition STK_Integer.h:82
static bool isNA(Integer const &x)
Test if x is a Non Available (NA) special number.
Definition STK_Integer.h:70
static Integer min()
We are using the minimal value of the Integer type for NA values, thus we add one in order to compute...
Definition STK_Integer.h:74
static bool isInfinite(Integer const &x)
Definition STK_Integer.h:78
static Integer NA()
Adding a Non Available (NA) special number.
Definition STK_Integer.h:66
Arithmetic properties of STK fundamental types.
static bool isFinite(Type const &x)
static bool isInfinite(Type const &x)
static const bool hasNA
True if the type has a representation for a "Not Available."
static Type NA()
Adding a Non Available (NA) special number.
static bool isNA(Type const &x)
static Base::IdType returnType()
Give the IdType of the type Integer.
Definition STK_Integer.h:92
Implementation of the return type.
static Base::IdType returnType()