1 /*
2 	Actiona
3 	Copyright (C) 2005 Jonathan Mercier-Ganady
4 
5 	Actiona is free software: you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation, either version 3 of the License, or
8 	(at your option) any later version.
9 
10 	Actiona is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 	Contact : jmgr@jmgr.info
19 */
20 
21 #pragma once
22 
23 #include "actiontools_global.h"
24 
25 #include <QMetaType>
26 #include <QString>
27 
28 namespace ActionTools
29 {
30 	class ACTIONTOOLSSHARED_EXPORT ActionException
31 	{
32 	public:
33 		enum Exception
34 		{
35 			InvalidParameterException,
36 			CodeErrorException,
37 			TimeoutException,
38 
39 			ExceptionCount,
40 			UserException = 32
41 		};
42 		enum ExceptionAction
43 		{
44 			StopExecutionExceptionAction,
45 			SkipExceptionAction,
46 			GotoLineExceptionAction,
47 
48 			ExceptionActionCount
49 		};
50 
51 		class ExceptionActionInstance
52 		{
53 		public:
54             ExceptionActionInstance()                   = default;
ExceptionActionInstance(ExceptionAction action,const QString & line)55 			ExceptionActionInstance(ExceptionAction action, const QString &line)
56 				: mAction(action), mLine(line)			{}
57 
setAction(ExceptionAction action)58 			void setAction(ExceptionAction action)		{ mAction = action; }
setLine(const QString & line)59 			void setLine(const QString &line)			{ mLine = line; }
60 
action()61 			ExceptionAction action() const				{ return mAction; }
line()62 			QString line() const						{ return mLine; }
63 
64 			bool operator ==(const ExceptionActionInstance &other) const
65 			{
66 				return (mAction == other.mAction && mLine == other.mLine);
67 			}
68 
69 		private:
70 			ExceptionAction mAction{StopExecutionExceptionAction};
71 			QString mLine;
72 		};
73 
ActionException(int id,const QString & name)74 		ActionException(int id, const QString &name)
75 			: mId(id), mName(name)								{}
76 
id()77 		int id() const											{ return mId; }
name()78 		QString name() const									{ return mName; }
79 
80 		static QString ExceptionName[ExceptionCount];
81 		static ExceptionAction ExceptionDefaultAction[ExceptionCount];
82 		static QString ExceptionActionName[ExceptionActionCount];
83 
84 	private:
85 		int mId;
86 		QString mName;
87 	};
88 
89 	ACTIONTOOLSSHARED_EXPORT QDataStream &operator >> (QDataStream &s, ActionException::Exception &exception);
90 	ACTIONTOOLSSHARED_EXPORT QDataStream &operator >> (QDataStream &s, ActionException::ExceptionAction &exceptionAction);
91 	ACTIONTOOLSSHARED_EXPORT QDataStream &operator >> (QDataStream &s, ActionException::ExceptionActionInstance &exceptionActionInstance);
92 	ACTIONTOOLSSHARED_EXPORT QDataStream &operator << (QDataStream &s, const ActionException::ExceptionActionInstance &exceptionActionInstance);
93 	ACTIONTOOLSSHARED_EXPORT QDebug &operator << (QDebug &dbg, const ActionException::ExceptionActionInstance &exceptionActionInstance);
94 }
95 
96 Q_DECLARE_METATYPE(ActionTools::ActionException::Exception)
97 
98