| 1 |
/* |
| 2 |
* Advanced Simulation Library <http://asl.org.il> |
| 3 |
* |
| 4 |
* Copyright 2015 Avtech Scientific <http://avtechscientific.com> |
| 5 |
* |
| 6 |
* |
| 7 |
* This file is part of Advanced Simulation Library (ASL). |
| 8 |
* |
| 9 |
* ASL is free software: you can redistribute it and/or modify it |
| 10 |
* under the terms of the GNU Affero General Public License as |
| 11 |
* published by the Free Software Foundation, version 3 of the License. |
| 12 |
* |
| 13 |
* ASL is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Affero General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Affero General Public License |
| 19 |
* along with ASL. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
|
| 24 |
#include <stdexcept> |
| 25 |
#include "aslUtilities.h" |
| 26 |
|
| 27 |
|
| 28 |
using namespace std; |
| 29 |
|
| 30 |
namespace asl |
| 31 |
{ |
| 32 |
|
| 33 |
template <typename T> T strToNum(string s) |
| 34 |
{ |
| 35 |
istringstream i(s); |
| 36 |
T x; |
| 37 |
char c; |
| 38 |
|
| 39 |
if (!(i >> x)) |
| 40 |
errorMessage("strToNum() - unable to convert " + s + " to the requested type"); |
| 41 |
|
| 42 |
if (i.get(c)) |
| 43 |
warningMessage("strToNum() - " + s + " contains a character"); |
| 44 |
|
| 45 |
/* |
| 46 |
ToDo: check whether it is needed at all. |
| 47 |
Commented out since it causes cyclic dependency aslcommon <-> aslacl through "aclUtilites.h" |
| 48 |
|
| 49 |
int decimal(0); |
| 50 |
if (acl::typeToTypeID<T>() == acl::TYPE_INT) |
| 51 |
{ |
| 52 |
i >> decimal; |
| 53 |
if (decimal != 0) |
| 54 |
warningMessage("strToNum() - " + s + " is not an integer"); |
| 55 |
} |
| 56 |
*/ |
| 57 |
return x; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
template cl_int strToNum<cl_int>(string s); |
| 62 |
template cl_uint strToNum<cl_uint>(string s); |
| 63 |
template cl_long strToNum<cl_long>(string s); |
| 64 |
template cl_float strToNum<cl_float>(string s); |
| 65 |
template cl_double strToNum<cl_double>(string s); |
| 66 |
|
| 67 |
|
| 68 |
void errorMessage(cl_int status, const char *errorMessage) |
| 69 |
{ |
| 70 |
if (status != CL_SUCCESS) |
| 71 |
{ |
| 72 |
throw std::logic_error("ASL ERROR: " + string(errorMessage) + " (" + to_string(status) + ")." ); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
void errorMessage(cl_int status, const string &errorMessage) |
| 78 |
{ |
| 79 |
if (status != CL_SUCCESS) |
| 80 |
{ |
| 81 |
throw std::logic_error("ASL ERROR: " + errorMessage + " (" + to_string(status) + ")." ); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
void errorMessage(const char *errorMessage) |
| 87 |
{ |
| 88 |
throw std::logic_error("ASL ERROR: " + string(errorMessage)); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
void errorMessage(const string & errorMessage) |
| 93 |
{ |
| 94 |
throw std::logic_error("ASL ERROR: " + errorMessage); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
void errorMessage(bool status) |
| 99 |
{ |
| 100 |
if (status) |
| 101 |
cout << " Ok" << endl; |
| 102 |
else |
| 103 |
cerr << " ERROR" << endl; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
void warningMessage(const char *warningMessage) |
| 108 |
{ |
| 109 |
cout << "ASL WARNING: " << warningMessage << "." << endl; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
void warningMessage(const string & warningMessage) |
| 114 |
{ |
| 115 |
cout << "ASL WARNING: " << warningMessage << "." << endl; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
string warningString(const char *warningMessage) |
| 120 |
{ |
| 121 |
return string("ASL WARNING: ") + warningMessage + "."; |
| 122 |
} |
| 123 |
|
| 124 |
} // asl namespace |