00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00037
00038
00039
00040 #ifndef OPENIMAGEIO_STRUTIL_H
00041 #define OPENIMAGEIO_STRUTIL_H
00042
00043 #include <cstdarg>
00044 #include <string>
00045 #include <cstring>
00046
00047 #ifdef _WIN32
00048 #include "hash.h"
00049 #endif
00050
00051 #include "export.h"
00052
00053 #ifndef OPENIMAGEIO_PRINTF_ARGS
00054 # ifndef __GNUC__
00055 # define __attribute__(x)
00056 # endif
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 # define OPENIMAGEIO_PRINTF_ARGS(fmtarg_pos, vararg_pos) \
00069 __attribute__ ((format (printf, fmtarg_pos, vararg_pos) ))
00070 #endif
00071
00072 #ifdef OPENIMAGEIO_NAMESPACE
00073 namespace OPENIMAGEIO_NAMESPACE {
00074 #endif
00075
00079 namespace Strutil {
00080
00081
00084 std::string DLLPUBLIC format (const char *fmt, ...)
00085 OPENIMAGEIO_PRINTF_ARGS(1,2);
00086
00089 std::string DLLPUBLIC vformat (const char *fmt, va_list ap)
00090 OPENIMAGEIO_PRINTF_ARGS(1,0);
00091
00097 std::string DLLPUBLIC memformat (off_t bytes, int digits=3);
00098
00101 std::string DLLPUBLIC timeintervalformat (double secs, int digits=1);
00102
00103
00104
00107 inline unsigned int
00108 strhash (const char *s)
00109 {
00110 if (!s) return 0;
00111 unsigned int h=0, g;
00112 while (*s) {
00113 h = (h<<4) + (unsigned char)(*s);
00114 if ((g = (h & 0xf0000000))) {
00115 h ^= g>>24;
00116 h ^= g;
00117 }
00118 ++s;
00119 }
00120 return h;
00121 }
00122
00123
00124
00135 class StringHash
00136 #ifdef _WIN32
00137 : public hash_compare<const char*>
00138 #endif
00139 {
00140 public:
00141 size_t operator() (const char *s) const {
00142 return (size_t)Strutil::strhash(s);
00143 }
00144 #ifdef _WIN32
00145 bool operator() (const char *a, const char *b) {
00146 return strcmp (a, b) < 0;
00147 }
00148 #endif
00149 };
00150
00151
00152
00155 class StringEqual {
00156 public:
00157 bool operator() (const char *a, const char *b) {
00158 return strcmp (a, b) == 0;
00159 }
00160 };
00161
00162
00163 };
00164
00165
00166 #ifdef OPENIMAGEIO_NAMESPACE
00167 };
00168 using namespace OPENIMAGEIO_NAMESPACE;
00169 #endif
00170
00171 #endif // OPENIMAGEIO_STRUTIL_H