Blame cairomm/private.cc

Packit 908522
/* Copyright (C) 2005 The cairomm Development Team
Packit 908522
 *
Packit 908522
 * This library is free software; you can redistribute it and/or
Packit 908522
 * modify it under the terms of the GNU Library General Public
Packit 908522
 * License as published by the Free Software Foundation; either
Packit 908522
 * version 2 of the License, or (at your option) any later version.
Packit 908522
 *
Packit 908522
 * This library is distributed in the hope that it will be useful,
Packit 908522
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 908522
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 908522
 * Library General Public License for more details.
Packit 908522
 *
Packit 908522
 * You should have received a copy of the GNU Library General Public
Packit 908522
 * License along with this library; if not, write to the Free Software
Packit 908522
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit 908522
 * 02110-1301, USA.
Packit 908522
 */
Packit 908522
Packit 908522
#include <cairommconfig.h> //For CAIROMM_EXCEPTIONS_ENABLED
Packit 908522
#include <cairomm/private.h>
Packit 908522
#include <cairomm/exception.h>
Packit 908522
#include <stdexcept>
Packit 908522
#include <iostream>
Packit 908522
Packit 908522
namespace Cairo
Packit 908522
{
Packit 908522
Packit 908522
#ifdef CAIROMM_EXCEPTIONS_ENABLED
Packit 908522
void throw_exception(ErrorStatus status)
Packit 908522
{
Packit 908522
  switch(status)
Packit 908522
  {
Packit 908522
    case CAIRO_STATUS_SUCCESS:
Packit 908522
      // we should never get here, but just in case
Packit 908522
      break;
Packit 908522
Packit 908522
    case CAIRO_STATUS_NO_MEMORY:
Packit 908522
      throw std::bad_alloc();
Packit 908522
      break;
Packit 908522
Packit 908522
    // Programmer error
Packit 908522
    case CAIRO_STATUS_INVALID_RESTORE:
Packit 908522
    case CAIRO_STATUS_INVALID_POP_GROUP:
Packit 908522
    case CAIRO_STATUS_NO_CURRENT_POINT:
Packit 908522
    case CAIRO_STATUS_INVALID_MATRIX:
Packit 908522
    //No longer in API?: case CAIRO_STATUS_NO_TARGET_SURFACE:
Packit 908522
    case CAIRO_STATUS_INVALID_STRING:
Packit 908522
    case CAIRO_STATUS_SURFACE_FINISHED:
Packit 908522
    //No longer in API?: case CAIRO_STATUS_BAD_NESTING:
Packit 908522
      throw Cairo::logic_error(status);
Packit 908522
      break;
Packit 908522
Packit 908522
    // Language binding implementation:
Packit 908522
    case CAIRO_STATUS_NULL_POINTER:
Packit 908522
    case CAIRO_STATUS_INVALID_PATH_DATA:
Packit 908522
    case CAIRO_STATUS_SURFACE_TYPE_MISMATCH:
Packit 908522
      throw Cairo::logic_error(status);
Packit 908522
      break;
Packit 908522
Packit 908522
    // Other
Packit 908522
    case CAIRO_STATUS_READ_ERROR:
Packit 908522
    case CAIRO_STATUS_WRITE_ERROR:
Packit 908522
      {
Packit 908522
        //The Cairo language binding advice suggests that these are stream errors 
Packit 908522
        //that should be mapped to their C++ equivalents.
Packit 908522
        const char* error_message = cairo_status_to_string(status);
Packit 908522
        throw std::ios_base::failure( error_message ? error_message : std::string() );
Packit 908522
      }
Packit 908522
      break;
Packit 908522
Packit 908522
    default:
Packit 908522
      throw Cairo::logic_error(status);
Packit 908522
      break;
Packit 908522
  }
Packit 908522
}
Packit 908522
#else
Packit 908522
void throw_exception(ErrorStatus /* status */)
Packit 908522
{
Packit 908522
  //Do nothing. The application should call get_status() instead.
Packit 908522
}
Packit 908522
#endif //CAIROMM_EXCEPTIONS_ENABLED
Packit 908522
Packit 908522
} //namespace Cairo
Packit 908522
Packit 908522
// vim: ts=2 sw=2 et