Audacious
$Id:Doxyfile42802007-03-2104:39:00Znenolod$
Main Page
Related Pages
Classes
Files
File List
File Members
src
libaudcore
core.h
Go to the documentation of this file.
1
/*
2
* core.h
3
* Copyright 2011 John Lindgren
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
*
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions, and the following disclaimer.
10
*
11
* 2. Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions, and the following disclaimer in the documentation
13
* provided with the distribution.
14
*
15
* This software is provided "as is" and without any warranty, express or
16
* implied. In no event shall the authors be liable for any damages arising from
17
* the use of this software.
18
*/
19
20
#ifndef LIBAUDCORE_CORE_H
21
#define LIBAUDCORE_CORE_H
22
23
/* #define STRPOOL_DEBUG */
24
25
#undef NULL
26
#ifdef __cplusplus
/* *sigh* */
27
#define NULL 0
28
#else
29
#define NULL ((void *) 0)
30
#endif
31
32
/* "bool_t" means "int" for compatibility with GLib */
33
#undef bool_t
34
#define bool_t int
35
36
#undef FALSE
37
#define FALSE ((bool_t) 0)
38
#undef TRUE
39
#define TRUE ((bool_t) 1)
40
41
#undef MIN
42
#define MIN(a,b) ((a) < (b) ? (a) : (b))
43
#undef MAX
44
#define MAX(a,b) ((a) > (b) ? (a) : (b))
45
#undef CLAMP
46
#define CLAMP(a,min,max) ((a) < (min) ? (min) : (a) > (max) ? (max) : (a))
47
48
#define SPRINTF(s,...) \
49
char s[snprintf (NULL, 0, __VA_ARGS__) + 1]; \
50
snprintf (s, sizeof s, __VA_ARGS__);
51
52
/* Simple sanity check to catch (1) strings that are still in use after their
53
* reference count has dropped to zero and (2) strings that should have been
54
* pooled but never were. If the check fails, the program is aborted. */
55
#define STR_CHECK(str) do {if ((str) && (str)[-1] != '@') strpool_abort (str);} while (0)
56
57
/* If the pool contains a copy of <str>, increments its reference count.
58
* Otherwise, adds a copy of <str> to the pool with a reference count of one.
59
* In either case, returns the copy. Because this copy may be shared by other
60
* parts of the code, it should not be modified. If <str> is NULL, simply
61
* returns NULL with no side effects. */
62
#ifdef STRPOOL_DEBUG
63
char
* str_get_debug (
const
char
* str,
const
char
* file,
int
line);
64
#define str_get(str) str_get_debug (str, __FILE__, __LINE__)
65
#else
66
char
*
str_get
(
const
char
* str);
67
#endif
68
69
/* Increments the reference count of <str>, where <str> is the address of a
70
* string already in the pool. Faster than calling str_get() a second time.
71
* Returns <str> for convenience. If <str> is NULL, simply returns NULL with no
72
* side effects. */
73
#ifdef STRPOOL_DEBUG
74
char
* str_ref_debug (
char
* str,
const
char
* file,
int
line);
75
#define str_ref(str) str_ref_debug (str, __FILE__, __LINE__)
76
#else
77
char
*
str_ref
(
char
* str);
78
#endif
79
80
/* Decrements the reference count of <str>, where <str> is the address of a
81
* string in the pool. If the reference count drops to zero, releases the
82
* memory used by <str>. If <str> is NULL, simply returns NULL with no side
83
* effects. */
84
#ifdef STRPOOL_DEBUG
85
void
str_unref_debug (
char
* str,
const
char
* file,
int
line);
86
#define str_unref(str) str_unref_debug (str, __FILE__, __LINE__)
87
#else
88
void
str_unref
(
char
* str);
89
#endif
90
91
/* Calls str_get() on the first <len> characters of <str>. If <str> has less
92
* than or equal to <len> characters, equivalent to str_get(). */
93
char
*
str_nget
(
const
char
* str,
int
len);
94
95
/* Calls sprintf() internally, then pools the produced string with str_get(). */
96
char
*
str_printf
(
const
char
*
format
, ...);
97
98
/* Used by STR_CHECK; should not be called directly. */
99
void
strpool_abort
(
char
* str);
100
101
/* Releases all memory used by the string pool. If strings remain in the pool,
102
* a warning may be printed to stderr in order to reveal memory leaks. */
103
void
strpool_shutdown
(
void
);
104
105
#endif
/* LIBAUDCORE_CORE_H */
Generated by
1.8.3.1