Blame IlmImf/ImfHeader.h

Packit 0d464f
///////////////////////////////////////////////////////////////////////////
Packit 0d464f
//
Packit 0d464f
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
Packit 0d464f
// Digital Ltd. LLC
Packit 0d464f
// 
Packit 0d464f
// All rights reserved.
Packit 0d464f
// 
Packit 0d464f
// Redistribution and use in source and binary forms, with or without
Packit 0d464f
// modification, are permitted provided that the following conditions are
Packit 0d464f
// met:
Packit 0d464f
// *       Redistributions of source code must retain the above copyright
Packit 0d464f
// notice, this list of conditions and the following disclaimer.
Packit 0d464f
// *       Redistributions in binary form must reproduce the above
Packit 0d464f
// copyright notice, this list of conditions and the following disclaimer
Packit 0d464f
// in the documentation and/or other materials provided with the
Packit 0d464f
// distribution.
Packit 0d464f
// *       Neither the name of Industrial Light & Magic nor the names of
Packit 0d464f
// its contributors may be used to endorse or promote products derived
Packit 0d464f
// from this software without specific prior written permission. 
Packit 0d464f
// 
Packit 0d464f
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 0d464f
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 0d464f
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit 0d464f
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit 0d464f
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit 0d464f
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit 0d464f
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit 0d464f
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit 0d464f
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit 0d464f
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 0d464f
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 0d464f
//
Packit 0d464f
///////////////////////////////////////////////////////////////////////////
Packit 0d464f
Packit 0d464f
Packit 0d464f
Packit 0d464f
#ifndef INCLUDED_IMF_HEADER_H
Packit 0d464f
#define INCLUDED_IMF_HEADER_H
Packit 0d464f
Packit 0d464f
//-----------------------------------------------------------------------------
Packit 0d464f
//
Packit 0d464f
//	class Header
Packit 0d464f
//
Packit 0d464f
//-----------------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
#include "ImfLineOrder.h"
Packit 0d464f
#include "ImfCompression.h"
Packit 0d464f
#include "ImfName.h"
Packit 0d464f
#include "ImfTileDescription.h"
Packit 0d464f
#include "ImfInt64.h"
Packit 0d464f
#include "ImathVec.h"
Packit 0d464f
#include "ImathBox.h"
Packit 0d464f
#include "IexBaseExc.h"
Packit 0d464f
Packit 0d464f
#include "ImfForward.h"
Packit 0d464f
#include "ImfNamespace.h"
Packit 0d464f
#include "ImfExport.h"
Packit 0d464f
Packit 0d464f
#include <map>
Packit 0d464f
#include <iosfwd>
Packit 0d464f
#include <string>
Packit 0d464f
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Packit 0d464f
Packit 0d464f
using std::string;
Packit 0d464f
Packit 0d464f
Packit 0d464f
class IMF_EXPORT Header
Packit 0d464f
{
Packit 0d464f
  public:
Packit 0d464f
    
Packit 0d464f
    //----------------------------------------------------------------
Packit 0d464f
    // Default constructor -- the display window and the data window
Packit 0d464f
    // are both set to Box2i (V2i (0, 0), V2i (width-1, height-1).
Packit 0d464f
    //----------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    Header (int width = 64,
Packit 0d464f
	    int height = 64,
Packit 0d464f
	    float pixelAspectRatio = 1,
Packit 0d464f
	    const IMATH_NAMESPACE::V2f &screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0),
Packit 0d464f
	    float screenWindowWidth = 1,
Packit 0d464f
	    LineOrder lineOrder = INCREASING_Y,
Packit 0d464f
	    Compression = ZIP_COMPRESSION);
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //--------------------------------------------------------------------
Packit 0d464f
    // Constructor -- the data window is specified explicitly; the display
Packit 0d464f
    // window is set to Box2i (V2i (0, 0), V2i (width-1, height-1).
Packit 0d464f
    //--------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    Header (int width,
Packit 0d464f
	    int height,
Packit 0d464f
	    const IMATH_NAMESPACE::Box2i &dataWindow,
