include/SDL_version.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 20 Feb 2011 10:42:51 -0800
changeset 5359 d5fe4ed3a28d
parent 5310 a9945ce48999
child 5535 96594ac5fd1a
permissions -rw-r--r--
Added a revision number for easy compile-time tests.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2011 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 /**
    24  *  \file SDL_version.h
    25  *  
    26  *  This header defines the current SDL version.
    27  */
    28 
    29 #ifndef _SDL_version_h
    30 #define _SDL_version_h
    31 
    32 #include "SDL_stdinc.h"
    33 
    34 #include "begin_code.h"
    35 /* Set up for C function definitions, even when using C++ */
    36 #ifdef __cplusplus
    37 /* *INDENT-OFF* */
    38 extern "C" {
    39 /* *INDENT-ON* */
    40 #endif
    41 
    42 /**
    43  *  \brief Information the version of SDL in use.
    44  *  
    45  *  Represents the library's version as three levels: major revision
    46  *  (increments with massive changes, additions, and enhancements),
    47  *  minor revision (increments with backwards-compatible changes to the
    48  *  major revision), and patchlevel (increments with fixes to the minor
    49  *  revision).
    50  *  
    51  *  \sa SDL_VERSION
    52  *  \sa SDL_GetVersion
    53  */
    54 typedef struct SDL_version
    55 {
    56     Uint8 major;        /**< major version */
    57     Uint8 minor;        /**< minor version */
    58     Uint8 patch;        /**< update version */
    59 } SDL_version;
    60 
    61 /* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
    62 */
    63 #define SDL_MAJOR_VERSION	1
    64 #define SDL_MINOR_VERSION	3
    65 #define SDL_PATCHLEVEL		0
    66 
    67 /**
    68  *  \brief Macro to determine SDL version program was compiled against.
    69  *  
    70  *  This macro fills in a SDL_version structure with the version of the
    71  *  library you compiled against. This is determined by what header the
    72  *  compiler uses. Note that if you dynamically linked the library, you might
    73  *  have a slightly newer or older version at runtime. That version can be
    74  *  determined with SDL_GetVersion(), which, unlike SDL_VERSION(),
    75  *  is not a macro.
    76  *  
    77  *  \param x A pointer to a SDL_version struct to initialize.
    78  *  
    79  *  \sa SDL_version
    80  *  \sa SDL_GetVersion
    81  */
    82 #define SDL_VERSION(x)							\
    83 {									\
    84 	(x)->major = SDL_MAJOR_VERSION;					\
    85 	(x)->minor = SDL_MINOR_VERSION;					\
    86 	(x)->patch = SDL_PATCHLEVEL;					\
    87 }
    88 
    89 /**
    90  *  This macro turns the version numbers into a numeric value:
    91  *  \verbatim
    92     (1,2,3) -> (1203)
    93     \endverbatim
    94  *  
    95  *  This assumes that there will never be more than 100 patchlevels.
    96  */
    97 #define SDL_VERSIONNUM(X, Y, Z)						\
    98 	((X)*1000 + (Y)*100 + (Z))
    99 
   100 /**
   101  *  This is the version number macro for the current SDL version.
   102  */
   103 #define SDL_COMPILEDVERSION \
   104 	SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL)
   105 
   106 /**
   107  *  This macro will evaluate to true if compiled with SDL at least X.Y.Z.
   108  */
   109 #define SDL_VERSION_ATLEAST(X, Y, Z) \
   110 	(SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
   111 
   112 /**
   113  *  \brief Get the version of SDL that is linked against your program.
   114  *
   115  *  If you are linking to SDL dynamically, then it is possible that the
   116  *  current version will be different than the version you compiled against.
   117  *  This function returns the current version, while SDL_VERSION() is a
   118  *  macro that tells you what version you compiled with.
   119  *  
   120  *  \code
   121  *  SDL_version compiled;
   122  *  SDL_version linked;
   123  *  
   124  *  SDL_VERSION(&compiled);
   125  *  SDL_GetVersion(&linked);
   126  *  printf("We compiled against SDL version %d.%d.%d ...\n",
   127  *         compiled.major, compiled.minor, compiled.patch);
   128  *  printf("But we linked against SDL version %d.%d.%d.\n",
   129  *         linked.major, linked.minor, linked.patch);
   130  *  \endcode
   131  *  
   132  *  This function may be called safely at any time, even before SDL_Init().
   133  *  
   134  *  \sa SDL_VERSION
   135  */
   136 extern DECLSPEC void SDLCALL SDL_GetVersion(SDL_version * ver);
   137 
   138 /**
   139  *  \brief Get the code revision of SDL that is linked against your program.
   140  *
   141  *  Returns an arbitrary string (a hash value) uniquely identifying the
   142  *  exact revision of the SDL library in use, and is only useful in comparing
   143  *  against other revisions. It is NOT an incrementing number.
   144  */
   145 extern DECLSPEC const char *SDLCALL SDL_GetRevision(void);
   146 
   147 /**
   148  *  \brief Get the revision number of SDL that is linked against your program.
   149  *
   150  *  Returns a number uniquely identifying the exact revision of the SDL
   151  *  library in use. It is an incrementing number based on commits to
   152  *  hg.libsdl.org.
   153  */
   154 extern DECLSPEC int SDLCALL SDL_GetRevisionNumber(void);
   155 
   156 
   157 /* Ends C function definitions when using C++ */
   158 #ifdef __cplusplus
   159 /* *INDENT-OFF* */
   160 }
   161 /* *INDENT-ON* */
   162 #endif
   163 #include "close_code.h"
   164 
   165 #endif /* _SDL_version_h */
   166 
   167 /* vi: set ts=4 sw=4 expandtab: */