1 // util.h
2 //
3 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
4 //
5 // Miscellaneous useful functions.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 
12 #ifndef _CELUTIL_UTIL_H_
13 #define _CELUTIL_UTIL_H_
14 
15 #include <string>
16 #include <vector>
17 #include <iostream>
18 #include <functional>
19 
20 // A little trickery to get something like a compile time assert in C++
21 #define COMPILE_TIME_ASSERT(pred) \
22     switch(0){case 0: case pred:;}
23 
24 #ifdef _WIN32
25 // The Windows header files define min and max macros. We prefer the min and
26 // max templates from STL because they don't result in unexpected multiple
27 // evaluations of arguments. In order to use them, we need to set NOMINMAX
28 // to prevent namespace pollution by the Windows macros.
29 #define NOMINMAX
30 #endif
31 
32 // gettext / libintl setup
33 #define _(string) gettext (string)
34 
35 #ifdef _WIN32
36 
37 #include "libintl.h"
38 
39 #else
40 
41 #ifndef TARGET_OS_MAC
42 #include <libintl.h>
43 #endif /* TARGET_OS_MAC */
44 
45 #endif
46 
47 extern int compareIgnoringCase(const std::string& s1, const std::string& s2);
48 extern int compareIgnoringCase(const std::string& s1, const std::string& s2, int n);
49 extern std::string LocaleFilename(const std::string & filename);
50 
51 class CompareIgnoringCasePredicate : public std::binary_function<std::string, std::string, bool>
52 {
53  public:
54     bool operator()(const std::string&, const std::string&) const;
55 };
56 
57 template <class T> struct printlineFunc : public std::unary_function<T, void>
58 {
printlineFuncprintlineFunc59     printlineFunc(std::ostream& o) : out(o) {};
operatorprintlineFunc60     void operator() (T x) { out << x << '\n'; };
61     std::ostream& out;
62 };
63 
64 template <class T> struct deleteFunc : public std::unary_function<T, void>
65 {
deleteFuncdeleteFunc66     deleteFunc() {};
operatordeleteFunc67     void operator() (T x) { delete x; };
68     int dummy;
69 };
70 
71 #endif // _CELUTIL_UTIL_H_
72