Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/3rdparty/openexr/IlmImf/ImfAttribute.cpp
16337 views
1
///////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
4
// Digital Ltd. LLC
5
//
6
// All rights reserved.
7
//
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
10
// met:
11
// * Redistributions of source code must retain the above copyright
12
// notice, this list of conditions and the following disclaimer.
13
// * Redistributions in binary form must reproduce the above
14
// copyright notice, this list of conditions and the following disclaimer
15
// in the documentation and/or other materials provided with the
16
// distribution.
17
// * Neither the name of Industrial Light & Magic nor the names of
18
// its contributors may be used to endorse or promote products derived
19
// from this software without specific prior written permission.
20
//
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
//
33
///////////////////////////////////////////////////////////////////////////
34
35
36
37
//-----------------------------------------------------------------------------
38
//
39
// class Attribute
40
//
41
//-----------------------------------------------------------------------------
42
43
#include <ImfAttribute.h>
44
#include "IlmThreadMutex.h"
45
#include "Iex.h"
46
#include <string.h>
47
#include <map>
48
49
50
namespace Imf {
51
52
using IlmThread::Mutex;
53
using IlmThread::Lock;
54
55
56
Attribute::Attribute () {}
57
58
59
Attribute::~Attribute () {}
60
61
62
namespace {
63
64
struct NameCompare: std::binary_function <const char *, const char *, bool>
65
{
66
bool
67
operator () (const char *x, const char *y) const
68
{
69
return strcmp (x, y) < 0;
70
}
71
};
72
73
74
typedef Attribute* (*Constructor)();
75
typedef std::map <const char *, Constructor, NameCompare> TypeMap;
76
77
78
class LockedTypeMap: public TypeMap
79
{
80
public:
81
82
Mutex mutex;
83
};
84
85
86
LockedTypeMap &
87
typeMap ()
88
{
89
static Mutex criticalSection;
90
Lock lock (criticalSection);
91
92
static LockedTypeMap* typeMap = 0;
93
94
if (typeMap == 0)
95
typeMap = new LockedTypeMap ();
96
97
return *typeMap;
98
}
99
100
101
} // namespace
102
103
104
bool
105
Attribute::knownType (const char typeName[])
106
{
107
LockedTypeMap& tMap = typeMap();
108
Lock lock (tMap.mutex);
109
110
return tMap.find (typeName) != tMap.end();
111
}
112
113
114
void
115
Attribute::registerAttributeType (const char typeName[],
116
Attribute *(*newAttribute)())
117
{
118
LockedTypeMap& tMap = typeMap();
119
Lock lock (tMap.mutex);
120
121
if (tMap.find (typeName) != tMap.end())
122
THROW (Iex::ArgExc, "Cannot register image file attribute "
123
"type \"" << typeName << "\". "
124
"The type has already been registered.");
125
126
tMap.insert (TypeMap::value_type (typeName, newAttribute));
127
}
128
129
130
void
131
Attribute::unRegisterAttributeType (const char typeName[])
132
{
133
LockedTypeMap& tMap = typeMap();
134
Lock lock (tMap.mutex);
135
136
tMap.erase (typeName);
137
}
138
139
140
Attribute *
141
Attribute::newAttribute (const char typeName[])
142
{
143
LockedTypeMap& tMap = typeMap();
144
Lock lock (tMap.mutex);
145
146
TypeMap::const_iterator i = tMap.find (typeName);
147
148
if (i == tMap.end())
149
THROW (Iex::ArgExc, "Cannot create image file attribute of "
150
"unknown type \"" << typeName << "\".");
151
152
return (i->second)();
153
}
154
155
156
} // namespace Imf
157
158