1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef CHAR_SCAN_SCRIPT_H
18 #define CHAR_SCAN_SCRIPT_H
20 //-------------------------------------------------------------------------------------------------
22 //-------------------------------------------------------------------------------------------------
24 #include "nel/misc/smart_ptr.h"
25 #include "character_scan_job.h"
28 //-------------------------------------------------------------------------------------------------
29 // forward class declarations
30 //-------------------------------------------------------------------------------------------------
32 class CCharScanScript
; // an object that represents a script (one or more cumulated files)
33 class CCharScanScriptFile
; // an object that represents a script file
34 class ICharScanScriptCommand
; // virtual base class for objects that represents commands that can be used in script files
35 class CCharScanScriptCommandRegistry
; // singleton registry for ICharScanScriptCommand objects
36 template <class C
> class CCharScanScriptCommandRegisterer
; // template class used to register script commands in the registry
39 //-------------------------------------------------------------------------------------------------
40 // class CCharScanScript
41 //-------------------------------------------------------------------------------------------------
47 bool addScriptFile(const std::string
& fileName
);
48 void applyToJob(CCharacterScanJob
& job
);
51 // prohibit implicit copy
52 CCharScanScript(const CCharScanScript
&);
56 std::vector
<CCharScanScriptFile
> _ScriptFiles
;
60 //-------------------------------------------------------------------------------------------------
61 // class CCharScanScriptFile
62 //-------------------------------------------------------------------------------------------------
64 class CCharScanScriptFile
68 bool parseFile(const std::string
& fileName
, CCharScanScript
* container
=NULL
);
69 bool applyToJob(CCharacterScanJob
& job
);
71 const std::string
& getFileName() const;
72 const std::string
& getDescription() const;
75 // interface for script commands
76 bool setDescription(const std::string
& description
);
77 bool setOutputPath(const std::string
& path
);
78 bool addFilter(const std::string
& rawArgs
);
79 bool addInfoExtractor(const std::string
& rawArgs
);
80 bool addInputFiles(const std::string
& rawArgs
);
84 std::string _FileName
;
85 std::string _Description
;
86 std::string _OutputPath
;
87 std::vector
<std::string
> _Filters
;
88 std::vector
<std::string
> _InfoExtractors
;
89 std::vector
<std::string
> _InputFiles
;
93 //-------------------------------------------------------------------------------------------------
94 // class ICharScanScriptCommand
95 //-------------------------------------------------------------------------------------------------
97 class ICharScanScriptCommand
: public NLMISC::CRefCount
100 virtual ~ICharScanScriptCommand() {}
101 virtual const char* getName()=0;
102 virtual const char* getSyntax()=0;
103 virtual const char* getDescription()=0;
104 virtual bool execute(CCharScanScriptFile
& scriptFile
,const NLMISC::CVectorSString
& args
,const NLMISC::CSString
& rawArgs
,const NLMISC::CSString
& rawCmdLine
,CCharScanScript
* container
)=0;
108 //-------------------------------------------------------------------------------------------------
109 // class CCharScanScriptCommandRegistry
110 //-------------------------------------------------------------------------------------------------
112 class CCharScanScriptCommandRegistry
115 // accessor for the singleton instance
116 static CCharScanScriptCommandRegistry
* getInstance();
119 // register a script command
120 void registerScriptCommand(NLMISC::CSmartPtr
<ICharScanScriptCommand
> scriptCommand
);
122 // display the set of script commands
123 void displayScriptCommands(NLMISC::CLog
* log
=NLMISC::InfoLog
);
125 // execute a script command for a given script file object
126 bool execute(CCharScanScriptFile
& scriptFile
,const NLMISC::CSString
& commandLine
,CCharScanScript
* container
);
129 // this is a singleton so ctor is private
130 CCharScanScriptCommandRegistry() {}
134 typedef std::vector
<NLMISC::CSmartPtr
<ICharScanScriptCommand
> > TScriptCommands
;
135 TScriptCommands _ScriptCommands
;
139 //-------------------------------------------------------------------------------------------------
140 // class CCharScanScriptCommandRegisterer
141 //-------------------------------------------------------------------------------------------------
144 class CCharScanScriptCommandRegisterer
147 CCharScanScriptCommandRegisterer()
149 CCharScanScriptCommandRegistry::getInstance()->registerScriptCommand(new C
);
154 //-------------------------------------------------------------------------------------------------
155 // MACRO CHAR_SCAN_SCRIPT_COMMAND()
156 //-------------------------------------------------------------------------------------------------
158 #define CHAR_SCAN_SCRIPT_COMMAND(name,syntax,description)\
159 class CCharScriptCommand_##name: public ICharScanScriptCommand\
162 virtual const char* getName() {return #name;}\
163 virtual const char* getSyntax() {return syntax;}\
164 virtual const char* getDescription() {return description;}\
166 virtual bool execute(CCharScanScriptFile& scriptFile,const NLMISC::CVectorSString& args,const NLMISC::CSString& rawArgs,const NLMISC::CSString& rawCmdLine,CCharScanScript* container);\
168 CCharScanScriptCommandRegisterer<CCharScriptCommand_##name> __Registerer_CCharScriptCommand_##name;\
169 bool CCharScriptCommand_##name::execute(CCharScanScriptFile& scriptFile,const NLMISC::CVectorSString& args,const NLMISC::CSString& rawArgs,const NLMISC::CSString& rawCmdLine,CCharScanScript* container)
172 //-------------------------------------------------------------------------------------------------