Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 5aca5b2274d691bf8050c8555c205f3c14ba6217 (plain)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
   core/info.h
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#ifndef __INCLUDED_CORE_INFO_H__
#define __INCLUDED_CORE_INFO_H__

#include <iostream>
#include <string>
#include <vector>
#include <deque>

#include "core/label.h"
#include "core/level.h"
#include "model/model.h"

namespace core
{

/**
 * @brief an information card category
 * The InfoType groups information records of the same type
 */
class InfoType : public Label
{
public:
	/**
	 * @brief info type registry type definition
	 * */
	typedef std::vector<InfoType*> 	Registry;

	/**
	 * @brief create a new information card category
	 * The constructor automaticly adds the instance to the registry
	 */
	InfoType(const char* label);

	virtual ~InfoType();

	/* ---- static inf type registry ----------------------------------- */
	
	/**
	 * @brief clear info type registry
	 * */
	static void clear();

	/**
	 * @brief search the info type registry for a label
	 * */
	static InfoType *find(const std::string & label);
	
	inline static const Registry &registry()
	{
		return infotype_registry;
	}

	/**
	 * @brief list the info types
	 * */
	static void list();
	
private:
	static Registry			infotype_registry;
}; // class InfoType

/**
 * @brief an information card
 * An information record holds extended information about a specific entity or item class.
 * This information is exchanged between server and the client, and can be used to build 
 * HUD widgets.
 */
class Info : public Label
{
public:
	/**
	 * @brief type definition for the text description
	 * */
	typedef std::deque<std::string> Text;
	
	/**
	 * @brief server-side constructor
	 * This constructor assigns an id
	 */
	Info(const InfoType *type, const char *label = 0);

	/**
	 * @brief client-side constructor
	 */
	Info(const unsigned int id);
	
	/**
	 * @brief default constructor
	 **/
	virtual ~Info();

	/* ---- inspectors ------------------------------------------------- */

	inline const unsigned int id() const
	{
		return info_id;
	}
	
	inline const InfoType* type() const
	{
		return info_type;
	}
	
	inline const std::string & modelname() const
	{
		return info_modelname;
	}

	inline const Level level() const
	{
		return info_level;
	}
	
	inline const long price() const
	{
		return info_price;
	}
	
	inline const float volume() const
	{
		return info_volume;
	}

	/**
	 * @brief timestamp
	 * The timestamp is used client-side, a non-zero value
	 * indicates the time when the info was last requested.
	 * If the info has been received from the server, the timestamp
	 * is set to 0
	 */
	inline const unsigned long &timestamp() const
	{
		return info_timestamp;
	}

	/**
	 * @brief info description text
	 */
	inline const Text & text() const
	{
		return info_text;
	}

	/* ---- mutators --------------------------------------------------- */
	
	void set_id(const unsigned int);
	
	void set_modelname(const std::string & modelname);

	void set_modelname(const char *modelname);
	
	/**
	 * @brief set level
	 * */
	void set_level(const Level level);
	
	/**
	 * @brief associated price, in credits
	 */
	void set_price(const long price);

	/**
	 * @brief associated volume, in cubic meters
	 */	
	void set_volume(const float volume);

	/**
	 * @brief set the timestamp
	 * */
	void set_timestamp(const unsigned long timestamp);

	/**
	 * @brief append a line of text to the info description
	 * add_line() adds a newline character
	 * */
	void add_line(const std::string & text);

	/**
	 * @brief append a line of text to the info description
	 * add_line() adds a newline character
	 * */
	void add_line(const char *text);
	
	/**
	 * @brief append text to the info description
	 * add_text() does not add a newline character
	 * */
	void add_text(const std::string & text);

	/**
	 * @brief append text to the info description
	 * add_text() does not add a newline character
	 * */
	void add_text(const char *text);

	/**
	 * @brief clear the info description text
	 * */
	void clear_text();

	/**
	 * @brief print the content of the info record to the system console
	 * */
	virtual void print() const;
	
	/**
	 * @brief clear the timestamp
	 * */
	void clear_timestamp();

	/**
	 * @brief set the info type
	 * */
	void set_type(const InfoType *type);

public:
	/* ---- serializers ------------------------------------------------ */
	
	/**
	 * @brief serialize a server-to-client update on a stream
	 * */
	void serialize_server_update(std::ostream & os) const;

	/**
	 * @brief receive a server-to-client update from a stream
	 * */
	void receive_server_update(std::istream &is);

private:
	const InfoType*		info_type;
	unsigned int		info_id;
	
	Level			info_level;
	
	long			info_price;
	float			info_volume;
	unsigned long		info_timestamp;
	std::string		info_modelname;

	Text			info_text;

	/* ---- static info registry --------------------------------------- */	
public:
	/**
	 * @brief info registry type definition
	 */
	typedef std::vector<Info*> Registry;

	/**
	 * @brief the info registry
	 */
	static inline Registry & registry() {
		return info_registry;
	}

	/**
	 * @brief search the info registry for a record with the specified id
	 */
	static Info *find(const unsigned int id);
	
	/**
	 * @brief search the info registry for a labeled item
	 */
	static Info *find(const char * label);

	/**
	 * @brief search the info registry for a label
	 */
	static Info *find(const std::string & label);
	
	/**
	 * @brief search the info register for a pointer
	 */
	static Info *find(const Info *info);
	
	/// search the info registry for a record with a matching label or name
	static Info *search(const std::string & searchstr);

	/// search the info registry for a labeled item, belonging to a specific class
	static Info *find(const InfoType *type, const char * label);

	/// search the info registry for a label, belonging to a specific class
	static Info *find(const InfoType *type, const std::string & label);

	/// search the info registry for a record with a matching label or name and belonging to a specific class
	static Info *search(const InfoType *type, const std::string & searchstr);

	/// clear the info registry
	static void clear();

	/// print the list header
	static void list_header();
	
	/// list a single record
	static void list(const Info *info);
	
	/// list the info registry
	static void list();

	/// list a single class in the info registry
	static void list(const InfoType *type);

private:
	static Registry				info_registry;
};

}
#endif // __INCLUDED_CORE_INFO_H__