aseprite/src/base/base.h
David Capello 16da2512b4 Remove dependency with Allegro library in config.h file
* Created base::write24bits() function (and detect endianness with a
  special base/config.h.cmakein)
* Use _WIN32 instead of ALLEGRO_WINDOWS
* Use _DEBUG instead of DEBUGMODE
* Replaced AL_CONST with "const" in bmp_format.cpp
* Replace stricmp() with base::utf8_icmp()
2015-02-12 10:55:58 -03:00

88 lines
1.6 KiB
C++

// Aseprite Base Library
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef BASE_BASE_H_INCLUDED
#define BASE_BASE_H_INCLUDED
#pragma once
#include "base/config.h"
#include <math.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#undef NULL
#ifdef __cplusplus
#define NULL nullptr
#else
#define NULL ((void*)0)
#endif
#undef MIN
#undef MAX
#undef MID
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
#define MID(x,y,z) ((x) > (y) ? ((y) > (z) ? (y) : ((x) > (z) ? \
(z) : (x))) : ((y) > (z) ? ((z) > (x) ? (z) : \
(x)): (y)))
#undef CLAMP
#define CLAMP(x,y,z) MAX((x), MIN((y), (z)))
#undef ABS
#undef SGN
#define ABS(x) (((x) >= 0) ? (x) : (-(x)))
#define SGN(x) (((x) >= 0) ? 1 : -1)
#undef PI
#define PI 3.14159265358979323846
//////////////////////////////////////////////////////////////////////
// Overloaded new/delete operators to detect memory-leaks
#if defined __cplusplus && defined MEMLEAK
#include <new>
#include "base/memory.h"
inline void* operator new(std::size_t size)
{
void* ptr = base_malloc(size);
if (!ptr)
throw std::bad_alloc();
return ptr;
}
inline void operator delete(void* ptr)
{
if (!ptr)
return;
base_free(ptr);
}
inline void* operator new[](std::size_t size)
{
void* ptr = base_malloc(size);
if (!ptr)
throw std::bad_alloc();
return ptr;
}
inline void operator delete[](void* ptr)
{
if (!ptr)
return;
base_free(ptr);
}
#endif
#endif