Packit 0d464f
	    float pixelAspectRatio = 1,
Packit 0d464f
	    const IMATH_NAMESPACE::V2f &screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0),
Packit 0d464f
	    float screenWindowWidth = 1,
Packit 0d464f
	    LineOrder lineOrder = INCREASING_Y,
Packit 0d464f
	    Compression = ZIP_COMPRESSION);
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //----------------------------------------------------------
Packit 0d464f
    // Constructor -- the display window and the data window are
Packit 0d464f
    // both specified explicitly.
Packit 0d464f
    //----------------------------------------------------------
Packit 0d464f
Packit 0d464f
    Header (const IMATH_NAMESPACE::Box2i &displayWindow,
Packit 0d464f
	    const IMATH_NAMESPACE::Box2i &dataWindow,
Packit 0d464f
	    float pixelAspectRatio = 1,
Packit 0d464f
	    const IMATH_NAMESPACE::V2f &screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0),
Packit 0d464f
	    float screenWindowWidth = 1,
Packit 0d464f
	    LineOrder lineOrder = INCREASING_Y,
Packit 0d464f
	    Compression = ZIP_COMPRESSION);
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //-----------------
Packit 0d464f
    // Copy constructor
Packit 0d464f
    //-----------------
Packit 0d464f
Packit 0d464f
    Header (const Header &other);
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //-----------
Packit 0d464f
    // Destructor
Packit 0d464f
    //-----------
Packit 0d464f
Packit 0d464f
    ~Header ();
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //-----------
Packit 0d464f
    // Assignment
Packit 0d464f
    //-----------
Packit 0d464f
Packit 0d464f
    Header &			operator = (const Header &other);
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //---------------------------------------------------------------
Packit 0d464f
    // Add an attribute:
Packit 0d464f
    //
Packit 0d464f
    // insert(n,attr)	If no attribute with name n exists, a new
Packit 0d464f
    //			attribute with name n, and the same type as
Packit 0d464f
    //			attr, is added, and the value of attr is
Packit 0d464f
    //			copied into the new attribute.
Packit 0d464f
    //
Packit 0d464f
    //			If an attribute with name n exists, and its
Packit 0d464f
    //			type is the same as attr, the value of attr
Packit 0d464f
    //			is copied into this attribute.
Packit 0d464f
    //
Packit 0d464f
    //			If an attribute with name n exists, and its
Packit 0d464f
    //			type is different from attr, an IEX_NAMESPACE::TypeExc
Packit 0d464f
    //			is thrown.
Packit 0d464f
    //
Packit 0d464f
    //---------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    void			insert (const char name[],
Packit 0d464f
				        const Attribute &attribute);
Packit 0d464f
Packit 0d464f
    void			insert (const std::string &name,
Packit 0d464f
				        const Attribute &attribute);
Packit 0d464f
Packit 0d464f
    //---------------------------------------------------------------
Packit 0d464f
    // Remove an attribute:
Packit 0d464f
    //
Packit 0d464f
    // remove(n)       If an attribute with name n exists, then it
Packit 0d464f
    //                 is removed from the map of present attributes.
Packit 0d464f
    //
Packit 0d464f
    //                 If no attribute with name n exists, then this
Packit 0d464f
    //                 functions becomes a 'no-op'
Packit 0d464f
    //
Packit 0d464f
    //---------------------------------------------------------------
Packit 0d464f
    void                        erase (const char name[]);
Packit 0d464f
    void                        erase (const std::string &name);
Packit 0d464f
Packit 0d464f
    
Packit 0d464f
    
Packit 0d464f
    //------------------------------------------------------------------
Packit 0d464f
    // Access to existing attributes:
Packit 0d464f
    //
Packit 0d464f
    // [n]			Returns a reference to the attribute
Packit 0d464f
    //				with name n.  If no attribute with
Packit 0d464f
    //				name n exists, an IEX_NAMESPACE::ArgExc is thrown.
Packit 0d464f
    //
Packit 0d464f
    // typedAttribute<T>(n)	Returns a reference to the attribute
Packit 0d464f
    //				with name n and type T.  If no attribute
