Debian Codegraph @

src/engine/safeWriter.h

raw
1 /**
2 * Furnace Tracker - multi-system chiptune tracker
3 * Copyright (C) 2021-2025 tildearrow and contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef _SAFEWRITER_H
21 #define _SAFEWRITER_H
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <stdint.h>
25 #include "safeReader.h"
26 #include "../ta-utils.h"
27
28 class SafeWriter {
29 bool operative;
30 unsigned char* buf;
31 size_t bufLen;
32 size_t len;
33
34 size_t curSeek;
35
36 void checkSize(size_t amount);
37
38 public:
39 unsigned char* getFinalBuf();
40
41 bool seek(ssize_t where, int whence);
42 size_t tell();
43 size_t size();
44
45 int write(const void* what, size_t count);
46
47 int writeC(signed char val);
48 int writeS(short val);
49 int writeS_BE(short val);
50 int writeI(int val);
51 int writeI_BE(int val);
52 int writeL(int64_t val);
53 int writeL_BE(int64_t val);
54 int writeF(float val);
55 int writeF_BE(float val);
56 int writeD(double val);
57 int writeD_BE(double val);
58 int writeWString(WString val, bool pascal);
59 int writeString(String val, bool pascal);
60 int writeText(String val);
61
62 void init();
63 SafeReader* toReader();
64 void finish();
65 void disown();
66
67 SafeWriter():
68 operative(false),
69 buf(NULL),
70 bufLen(0),
71 len(0),
72 curSeek(0) {}
73 };
74
75 #endif