File: store.h

package info (click to toggle)
ht 2.1.0%2Brepack1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,712 kB
  • ctags: 15,753
  • sloc: cpp: 88,932; ansic: 12,693; sh: 4,081; lex: 226; makefile: 184; yacc: 128
file content (152 lines) | stat: -rw-r--r-- 5,227 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 *	HT Editor
 *	store.h
 *
 *	Copyright (C) 1999-2003 Sebastian Biallas (sb@biallas.net)
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License version 2 as
 *	published by the Free Software Foundation.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the Free Software
 *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef STORE_H
#define STORE_H

#include "data.h"
#include "sys/types.h"

typedef Object *(*object_builder)();

#include "stream.h"
#include "except.h"

class ObjectNotRegisteredException: public MsgfException {
	ObjectID mID;
public:
	ObjectNotRegisteredException(ObjectID aID);
};

class ObjectStreamInter: public ObjectStream {
public:
			ObjectStreamInter(Stream *s, bool own_stream) : ObjectStream(s, own_stream) {};
	/* extends ObjectStream */
	virtual Object *getObjectInternal(const char *name, ObjectID id = OBJID_INVALID);
	virtual void	putObject(const Object *object, const char *name, ObjectID id = OBJID_INVALID);
};

class ObjectStreamBin: public ObjectStreamInter {
public:
				ObjectStreamBin(Stream *s, bool own_s): ObjectStreamInter(s, own_s) {};
	/* extends ObjectStream */
	virtual void		getBinary(void *buf, uint size, const char *desc);
	virtual bool		getBool(const char *desc);
	virtual uint64		getInt(uint size, const char *desc);
	virtual char *		getString(const char *desc);
	virtual byte *		getLenString(int &length, const char *desc);

	virtual void		putBinary(const void *mem, uint size, const char *desc);
	virtual void		putBool(bool b, const char *desc);
	virtual void		putComment(const char *comment);
	virtual void		putCommentf(const char *comment_format, ...);
	virtual void		putInt(uint64 i, uint size, const char *desc, uint int_fmt_hint = OS_FMT_DEC);
	virtual void		putSeparator();
	virtual void		putString(const char *string, const char *desc);
	virtual void		putLenString(const byte *string, int length, const char *desc);

	virtual void		corrupt();
};

class ObjectStreamText: public ObjectStreamInter {
protected:
	char		cur;
	int		line;
	int		errorline;
	int		indent;
public:
	   
				ObjectStreamText(Stream *s, bool own_stream);
	/* extends ObjectStreamInter */
	virtual Object *	getObjectInternal(const char *name, ObjectID id = OBJID_INVALID);
	virtual void		putObject(const Object *object, const char *name, ObjectID id = OBJID_INVALID);
	/* extends ObjectStream */
	virtual void		getBinary(void *buf, uint size, const char *desc);
	virtual bool		getBool(const char *desc);
	virtual uint64		getInt(uint size, const char *desc);
	virtual char *		getString(const char *desc);
	virtual byte *		getLenString(int &length, const char *desc);
	
	virtual void		putBinary(const void *mem, uint size, const char *desc);
	virtual void		putBool(bool b, const char *desc);
	virtual void		putComment(const char *comment);
	virtual void		putInt(uint64 i, uint size, const char *desc, uint int_fmt_hint = OS_FMT_DEC);
	virtual void		putSeparator();
	virtual void		putString(const char *string, const char *desc);
	virtual void		putLenString(const byte *string, int length, const char *desc);

	virtual void		corrupt();

		   void		setSyntaxError();
		   int		getErrorLine();
private:
/* io */
		   void	expect(char c);
		   void	skipWhite();
		   char	readChar();
		   void	readDesc(const char *desc);

		   
		   void	putDesc(const char *desc);
		   void	putIndent();
		   void	putChar(char c);
		   void	putS(const char *s);
};

/*
 *   ObjectStreamNative View:set/getData() methods
 *	(endian-dependend)
 */

#define DATABUF_BOOL(name)		bool		name PACKED
#define DATABUF_UINT(name)		uint		name PACKED
#define DATABUF_PTR(type, name)		type*		name PACKED

class ObjectStreamNative: public ObjectStream {
protected:
	bool duplicate;
	Array allocd;

		void		*duppa(const void *p, int size);
public:
				ObjectStreamNative(Stream *s, bool own_s, bool duplicate);
/* extends ObjectStream */
	virtual void		getBinary(void *buf, uint size, const char *desc);
	virtual bool		getBool(const char *desc);
	virtual uint64		getInt(uint size, const char *desc);
	virtual Object *	getObjectInternal(const char *name, ObjectID id = OBJID_INVALID);
	virtual char *		getString(const char *desc);
	virtual byte *		getLenString(int &length, const char *desc);

	virtual void		putBinary(const void *mem, uint size, const char *desc);
	virtual void		putBool(bool b, const char *desc);
	virtual void		putComment(const char *comment);
	virtual void		putInt(uint64 i, uint size, const char *desc, uint int_fmt_hint = OS_FMT_DEC);
	virtual void		putObject(const Object *object, const char *name, ObjectID id = OBJID_INVALID);
	virtual void		putSeparator();
	virtual void		putString(const char *string, const char *desc);
	virtual void		putLenString(const byte *string, int length, const char *desc);

	virtual void		corrupt();
};

void putIDComment(ObjectStream &o, uint32 id);

#endif