Packit 0d464f
    //				with name n exists, an IEX_NAMESPACE::ArgExc is
Packit 0d464f
    //				thrown.  If an attribute with name n
Packit 0d464f
    //				exists, but its type is not T, an
Packit 0d464f
    //				IEX_NAMESPACE::TypeExc is thrown.
Packit 0d464f
    //
Packit 0d464f
    // findTypedAttribute<T>(n)	Returns a pointer to the attribute with
Packit 0d464f
    //				name n and type T, or 0 if no attribute
Packit 0d464f
    //				with name n and type T exists.
Packit 0d464f
    //
Packit 0d464f
    //------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    Attribute &			operator [] (const char name[]);
Packit 0d464f
    const Attribute &		operator [] (const char name[]) const;
Packit 0d464f
Packit 0d464f
    Attribute &			operator [] (const std::string &name);
Packit 0d464f
    const Attribute &		operator [] (const std::string &name) const;
Packit 0d464f
Packit 0d464f
    template <class T> T&	typedAttribute (const char name[]);
Packit 0d464f
    template <class T> const T&	typedAttribute (const char name[]) const;
Packit 0d464f
Packit 0d464f
    template <class T> T&	typedAttribute (const std::string &name);
Packit 0d464f
    template <class T> const T&	typedAttribute (const std::string &name) const;
Packit 0d464f
Packit 0d464f
    template <class T> T*	findTypedAttribute (const char name[]);
Packit 0d464f
    template <class T> const T*	findTypedAttribute (const char name[]) const;
Packit 0d464f
Packit 0d464f
    template <class T> T*	findTypedAttribute (const std::string &name);
Packit 0d464f
    template <class T> const T*	findTypedAttribute (const std::string &name)
Packit 0d464f
								       const;
Packit 0d464f
Packit 0d464f
    //---------------------------------------------
Packit 0d464f
    // Iterator-style access to existing attributes
Packit 0d464f
    //---------------------------------------------
Packit 0d464f
Packit 0d464f
    typedef std::map <Name, Attribute *> AttributeMap;
Packit 0d464f
Packit 0d464f
    class Iterator;
Packit 0d464f
    class ConstIterator;
Packit 0d464f
Packit 0d464f
    Iterator			begin ();
Packit 0d464f
    ConstIterator		begin () const;
Packit 0d464f
Packit 0d464f
    Iterator			end ();
Packit 0d464f
    ConstIterator		end () const;
Packit 0d464f
Packit 0d464f
    Iterator			find (const char name[]);
Packit 0d464f
    ConstIterator		find (const char name[]) const;
Packit 0d464f
Packit 0d464f
    Iterator			find (const std::string &name);
Packit 0d464f
    ConstIterator		find (const std::string &name) const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //--------------------------------
Packit 0d464f
    // Access to predefined attributes
Packit 0d464f
    //--------------------------------
Packit 0d464f
Packit 0d464f
    IMATH_NAMESPACE::Box2i &		displayWindow ();
Packit 0d464f
    const IMATH_NAMESPACE::Box2i &	displayWindow () const;
Packit 0d464f
Packit 0d464f
    IMATH_NAMESPACE::Box2i &		dataWindow ();
Packit 0d464f
    const IMATH_NAMESPACE::Box2i &	dataWindow () const;
Packit 0d464f
Packit 0d464f
    float &			pixelAspectRatio ();
Packit 0d464f
    const float &		pixelAspectRatio () const;
Packit 0d464f
Packit 0d464f
    IMATH_NAMESPACE::V2f &		screenWindowCenter ();
Packit 0d464f
    const IMATH_NAMESPACE::V2f &		screenWindowCenter () const;
Packit 0d464f
Packit 0d464f
    float &			screenWindowWidth ();
Packit 0d464f
    const float &		screenWindowWidth () const;
Packit 0d464f
Packit 0d464f
    ChannelList &		channels ();
Packit 0d464f
    const ChannelList &		channels () const;
Packit 0d464f
Packit 0d464f
    LineOrder &			lineOrder ();
Packit 0d464f
    const LineOrder &		lineOrder () const;
