PageRenderTime 64ms CodeModel.GetById 23ms app.highlight 36ms RepoModel.GetById 1ms app.codeStats 0ms

/src/FreeImage/Source/OpenEXR/IlmImf/ImfChannelList.cpp

https://bitbucket.org/cabalistic/ogredeps/
C++ | 321 lines | 204 code | 77 blank | 40 comment | 34 complexity | d622f01b7505209ee27bd85d2c70ddef MD5 | raw file
  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 Channel
 40//	class ChannelList
 41//
 42//-----------------------------------------------------------------------------
 43
 44#include <ImfChannelList.h>
 45#include <Iex.h>
 46
 47
 48using std::string;
 49using std::set;
 50
 51namespace Imf {
 52
 53
 54Channel::Channel (PixelType t, int xs, int ys, bool pl):
 55    type (t),
 56    xSampling (xs),
 57    ySampling (ys),
 58    pLinear (pl)
 59{
 60    // empty
 61}
 62
 63
 64bool	
 65Channel::operator == (const Channel &other) const
 66{
 67    return type == other.type &&
 68	   xSampling == other.xSampling &&
 69	   ySampling == other.ySampling &&
 70	   pLinear == other.pLinear;
 71}
 72
 73
 74void	
 75ChannelList::insert (const char name[], const Channel &channel)
 76{
 77    if (name[0] == 0)
 78	THROW (Iex::ArgExc, "Image channel name cannot be an empty string.");
 79
 80    _map[name] = channel;
 81}
 82
 83
 84void	
 85ChannelList::insert (const string &name, const Channel &channel)
 86{
 87    insert (name.c_str(), channel);
 88}
 89
 90
 91Channel &
 92ChannelList::operator [] (const char name[])
 93{
 94    ChannelMap::iterator i = _map.find (name);
 95
 96    if (i == _map.end())
 97	THROW (Iex::ArgExc, "Cannot find image channel \"" << name << "\".");
 98
 99    return i->second;
100}
101
102
103const Channel &
104ChannelList::operator [] (const char name[]) const
105{
106    ChannelMap::const_iterator i = _map.find (name);
107
108    if (i == _map.end())
109	THROW (Iex::ArgExc, "Cannot find image channel \"" << name << "\".");
110
111    return i->second;
112}
113
114
115Channel &
116ChannelList::operator [] (const string &name)
117{
118    return this->operator[] (name.c_str());
119}
120
121
122const Channel &
123ChannelList::operator [] (const string &name) const
124{
125    return this->operator[] (name.c_str());
126}
127
128
129Channel *
130ChannelList::findChannel (const char name[])
131{
132    ChannelMap::iterator i = _map.find (name);
133    return (i == _map.end())? 0: &i->second;
134}
135
136
137const Channel *
138ChannelList::findChannel (const char name[]) const
139{
140    ChannelMap::const_iterator i = _map.find (name);
141    return (i == _map.end())? 0: &i->second;
142}
143
144
145Channel *
146ChannelList::findChannel (const string &name)
147{
148    return findChannel (name.c_str());
149}
150
151
152const Channel *
153ChannelList::findChannel (const string &name) const
154{
155    return findChannel (name.c_str());
156}
157
158
159ChannelList::Iterator		
160ChannelList::begin ()
161{
162    return _map.begin();
163}
164
165
166ChannelList::ConstIterator	
167ChannelList::begin () const
168{
169    return _map.begin();
170}
171
172
173ChannelList::Iterator
174ChannelList::end ()
175{
176    return _map.end();
177}
178
179
180ChannelList::ConstIterator	
181ChannelList::end () const
182{
183    return _map.end();
184}
185
186
187ChannelList::Iterator
188ChannelList::find (const char name[])
189{
190    return _map.find (name);
191}
192
193
194ChannelList::ConstIterator
195ChannelList::find (const char name[]) const
196{
197    return _map.find (name);
198}
199
200
201ChannelList::Iterator
202ChannelList::find (const string &name)
203{
204    return find (name.c_str());
205}
206
207
208ChannelList::ConstIterator
209ChannelList::find (const string &name) const
210{
211    return find (name.c_str());
212}
213
214
215void
216ChannelList::layers (set <string> &layerNames) const
217{
218    layerNames.clear();
219
220    for (ConstIterator i = begin(); i != end(); ++i)
221    {
222	string layerName = i.name();
223	size_t pos = layerName.rfind ('.');
224
225	if (pos != string::npos && pos != 0 && pos + 1 < layerName.size())
226	{
227	    layerName.erase (pos);
228	    layerNames.insert (layerName);
229	}
230    }
231}
232
233
234void
235ChannelList::channelsInLayer (const string &layerName,
236			      Iterator &first,
237			      Iterator &last)
238{
239    channelsWithPrefix (layerName + '.', first, last);
240}
241
242
243void
244ChannelList::channelsInLayer (const string &layerName,
245			      ConstIterator &first,
246			      ConstIterator &last) const
247{
248    channelsWithPrefix (layerName + '.', first, last);
249}
250
251
252void		
253ChannelList::channelsWithPrefix (const char prefix[],
254				 Iterator &first,
255				 Iterator &last)
256{
257    first = last = _map.lower_bound (prefix);
258    int n = strlen (prefix);
259
260    while (last != Iterator (_map.end()) &&
261	   strncmp (last.name(), prefix, n) <= 0)
262    {
263	++last;
264    }
265}
266
267
268void
269ChannelList::channelsWithPrefix (const char prefix[],
270				 ConstIterator &first,
271				 ConstIterator &last) const
272{
273    first = last = _map.lower_bound (prefix);
274    int n = strlen (prefix);
275
276    while (last != ConstIterator (_map.end()) &&
277	   strncmp (last.name(), prefix, n) <= 0)
278    {
279	++last;
280    }
281}
282
283
284void		
285ChannelList::channelsWithPrefix (const string &prefix,
286				 Iterator &first,
287				 Iterator &last)
288{
289    return channelsWithPrefix (prefix.c_str(), first, last);
290}
291
292
293void
294ChannelList::channelsWithPrefix (const string &prefix,
295				 ConstIterator &first,
296				 ConstIterator &last) const
297{
298    return channelsWithPrefix (prefix.c_str(), first, last);
299}
300
301
302bool		
303ChannelList::operator == (const ChannelList &other) const
304{
305    ConstIterator i = begin();
306    ConstIterator j = other.begin();
307
308    while (i != end() && j != other.end())
309    {
310	if (!(i.channel() == j.channel()))
311	    return false;
312
313	++i;
314	++j;
315    }
316
317    return i == end() && j == other.end();
318}
319
320
321} // namespace Imf