]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - include/iscriplib.h
Callback: work at any arity
[xonotic/netradiant.git] / include / iscriplib.h
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #if !defined( INCLUDED_ISCRIPLIB_H )
23 #define INCLUDED_ISCRIPLIB_H
24
25 /// \file iscriplib.h
26 /// \brief Token input/output stream module.
27
28 #include <cstddef>
29 #include "generic/constant.h"
30
31 #define MAXTOKEN    1024
32
33 class Tokeniser
34 {
35 public:
36 virtual ~Tokeniser() = default;
37 virtual void release() = 0;
38 virtual void nextLine() = 0;
39 virtual const char* getToken() = 0;
40 virtual void ungetToken() = 0;
41 virtual std::size_t getLine() const = 0;
42 virtual std::size_t getColumn() const = 0;
43 };
44
45 class TextInputStream;
46
47 class TokenWriter
48 {
49 public:
50 virtual ~TokenWriter() = default;
51 virtual void release() = 0;
52 virtual void nextLine() = 0;
53 virtual void writeToken( const char* token ) = 0;
54 virtual void writeString( const char* string ) = 0;
55 virtual void writeInteger( int i ) = 0;
56 virtual void writeUnsigned( std::size_t i ) = 0;
57 virtual void writeFloat( double f ) = 0;
58 };
59
60 class TextOutputStream;
61
62 struct _QERScripLibTable
63 {
64         INTEGER_CONSTANT( Version, 1 );
65         STRING_CONSTANT( Name, "scriptlib" );
66
67         Tokeniser& ( *m_pfnNewScriptTokeniser )( TextInputStream & istream );
68         Tokeniser& ( *m_pfnNewSimpleTokeniser )( TextInputStream & istream );
69         TokenWriter& ( *m_pfnNewSimpleTokenWriter )( TextOutputStream & ostream );
70 };
71
72 #include "modulesystem.h"
73
74 template<typename Type>
75 class GlobalModule;
76 typedef GlobalModule<_QERScripLibTable> GlobalScripLibModule;
77
78 template<typename Type>
79 class GlobalModuleRef;
80 typedef GlobalModuleRef<_QERScripLibTable> GlobalScripLibModuleRef;
81
82 inline _QERScripLibTable& GlobalScriptLibrary(){
83         return GlobalScripLibModule::getTable();
84 }
85
86 #endif