[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

utilities.hxx |

1 /************************************************************************/
2 /* */
3 /* Copyright 1998-2002 by Ullrich Koethe */
4 /* */
5 /* This file is part of the VIGRA computer vision library. */
6 /* The VIGRA Website is */
7 /* http://hci.iwr.uni-heidelberg.de/vigra/ */
8 /* Please direct questions, bug reports, and contributions to */
9 /* ullrich.koethe@iwr.uni-heidelberg.de or */
10 /* vigra@informatik.uni-hamburg.de */
11 /* */
12 /* Permission is hereby granted, free of charge, to any person */
13 /* obtaining a copy of this software and associated documentation */
14 /* files (the "Software"), to deal in the Software without */
15 /* restriction, including without limitation the rights to use, */
16 /* copy, modify, merge, publish, distribute, sublicense, and/or */
17 /* sell copies of the Software, and to permit persons to whom the */
18 /* Software is furnished to do so, subject to the following */
19 /* conditions: */
20 /* */
21 /* The above copyright notice and this permission notice shall be */
22 /* included in all copies or substantial portions of the */
23 /* Software. */
24 /* */
25 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
26 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
27 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
28 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
29 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
30 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
31 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
32 /* OTHER DEALINGS IN THE SOFTWARE. */
33 /* */
34 /************************************************************************/
35
36
37 #ifndef VIGRA_BASICS_HXX
38 #define VIGRA_BASICS_HXX
39
40 #include "config.hxx"
41 #include "error.hxx"
42 #include "metaprogramming.hxx"
43 #include "tuple.hxx"
44 #include "diff2d.hxx"
45 #include "mathutil.hxx"
46 #include <string>
47 #include <sstream>
48 #include <cctype>
49
50 namespace vigra {
51
52 /** Convert a value to a string. Available for integral and floating point types
53 and void *.
54 */
55 doxygen_overloaded_function(template <class T> std::string asString(T t))
56
57 #define VIGRA_AS_STRING(T) \
58 inline std::string asString(T t) \
59 { \
60 std::stringstream s; \
61 s << t; \
62 return s.str(); \
63 }
64
65 VIGRA_AS_STRING(bool)
66 VIGRA_AS_STRING(signed char)
67 VIGRA_AS_STRING(unsigned char)
68 VIGRA_AS_STRING(signed short)
69 VIGRA_AS_STRING(unsigned short)
70 VIGRA_AS_STRING(signed long)
71 VIGRA_AS_STRING(unsigned long)
72 VIGRA_AS_STRING(signed long long)
73 VIGRA_AS_STRING(unsigned long long)
74 VIGRA_AS_STRING(signed int)
75 VIGRA_AS_STRING(unsigned int)
76 VIGRA_AS_STRING(float)
77 VIGRA_AS_STRING(double)
78 VIGRA_AS_STRING(long double)
79 VIGRA_AS_STRING(void *)
80
81 #undef VIGRA_AS_STRING
82
83 template <class T>
84 std::string & operator<<(std::string & s, T const & t)
85 {
86 std::stringstream ss;
87 ss << t;
88 return s += ss.str();
89 }
90
91 /** Convert string to lower case.
92 */
93 inline std::string tolower(std::string s)
94 {
95 for(unsigned int k=0; k<s.size(); ++k)
96 s[k] = (std::string::value_type)std::tolower(s[k]);
97 return s;
98 }
99
100 inline std::string tolower(const char * s)
101 {
102 return tolower(std::string(s));
103 }
104
105 /** Convert string to lower case and remove any white space characters.
106 */
107 inline std::string normalizeString(std::string const & s)
108 {
109 std::string res;
110
111 for(unsigned int k=0; k<s.size(); ++k)
112 {
113 if(std::isspace(s[k]))
114 continue;
115 res += (std::string::value_type)std::tolower(s[k]);
116 }
117 return res;
118 }
119
120 inline std::string normalizeString(const char * s)
121 {
122 return normalizeString(std::string(s));
123 }
124
125 } // namespace vigra
126
127 namespace std {
128
129 template <class T1, class T2>
130 ostream & operator<<(ostream & s, std::pair<T1, T2> const & p)
131 {
132 s << "(" << p.first << ", " << p.second << ")";
133 return s;
134 }
135
136 }
137
138 /** \page Utilities Utilities
139 Basic helper functionality needed throughout.
140
141 <UL style="list-style-image:url(documents/bullet.gif)">
142 <LI> \ref vigra::ArrayVector
143 <BR>&nbsp;&nbsp;&nbsp;<em>replacement for std::vector (always uses consecutive memory)</em>
144 <LI> \ref vigra::BucketQueue and \ref vigra::MappedBucketQueue
145 <BR>&nbsp;&nbsp;&nbsp;<em>efficient priority queues for integer priorities</em>
146 <LI> \ref RangesAndPoints
147 <BR>&nbsp;&nbsp;&nbsp;<em>2-D and N-D positions, extents, and boxes</em>
148 <LI> \ref PixelNeighborhood
149 <BR>&nbsp;&nbsp;&nbsp;<em>4- and 8-neighborhood definitions and circulators</em>
150 <LI> \ref VoxelNeighborhood
151 <BR>&nbsp;&nbsp;&nbsp;<em>6- and 26-neighborhood definitions and circulators</em>
152 <LI> \ref vigra::IteratorAdaptor
153 <BR>&nbsp;&nbsp;&nbsp;<em>Quickly create STL-compatible 1D iterator adaptors</em>
154 <LI> \ref TupleTypes
155 <BR>&nbsp;&nbsp;&nbsp;<em>pair, triple, tuple4, tuple5</em>
156 <LI> \ref MathConstants
157 <BR>&nbsp;&nbsp;&nbsp;<em>M_PI, M_SQRT2</em>
158 <LI> \ref TimingMacros
159 <BR>&nbsp;&nbsp;&nbsp;<em>Macros for taking execution speed measurements</em>
160 </UL>
161 */
162
163 #endif // VIGRA_BASICS_HXX

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.10.0 (Mon Nov 18 2013)