Packit 0d464f
Packit 0d464f
    Compression &		compression ();
Packit 0d464f
    const Compression &		compression () const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //-----------------------------------------------------
Packit 0d464f
    // Access to required attributes for multipart files
Packit 0d464f
    // They are optional to non-multipart files and mandatory
Packit 0d464f
    // for multipart files.
Packit 0d464f
    //-----------------------------------------------------
Packit 0d464f
    void                        setName (const string& name);
Packit 0d464f
Packit 0d464f
    string&                     name();
Packit 0d464f
    const string&               name() const;
Packit 0d464f
Packit 0d464f
    bool                        hasName() const;
Packit 0d464f
Packit 0d464f
    void                        setType (const string& Type);
Packit 0d464f
Packit 0d464f
    string&                     type();
Packit 0d464f
    const string&               type() const;
Packit 0d464f
Packit 0d464f
    bool                        hasType() const;
Packit 0d464f
Packit 0d464f
    void                        setVersion (const int version);
Packit 0d464f
Packit 0d464f
    int&                        version();
Packit 0d464f
    const int&                  version() const;
Packit 0d464f
Packit 0d464f
    bool                        hasVersion() const;
Packit 0d464f
Packit 0d464f
    //
Packit 0d464f
    // the chunkCount attribute is set automatically when a file is written.
Packit 0d464f
    // There is no need to set it manually
Packit 0d464f
    //
Packit 0d464f
    void                        setChunkCount(int chunks);
Packit 0d464f
    bool                        hasChunkCount() const;
Packit 0d464f
    const int &                 chunkCount() const;
Packit 0d464f
    int &                       chunkCount();
Packit 0d464f
Packit 0d464f
    
Packit 0d464f
    //
Packit 0d464f
    // for multipart files, return whether the file has a view string attribute
Packit 0d464f
    // (for the deprecated single part multiview format EXR, see ImfMultiView.h)
Packit 0d464f
    //
Packit 0d464f
    void                       setView(const string & view);
Packit 0d464f
    bool                       hasView() const;
Packit 0d464f
    string &                   view();
Packit 0d464f
    const string &             view() const;
Packit 0d464f
    
Packit 0d464f
Packit 0d464f
    //----------------------------------------------------------------------
Packit 0d464f
    // Tile Description:
Packit 0d464f
    //
Packit 0d464f
    // The tile description is a TileDescriptionAttribute whose name
Packit 0d464f
    // is "tiles".  The "tiles" attribute must be present in any tiled
Packit 0d464f
    // image file. When present, it describes various properties of the
Packit 0d464f
    // tiles that make up the file.
Packit 0d464f
    //
Packit 0d464f
    // Convenience functions:
Packit 0d464f
    //
Packit 0d464f
    // setTileDescription(td)
Packit 0d464f
    //     calls insert ("tiles", TileDescriptionAttribute (td))
Packit 0d464f
    //
Packit 0d464f
    // tileDescription()
Packit 0d464f
    //     returns typedAttribute<TileDescriptionAttribute>("tiles").value()
Packit 0d464f
    //
Packit 0d464f
    // hasTileDescription()
Packit 0d464f
    //     return findTypedAttribute<TileDescriptionAttribute>("tiles") != 0
Packit 0d464f
    //
Packit 0d464f
    //----------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    void			setTileDescription (const TileDescription & td);
Packit 0d464f
Packit 0d464f
    TileDescription &		tileDescription ();
Packit 0d464f
    const TileDescription &	tileDescription () const;
Packit 0d464f
Packit 0d464f
    bool			hasTileDescription() const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //----------------------------------------------------------------------
Packit 0d464f
    // Preview image:
Packit 0d464f
    //
Packit 0d464f
    // The preview image is a PreviewImageAttribute whose name is "preview".
Packit 0d464f
    // This attribute is special -- while an image file is being written,
Packit 0d464f
    // the pixels of the preview image can be changed repeatedly by calling
Packit 0d464f
    // OutputFile::updatePreviewImage().
Packit 0d464f
    //
Packit 0d464f
    // Convenience functions:
