HdfUtilities.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef HDFUTILITIES_H
00011 #define HDFUTILITIES_H
00012 
00013 #include <string>
00014 #include <vector>
00015 
00016 #include "TypesFile.h"
00017 
00018 /**
00019  * A collection of generic utilities provided to simplify use of the application's HDF API.
00020  */
00021 namespace HdfUtilities
00022 {
00023    /**
00024     * Represents an unknown type found in the Hdf file.  The HdfPlugInLib will not parse data of this type.
00025     */
00026    static const std::string UNKNOWN_TYPE = "Unknown";
00027 
00028    /**
00029     * An %HdfUtilities::Exception is a simple exception that wraps a string.
00030     *
00031     * Various HdfUtilities throw an HdfUtilities::Exception when an error
00032     * condition occurrs and the function can't just 'return false.'
00033     */
00034    class Exception
00035    {
00036    public:
00037       /**
00038        * Creates an %HdfUtilities::Exception based on a string.
00039        *
00040        * @param  str
00041        *         Text to place into the exception. Should not be empty (but can be).
00042        */
00043       explicit Exception(const std::string& str) :
00044          mText(str)
00045       {
00046       }
00047 
00048       /**
00049        * Gets the message from the exception.
00050        *
00051        * @return The string that was passed in to the constructor.
00052        */
00053       std::string getText() const
00054       {
00055          return mText;
00056       }
00057 
00058    private:
00059       std::string mText;
00060    };
00061 
00062    /**
00063     * Returns the size of each data element given an %EncodingType.
00064     *
00065     * Throws an HdfUtilities::Exception() if an invalid data type is encountered.
00066     * 
00067     * @param  dataType
00068     *         An %EncodingType that represents the data. Never returns 0.
00069     *
00070     * @return The size of the data type passed in. Returns 0 if the type is unknown or unsupported.
00071     */
00072    unsigned int getDataSize(EncodingType dataType);
00073 
00074    /**
00075     * Takes a void pointer and produces a wavelength vector.
00076     *
00077     * WARNING: This function cannot provide range checking! If passed invalid values, this method
00078     *          throws an HdfUtilities::Exception.
00079     *
00080     * @param  pData
00081     *         A pointer to memory (most frequently read in using HdfImporter::loadDatasetFromFile())
00082     *         that represents the wavelength vector.
00083     * @param  numElements
00084     *         The number of elements in the vector.
00085     * @param  type
00086     *         The data type of the wavelength vector. Valid values are INT1SBYTE, INT1UBYTE, INT2SBYTES,
00087     *         INT2UBYTES, INT4SBYTES, INT4UBYTES, INT4SCOMPLEX, FLT4BYTES, FLT8BYTES. If an invalid
00088     *         value is passed in for this argument (ie. UNKNOWN or INT4SCOMPLEX), an HdfUtilities::Exception
00089     *         is thrown.
00090     *
00091     * @return Returns a vector containing the wavelength data.
00092     */
00093    std::vector<double> createWavelengthVector(void* pData, size_t numElements, EncodingType type);
00094 };
00095 
00096 #endif

Software Development Kit - Opticks 4.9.0 Build 16218