Point Cloud Library (PCL)  1.7.0
/tmp/buildd/pcl-1.7-1.7.0/io/include/pcl/io/openni_camera/openni_exception.h
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011 Willow Garage, Inc.
00005  *
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the copyright holder(s) nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  */
00036 
00037 #include <pcl/pcl_config.h>
00038 #ifdef HAVE_OPENNI
00039 
00040 #ifndef __OPENNI_EXCEPTION__
00041 #define __OPENNI_EXCEPTION__
00042 
00043 #include <cstdarg>
00044 #include <cstdio>
00045 #include <exception>
00046 #include <string>
00047 //#include <pcl/pcl_macros.h> <-- because current header is included in NVCC-compiled code and contains <Eigen/Core>. Consider <pcl/pcl_exports.h>
00048 
00049 
00050 //fom <pcl/pcl_macros.h>
00051 #if defined _WIN32 && defined _MSC_VER && !defined __PRETTY_FUNCTION__
00052   #define __PRETTY_FUNCTION__ __FUNCTION__  
00053 #endif
00054 
00055 
00056 #define THROW_OPENNI_EXCEPTION(format,...) throwOpenNIException( __PRETTY_FUNCTION__, __FILE__, __LINE__, format , ##__VA_ARGS__ )
00057 
00058 
00059 namespace openni_wrapper
00060 {
00061 
00062   /**
00063    * @brief General exception class
00064    * @author Suat Gedikli
00065    * @date 02.january 2011
00066    * @ingroup io
00067    */
00068   class OpenNIException : public std::exception
00069   {
00070   public:
00071     /**
00072      * @brief Constructor
00073      * @note use the MACRO THROW_OPENNI_EXCEPTION, that takes care about the parameters function_name, file_name and line_number
00074      * @param[in] function_name the function in which this exception was created.
00075      * @param[in] file_name the file name in which this exception was created.
00076      * @param[in] line_number the line number where this exception was created.
00077      * @param[in] message the message of the exception
00078      */
00079     OpenNIException (const std::string& function_name, const std::string& file_name, unsigned line_number, const std::string& message) throw ();
00080 
00081     /**
00082      * @brief virtual Destructor that never throws an exception
00083      */
00084     virtual ~OpenNIException () throw ();
00085 
00086     /**
00087      * @brief Assignment operator to allow copying the message of another exception variable.
00088      * @param[in] exception left hand side
00089      * @return
00090      */
00091     OpenNIException & operator= (const OpenNIException& exception) throw ();
00092 
00093     /**
00094      * @brief virtual method, derived from std::exception
00095      * @return the message of the exception.
00096      */
00097     virtual const char* what () const throw ();
00098 
00099     /**
00100      * @return the function name in which the exception was created.
00101      */
00102     const std::string& getFunctionName () const throw ();
00103 
00104     /**
00105      * @return the filename in which the exception was created.
00106      */
00107     const std::string& getFileName () const throw ();
00108 
00109     /**
00110      * @return the line number where the exception was created.
00111      */
00112     unsigned getLineNumber () const throw ();
00113   protected:
00114     std::string function_name_;
00115     std::string file_name_;
00116     unsigned line_number_;
00117     std::string message_;
00118     std::string message_long_;
00119   } ;
00120 
00121   /**
00122    * @brief inline function used by the macro THROW_OPENNI_EXCEPTION to create an instance of OpenNIException with correct values for function, file and line_number
00123    * @param[in] function_name the function name. Will be filled in by the macro THROW_OPENNI_EXCEPTION
00124    * @param[in] file_name the file name. Will be filled in by the macro THROW_OPENNI_EXCEPTION
00125    * @param[in] line_number the line number. Will be filled in by the macro THROW_OPENNI_EXCEPTION
00126    * @param[in] format the printf-style format string
00127    * @param[in] ... optional arguments for the printf style format.
00128    */
00129   inline void
00130   throwOpenNIException (const char* function_name, const char* file_name, unsigned line_number, const char* format, ...)
00131   {
00132     static char msg[1024];
00133     va_list args;
00134     va_start (args, format);
00135     vsprintf (msg, format, args);
00136     throw OpenNIException (function_name, file_name, line_number, msg);
00137   }
00138 } // namespace openni_camera
00139 #endif
00140 #endif