|
|
1 | /* |
|
|
2 | * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. |
|
|
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
|
|
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
|
|
9 | * under the terms of the GNU General Public License as published by the Free |
|
|
10 | * Software Foundation; either version 2 of the License, or (at your option) |
|
|
11 | * any later version. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, but |
|
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
|
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
|
16 | * for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the GNU General Public License along |
|
|
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
|
|
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
|
21 | * |
|
|
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
|
|
23 | */ |
|
|
24 | |
1 | #ifndef DYNBUF_H__ |
25 | #ifndef DYNBUF_H__ |
2 | #define DYNBUF_H__ |
26 | #define DYNBUF_H__ |
3 | |
27 | |
4 | #include <cstring> |
28 | #include <cstring> |
5 | #include <cassert> |
29 | #include <cassert> |
… | |
… | |
54 | _reserve (size); |
78 | _reserve (size); |
55 | |
79 | |
56 | return ptr; |
80 | return ptr; |
57 | } |
81 | } |
58 | |
82 | |
59 | char *alloc (int size) |
83 | char *falloc (int size) |
60 | { |
84 | { |
61 | char *res = force (size); |
85 | char *res = ptr; |
62 | ptr += size; |
86 | ptr += size; |
63 | return res; |
87 | return res; |
64 | } |
88 | } |
65 | |
89 | |
|
|
90 | char *alloc (int size) |
|
|
91 | { |
|
|
92 | force (size); |
|
|
93 | return falloc (size); |
|
|
94 | } |
|
|
95 | |
66 | void fadd (char c) { *ptr++ = c; } |
96 | void fadd (char c) { *ptr++ = c; } |
67 | void fadd (unsigned char c) { fadd (char (c)); } |
97 | void fadd (unsigned char c) { fadd (char (c)); } |
|
|
98 | void fadd (const void *p, int len) |
|
|
99 | { |
|
|
100 | memcpy (falloc (len), p, len); |
|
|
101 | } |
68 | |
102 | |
69 | void add (const void *p, int len) |
103 | void add (const void *p, int len) |
70 | { |
104 | { |
71 | memcpy (alloc (len), p, len); |
105 | force (len); |
|
|
106 | fadd (p, len); |
72 | } |
107 | } |
73 | |
108 | |
74 | void add (char c) |
109 | void add (char c) |
75 | { |
110 | { |
76 | alloc (1)[0] = c; |
111 | alloc (1)[0] = c; |
… | |
… | |
104 | : dynbuf (initial, extend) |
139 | : dynbuf (initial, extend) |
105 | { } |
140 | { } |
106 | |
141 | |
107 | using dynbuf::add; |
142 | using dynbuf::add; |
108 | |
143 | |
109 | static const int max_sint32_size = 11; |
|
|
110 | static const int max_sint64_size = 20; |
|
|
111 | |
|
|
112 | void add (sint32 i); |
144 | void add (sint32 i); |
113 | void add (sint64 i); |
145 | void add (sint64 i); |
114 | |
146 | |
115 | void printf (const char *format, ...); |
147 | void printf (const char *format, ...); |
116 | }; |
148 | }; |