CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418384
1
/*
2
* Normaliz
3
* Copyright (C) 2007-2014 Winfried Bruns, Bogdan Ichim, Christof Soeger
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (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 General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*
17
* As an exception, when this program is distributed through (i) the App Store
18
* by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or (iii) Google Play
19
* by Google Inc., then that store may impose any digital rights management,
20
* device limits and/or redistribution restrictions that are required by its
21
* terms of service.
22
*/
23
24
//---------------------------------------------------------------------------
25
26
#ifndef CONVERT_H
27
#define CONVERT_H
28
29
//---------------------------------------------------------------------------
30
31
//#include <ostream>
32
#include <libQnormaliz/Qnormaliz_exception.h>
33
#include <libQnormaliz/Qinteger.h>
34
35
namespace libQnormaliz {
36
37
// conversion for integers, throws ArithmeticException if conversion fails
38
template<typename ToType, typename FromType>
39
void convert(ToType& ret, const FromType& val) {
40
if (!try_convert(ret,val)) {
41
throw ArithmeticException(val);
42
}
43
}
44
45
// conversion of vectors
46
template<typename ToType, typename FromType>
47
void convert(vector<ToType>& ret_vect, const vector<FromType>& from_vect){
48
size_t s = from_vect.size();
49
ret_vect.resize(s);
50
for (size_t i=0; i<s; ++i)
51
convert(ret_vect[i], from_vect[i]);
52
}
53
54
// general conversion with return, throws ArithmeticException if conversion fails
55
template<typename ToType, typename FromType>
56
ToType convertTo(const FromType& val) {
57
ToType copy;
58
convert(copy,val);
59
return copy;
60
}
61
62
} //end namespace
63
64
//---------------------------------------------------------------------------
65
#endif
66
//---------------------------------------------------------------------------
67
68