summaryrefslogtreecommitdiff
path: root/include/compobject.h
blob: 9ff1cde70020c3de0f808390f682d0dcdf937d35 (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
#ifndef _COMPOBJECT_H
#define _COMPOBJECT_H

#include <vector>

typedef int CompObjectType;


#define COMP_OBJECT_TYPE_ALL     -1
#define COMP_OBJECT_TYPE_CORE    0
#define COMP_OBJECT_TYPE_DISPLAY 1
#define COMP_OBJECT_TYPE_SCREEN  2
#define COMP_OBJECT_TYPE_WINDOW  3


typedef bool (*ObjectCallBackProc) (CompObject *object,
				    void       *closure);

#define ARRAY_SIZE(array)		 \
    (sizeof (array) / sizeof (array[0]))

#define DISPATCH_CHECK(object, dispTab, tabSize)	      \
    ((object)->type () < (tabSize) && (dispTab)[(object)->type ()])

#define DISPATCH(object, dispTab, tabSize, args)   \
    if (DISPATCH_CHECK (object, dispTab, tabSize)) \
	(*(dispTab)[(object)->type ()]) args

#define RETURN_DISPATCH(object, dispTab, tabSize, def, args) \
    if (DISPATCH_CHECK (object, dispTab, tabSize))	     \
	return (*(dispTab)[(object)->type ()]) args;	     \
    else						     \
	return (def)

class PrivateObject;

class CompObject {

    public:
	typedef std::vector<bool> indices;

    public:
	CompObject (CompObjectType type, const char* typeName,
		    indices *iList = NULL);
	virtual ~CompObject ();

        const char *typeName ();
	CompObjectType type ();

	void addChild (CompObject *);

        bool forEachChild (ObjectCallBackProc proc,
			   void	              *closure = NULL,
			   int                type = -1);

	virtual CompString name () = 0;

    public:

	std::vector<CompPrivate> privates;

    protected:
	static int allocatePrivateIndex (CompObjectType type, indices *iList);
	static void freePrivateIndex (CompObjectType type,
				      indices *iList, int idx);

    private:
	PrivateObject *priv;
};


#endif