ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.127 by root, Sat Nov 17 23:40:02 2018 UTC vs.
Revision 1.129 by root, Sat Dec 1 20:22:13 2018 UTC

37#include <new> 37#include <new>
38#include <vector> 38#include <vector>
39 39
40#include <glib.h> 40#include <glib.h>
41 41
42#include <flat_hash_map.hpp>
43
42#include <shstr.h> 44#include <shstr.h>
43#include <traits.h> 45#include <traits.h>
44 46
45#if DEBUG_SALLOC 47#if DEBUG_SALLOC
46# define g_slice_alloc0(s) debug_slice_alloc0(s) 48# define g_slice_alloc0(s) debug_slice_alloc0(s)
53# define g_slice_alloc0(s) calloc (1, (s)) 55# define g_slice_alloc0(s) calloc (1, (s))
54# define g_slice_alloc(s) malloc ((s)) 56# define g_slice_alloc(s) malloc ((s))
55# define g_slice_free1(s,p) free ((p)) 57# define g_slice_free1(s,p) free ((p))
56#endif 58#endif
57 59
58// use C0X decltype for auto declarations until ISO C++ sanctifies them (if ever)
59#define auto(var,expr) decltype(expr) var = (expr)
60
61#if cplusplus_does_not_suck /* still sucks in codesize with gcc 6, although local types work now */
62// does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm)
63template<typename T, int N>
64static inline int array_length (const T (&arr)[N])
65{
66 return N;
67}
68#else
69#define array_length(name) (sizeof (name) / sizeof (name [0]))
70#endif
71
72// very ugly macro that basically declares and initialises a variable 60// very ugly macro that basically declares and initialises a variable
73// that is in scope for the next statement only 61// that is in scope for the next statement only
74// works only for stuff that can be assigned 0 and converts to false 62// works only for stuff that can be assigned 0 and converts to false
75// (note: works great for pointers) 63// (note: works great for pointers)
76// most ugly macro I ever wrote 64// most ugly macro I ever wrote
617 605
618 std::size_t operator ()(const shstr &s) const 606 std::size_t operator ()(const shstr &s) const
619 { 607 {
620 return strhsh (s); 608 return strhsh (s);
621 } 609 }
610
611 typedef ska::power_of_two_hash_policy hash_policy;
622}; 612};
623 613
624struct str_equal 614struct str_equal
625{ 615{
626 bool operator ()(const char *a, const char *b) const 616 bool operator ()(const char *a, const char *b) const

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines