1 | /*
|
---|
2 | Copyright (C) 2005-2006 Feeling Software Inc.
|
---|
3 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
4 | */
|
---|
5 | /*
|
---|
6 | Based on the FS Import classes:
|
---|
7 | Copyright (C) 2005-2006 Feeling Software Inc
|
---|
8 | Copyright (C) 2005-2006 Autodesk Media Entertainment
|
---|
9 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
10 | */
|
---|
11 |
|
---|
12 | /**
|
---|
13 | @file FUtils.h
|
---|
14 | Includes the common utilities classes and macros.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /** @defgroup FUtils Utility Classes. */
|
---|
18 |
|
---|
19 | #ifndef _F_UTILS_H_
|
---|
20 | #define _F_UTILS_H_
|
---|
21 |
|
---|
22 | // STL
|
---|
23 | #ifdef _WIN32
|
---|
24 | #pragma warning(disable:4702)
|
---|
25 | #endif
|
---|
26 | #include <string>
|
---|
27 | #include <vector>
|
---|
28 | #include <set>
|
---|
29 | #include <xtree>
|
---|
30 | #include <map>
|
---|
31 | #include <algorithm>
|
---|
32 | #ifdef _WIN32
|
---|
33 | #pragma warning(default:4702)
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | // Pre-include the platform-specific macros and definitions
|
---|
37 | #include "FUtils/Platforms.h"
|
---|
38 | #include "FUtils/FUAssert.h"
|
---|
39 |
|
---|
40 | // PLUG_CRT enforces CRT memory checks every 128 allocations
|
---|
41 | // and CRT memory leaks output
|
---|
42 | #if defined(_DEBUG) && defined(WIN32) && defined(MEMORY_DEBUG)
|
---|
43 | #define PLUG_CRT
|
---|
44 | #ifdef PLUG_CRT
|
---|
45 | #include <crtdbg.h>
|
---|
46 | #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
|
---|
47 | #define new DEBUG_CLIENTBLOCK
|
---|
48 | #endif // PLUG_CRT
|
---|
49 | #endif // _DEBUG & WIN32 & MEMORY_DEBUG
|
---|
50 | |
---|
51 | // FMath |
---|
52 | #define HAS_VECTORTYPES /**< Used by FCollada, this #define implies that we are including all the common dynamically-sized arrays. */
|
---|
53 | #include "FMath/FMath.h" |
---|
54 |
|
---|
55 | // LibXML
|
---|
56 | #ifndef NO_LIBXML
|
---|
57 | #define HAS_LIBXML /**< Used by FCollada, this #define implies that we are including LibXML functions in the library interface. */
|
---|
58 | #define LIBXML_STATIC /**< Used by LibXML, this #define implies that we are statically-linking the LibXML. */
|
---|
59 | #include <libxml/tree.h>
|
---|
60 | #else
|
---|
61 | typedef struct _xmlNode xmlNode;
|
---|
62 | #endif
|
---|
63 | typedef vector<struct _xmlNode*> xmlNodeList; /**< A dynamically-sized array of XML nodes. */
|
---|
64 |
|
---|
65 | // SAFE_DELETE Macro set.
|
---|
66 | #define SAFE_DELETE(ptr) if ((ptr) != NULL) { delete (ptr); (ptr) = NULL; } /**< This macro safely deletes a pointer and sets the given pointer to NULL. */
|
---|
67 | #define SAFE_DELETE_ARRAY(ptr) if (ptr != NULL) { delete [] ptr; ptr = NULL; } /**< This macro safely deletes an heap array and sets the given pointer to NULL. */
|
---|
68 | #define SAFE_FREE(ptr) if (ptr != NULL) { free(ptr); ptr = NULL; } /**< This macro safely frees a memory block and sets the given pointer to NULL. */
|
---|
69 | #define SAFE_RELEASE(ptr) if ((ptr) != NULL) { (ptr)->Release(); (ptr) = NULL; } /**< This macro safely releases an interface and sets the given pointer to NULL. */
|
---|
70 | #define CLEAR_POINTER_VECTOR(a) { size_t l = (a).size(); for (size_t i = 0; i < l; ++i) SAFE_DELETE((a)[i]); (a).clear(); } /**< This macro deletes all the object pointers contained within a vector and clears it. */
|
---|
71 | #define CLEAR_POINTER_MAP(mapT, a) { for (mapT::iterator it = (a).begin(); it != (a).end(); ++it) SAFE_DELETE((*it).second); (a).clear(); } /**< This macro deletes all the object pointers contained within a map and clears it. */
|
---|
72 |
|
---|
73 | // Conversion macros
|
---|
74 | #define UNUSED(a) /**< Removes a piece of code during the pre-process. This macro is useful for these pesky unused variable warnings. */
|
---|
75 | #ifdef _DEBUG
|
---|
76 | #define UNUSED_NDEBUG(a) a
|
---|
77 | #else
|
---|
78 | #define UNUSED_NDEBUG(a) /**< Removes a piece of debug code during the pre-process. This macro is useful for these pesky unused variable warnings. */
|
---|
79 | #endif // _DEBUG
|
---|
80 |
|
---|
81 | #undef min
|
---|
82 | #define min(a, b) std::min(a, b) /**< Retrieves the smallest of two values. */
|
---|
83 | #undef max
|
---|
84 | #define max(a, b) std::max(a, b) /**< Retrieves the largest of two values. */
|
---|
85 |
|
---|
86 | // More complex utility classes
|
---|
87 | #include "FUtils/FUString.h"
|
---|
88 | #include "FUtils/FUCrc32.h"
|
---|
89 | #include "FUtils/FUDebug.h"
|
---|
90 | #include "FUtils/FUStatus.h"
|
---|
91 |
|
---|
92 | /** Retrieves whether two values are equivalent.
|
---|
93 | This template simply calls the operator== on the two values.
|
---|
94 | @param v1 A first value.
|
---|
95 | @param v2 A second value.
|
---|
96 | @return Whether the two values are equivalent. */
|
---|
97 | template <class T>
|
---|
98 | bool IsEquivalent(const T& v1, const T& v2) { return v1 == v2; }
|
---|
99 |
|
---|
100 | #endif // _F_UTILS_H_
|
---|