Packit 0d464f
    //
Packit 0d464f
    // setPreviewImage(p)
Packit 0d464f
    //     calls insert ("preview", PreviewImageAttribute (p))
Packit 0d464f
    //
Packit 0d464f
    // previewImage()
Packit 0d464f
    //     returns typedAttribute<PreviewImageAttribute>("preview").value()
Packit 0d464f
    //
Packit 0d464f
    // hasPreviewImage()
Packit 0d464f
    //     return findTypedAttribute<PreviewImageAttribute>("preview") != 0
Packit 0d464f
    //
Packit 0d464f
    //----------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    void			setPreviewImage (const PreviewImage &p);
Packit 0d464f
Packit 0d464f
    PreviewImage &		previewImage ();
Packit 0d464f
    const PreviewImage &	previewImage () const;
Packit 0d464f
Packit 0d464f
    bool			hasPreviewImage () const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //-------------------------------------------------------------
Packit 0d464f
    // Sanity check -- examines the header, and throws an exception
Packit 0d464f
    // if it finds something wrong (empty display window, negative
Packit 0d464f
    // pixel aspect ratio, unknown compression sceme etc.)
Packit 0d464f
    //
Packit 0d464f
    // set isTiled to true if you are checking a tiled/multi-res
Packit 0d464f
    // header
Packit 0d464f
    //-------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    void			sanityCheck (bool isTiled = false,
Packit 0d464f
        			             bool isMultipartFile = false) const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //----------------------------------------------------------------
Packit 0d464f
    // Maximum image size and maximim tile size:
Packit 0d464f
    //
Packit 0d464f
    // sanityCheck() will throw an exception if the width or height of
Packit 0d464f
    // the data window exceeds the maximum image width or height, or
Packit 0d464f
    // if the size of a tile exceeds the maximum tile width or height.
Packit 0d464f
    // 
Packit 0d464f
    // At program startup the maximum image and tile width and height
Packit 0d464f
    // are set to zero, meaning that width and height are unlimited.
Packit 0d464f
    //
Packit 0d464f
    // Limiting image and tile width and height limits how much memory
Packit 0d464f
    // will be allocated when a file is opened.  This can help protect
Packit 0d464f
    // applications from running out of memory while trying to read
Packit 0d464f
    // a damaged image file.
Packit 0d464f
    //----------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    static void			setMaxImageSize (int maxWidth, int maxHeight);
Packit 0d464f
    static void			setMaxTileSize (int maxWidth, int maxHeight);
Packit 0d464f
Packit 0d464f
    //
Packit 0d464f
    // Check if the header reads nothing.
Packit 0d464f
    //
Packit 0d464f
    bool                        readsNothing();
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //------------------------------------------------------------------
Packit 0d464f
    // Input and output:
Packit 0d464f
    //
Packit 0d464f
    // If the header contains a preview image attribute, then writeTo()
Packit 0d464f
    // returns the position of that attribute in the output stream; this
Packit 0d464f
    // information is used by OutputFile::updatePreviewImage().
Packit 0d464f
    // If the header contains no preview image attribute, then writeTo()
Packit 0d464f
    // returns 0.
Packit 0d464f
    //------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
Packit 0d464f
    Int64			writeTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os,
Packit 0d464f
					 bool isTiled = false) const;
Packit 0d464f
Packit 0d464f
    void			readFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is,
Packit 0d464f
        			          int &version);
Packit 0d464f
    
Packit 0d464f
Packit 0d464f
  private:
Packit 0d464f
Packit 0d464f
    AttributeMap		_map;
Packit 0d464f
Packit 0d464f
    bool                        _readsNothing;
