ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/dynbuf.h
(Generate patch)

Comparing deliantra/server/include/dynbuf.h (file contents):
Revision 1.8 by root, Sat May 26 15:44:03 2007 UTC vs.
Revision 1.12 by root, Sun Jul 1 05:00:18 2007 UTC

1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
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
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
22 */
23
1#ifndef DYNBUF_H__ 24#ifndef DYNBUF_H__
2#define DYNBUF_H__ 25#define DYNBUF_H__
3 26
4#include <cstring> 27#include <cstring>
5#include <cassert> 28#include <cassert>
54 _reserve (size); 77 _reserve (size);
55 78
56 return ptr; 79 return ptr;
57 } 80 }
58 81
82 char *falloc (int size)
83 {
84 char *res = ptr;
85 ptr += size;
86 return res;
87 }
88
59 char *alloc (int size) 89 char *alloc (int size)
60 { 90 {
61 char *res = force (size); 91 force (size);
62 ptr += size; 92 return falloc (size);
63 return res;
64 } 93 }
65 94
66 void fadd (char c) { *ptr++ = c; } 95 void fadd (char c) { *ptr++ = c; }
67 void fadd (unsigned char c) { fadd (char (c)); } 96 void fadd (unsigned char c) { fadd (char (c)); }
97 void fadd (const void *p, int len)
98 {
99 memcpy (falloc (len), p, len);
100 }
68 101
69 void add (const void *p, int len) 102 void add (const void *p, int len)
70 { 103 {
71 memcpy (alloc (len), p, len); 104 force (len);
105 fadd (p, len);
72 } 106 }
73 107
74 void add (char c) 108 void add (char c)
75 { 109 {
76 alloc (1)[0] = c; 110 alloc (1)[0] = c;
104 : dynbuf (initial, extend) 138 : dynbuf (initial, extend)
105 { } 139 { }
106 140
107 using dynbuf::add; 141 using dynbuf::add;
108 142
109 static const int max_sint32_size = 11;
110 static const int max_sint64_size = 20;
111
112 void add (sint32 i); 143 void add (sint32 i);
113 void add (sint64 i); 144 void add (sint64 i);
114 145
115 void printf (const char *format, ...); 146 void printf (const char *format, ...);
116}; 147};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines