1 | /* $Id: kRdrInternal.h 2 2007-11-16 16:07:14Z bird $ */
|
---|
2 | /** @file
|
---|
3 | * kRdr - Internal Header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (c) 2006-2007 knut st. osmundsen <bird-kStuff-spam@anduin.net>
|
---|
8 | *
|
---|
9 | * This file is part of kStuff.
|
---|
10 | *
|
---|
11 | * kStuff is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU Lesser General Public
|
---|
13 | * License as published by the Free Software Foundation; either
|
---|
14 | * version 2.1 of the License, or (at your option) any later version.
|
---|
15 | *
|
---|
16 | * In addition to the permissions in the GNU Lesser General Public
|
---|
17 | * License, you are granted unlimited permission to link the compiled
|
---|
18 | * version of this file into combinations with other programs, and to
|
---|
19 | * distribute those combinations without any restriction coming from
|
---|
20 | * the use of this file.
|
---|
21 | *
|
---|
22 | * kStuff is distributed in the hope that it will be useful,
|
---|
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
25 | * Lesser General Public License for more details.
|
---|
26 | *
|
---|
27 | * You should have received a copy of the GNU Lesser General Public
|
---|
28 | * License along with kStuff; if not, write to the Free Software
|
---|
29 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
---|
30 | * 02110-1301, USA
|
---|
31 | */
|
---|
32 |
|
---|
33 | #ifndef ___kRdrInternal_h___
|
---|
34 | #define ___kRdrInternal_h___
|
---|
35 |
|
---|
36 | #include <k/kHlpAssert.h>
|
---|
37 | #include <k/kMagics.h>
|
---|
38 | #include <k/kRdrAll.h>
|
---|
39 | #include <k/kErrors.h>
|
---|
40 |
|
---|
41 | #ifdef __cplusplus
|
---|
42 | extern "C" {
|
---|
43 | #endif
|
---|
44 |
|
---|
45 | /** @defgroup grp_kRdrInternal - Internals
|
---|
46 | * @internal
|
---|
47 | * @addtogroup grp_kRdr
|
---|
48 | * @{
|
---|
49 | */
|
---|
50 |
|
---|
51 | /** @def KRDR_STRICT
|
---|
52 | * If defined the kRdr assertions and other runtime checks will be enabled. */
|
---|
53 | #ifdef K_ALL_STRICT
|
---|
54 | # undef KRDR_STRICT
|
---|
55 | # define KRDR_STRICT
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | /** @name Our Assert macros
|
---|
59 | * @{ */
|
---|
60 | #ifdef KRDR_STRICT
|
---|
61 | # define kRdrAssert(expr) kHlpAssert(expr)
|
---|
62 | # define kRdrAssertReturn(expr, rcRet) kHlpAssertReturn(expr, rcRet)
|
---|
63 | # define kRdrAssertMsg(expr, msg) kHlpAssertMsg(expr, msg)
|
---|
64 | # define kRdrAssertMsgReturn(expr, msg, rcRet) kHlpAssertMsgReturn(expr, msg, rcRet)
|
---|
65 | #else /* !KRDR_STRICT */
|
---|
66 | # define kRdrAssert(expr) do { } while (0)
|
---|
67 | # define kRdrAssertReturn(expr, rcRet) do { if (!(expr)) return (rcRet); } while (0)
|
---|
68 | # define kRdrAssertMsg(expr, msg) do { } while (0)
|
---|
69 | # define kRdrAssertMsgReturn(expr, msg, rcRet) do { if (!(expr)) return (rcRet); } while (0)
|
---|
70 | #endif /* !KRDR_STRICT */
|
---|
71 |
|
---|
72 | #define kRdrAssertPtr(ptr) kRdrAssertMsg(K_VALID_PTR(ptr), ("%s = %p\n", #ptr, (ptr)))
|
---|
73 | #define kRdrAssertPtrReturn(ptr, rcRet) kRdrAssertMsgReturn(K_VALID_PTR(ptr), ("%s = %p -> %d\n", #ptr, (ptr), (rcRet)), (rcRet))
|
---|
74 | #define kRdrAssertPtrNull(ptr) kRdrAssertMsg(!(ptr) || K_VALID_PTR(ptr), ("%s = %p\n", #ptr, (ptr)))
|
---|
75 | #define kRdrAssertPtrNullReturn(ptr, rcRet) kRdrAssertMsgReturn(!(ptr) || K_VALID_PTR(ptr), ("%s = %p -> %d\n", #ptr, (ptr), (rcRet)), (rcRet))
|
---|
76 | #define kRdrAssertRC(rc) kRdrAssertMsg((rc) == 0, ("%s = %d\n", #rc, (rc)))
|
---|
77 | #define kRdrAssertRCReturn(rc, rcRet) kRdrAssertMsgReturn((rc) == 0, ("%s = %d -> %d\n", #rc, (rc), (rcRet)), (rcRet))
|
---|
78 | #define kRdrAssertFailed() kRdrAssert(0)
|
---|
79 | #define kRdrAssertFailedReturn(rcRet) kRdrAssertReturn(0, (rcRet))
|
---|
80 | #define kRdrAssertMsgFailed(msg) kRdrAssertMsg(0, msg)
|
---|
81 | #define kRdrAssertMsgFailedReturn(msg, rcRet) kRdrAssertMsgReturn(0, msg, (rcRet))
|
---|
82 | /** @} */
|
---|
83 |
|
---|
84 | /** Return / crash validation of a reader argument. */
|
---|
85 | #define KRDR_VALIDATE_EX(pRdr, rc) \
|
---|
86 | do { \
|
---|
87 | if ( (pRdr)->u32Magic != KRDR_MAGIC \
|
---|
88 | || (pRdr)->pOps == NULL \
|
---|
89 | )\
|
---|
90 | { \
|
---|
91 | return (rc); \
|
---|
92 | } \
|
---|
93 | } while (0)
|
---|
94 |
|
---|
95 | /** Return / crash validation of a reader argument. */
|
---|
96 | #define KRDR_VALIDATE(pRdr) \
|
---|
97 | KRDR_VALIDATE_EX(pRdr, KERR_INVALID_PARAMETER)
|
---|
98 |
|
---|
99 | /** Return / crash validation of a reader argument. */
|
---|
100 | #define KRDR_VALIDATE_VOID(pRdr) \
|
---|
101 | do { \
|
---|
102 | if ( !K_VALID_PTR(pRdr) \
|
---|
103 | || (pRdr)->u32Magic != KRDR_MAGIC \
|
---|
104 | || (pRdr)->pOps == NULL \
|
---|
105 | )\
|
---|
106 | { \
|
---|
107 | return; \
|
---|
108 | } \
|
---|
109 | } while (0)
|
---|
110 |
|
---|
111 |
|
---|
112 | /** @name Built-in Providers
|
---|
113 | * @{ */
|
---|
114 | extern const KRDROPS g_kRdrFileOps;
|
---|
115 | /** @} */
|
---|
116 |
|
---|
117 | /** @} */
|
---|
118 |
|
---|
119 | #ifdef __cplusplus
|
---|
120 | }
|
---|
121 | #endif
|
---|
122 |
|
---|
123 | #endif
|
---|
124 |
|
---|