Packit 0d464f
};
Packit 0d464f
Packit 0d464f
Packit 0d464f
//----------
Packit 0d464f
// Iterators
Packit 0d464f
//----------
Packit 0d464f
Packit 0d464f
class Header::Iterator
Packit 0d464f
{
Packit 0d464f
  public:
Packit 0d464f
Packit 0d464f
    Iterator ();
Packit 0d464f
    Iterator (const Header::AttributeMap::iterator &i);
Packit 0d464f
Packit 0d464f
    Iterator &			operator ++ ();
Packit 0d464f
    Iterator 			operator ++ (int);
Packit 0d464f
Packit 0d464f
    const char *		name () const;
Packit 0d464f
    Attribute &			attribute () const;
Packit 0d464f
Packit 0d464f
  private:
Packit 0d464f
Packit 0d464f
    friend class Header::ConstIterator;
Packit 0d464f
Packit 0d464f
    Header::AttributeMap::iterator _i;
Packit 0d464f
};
Packit 0d464f
Packit 0d464f
Packit 0d464f
class Header::ConstIterator
Packit 0d464f
{
Packit 0d464f
  public:
Packit 0d464f
Packit 0d464f
    ConstIterator ();
Packit 0d464f
    ConstIterator (const Header::AttributeMap::const_iterator &i);
Packit 0d464f
    ConstIterator (const Header::Iterator &other);
Packit 0d464f
Packit 0d464f
    ConstIterator &		operator ++ ();
Packit 0d464f
    ConstIterator 		operator ++ (int);
Packit 0d464f
Packit 0d464f
    const char *		name () const;
Packit 0d464f
    const Attribute &		attribute () const;
Packit 0d464f
Packit 0d464f
  private:
Packit 0d464f
Packit 0d464f
    friend bool operator == (const ConstIterator &, const ConstIterator &);
Packit 0d464f
    friend bool operator != (const ConstIterator &, const ConstIterator &);
Packit 0d464f
Packit 0d464f
    Header::AttributeMap::const_iterator _i;
Packit 0d464f
};
Packit 0d464f
Packit 0d464f
Packit 0d464f
//------------------------------------------------------------------------
Packit 0d464f
// Library initialization:
Packit 0d464f
//
Packit 0d464f
// In a multithreaded program, staticInitialize() must be called once
Packit 0d464f
// during startup, before the program accesses any other functions or
Packit 0d464f
// classes in the IlmImf library.  Calling staticInitialize() in this
Packit 0d464f
// way avoids races during initialization of the library's global
Packit 0d464f
// variables.
Packit 0d464f
//
Packit 0d464f
// Single-threaded programs are not required to call staticInitialize();
Packit 0d464f
// initialization of the library's global variables happens automatically.
Packit 0d464f
//
Packit 0d464f
//------------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
void staticInitialize ();
Packit 0d464f
Packit 0d464f
Packit 0d464f
//-----------------
Packit 0d464f
// Inline Functions
Packit 0d464f
//-----------------
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline
Packit 0d464f
Header::Iterator::Iterator (): _i()
Packit 0d464f
{
Packit 0d464f
    // empty
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline
Packit 0d464f
Header::Iterator::Iterator (const Header::AttributeMap::iterator &i): _i (i)
Packit 0d464f
{
Packit 0d464f
    // empty
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline Header::Iterator &		
Packit 0d464f
Header::Iterator::operator ++ ()
Packit 0d464f
{
Packit 0d464f
    ++_i;
Packit 0d464f
    return *this;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline Header::Iterator 	
Packit 0d464f
Header::Iterator::operator ++ (int)
Packit 0d464f
{
Packit 0d464f
    Iterator tmp = *this;
Packit 0d464f
    ++_i;
Packit 0d464f
    return tmp;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline const char *
Packit 0d464f
Header::Iterator::name () const
Packit 0d464f
{
Packit 0d464f
    return *_i->first;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline Attribute &	
Packit 0d464f
Header::Iterator::attribute () const
Packit 0d464f
{
Packit 0d464f
    return *_i->second;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline
Packit 0d464f
Header::ConstIterator::ConstIterator (): _i()
Packit 0d464f
{
Packit 0d464f
    // empty
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
inline
Packit 0d464f
Header::ConstIterator::ConstIterator
Packit 0d464f
    (const Header::AttributeMap::const_iterator &i): _i (i)
Packit 0d464f
{
Packit 0d464f
    // empty
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline
Packit 0d464f
Header::ConstIterator::ConstIterator (const Header::Iterator &other):
Packit 0d464f
    _i (other._i)
Packit 0d464f
{
Packit 0d464f
    // empty
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
inline Header::ConstIterator &
Packit 0d464f
Header::ConstIterator::operator ++ ()
Packit 0d464f
{
Packit 0d464f
    ++_i;
Packit 0d464f
    return *this;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline Header::ConstIterator 		
Packit 0d464f
Header::ConstIterator::operator ++ (int)
Packit 0d464f
{
Packit 0d464f
    ConstIterator tmp = *this;
Packit 0d464f
    ++_i;
Packit 0d464f
    return tmp;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline const char *
Packit 0d464f
Header::ConstIterator::name () const
Packit 0d464f
{
Packit 0d464f
    return *_i->first;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline const Attribute &	
Packit 0d464f
Header::ConstIterator::attribute () const
Packit 0d464f
{
Packit 0d464f
    return *_i->second;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline bool
Packit 0d464f
operator == (const Header::ConstIterator &x, const Header::ConstIterator &y)
Packit 0d464f
{
Packit 0d464f
    return x._i == y._i;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline bool
Packit 0d464f
operator != (const Header::ConstIterator &x, const Header::ConstIterator &y)
Packit 0d464f
{
Packit 0d464f
    return !(x == y);
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
//---------------------
Packit 0d464f
// Template definitions
Packit 0d464f
//---------------------
Packit 0d464f
Packit 0d464f
template <class T>
Packit 0d464f
T &
Packit 0d464f
Header::typedAttribute (const char name[])
Packit 0d464f
{
Packit 0d464f
    Attribute *attr = &(*this)[name];
Packit 0d464f
    T *tattr = dynamic_cast <T*> (attr);
Packit 0d464f
Packit 0d464f
    if (tattr == 0)
Packit 0d464f
	throw IEX_NAMESPACE::TypeExc ("Unexpected attribute type.");
Packit 0d464f
Packit 0d464f
    return *tattr;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
template <class T>
Packit 0d464f
const T &
Packit 0d464f
Header::typedAttribute (const char name[]) const
Packit 0d464f
{
Packit 0d464f
    const Attribute *attr = &(*this)[name];
Packit 0d464f
    const T *tattr = dynamic_cast <const T*> (attr);
Packit 0d464f
Packit 0d464f
    if (tattr == 0)
Packit 0d464f
	throw IEX_NAMESPACE::TypeExc ("Unexpected attribute type.");
Packit 0d464f
Packit 0d464f
    return *tattr;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
template <class T>
Packit 0d464f
T &
Packit 0d464f
Header::typedAttribute (const std::string &name)
Packit 0d464f
{
Packit 0d464f
    return typedAttribute<T> (name.c_str());
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
template <class T>
Packit 0d464f
const T &
Packit 0d464f
Header::typedAttribute (const std::string &name) const
Packit 0d464f
{
Packit 0d464f
    return typedAttribute<T> (name.c_str());
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
template <class T>
Packit 0d464f
T *
Packit 0d464f
Header::findTypedAttribute (const char name[])
Packit 0d464f
{
Packit 0d464f
    AttributeMap::iterator i = _map.find (name);
Packit 0d464f
    return (i == _map.end())? 0: dynamic_cast <T*> (i->second);
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
template <class T>
Packit 0d464f
const T *
Packit 0d464f
Header::findTypedAttribute (const char name[]) const
Packit 0d464f
{
Packit 0d464f
    AttributeMap::const_iterator i = _map.find (name);
Packit 0d464f
    return (i == _map.end())? 0: dynamic_cast <const T*> (i->second);
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
template <class T>
Packit 0d464f
T *
Packit 0d464f
Header::findTypedAttribute (const std::string &name)
Packit 0d464f
{
Packit 0d464f
    return findTypedAttribute<T> (name.c_str());
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
template <class T>
Packit 0d464f
const T *
Packit 0d464f
Header::findTypedAttribute (const std::string &name) const
Packit 0d464f
{
Packit 0d464f
    return findTypedAttribute<T> (name.c_str());
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Packit 0d464f
Packit 0d464f
#endif