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"
20 // A macro to disallow the copy constructor and operator= functions
21 // This must be used in the private: declarations for a class
22 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
23 TypeName(const TypeName&); \
24 void operator=(const TypeName&)
26 template <typename T, unsigned int N>
27 inline unsigned int ArraySize(T(&)[N])
32 template <typename T, unsigned int N>
33 void SafeRelease(T (&resourceBlock)[N])
35 for (unsigned int i = 0; i < N; i++)
37 SafeRelease(resourceBlock[i]);
42 void SafeRelease(T& resource)
52 void SafeDelete(T*& resource)
59 void SafeDeleteContainer(T& resource)
61 for (typename T::iterator i = resource.begin(); i != resource.end(); i++)
69 void SafeDeleteArray(T*& resource)
75 // Provide a less-than function for comparing structs
76 // Note: struct memory must be initialized to zero, because of packing gaps
78 inline bool StructLessThan(const T &a, const T &b)
80 return (memcmp(&a, &b, sizeof(T)) < 0);
83 // Provide a less-than function for comparing structs
84 // Note: struct memory must be initialized to zero, because of packing gaps
86 inline bool StructEquals(const T &a, const T &b)
88 return (memcmp(&a, &b, sizeof(T)) == 0);
92 inline void StructZero(T *obj)
94 memset(obj, 0, sizeof(T));
97 inline const char* MakeStaticString(const std::string &str)
99 static std::set<std::string> strings;
100 std::set<std::string>::iterator it = strings.find(str);
101 if (it != strings.end())
106 return strings.insert(str).first->c_str();
109 inline std::string ArrayString(unsigned int i)
111 // We assume UINT_MAX and GL_INVALID_INDEX are equal
112 // See DynamicHLSL.cpp
118 std::stringstream strstr;
127 inline std::string Str(int i)
129 std::stringstream strstr;
134 #if defined(_MSC_VER)
135 #define snprintf _snprintf
138 #define VENDOR_ID_AMD 0x1002
139 #define VENDOR_ID_INTEL 0x8086
140 #define VENDOR_ID_NVIDIA 0x10DE
142 #define GL_BGRA4_ANGLEX 0x6ABC
143 #define GL_BGR5_A1_ANGLEX 0x6ABD
144 #define GL_INT_64_ANGLEX 0x6ABE
145 #define GL_STRUCT_ANGLEX 0x6ABF
147 #endif // COMMON_ANGLEUTILS_H_