IMP logo
IMP Reference Guide  develop.d97d4ead1f,2024/11/21
The Integrative Modeling Platform
utility.h
Go to the documentation of this file.
1 /**
2  * \file IMP/utility.h
3  * \brief Various general useful functions for IMP.
4  *
5  * Copyright 2007-2023 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_UTILITY_H
10 #define IMPKERNEL_UTILITY_H
11 
12 #include <IMP/kernel_config.h>
13 #include <boost/utility.hpp>
14 #include <cmath>
15 #include "base_macros.h"
16 #include <IMP/Vector.h>
17 #include <IMP/math.h>
18 
19 IMPKERNEL_BEGIN_NAMESPACE
20 
21 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
22 template <class T>
23 inline T square(T t) IMP_NO_SIDEEFFECTS;
24 template <class T>
25 inline T cube(T t) IMP_NO_SIDEEFFECTS;
26 
27 //! Compute the square of a number
28 template <class T>
29 inline T square(T t) {
30  return t * t;
31 }
32 
33 //! Compute the cube of a number
34 template <class T>
35 inline T cube(T t) {
36  return t * t * t;
37 }
38 
39 template <class T>
40 inline bool is_nan(const T &a) {
41  return isnan(a);
42 }
43 
44 //! A version of std::for_each which works with ranges
45 /** This is needed to apply the functor to a range which is a temporary
46  object, since you can't call both begin and end on it.
47  */
48 template <class Range, class Functor>
49 inline void for_each(const Range &r, const Functor &f) {
50  std::for_each(r.begin(), r.end(), f);
51 }
52 
53 template <class T>
54 inline int compare(const T &a, const T &b) {
55  return a.compare(b);
56 }
57 
58 //! Convert between different types of lists.
59 template <class Out, class In>
60 inline Out get_as(const In &in) {
61  return Out(in.begin(), in.end());
62 }
63 #endif
64 
65 //! Return a unique name produced from the string.
66 /** This is done by replacing %1% with a sequential number.*/
67 IMPKERNELEXPORT std::string get_unique_name(std::string templ);
68 
69 //! Get the IMP copyright notice
70 IMPKERNELEXPORT std::string get_copyright();
71 
72 IMPKERNEL_END_NAMESPACE
73 
74 #endif /* IMPKERNEL_UTILITY_H */
Helper functions to check for NaN or infinity.
std::string get_unique_name(std::string templ)
Return a unique name produced from the string.
#define IMP_NO_SIDEEFFECTS
Use this to label a function with no side effects.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two vectors
Definition: VectorD.h:166
A class for storing lists of IMP items.
bool isnan(const T &a)
Return true if a number is NaN.
Definition: math.h:24
Various general useful macros for IMP.
std::string get_copyright()
Get the IMP copyright notice.