KVIrc  4.9.2
DeveloperAPIs
KviKvsScript.h
Go to the documentation of this file.
1 #ifndef _KVI_KVS_SCRIPT_H_
2 #define _KVI_KVS_SCRIPT_H_
3 //=============================================================================
4 //
5 // File : KviKvsScript.h
6 // Creation date : Thu 25 Sep 2003 05.12 CEST by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2003-2010 Szymon Stefanek (pragma at kvirc dot net)
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
33 #include "kvi_settings.h"
34 #include "KviQString.h"
35 #include "KviWindow.h"
36 #include "KviPointerList.h"
37 #include "KviKvsVariant.h"
38 #include "KviKvsVariantList.h"
39 #include "KviHeapObject.h"
40 
43 class KviKvsScriptData;
44 class KviKvsReport;
46 
47 // X defines this stuff: ugly :/
48 #ifdef Error
49 #undef Error
50 #endif
51 #ifdef Success
52 #undef Success
53 #endif
54 
60 {
61  friend class KviKvsObject;
62  friend class KviKvsParser;
63  friend class KviKvsRunTimeContext;
64 
65 public:
70  enum RunStatus
71  {
72  Error = 0,
73  Success = 1,
74  HaltEncountered = 2
75  };
76 
82  {
85  Parameter
86  };
87 
92  enum RunFlags
93  {
94  PreserveParams = 1,
95  // FIXME: This should be a global option, eventually
96  AssumeLocals = 2,
97  // FIXME: This should be a global option, eventually
98  Pedantic = 4,
99  Quiet = 8
100  };
101 
102 public:
111  KviKvsScript(const KviKvsScript & src);
112 
120  KviKvsScript(const QString & szName, const QString & szBuffer, ScriptType eType = InstructionList);
121 
125  ~KviKvsScript();
126 
127 protected:
136  KviKvsScript(const QString & szName, const QString & szBuffer, KviKvsTreeNodeInstruction * pPreparsedTree, ScriptType eType = InstructionList);
137 
138 private:
140 
141 public:
146  const QString & name() const;
147 
152  const QString & code() const;
153 
160  bool locked() const;
161 
167  void setName(const QString & szName);
168 
184  int run(KviWindow * pWnd, KviKvsVariantList * pParams = 0, KviKvsVariant * pRetVal = 0, int iRunFlags = 0, KviKvsExtendedRunTimeData * pExtData = 0);
185 
202  int run(KviWindow * pWnd, KviKvsVariantList * pParams, QString & szRetVal, int iRunFlags = 0, KviKvsExtendedRunTimeData * pExtData = 0);
203 
215  int run(KviKvsRunTimeContext * pContext, int iRunFlags = 0);
216 
228  static int run(const QString & szCode, KviWindow * pWindow, KviKvsVariantList * pParams = 0, KviKvsVariant * pRetVal = 0);
229 
242  static int evaluate(const QString & szCode, KviWindow * pWindow, KviKvsVariantList * pParams, KviKvsVariant * pRetVal);
243 
256  static int evaluateAsString(const QString & szCode, KviWindow * pWindow, KviKvsVariantList * pParams, QString & szRetVal);
257 
263  void dump(const char * prefix);
264 
265 protected:
274  bool parse(KviWindow * pOutput = 0, int iRunFlags = 0);
275 
288  int execute(KviWindow * pWnd, KviKvsVariantList * pParams = 0, KviKvsVariant * pRetVal = 0, int iRunFlags = 0, KviKvsExtendedRunTimeData * pExtData = 0);
289 
298  int executeInternal(KviKvsRunTimeContext * pContext);
299 
304  const QChar * buffer() const;
305 
310  void detach();
311 };
312 
318 {
319  friend class KviKvsScript;
320 
321 protected:
322  unsigned int m_uRefs; // Reference count for this structure
323 
324  QString m_szName; // script context name
325  QString m_szBuffer; // NEVER TOUCH THIS
326  const QChar * m_pBuffer; // this points to m_szBuffer: use it to extract string data
327 
328  KviKvsScript::ScriptType m_eType; // the type of the code in m_szBuffer
329 
331  unsigned int m_uLock; // this is increased while the script is being executed
332 };
333 
334 #endif //_KVI_KVS_SCRIPT_H_
Definition: KviHeapObject.h:124
KVIRC_API int run(const QString &url, int contextSpec=FirstFreeContext, KviConsoleWindow *pConsole=0)
Definition: KviIrcUrl.cpp:212
Definition: KviOptions.h:601
Definition: KviKvsScript.h:83
This class defines a new data type which contains variant data.
Definition: KviKvsVariant.h:351
#define KVIRC_API
Definition: kvi_settings.h:128
KviKvsTreeNodeInstruction * m_pTree
Definition: KviKvsScript.h:330
RunStatus
Holds the run status of the script.
Definition: KviKvsScript.h:70
Class to handle variant variables lists.
Definition: KviKvsVariantList.h:41
The KVIrc Script class.
Definition: KviKvsScript.h:59
ScriptType
Holds the type of the script.
Definition: KviKvsScript.h:81
Definition: KviKvsObject.h:50
QString m_szBuffer
Definition: KviKvsScript.h:325
KviKvsScript::ScriptType m_eType
Definition: KviKvsScript.h:328
Definition: KviKvsParser.h:54
Definition: KviKvsRunTimeContext.h:43
Definition: KviKvsScript.h:84
Definition: KviKvsReport.h:33
Treenode class to handle instructions.
Definition: KviKvsTreeNodeInstruction.h:42
unsigned int m_uLock
Definition: KviKvsScript.h:331
C++ Template based double linked pointer list class.
Base class for all windows in KVIrc.
Definition: KviWindow.h:74
Definition: KviKvsRunTimeContext.h:103
Heap Object.
Parser class to handle variant variables lists.
QString name()
Definition: KviRuntimeInfo.cpp:655
friend class KviKvsScript
Definition: KviKvsRunTimeContext.h:105
Contains the KviWindow class.
KviKvsScriptData * m_pData
Definition: KviKvsScript.h:139
Handling of variant data type in KVS.
RunFlags
Holds the run flags of the script.
Definition: KviKvsScript.h:92
Holds the data of the script.
Definition: KviKvsScript.h:317
char szBuffer[4096]
Definition: winamp.cpp:77
This file contains compile time settings.
unsigned int m_uRefs
Definition: KviKvsScript.h:322
KVIRC_API bool parse(const char *url, KviCString &cmdBuffer, int contextSpec=KVI_IRCURL_CONTEXT_FIRSTFREE)
Definition: KviIrcUrl.cpp:46
Helper functions for the QString class.
const QChar * m_pBuffer
Definition: KviKvsScript.h:326
QString m_szName
Definition: KviKvsScript.h:324
Definition: KviError.h:49