summaryrefslogtreecommitdiffstats
path: root/kexi/plugins/macros/lib/context.h
blob: a7986167bc8851c2cf3ff85818a4ba7c09894f82 (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
/***************************************************************************
 * This file is part of the KDE project
 * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
 * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 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
 * Library General Public License for more details.
 * You should have received a copy of the GNU Library General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 ***************************************************************************/

#ifndef KOMACRO_CONTEXT_H
#define KOMACRO_CONTEXT_H

#include <tqobject.h>
#include <ksharedptr.h>

#include "variable.h"

namespace KoMacro {

	// Forward declaration.
	class Macro;
	class MacroItem;
	class Action;
	class Exception;

	/**
	* The context of an execution. If a @a Macro got executed it creates
	* an instance of this class and passes it around all it's children
	* as local execution context.
	*/
	class KOMACRO_EXPORT Context
		: public TQObject
		, public KShared
	{
			Q_OBJECT
  TQ_OBJECT
		public:

			/**
			* Constructor.
			* 
			* @param macro The @a Macro this @a Context belongs to.
			*/
			explicit Context(KSharedPtr<Macro> macro);

			/**
			* Destructor.
			*/
			~Context();

			/**
			* @return true if there exists a variable with name @p name
			* else false got returned.
			*/
			bool hasVariable(const TQString& name) const;

			/**
			* @return the @a Variable defined with name @p name or
			* NULL if there exists no such variable.
			*/
			KSharedPtr<Variable> variable(const TQString& name) const;

			/**
			* @return a map of all @a Variable instance that are defined
			* within this context.
			*/
			Variable::Map variables() const;

			/**
			* Set the variable @p variable defined with name @p name . If
			* there exists already a variable with that name replace it.
			*/
			void setVariable(const TQString& name, KSharedPtr<Variable> variable);

			/**
			* @return the associated macro 
			*/
			KSharedPtr<Macro> macro() const;

			/**
			* @return the currently selected @a MacroItem instance
			* or NULL if there is no @a MacroItem selected yet.
			*/
			KSharedPtr<MacroItem> macroItem() const;

			/**
			* @return true if the last @a activate() stopped with an
			* exception else false is returned.
			*/
			bool hadException() const;

			/**
			* @return the @a Exception instance that was thrown on
			* the last call of @a activate() . If there was no
			* exception NULL is returned.
			*/
			Exception* exception() const;

		private slots:

			/**
			* A @a Context does take care of an execution-chain which
			* should be activated one after another. The @a Context
			* remembers what @a Action should be executed next and
			* calling this slot just activates those @a Action .
			*/
			virtual void activate(TQValueList<KSharedPtr <MacroItem> >::ConstIterator it);

		public slots:

			/**
			* This slot extends the slot above with the passed
			* @a Context @p context which will be used as
			* parent context for this context.
			*/
			virtual void activate(KSharedPtr<Context> context);

			/**
			* This slot continues execution.
			*/
			virtual void activateNext();

		private:
			/// @internal d-pointer class.
			class Private;
			/// @internal d-pointer instance.
			Private* const d;
	};

}

#endif