vigra - vigra/utilities.hxx Source File

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

vigra/utilities.hxx |

    00001 /************************************************************************/
    00002 /*                                                                      */
    00003 /*               Copyright 1998-2002 by Ullrich Koethe                  */
    00004 /*                                                                      */
    00005 /*    This file is part of the VIGRA computer vision library.           */
    00006 /*    The VIGRA Website is                                              */
    00007 /*        http://hci.iwr.uni-heidelberg.de/vigra/                       */
    00008 /*    Please direct questions, bug reports, and contributions to        */
    00009 /*        ullrich.koethe@iwr.uni-heidelberg.de    or                    */
    00010 /*        vigra@informatik.uni-hamburg.de                               */
    00011 /*                                                                      */
    00012 /*    Permission is hereby granted, free of charge, to any person       */
    00013 /*    obtaining a copy of this software and associated documentation    */
    00014 /*    files (the "Software"), to deal in the Software without           */
    00015 /*    restriction, including without limitation the rights to use,      */
    00016 /*    copy, modify, merge, publish, distribute, sublicense, and/or      */
    00017 /*    sell copies of the Software, and to permit persons to whom the    */
    00018 /*    Software is furnished to do so, subject to the following          */
    00019 /*    conditions:                                                       */
    00020 /*                                                                      */
    00021 /*    The above copyright notice and this permission notice shall be    */
    00022 /*    included in all copies or substantial portions of the             */
    00023 /*    Software.                                                         */
    00024 /*                                                                      */
    00025 /*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
    00026 /*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
    00027 /*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
    00028 /*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
    00029 /*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
    00030 /*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
    00031 /*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
    00032 /*    OTHER DEALINGS IN THE SOFTWARE.                                   */
    00033 /*                                                                      */
    00034 /************************************************************************/
    00035
    00036
    00037 #ifndef VIGRA_BASICS_HXX
    00038 #define VIGRA_BASICS_HXX
    00039
    00040 #include "config.hxx"
    00041 #include "error.hxx"
    00042 #include "metaprogramming.hxx"
    00043 #include "tuple.hxx"
    00044 #include "diff2d.hxx"
    00045 #include "mathutil.hxx"
    00046 #include <string>
    00047 #include <sstream>
    00048 #include <cctype>
    00049
    00050 namespace vigra {
    00051
    00052 /** Convert a value to a string. Available for integral and floating point types
    00053     and void *.
    00054 */
    00055 doxygen_overloaded_function(template <class T> std::string asString(T t))
    00056
    00057 #define VIGRA_AS_STRING(T) \
    00058 inline std::string asString(T t) \
    00059 { \
    00060     std::stringstream s; \
    00061     s << t; \
    00062     return s.str(); \
    00063 }
    00064
    00065 VIGRA_AS_STRING(bool)
    00066 VIGRA_AS_STRING(signed char)
    00067 VIGRA_AS_STRING(unsigned char)
    00068 VIGRA_AS_STRING(signed short)
    00069 VIGRA_AS_STRING(unsigned short)
    00070 VIGRA_AS_STRING(signed long)
    00071 VIGRA_AS_STRING(unsigned long)
    00072 VIGRA_AS_STRING(signed long long)
    00073 VIGRA_AS_STRING(unsigned long long)
    00074 VIGRA_AS_STRING(signed int)
    00075 VIGRA_AS_STRING(unsigned int)
    00076 VIGRA_AS_STRING(float)
    00077 VIGRA_AS_STRING(double)
    00078 VIGRA_AS_STRING(long double)
    00079 VIGRA_AS_STRING(void *)
    00080
    00081 #undef VIGRA_AS_STRING
    00082
    00083 template <class T>
    00084 std::string & operator<<(std::string & s, T const & t)
    00085 {
    00086     std::stringstream ss;
    00087     ss << t;
    00088     return s += ss.str();
    00089 }
    00090
    00091     /** Convert string to lower case.
    00092     */
    00093 inline std::string tolower(std::string s)
    00094 {
    00095     for(unsigned int k=0; k<s.size(); ++k)
    00096         s[k] = (std::string::value_type)std::tolower(s[k]);
    00097     return s;
    00098 }
    00099
    00100 inline std::string tolower(const char * s)
    00101 {
    00102     return tolower(std::string(s));
    00103 }
    00104
    00105     /** Convert string to lower case and remove any white space characters.
    00106     */
    00107 inline std::string normalizeString(std::string const & s)
    00108 {
    00109     std::string res;
    00110
    00111     for(unsigned int k=0; k<s.size(); ++k)
    00112     {
    00113         if(std::isspace(s[k]))
    00114             continue;
    00115         res += (std::string::value_type)std::tolower(s[k]);
    00116     }
    00117     return res;
    00118 }
    00119
    00120 inline std::string normalizeString(const char * s)
    00121 {
    00122     return normalizeString(std::string(s));
    00123 }
    00124
    00125 } // namespace vigra
    00126
    00127 namespace std {
    00128
    00129 template <class T1, class T2>
    00130 ostream & operator<<(ostream & s, std::pair<T1, T2> const & p)
    00131 {
    00132     s << "(" << p.first << ", " << p.second << ")";
    00133     return s;
    00134 }
    00135
    00136 }
    00137
    00138 /*! \page Utilities Utilities
    00139     Basic helper functionality needed throughout.
    00140
    00141     <UL style="list-style-image:url(documents/bullet.gif)">
    00142     <LI> \ref vigra::ArrayVector
    00143          <BR>&nbsp;&nbsp;&nbsp;<em>replacement for std::vector (always uses consecutive memory)</em>
    00144     <LI> \ref vigra::BucketQueue and \ref vigra::MappedBucketQueue
    00145          <BR>&nbsp;&nbsp;&nbsp;<em>efficient priority queues for integer priorities</em>
    00146     <LI> \ref RangesAndPoints
    00147          <BR>&nbsp;&nbsp;&nbsp;<em>2-D and N-D positions, extents, and boxes</em>
    00148     <LI> \ref PixelNeighborhood
    00149          <BR>&nbsp;&nbsp;&nbsp;<em>4- and 8-neighborhood definitions and circulators</em>
    00150     <LI> \ref VoxelNeighborhood
    00151          <BR>&nbsp;&nbsp;&nbsp;<em>6- and 26-neighborhood definitions and circulators</em>
    00152     <LI> \ref vigra::IteratorAdaptor
    00153          <BR>&nbsp;&nbsp;&nbsp;<em>Quickly create STL-compatible 1D iterator adaptors</em>
    00154     <LI> \ref TupleTypes
    00155          <BR>&nbsp;&nbsp;&nbsp;<em>pair, triple, tuple4, tuple5</em>
    00156     <LI> \ref MathConstants
    00157          <BR>&nbsp;&nbsp;&nbsp;<em>M_PI, M_SQRT2</em>
    00158     <LI> \ref TimingMacros
    00159          <BR>&nbsp;&nbsp;&nbsp;<em>Macros for taking execution speed measurements</em>
    00160     </UL>
    00161 */
    00162
    00163 #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.9.0 (Tue Nov 6 2012)