File: factory.h

package info (click to toggle)
amoeba 1.1-32
  • links: PTS
  • area: contrib
  • in suites: forky, sid
  • size: 1,492 kB
  • sloc: cpp: 8,384; makefile: 140
file content (85 lines) | stat: -rw-r--r-- 1,671 bytes parent folder | download | duplicates (6)
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
#ifndef _FACTORY_H
#define _FACTORY_H

#include <string.h>

#include "main/mainloop.h"
#include "util/hashtable.h"

class Event;
class MainLoop;

class Factory {
public:
	Factory();
	virtual ~Factory();

	virtual bool can_handle(const char *el) = 0;
	virtual Event *instantiate(MainLoop *ml, const char *title, const char *el, Hashtable *attr) = 0;
	
	virtual char *get_short_effectname() = 0;
	virtual char *get_long_effectname() = 0;
	virtual char *get_display_parameter() = 0;
};

template <class E> class HandlerFactory : public Factory {
private:
	char *elem, *longdesc, *mainparm;

public:
	HandlerFactory(const char *element)
	{
		this->elem = strdup(element);
		this->longdesc = NULL;
		this->mainparm = NULL;
	}
	HandlerFactory(const char *element, const char *longdesc)
	{
		this->elem = strdup(element);
		this->longdesc = strdup(longdesc);
		this->mainparm = NULL;
	}
	HandlerFactory(const char *element, const char *longdesc, const char *mainparm)
	{
		this->elem = strdup(element);
		this->longdesc = strdup(longdesc);
		this->mainparm = strdup(mainparm);
	}
	~HandlerFactory()
	{
		free(this->elem);
		this->elem = NULL;

		free(this->longdesc);
		this->longdesc = NULL;

		free(this->mainparm);
		this->mainparm = NULL;
	}

	bool can_handle(const char *el)
	{
		return (strcmp(this->elem, el) == 0);
	}
	Event *instantiate(MainLoop *ml, const char *title, const char *el, Hashtable *attr)
	{
		return new E(ml, title, el, attr);
	}

	char *get_short_effectname()
	{
		return this->elem;
	}
	
	char *get_long_effectname()
	{
		return this->longdesc;
	}
	
	char *get_display_parameter()
	{
		return this->mainparm;
	}
}; 

#endif /* !defined(_FACTORY_H) */