]> git.cworth.org Git - vogl/blob - src/voglcore/vogl_helpers.h
Initial vogl checkin
[vogl] / src / voglcore / vogl_helpers.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  *
25  **************************************************************************/
26
27 // File: vogl_helpers.h
28 #pragma once
29
30 #include "vogl_core.h"
31
32 #define VOGL_NO_COPY_OR_ASSIGNMENT_OP(c) \
33     c(const c &);                          \
34     c &operator=(const c &);
35 #define VOGL_NO_HEAP_ALLOC()         \
36     \
37 private:                               \
38     static void *operator new(size_t); \
39     static void *operator new[](size_t);
40
41 namespace vogl
42 {
43     namespace helpers
44     {
45         template <typename T>
46         struct rel_ops
47         {
48             friend bool operator!=(const T &x, const T &y)
49             {
50                 return (!(x == y));
51             }
52             friend bool operator>(const T &x, const T &y)
53             {
54                 return (y < x);
55             }
56             friend bool operator<=(const T &x, const T &y)
57             {
58                 return (!(y < x));
59             }
60             friend bool operator>=(const T &x, const T &y)
61             {
62                 return (!(x < y));
63             }
64         };
65
66         template <typename T>
67         inline T *construct(T *p)
68         {
69             return new (static_cast<void *>(p)) T;
70         }
71
72         template <typename T, typename U>
73         inline T *construct(T *p, const U &init)
74         {
75             return new (static_cast<void *>(p)) T(init);
76         }
77
78         template <typename T>
79         inline void construct_array(T *p, uint n)
80         {
81             T *q = p + n;
82             for (; p != q; ++p)
83                 new (static_cast<void *>(p)) T;
84         }
85
86         template <typename T, typename U>
87         inline void construct_array(T *p, uint n, const U &init)
88         {
89             T *q = p + n;
90             for (; p != q; ++p)
91                 new (static_cast<void *>(p)) T(init);
92         }
93
94         template <typename T>
95         inline void destruct(T *p)
96         {
97             p->~T();
98         }
99
100         template <typename T>
101         inline void destruct_array(T *p, uint n)
102         {
103             T *q = p + n;
104             for (; p != q; ++p)
105                 p->~T();
106         }
107
108     } // namespace helpers
109
110 } // namespace vogl