2 // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
7 // angleutils.h: Common ANGLE utilities.
9 #ifndef COMMON_ANGLEUTILS_H_
10 #define COMMON_ANGLEUTILS_H_
12 #include "common/platform.h"
22 // A macro to disallow the copy constructor and operator= functions
23 // This must be used in the private: declarations for a class
24 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
25 TypeName(const TypeName&); \
26 void operator=(const TypeName&)
28 template <typename T, size_t N>
29 inline size_t ArraySize(T(&)[N])
34 template <typename T, unsigned int N>
35 void SafeRelease(T (&resourceBlock)[N])
37 for (unsigned int i = 0; i < N; i++)
39 SafeRelease(resourceBlock[i]);
44 void SafeRelease(T& resource)
54 void SafeDelete(T*& resource)
61 void SafeDeleteContainer(T& resource)
63 for (typename T::iterator i = resource.begin(); i != resource.end(); i++)
71 void SafeDeleteArray(T*& resource)
77 // Provide a less-than function for comparing structs
78 // Note: struct memory must be initialized to zero, because of packing gaps
80 inline bool StructLessThan(const T &a, const T &b)
82 return (memcmp(&a, &b, sizeof(T)) < 0);
85 // Provide a less-than function for comparing structs
86 // Note: struct memory must be initialized to zero, because of packing gaps
88 inline bool StructEquals(const T &a, const T &b)
90 return (memcmp(&a, &b, sizeof(T)) == 0);
94 inline void StructZero(T *obj)
96 memset(obj, 0, sizeof(T));
100 inline bool IsMaskFlagSet(T mask, T flag)
102 // Handles multibit flags as well
103 return (mask & flag) == flag;
106 inline const char* MakeStaticString(const std::string &str)
108 static std::set<std::string> strings;
109 std::set<std::string>::iterator it = strings.find(str);
110 if (it != strings.end())
115 return strings.insert(str).first->c_str();
118 inline std::string ArrayString(unsigned int i)
120 // We assume UINT_MAX and GL_INVALID_INDEX are equal
121 // See DynamicHLSL.cpp
127 std::stringstream strstr;
136 inline std::string Str(int i)
138 std::stringstream strstr;
143 size_t FormatStringIntoVector(const char *fmt, va_list vararg, std::vector<char>& buffer);
145 std::string FormatString(const char *fmt, va_list vararg);
146 std::string FormatString(const char *fmt, ...);
148 #if defined(_MSC_VER)
149 #define snprintf _snprintf
152 #define VENDOR_ID_AMD 0x1002
153 #define VENDOR_ID_INTEL 0x8086
154 #define VENDOR_ID_NVIDIA 0x10DE
156 #define GL_BGRA4_ANGLEX 0x6ABC
157 #define GL_BGR5_A1_ANGLEX 0x6ABD
158 #define GL_INT_64_ANGLEX 0x6ABE
159 #define GL_STRUCT_ANGLEX 0x6ABF
161 #endif // COMMON_ANGLEUTILS_H_