Coverage Report

Created: 2023-06-07 06:57

/src/opencv/3rdparty/openexr/IlmImf/ImfAttribute.cpp
Line
Count
Source (jump to first uncovered line)
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
#include "ImfNamespace.h"
50
51
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER 
52
53
54
using ILMTHREAD_NAMESPACE::Mutex;
55
using ILMTHREAD_NAMESPACE::Lock;
56
57
58
0
Attribute::Attribute () {}
59
60
61
0
Attribute::~Attribute () {}
62
63
64
namespace {
65
66
struct NameCompare
67
{
68
    bool
69
    operator () (const char *x, const char *y) const
70
0
    {
71
0
  return strcmp (x, y) < 0;
72
0
    }
73
};
74
75
76
typedef Attribute* (*Constructor)();
77
typedef std::map <const char *, Constructor, NameCompare> TypeMap;
78
79
80
class LockedTypeMap: public TypeMap
81
{
82
  public:
83
84
    Mutex mutex;
85
};
86
87
88
LockedTypeMap &
89
typeMap ()
90
0
{
91
    // c++11 requires thread-safe static variable initialization
92
0
#if __cplusplus >= 201103L
93
0
    static LockedTypeMap tMap;
94
0
    return tMap;
95
#else
96
    static Mutex criticalSection;
97
    Lock lock (criticalSection);
98
99
    static LockedTypeMap* typeMap = 0;
100
101
    if (typeMap == 0)
102
  typeMap = new LockedTypeMap ();
103
104
    return *typeMap;
105
#endif
106
0
}
107
108
109
} // namespace
110
111
112
bool    
113
Attribute::knownType (const char typeName[])
114
0
{
115
0
    LockedTypeMap& tMap = typeMap();
116
0
    Lock lock (tMap.mutex);
117
118
0
    return tMap.find (typeName) != tMap.end();
119
0
}
120
121
122
void  
123
Attribute::registerAttributeType (const char typeName[],
124
                Attribute *(*newAttribute)())
125
0
{
126
0
    LockedTypeMap& tMap = typeMap();
127
0
    Lock lock (tMap.mutex);
128
129
0
    if (tMap.find (typeName) != tMap.end())
130
0
  THROW (IEX_NAMESPACE::ArgExc, "Cannot register image file attribute "
131
0
          "type \"" << typeName << "\". "
132
0
          "The type has already been registered.");
133
134
0
    tMap.insert (TypeMap::value_type (typeName, newAttribute));
135
0
}
136
137
138
void
139
Attribute::unRegisterAttributeType (const char typeName[])
140
0
{
141
0
    LockedTypeMap& tMap = typeMap();
142
0
    Lock lock (tMap.mutex);
143
144
0
    tMap.erase (typeName);
145
0
}
146
147
148
Attribute *
149
Attribute::newAttribute (const char typeName[])
150
0
{
151
0
    LockedTypeMap& tMap = typeMap();
152
0
    Lock lock (tMap.mutex);
153
154
0
    TypeMap::const_iterator i = tMap.find (typeName);
155
156
0
    if (i == tMap.end())
157
0
  THROW (IEX_NAMESPACE::ArgExc, "Cannot create image file attribute of "
158
0
          "unknown type \"" << typeName << "\".");
159
160
0
    return (i->second)();
161
0
}
162
163
164
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT