<commit_before>/******************************************************************************
    SDL_Canvas.cpp

    Abstraction of SDL Surfaces

  Copyright (c) 2013 <NAME>

******************************************************************************/
#include "SDL_Canvas.hpp"

// Default constructor; initializes object to its respective defaults
nom::SDL_Canvas::SDL_Canvas ( void )  : canvas_buffer ( nullptr ),
                                        coords ( 0, 0, -1, -1 ), // only x, y position is used in blitting
                                        offsets ( 0, 0, -1, -1 ), // only the width, height is used in source blitting
                                        colorkey ( 0, 0, 0, -1 )
{
  #ifdef DEBUG_SDL_CANVAS_OBJ
    std::cout << "nom::SDL_Canvas::SDL_Canvas(): Hello, world!" << "\n" << std::endl;
  #endif
}

// Constructor variant for setting the canvas with existing data
nom::SDL_Canvas::SDL_Canvas ( void* video_buffer )
{
  #ifdef DEBUG_SDL_CANVAS_OBJ
    std::cout << "nom::SDL_Canvas::SDL_Canvas(): Hello, world!" << "\n" << std::endl;
  #endif

  this->canvas_buffer = nullptr;

  this->canvas_buffer = static_cast<SDL_Surface*> ( video_buffer );
}

// Constructor variant for setting the canvas with an empty surface
//
// As per libSDL docs, this must be called only after video initialization;
// (SDL_SetVideoMode)
//
// http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurface
//
nom::SDL_Canvas::SDL_Canvas ( uint32_t flags, int32_t width, int32_t height, int32_t bitsPerPixel, uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask )
{
  #ifdef DEBUG_SDL_CANVAS_OBJ
    std::cout << "nom::SDL_Canvas::SDL_Canvas(): Hello, world!" << "\n" << std::endl;
  #endif

  this->canvas_buffer = nullptr;
  this->canvas_buffer = SDL_CreateRGBSurface ( flags, width, height, bitsPerPixel, Rmask, Gmask, Bmask, Amask );
}

// Constructor variant for setting the canvas with existing pixel data
//
// http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurfaceFrom
//
nom::SDL_Canvas::SDL_Canvas ( void* pixels, int32_t width, int32_t height, int32_t depth, int32_t pitch, uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask )
{
  this->canvas_buffer = nullptr;

  this->canvas_buffer = SDL_CreateRGBSurfaceFrom ( pixels, width, height, depth, pitch, Rmask, Gmask, Bmask, Amask );
}

nom::SDL_Canvas::~SDL_Canvas ( void )
{
  #ifdef DEBUG_SDL_CANVAS_OBJ
    std::cout << "nom::SDL_Canvas::~SDL_Canvas(): " << "Goodbye cruel world!" << "\n" << std::endl;
  #endif

  this->destroy();
}

// We sometimes need to call this method call from outside of this class, such
// as in SDL_Font::Draw, in order to prevent memory leaks from occurring
void nom::SDL_Canvas::destroy ( void )
{
  if ( this->valid() )
  {
    SDL_FreeSurface ( static_cast<SDL_Surface*> ( this->get() ) );
    this->canvas_buffer = nullptr;
  }
}

// This is important to return precisely as a SDL_Surface for it changes nullptr
// result potentially
void* nom::SDL_Canvas::get ( void ) const
{
  return static_cast<SDL_Surface*> ( this->canvas_buffer );
}

bool nom::SDL_Canvas::valid ( void ) const
{
  if ( static_cast<SDL_Surface*> ( this->canvas_buffer ) != nullptr )
    return true;
  else
    return false;
}

// Constructor variant for setting the canvas (SDL backwards-compatibility wrapper)
void nom::SDL_Canvas::setCanvas ( SDL_Surface *video_buffer )
{
  this->canvas_buffer = video_buffer;
}

void nom::SDL_Canvas::setCanvas ( void* video_buffer )
{
  this->destroy();

  this->canvas_buffer = (SDL_Surface*) video_buffer;
}
<commit_msg>Additional ERR checks<commit_after>/******************************************************************************
    SDL_Canvas.cpp

    Abstraction of SDL Surfaces

  Copyright (c) 2013 <NAME>

******************************************************************************/
#include "SDL_Canvas.hpp"

// Default constructor; initializes object to its respective defaults
nom::SDL_Canvas::SDL_Canvas ( void )  : canvas_buffer ( nullptr ),
                                        coords ( 0, 0, -1, -1 ), // only x, y position is used in blitting
                                        offsets ( 0, 0, -1, -1 ), // only the width, height is used in source blitting
                                        colorkey ( 0, 0, 0, -1 )
{
  #ifdef DEBUG_SDL_CANVAS_OBJ
    std::cout << "nom::SDL_Canvas::SDL_Canvas(): Hello, world!" << "\n" << std::endl;
  #endif
}

// Constructor variant for setting the canvas with existing data
nom::SDL_Canvas::SDL_Canvas ( void* video_buffer )
{
  #ifdef DEBUG_SDL_CANVAS_OBJ
    std::cout << "nom::SDL_Canvas::SDL_Canvas(): Hello, world!" << "\n" << std::endl;
  #endif

  this->canvas_buffer = nullptr;

  this->canvas_buffer = static_cast<SDL_Surface*> ( video_buffer );
}

// Constructor variant for setting the canvas with an empty surface
//
// As per libSDL docs, this must be called only after video initialization;
// (SDL_SetVideoMode)
//
// http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurface
//
nom::SDL_Canvas::SDL_Canvas ( uint32_t flags, int32_t width, int32_t height, int32_t bitsPerPixel, uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask )
{
  #ifdef DEBUG_SDL_CANVAS_OBJ
    std::cout << "nom::SDL_Canvas::SDL_Canvas(): Hello, world!" << "\n" << std::endl;
  #endif

  this->canvas_buffer = nullptr;
  this->canvas_buffer = SDL_CreateRGBSurface ( flags, width, height, bitsPerPixel, Rmask, Gmask, Bmask, Amask );
}

// Constructor variant for setting the canvas with existing pixel data
//
// http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurfaceFrom
//
nom::SDL_Canvas::SDL_Canvas ( void* pixels, int32_t width, int32_t height, int32_t depth, int32_t pitch, uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask )
{
  this->canvas_buffer = nullptr;

  this->canvas_buffer = SDL_CreateRGBSurfaceFrom ( pixels, width, height, depth, pitch, Rmask, Gmask, Bmask, Amask );
}

nom::SDL_Canvas::~SDL_Canvas ( void )
{
  #ifdef DEBUG_SDL_CANVAS_OBJ
    std::cout << "nom::SDL_Canvas::~SDL_Canvas(): " << "Goodbye cruel world!" << "\n" << std::endl;
  #endif

  this->destroy();
}

// We sometimes need to call this method call from outside of this class, such
// as in SDL_Font::Draw, in order to prevent memory leaks from occurring
void nom::SDL_Canvas::destroy ( void )
{
  if ( this->valid() )
  {
    SDL_FreeSurface ( static_cast<SDL_Surface*> ( this->get() ) );
    this->canvas_buffer = nullptr;
  }
}

// This is important to return precisely as a SDL_Surface for it changes nullptr
// result potentially
void* nom::SDL_Canvas::get ( void ) const
{
  return static_cast<SDL_Surface*> ( this->canvas_buffer );
}

bool nom::SDL_Canvas::valid ( void ) const
{
  if ( static_cast<SDL_Surface*> ( this->canvas_buffer ) != nullptr )
    return true;
  else
    return false;
}

// Constructor variant for setting the canvas (SDL backwards-compatibility wrapper)
void nom::SDL_Canvas::setCanvas ( SDL_Surface *video_buffer )
{
  if ( this->valid() )
    this->destroy();

  this->canvas_buffer = video_buffer;
}

void nom::SDL_Canvas::setCanvas ( void* video_buffer )
{
  if ( this->valid() )
    this->destroy();

  this->canvas_buffer = (SDL_Surface*) video_buffer;
}

{'fraction_non_alphanumeric': 0.16736227045075125, 'fraction_numerical': 0.01335559265442404, 'mean_word_length': 3.8443396226415096, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4357961', 'n_tokens_mistral': 2385, 'n_tokens_neox': 2198, 'n_words': 611}