Dirac - A Video Codec

Created by the British Broadcasting Corporation.


dirac_exception.h

Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002 *
00003 * $Id: dirac_exception.h,v 1.2 2006/04/21 13:20:22 dirac_dev Exp $ $Name: Dirac_0_6_0 $
00004 *
00005 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006 *
00007 * The contents of this file are subject to the Mozilla Public License
00008 * Version 1.1 (the "License"); you may not use this file except in compliance
00009 * with the License. You may obtain a copy of the License at
00010 * http://www.mozilla.org/MPL/
00011 *
00012 * Software distributed under the License is distributed on an "AS IS" basis,
00013 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
00014 * the specific language governing rights and limitations under the License.
00015 *
00016 * The Original Code is BBC Research and Development code.
00017 *
00018 * The Initial Developer of the Original Code is the British Broadcasting
00019 * Corporation.
00020 * Portions created by the Initial Developer are Copyright (C) 2004.
00021 * All Rights Reserved.
00022 *
00023 * Contributor(s): Andrew Kennedy (Original Author)
00024 *
00025 * Alternatively, the contents of this file may be used under the terms of
00026 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
00027 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
00028 * the GPL or the LGPL are applicable instead of those above. If you wish to
00029 * allow use of your version of this file only under the terms of the either
00030 * the GPL or LGPL and not to allow others to use your version of this file
00031 * under the MPL, indicate your decision by deleting the provisions above
00032 * and replace them with the notice and other provisions required by the GPL
00033 * or LGPL. If you do not delete the provisions above, a recipient may use
00034 * your version of this file under the terms of any one of the MPL, the GPL
00035 * or the LGPL.
00036 * ***** END LICENSE BLOCK ***** */
00037 
00041 #ifndef DiracException_h
00042 #define DiracException_h
00043 
00044 
00045 // SYSTEM INCLUDES
00046 //
00047 #include <string>                           // has a string
00048 #include <iostream>                          // has an ostringstream
00049 
00050 
00051 namespace dirac {
00052 
00058     enum DiracErrorCode {
00059         ERR_UNSUPPORTED_STREAM_DATA=0,
00060         ERR_END_OF_STREAM,
00061         ERR_INVALID_VIDEO_FORMAT,
00062         ERR_INVALID_CHROMA_FORMAT,
00063         ERR_INVALID_FRAME_RATE,
00064         ERR_INVALID_SIGNAL_RANGE,
00065         ERR_INVALID_ASPECT_RATIO,
00066         ERR_INVALID_VIDEO_DEPTH,
00067         ERR_INVALID_MOTION_VECTOR_PRECISION
00068 
00069     };
00070 
00074     enum DiracSeverityCode {
00075         SEVERITY_NO_ERROR=0,
00076         SEVERITY_WARNING,
00077         SEVERITY_FRAME_ERROR,
00078         SEVERITY_ACCESSUNIT_ERROR,
00079         SEVERITY_SEQUENCE_ERROR,
00080         SEVERITY_TERMINATE
00081     };
00082 
00087 class DiracException
00088 {
00089 public:
00090 
00091 
00099     DiracException(
00100         const DiracErrorCode& errorCode,
00101         const std::string& errorMessage,
00102         const DiracSeverityCode& severityCode);
00103 
00107     DiracException(
00108         const DiracException& src);
00109 
00113     virtual ~DiracException();
00114 
00115 
00122     void AddFileNameAndLineNumber(
00123         const std::string& fileName,
00124         long lineNumber);
00125 
00126 // OPERATORS
00127 
00128 
00129 // ACCESS
00130 
00136     DiracErrorCode GetErrorCode() const;
00137 
00143     DiracSeverityCode GetSeverityCode() const;
00144 
00150     std::string GetErrorMessage() const;
00151 
00152 
00153 
00154 private:
00155 
00156 // ATTRIBUTES
00157 
00161     DiracErrorCode mErrorCode;
00162 
00166     DiracSeverityCode mSeverityCode;
00167 
00171     std::string mErrorMessage;
00172 
00173     
00174 
00175 // UNIMPLEMENTED METHODS
00176     DiracException& operator=(const DiracException&);
00177 
00178 }; // class DiracException
00179 
00180 
00181 
00182 
00183 
00184 // GLOBAL OPERATORS
00185 //
00186 std::ostream& operator<<(std::ostream& dst, const DiracException& exception);
00187 
00188 
00189 // MACROS FOR LOGGING AND THROWING DIRAC EXCEPTIONS
00190 //
00191 
00192 
00196 #define DIRAC_LOG_EXCEPTION(exception)                           \
00197     {                                                                   \
00198        if(exception.GetSeverityCode()!=SEVERITY_NO_ERROR)       \
00199             std::cerr << exception.GetErrorMessage();          \
00200     }
00201 
00205 #define DIRAC_THROW_EXCEPTION(arg1,arg2,arg3)                          \
00206     {                                                                   \
00207         DiracException exception(arg1,arg2, arg3);      \
00208         DIRAC_LOG_EXCEPTION(exception)  \
00209         throw exception;                        \
00210     }
00211 
00215 #define DIRAC_CATCH_AND_RETHROW()                                 \
00216     catch (const DiracException& e) {                                     \
00217         DiracException exception(e);           \
00218         DIRAC_LOG_EXCEPTION(exception)\
00219         throw exception;                     \
00220     }
00221 
00222 } // namespace Dirac
00223 
00224 #endif // DiracException_h

© 2004 British Broadcasting Corporation. Dirac code licensed under the Mozilla Public License (MPL) Version 1.1.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.