26 #ifndef ASLUTILITIES_H 27 #define ASLUTILITIES_H 48 template <
typename T>
inline std::string
numToStr(T i)
57 template <
typename T> std::string
numToStr(T i,
int numberOf0)
60 s << std::setfill(
'0') << std::setw(numberOf0) << i;
66 template <
typename T> T
strToNum(std::string s);
69 template <
int I>
class I2T{
public:
static const int i = I;};
72 template <
int I>
inline const double P(
const double& a){
return P<I-1>(a)*a;}
73 template <
int I>
inline const float P(
const float& a){
return P<I-1>(a)*a;}
74 template <
int I>
inline const int P(
const int& a){
return P<I-1>(a)*a;}
77 template <>
inline const double P<1>(
const double& a){
return a;}
78 template <>
inline const float P<1>(
const float& a){
return a;}
79 template <>
inline const int P<1>(
const int& a){
return a;}
84 template <
typename T>
inline bool in(
const T& xx,
const T& x1,
const T& x2)
86 return (((x1-xx)*(x2-xx))<=0);
90 template <
typename T>
inline bool inO(
const T& xx,
const T& x1,
const T& x2)
92 return (((x1 - xx) * (x2 - xx)) < 0);
95 static const double pi=4.*atan(1.);
98 inline const double deg(
double a){
return a/pi*180.;}
99 inline const float deg(
float a){
return a/pi*180.;}
101 inline const double rad(
double a){
return a*pi/180.;}
102 inline const float rad(
float a){
return a*pi/180.;}
105 inline const bool approxEqual(
const double &a,
const double &b,
const double p_ = 1e-6)
110 inline const bool approxEqual(
const float &a,
const float &b,
const float p_ = 1e-6)
145 template <
typename T> std::ostream &
operator<<(std::ostream & output,
146 const std::vector<T> & vector);
150 template <
typename T>
bool operator==(
const std::vector<T> & vector1,
151 const std::vector<T> & vector2);
155 template <
class T,
int N>
inline void output1OfN(
const std::string &s);
158 template <
class T>
inline void setupAll(std::vector<std::shared_ptr<T> > & v);
161 template <
class T>
inline void computeAll(std::vector<std::shared_ptr<T> > & v);
164 template <
class T1,
class T2>
inline void sortTwoVectors(std::vector<T1> & v1, std::vector<T2> & v2);
167 template <
class T>
inline void reorderVector(std::vector<unsigned int> & ind, std::vector<T> & v);
173 template <
typename T> std::ostream &
operator<<(std::ostream & output,
const std::vector<T> & vector)
175 typename std::vector<T>::const_iterator iter;
177 for (iter = vector.begin(); iter != vector.end(); ++iter)
178 output << *iter <<
" ";
185 template <
typename T>
bool operator==(
const std::vector<T> & vector1,
186 const std::vector<T> & vector2)
188 if (vector1.size() != vector2.size())
196 equal = (vector1[i] == vector2[i]);
198 }
while ((i < vector1.size()) && equal);
204 template <
class T,
int N>
inline void output1OfN(
const std::string &s)
208 std::cout << s << std::endl;
212 template <
class T>
void setupAll(std::vector<std::shared_ptr<T> > &v)
214 for (
unsigned int i(0); i < v.size(); ++i)
218 template <
class T>
void computeAll(std::vector<std::shared_ptr<T> > &v)
220 for (
unsigned int i(0); i < v.size(); ++i)
226 std::vector<T1> & v1;
229 inline bool operator()(
unsigned int i,
unsigned int j) {
return v1[i]<v1[j];}
232 template <
typename T1,
typename T2>
inline void sortTwoVectors(std::vector<T1> & v1, std::vector<T2> & v2)
234 if(v1.size()!=v2.size())
235 errorMessage(
"sortTwoVectors: the vectors have different sizes");
238 std::vector<unsigned int> ind(v1.size());
239 for(
unsigned int i(0); i<v1.size(); ++i)
247 template <
class T>
inline void reorderVector(std::vector<unsigned int> & ind, std::vector<T> & v)
249 if(ind.size()!=v.size())
250 errorMessage(
"reorderVector: the vectors have different sizes");
252 unsigned int n(v.size());
253 std::vector<T> nContainer(n);
254 for(
unsigned int i(0); i<n; ++i)
255 nContainer[i]=v[ind[i]];
262 #endif // ASLUTILITIES_H Advanced Simulation Library.
bool inO(const T &xx, const T &x1, const T &x2)
Checks the belonging to an open interval (x1,x2), .
const double rad(double a)
Translation degrees to radians.
T strToNum(std::string s)
Converts string to number, exits if not able to convert.
void computeAll(std::vector< std::shared_ptr< T > > &v)
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
std::string numToStr(T i)
Converts numbers or another type to string.
std::string warningString(const char *warningMessage)
Returns warningMessage.
bool operator==(const std::vector< T > &vector1, const std::vector< T > &vector2)
Compares two vectors.
bool in(const T &xx, const T &x1, const T &x2)
Checks the belonging to a closed interval [x1,x2], .
const double deg(double a)
Translation radians to degrees.
const bool approxEqual(const double &a, const double &b, const double p_=1e-6)
Approximately equal; the precision is defined as p_.
C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33) and OpenCL 1.2 (rev 15)
void output1OfN(const std::string &s)
Makes output 1 of n times.
std::ostream & operator<<(std::ostream &output, const std::vector< T > &vector)
Prints elements of the vector separated by space.
comparatorIndeces(std::vector< T1 > &v)
void sortTwoVectors(std::vector< T1 > &v1, std::vector< T2 > &v2)
sorts two vectors with respect of the fist one
void setupAll(std::vector< std::shared_ptr< T > > &v)
This class is used in order to overload function according to an integer parameter.
void warningMessage(const char *warningMessage)
Prints warningMessage.
const double P(const double &a)
Realization of .
bool operator()(unsigned int i, unsigned int j)
void reorderVector(std::vector< unsigned int > &ind, std::vector< T > &v)
reorders vector according to indeces