IMP  2.2.1
The Integrative Modeling Platform
base/utility.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base/utility.h \brief Various general useful functions for IMP.
3  *
4  * Copyright 2007-2014 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPBASE_UTILITY_H
9 #define IMPBASE_UTILITY_H
10 
11 #include <IMP/base/base_config.h>
12 #include <boost/utility.hpp>
13 #include <cmath>
14 #include "base_macros.h"
15 #include <IMP/base/Vector.h>
16 #include <IMP/base/math.h>
17 
18 IMPBASE_BEGIN_NAMESPACE
19 
20 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
21 template <class T>
22 inline T square(T t) IMP_NO_SIDEEFFECTS;
23 template <class T>
24 inline T cube(T t) IMP_NO_SIDEEFFECTS;
25 
26 //! Compute the square of a number
27 template <class T>
28 inline T square(T t) {
29  return t * t;
30 }
31 
32 //! Compute the cube of a number
33 template <class T>
34 inline T cube(T t) {
35  return t * t * t;
36 }
37 
38 template <class T>
39 inline bool is_nan(const T &a) {
40  return isnan(a);
41 }
42 
43 //! A version of std::for_each which works with ranges
44 /** This is needed to apply the functor to a range which is a temporary
45  object, since you can't call both begin and end on it.
46  */
47 template <class Range, class Functor>
48 inline void for_each(const Range &r, const Functor &f) {
49  std::for_each(r.begin(), r.end(), f);
50 }
51 
52 template <class T>
53 inline int compare(const T &a, const T &b) {
54  return a.compare(b);
55 }
56 
57 /** Convert between different types of lists.
58  */
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 by replacing
66  %1% with a sequential number.*/
67 IMPBASEEXPORT std::string get_unique_name(std::string templ);
68 
69 IMPBASE_END_NAMESPACE
70 
71 #endif /* IMPBASE_UTILITY_H */
Various general useful macros for IMP.
Declare an efficient stl-compatible map.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two vectors
Definition: VectorD.h:179
std::string get_unique_name(std::string templ)
A class for storing lists of IMP items.
bool isnan(const T &a)
Return true if a number is NaN.
Definition: base/math.h:24