Alembic 1.8.11

Loading...
Searching...
No Matches
Foundation.h
1//-*****************************************************************************
2//
3// Copyright (c) 2009-2015,
4// Sony Pictures Imageworks Inc. and
5// Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6//
7// All rights reserved.
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12// * Redistributions of source code must retain the above copyright
13// notice, this list of conditions and the following disclaimer.
14// * Redistributions in binary form must reproduce the above
15// copyright notice, this list of conditions and the following disclaimer
16// in the documentation and/or other materials provided with the
17// distribution.
18// * Neither the name of Industrial Light & Magic nor the names of
19// its contributors may be used to endorse or promote products derived
20// from this software without specific prior written permission.
21//
22// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33//
34//-*****************************************************************************
35
36#ifndef Alembic_Util_Foundation_h
37#define Alembic_Util_Foundation_h
38
39#include <Alembic/Util/Config.h>
40
41#include <unordered_map>
42
43#include <memory>
44
45#include <Imath/half.h>
46
47#include <iomanip>
48#include <iostream>
49#include <sstream>
50#include <exception>
51#include <limits>
52
53#include <list>
54#include <map>
55#include <string>
56#include <vector>
57
58#include <cstdio>
59#include <cstdlib>
60#include <cstring>
61#include <cassert>
62
63#include <Alembic/Util/Export.h>
64
65#ifdef _MSC_VER
66
67#ifndef WIN32_LEAN_AND_MEAN
68#define WIN32_LEAN_AND_MEAN
69#endif
70
71// avoid windows min/max predefined macro conflicts
72#ifndef NOMINMAX
73#define NOMINMAX
74#endif
75
76// needed for mutex stuff
77#include <windows.h>
78#endif
79
80// needed for std min/max
81#include <algorithm>
82
83// When we change this version (because of an ABI change) Make sure to at
84// LEAST bump the minor version in CMakeLists.txt i.e. PROJECT_VERSION_MINOR
85// This way we will hopefully not break any distros that kindly include us.
86// See Issue243
87#ifndef ALEMBIC_VERSION_NS
88#define ALEMBIC_VERSION_NS v12
89#endif
90
91 namespace Alembic {
92 namespace Util {
93 namespace ALEMBIC_VERSION_NS {
94
95// similiar to boost::noncopyable
96// explicitly hides copy construction and copy assignment
97 class ALEMBIC_EXPORT noncopyable
98{
99 protected:
100 noncopyable() {}
101 ~noncopyable() {}
102
103 private:
104 noncopyable( const noncopyable& );
105 const noncopyable& operator=( const noncopyable& );
106};
107
108 using std::dynamic_pointer_cast;
109 using std::enable_shared_from_this;
110 using std::shared_ptr;
111 using std::static_pointer_cast;
112 using std::weak_ptr;
113 using std::unordered_map;
114 using std::unique_ptr;
115
116// similiar to boost::totally_ordered
117// only need < and == operators and this fills in the rest
118 template < class T >
119 class totally_ordered
120{
121 friend bool operator > ( const T& x, const T& y )
122 {
123 return y < x;
124 }
125
126 friend bool operator <= ( const T& x, const T& y )
127 {
128 return !( y < x );
129 }
130
131 friend bool operator >= ( const T& x, const T& y )
132 {
133 return !( x < y );
134 }
135
136 friend bool operator != ( const T& x, const T& y )
137 {
138 return !( x == y );
139 }
140};
141
142// inspired by boost::mutex
143#ifdef _MSC_VER
144
145 class mutex : noncopyable
146{
147 public:
148 mutex()
149 {
150 InitializeCriticalSection(&cs);
151 }
152
153 ~mutex()
154 {
155 DeleteCriticalSection(&cs);
156 }
157
158 void lock()
159 {
160 EnterCriticalSection(&cs);
161 }
162
163 void unlock()
164 {
165 LeaveCriticalSection(&cs);
166 }
167
168 private:
169 CRITICAL_SECTION cs;
170};
171
172#else
173
174
175 class mutex : noncopyable
176{
177 public:
178 mutex()
179 {
180 pthread_mutex_init( &m, NULL );
181 }
182
183 ~mutex()
184 {
185 pthread_mutex_destroy( &m );
186 }
187
188 void lock()
189 {
190 pthread_mutex_lock( &m );
191 }
192
193 void unlock()
194 {
195 pthread_mutex_unlock( &m );
196 }
197
198 private:
199 pthread_mutex_t m;
200};
201
202#endif
203
204 class scoped_lock : noncopyable
205{
206 public:
207 scoped_lock( mutex & l ) : m( l )
208 {
209 m.lock();
210 }
211
212 ~scoped_lock()
213 {
214 m.unlock();
215 }
216
217 private:
218 mutex & m;
219};
220
221} // End namespace ALEMBIC_VERSION_NS
222
223 using namespace ALEMBIC_VERSION_NS;
224
225} // End namespace Util
226} // End namespace Alembic
227
228#endif
Alembic::Util::ALEMBIC_VERSION_NS::mutex
Definition Foundation.h:176
Alembic::Util::ALEMBIC_VERSION_NS::noncopyable
Definition Foundation.h:98
Alembic::Util::ALEMBIC_VERSION_NS::totally_ordered
Definition Foundation.h:120
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39