ParCompMark::SqVM Class Reference

#include <PCMSqVM.h>

Inheritance diagram for ParCompMark::SqVM:

Inheritance graph
[legend]
Collaboration diagram for ParCompMark::SqVM:

Collaboration graph
[legend]
List of all members.

Detailed Description

Squirrel virtual machine.

Definition at line 70 of file PCMSqVM.h.


Getters & setters

const bool & getError () const
 Getter of mError.
void setError (const bool &error)
 Setter of mError.
const bool & getInitialized () const
 Getter of mInitialized.
static const SqVM::ScriptOutputgetScriptOutput ()
 Getter of mScriptOutput.
static void setScriptOutput (const SqVM::ScriptOutput &scriptoutput)
 Setter of mScriptOutput.
static const u32getStringBufferSize ()
 Getter of mStringBufferSize.

Methods

virtual std::string runScriptFromFile (const std::string &filename, const std::string &mainMethod="main", const std::list< std::string > &parameters=std::list< std::string >(), const bool &hasReturn=false)
 Execute script loaded from file.
virtual std::string runScriptFromString (const std::string &scriptString, const std::string &scriptName="", const std::string &mainMethod="main", const std::list< std::string > &parameters=std::list< std::string >(), const bool &hasReturn=false)
 Execute script from the given string.
virtual std::string runScriptByName (const std::string &scriptName, const std::list< std::string > &parameters=std::list< std::string >())
 Execute a previously stored script.
virtual void finalize ()
 Finalize virtual machine.
virtual void activate ()
 Activate this VM.
virtual void deactivate ()
 Deactivate this VM.
virtual void initialize ()
 Initialize virtual machine.
virtual SqVM::Script::Pointer createScript (const std::string &scriptName="", const bool &dynamic=false, const std::string &mainMethod="main", const bool &hasReturn=false)
 Create script object with the specified name and entry point.
virtual SqVM::Script::Pointer findScript (const std::string &scriptName)
 Finds a prevously added script.
virtual SqVM::Script::Pointer findOrAddScript (const std::string &scriptName, const bool &dynamic=false, const std::string &mainMethod="main", const bool &hasReturn=false)
 If the script exists with the given name then returns, if not then adds it to the internal class level container and return it.
virtual void compileAndExecuteScript (SqVM::Script::Pointer &script)
 Compile and execute the script.
virtual void setParameters (SqVM::Script::Pointer &script, const std::list< std::string > &parameters)
 Set parameters of a script.

Class constants

static const std::string NOMAINMETHOD = "null"
 Constant for indicating that no main method are defined for a script.
static const u32 mStringBufferSize = 32768
 Size of mStringBuffer.

Public Types

typedef Pointer< SqVM, MutexPointer
 Type for pointer on this class.
 LOG
 The output of the script is the ParCompMark logging system.
 STD
 The output of the script is the standard output and the standard error stream.
enum  ScriptOutput { LOG, STD }
 Definitions for output of scripts. More...

Public Member Functions

Constructors & destructor
 SqVM (const std::string &name)
 Create Squirrel virtual machine.
virtual ~SqVM ()
 The destructor.

Protected Types

typedef ParCompMark::SqVM::Script Script
 Struct for script attributes.
 UNCOMPILED
 The script is not compiled.
 COMPILED
 The script is compiled.
 EXECUTED
 The script is executed (main method called).
enum  ScriptState { UNCOMPILED, COMPILED, EXECUTED }
 Definitions of script states. More...

Static Protected Member Functions

Class methods
static void printFunction (::HSQUIRRELVM sqVM, const SQChar *s,...)
 The print function of the virtual machine.

Protected Attributes

Variables
SqVM::Pointer mThis
 Smart pointer on this object.
SquirrelVMSys * mSquirrelVMSys
 Squirrel virtual machine.
bool mError
 An error occured on this virtual machine.
bool mInitialized
 The virtual machine is initialized.
Container< SqVM::Script, Mutex
>::Pointer 
mScripts
 Script container.

Static Protected Attributes

Class variables
static SqVM::Pointer mCurrentVM
 Currently active Squirrel Virtual Machine.
static Mutex mCurrentVMLock
 External mutex for mCurrentVM.
static SqVM::ScriptOutput mScriptOutput = SqVM::LOG
 Script output.
static char mStringBuffer [32768] = ""
 Common C style string buffer of printFunction.

Classes

struct  Script
 Struct for script attributes. More...

Member Typedef Documentation

Type for pointer on this class.

Definition at line 121 of file PCMSqVM.h.

Struct for script attributes.


Member Enumeration Documentation

Definitions for output of scripts.

Enumerator:
LOG  The output of the script is the ParCompMark logging system.
STD  The output of the script is the standard output and the standard error stream.

Definition at line 87 of file PCMSqVM.h.

Definitions of script states.

Enumerator:
UNCOMPILED  The script is not compiled.
COMPILED  The script is compiled.
EXECUTED  The script is executed (main method called).

Definition at line 100 of file PCMSqVM.h.


Constructor & Destructor Documentation

ParCompMark::SqVM::SqVM ( const std::string &  name  ) 

Create Squirrel virtual machine.

Parameters:
[in] name Name of the virtual machine.

Definition at line 62 of file PCMSqVM.cpp.

References ParCompMark::Singleton< T >::getInstance(), mError, mInitialized, ParCompMark::Name::mName, mScripts, mSquirrelVMSys, and ParCompMark::Logger::NOTICE.

Here is the call graph for this function:

ParCompMark::SqVM::~SqVM (  )  [virtual]

The destructor.

This class has virtual destructor.

Definition at line 95 of file PCMSqVM.cpp.

References finalize(), ParCompMark::Singleton< T >::getInstance(), mInitialized, ParCompMark::Name::mName, and ParCompMark::Logger::NOTICE.

Here is the call graph for this function:


Member Function Documentation

void ParCompMark::SqVM::activate (  )  [protected, virtual]

Activate this VM.

This virtual machine will be selected to operate.

Definition at line 284 of file PCMSqVM.cpp.

References initialize(), ParCompMark::Mutex::lock(), mCurrentVM, mCurrentVMLock, mInitialized, mSquirrelVMSys, and mThis.

Referenced by finalize(), runScriptByName(), runScriptFromFile(), and runScriptFromString().

Here is the call graph for this function:

void ParCompMark::SqVM::compileAndExecuteScript ( SqVM::Script::Pointer script  )  [protected, virtual]

Compile and execute the script.

Parameters:
[out] script Script handle.

Definition at line 437 of file PCMSqVM.cpp.

References COMPILED, deactivate(), ParCompMark::Logger::ERROR, Except, EXECUTED, ParCompMark::Logger::FATAL, ParCompMark::Singleton< T >::getInstance(), mError, NOMAINMETHOD, ParCompMark::Logger::NOTICE, and UNCOMPILED.

Referenced by runScriptByName(), runScriptFromFile(), and runScriptFromString().

Here is the call graph for this function:

SqVM::Script::Pointer ParCompMark::SqVM::createScript ( const std::string &  scriptName = "",
const bool &  dynamic = false,
const std::string &  mainMethod = "main",
const bool &  hasReturn = false 
) [protected, virtual]

Create script object with the specified name and entry point.

The dynamic flag is also set, and the returned script object is locked by default.

Parameters:
[in] scriptName Name of the script.
[in] dynamic Dynamic flag.
[in] mainMethod Script entry method name. Giving SqVM::NOMAINMETHOD as mainMethod indicates that no main method.
[in] hasReturn The script has a return value
Returns:
Pointer to the created script object.

Definition at line 340 of file PCMSqVM.cpp.

Referenced by findOrAddScript(), and runScriptFromString().

void ParCompMark::SqVM::deactivate (  )  [protected, virtual]

Deactivate this VM.

This virtual machine will go to sleep and let other VMs to be activated.

Definition at line 303 of file PCMSqVM.cpp.

References mCurrentVM, mCurrentVMLock, and ParCompMark::Mutex::unlock().

Referenced by compileAndExecuteScript(), finalize(), findOrAddScript(), findScript(), runScriptByName(), runScriptFromFile(), and runScriptFromString().

Here is the call graph for this function:

void ParCompMark::SqVM::finalize (  )  [virtual]

Finalize virtual machine.

Definition at line 262 of file PCMSqVM.cpp.

References activate(), Assert, deactivate(), ParCompMark::Logger::DEBUG, ParCompMark::Singleton< T >::getInstance(), mInitialized, ParCompMark::Name::mName, and mSquirrelVMSys.

Referenced by ~SqVM().

Here is the call graph for this function:

SqVM::Script::Pointer ParCompMark::SqVM::findOrAddScript ( const std::string &  scriptName,
const bool &  dynamic = false,
const std::string &  mainMethod = "main",
const bool &  hasReturn = false 
) [protected, virtual]

If the script exists with the given name then returns, if not then adds it to the internal class level container and return it.

Parameters:
[in] scriptName Name of the searched script.
[in] dynamic Dynamic flag; if the script is have to be created this flag is set.
[in] mainMethod Script entry method name. Giving SqVM::NOMAINMETHOD as mainMethod indicates that no main method.
[in] hasReturn The script has a return value
Returns:
Pointer of the found or the newly created script object.

Definition at line 380 of file PCMSqVM.cpp.

References createScript(), deactivate(), Except, ParCompMark::Pointer< T, Lock >::lock(), mScripts, and ParCompMark::Pointer< T, Lock >::unlock().

Referenced by runScriptFromFile(), and runScriptFromString().

Here is the call graph for this function:

SqVM::Script::Pointer ParCompMark::SqVM::findScript ( const std::string &  scriptName  )  [protected, virtual]

Finds a prevously added script.

Parameters:
[in] scriptName Name of a dynamic script name or filename.
Returns:
Pointer of the found script object.

Definition at line 357 of file PCMSqVM.cpp.

References deactivate(), Except, ParCompMark::Pointer< T, Lock >::lock(), mScripts, and ParCompMark::Pointer< T, Lock >::unlock().

Referenced by runScriptByName().

Here is the call graph for this function:

const bool & ParCompMark::SqVM::getError (  )  const [inline]

Getter of mError.

Returns value of mError.

Returns:
The value of mError

Definition at line 520 of file PCMSqVM.h.

const bool & ParCompMark::SqVM::getInitialized (  )  const [inline]

Getter of mInitialized.

Returns value of mInitialized.

Returns:
The value of mInitialized

Definition at line 534 of file PCMSqVM.h.

const SqVM::ScriptOutput & ParCompMark::SqVM::getScriptOutput (  )  [inline, static]

Getter of mScriptOutput.

Returns value of mScriptOutput.

Returns:
The value of mScriptOutput

Definition at line 541 of file PCMSqVM.h.

Referenced by ParCompMark::Application::commanderOperation(), ParCompMark::Application::createVirtualMachines(), and ParCompMark::Application::executeUserCommand().

const u32 & ParCompMark::SqVM::getStringBufferSize (  )  [inline, static]

Getter of mStringBufferSize.

Returns value of mStringBufferSize.

Returns:
The value of mStringBufferSize

Definition at line 555 of file PCMSqVM.h.

void ParCompMark::SqVM::initialize (  )  [protected, virtual]

Initialize virtual machine.

Definition at line 316 of file PCMSqVM.cpp.

References Assert, ParCompMark::Logger::DEBUG, ParCompMark::Singleton< T >::getInstance(), mInitialized, ParCompMark::Name::mName, mSquirrelVMSys, printFunction(), and ParCompMark::squirrelClassBindings().

Referenced by activate().

Here is the call graph for this function:

void ParCompMark::SqVM::printFunction ( ::HSQUIRRELVM  sqVM,
const SQChar *  s,
  ... 
) [static, protected]

The print function of the virtual machine.

This function is used by the built-in function 'print()' to output text.

Parameters:
[in] sqVM Squirrel VM
[in] s Format string
[in] ... Additional parameters

Definition at line 109 of file PCMSqVM.cpp.

References ParCompMark::Logger::ERROR, ParCompMark::Singleton< T >::getInstance(), LOG, mCurrentVM, mScriptOutput, mStringBuffer, ParCompMark::Logger::NOTICE, and STD.

Referenced by initialize().

Here is the call graph for this function:

std::string ParCompMark::SqVM::runScriptByName ( const std::string &  scriptName,
const std::list< std::string > &  parameters = std::list< std::string >() 
) [virtual]

Execute a previously stored script.

Parameters:
[in] scriptName Name of a dynamic script name or filename.
[in] parameters List of passed string parameters
Returns:
The return value of the script.

Definition at line 239 of file PCMSqVM.cpp.

References activate(), compileAndExecuteScript(), deactivate(), and findScript().

Here is the call graph for this function:

std::string ParCompMark::SqVM::runScriptFromFile ( const std::string &  filename,
const std::string &  mainMethod = "main",
const std::list< std::string > &  parameters = std::list< std::string >(),
const bool &  hasReturn = false 
) [virtual]

Execute script loaded from file.

Giving SqVM::NOMAINMETHOD as mainMethod indicates that no main method.

Parameters:
[in] filename Script filename
[in] mainMethod Script entry method name. Giving SqVM::NOMAINMETHOD as mainMethod indicates that no main method.
[in] parameters List of passed string parameters
[in] hasReturn The script has a return value
Returns:
The return value of the script.

Definition at line 157 of file PCMSqVM.cpp.

References activate(), compileAndExecuteScript(), deactivate(), findOrAddScript(), and setParameters().

Here is the call graph for this function:

std::string ParCompMark::SqVM::runScriptFromString ( const std::string &  scriptString,
const std::string &  scriptName = "",
const std::string &  mainMethod = "main",
const std::list< std::string > &  parameters = std::list< std::string >(),
const bool &  hasReturn = false 
) [virtual]

Execute script from the given string.

If the scriptName is not empty the VM store this script into the class level store for better performance. Giving SqVM::NOMAINMETHOD as mainMethod indicates that no main method.

Parameters:
[in] scriptString Script string
[in] scriptName Name of the script. If it is not empty the VM store this script into the class level store for better performance.
[in] mainMethod Script entry method name. Giving SqVM::NOMAINMETHOD as mainMethod indicates that no main method.
[in] parameters List of passed string parameters
[in] hasReturn The script has a return value
Returns:
The return value of the script.

Definition at line 184 of file PCMSqVM.cpp.

References activate(), compileAndExecuteScript(), createScript(), deactivate(), findOrAddScript(), and setParameters().

Here is the call graph for this function:

void ParCompMark::SqVM::setError ( const bool &  error  )  [inline]

Setter of mError.

Sets value of mError.

Parameters:
[in] error The value of mError

Definition at line 527 of file PCMSqVM.h.

void ParCompMark::SqVM::setParameters ( SqVM::Script::Pointer script,
const std::list< std::string > &  parameters 
) [protected, virtual]

Set parameters of a script.

Parameters:
[out] script Script handle.
[in] parameters List of passed string parameters

Definition at line 629 of file PCMSqVM.cpp.

Referenced by runScriptFromFile(), and runScriptFromString().

void ParCompMark::SqVM::setScriptOutput ( const SqVM::ScriptOutput scriptoutput  )  [inline, static]

Setter of mScriptOutput.

Sets value of mScriptOutput.

Parameters:
[in] scriptoutput The value of mScriptOutput

Definition at line 548 of file PCMSqVM.h.

Referenced by ParCompMark::Application::commanderOperation(), ParCompMark::Application::createVirtualMachines(), and ParCompMark::Application::executeUserCommand().


Member Data Documentation

Currently active Squirrel Virtual Machine.

Only one VM can be active.

Remarks:
This is own attribute of this class.

Definition at line 194 of file PCMSqVM.h.

Referenced by activate(), deactivate(), and printFunction().

External mutex for mCurrentVM.

Remarks:
This is own attribute of this class.

Definition at line 202 of file PCMSqVM.h.

Referenced by activate(), and deactivate().

bool ParCompMark::SqVM::mError [protected]

An error occured on this virtual machine.

Remarks:
This is own attribute of this class.

Definition at line 248 of file PCMSqVM.h.

Referenced by compileAndExecuteScript(), and SqVM().

The virtual machine is initialized.

Remarks:
This is own attribute of this class.

Definition at line 255 of file PCMSqVM.h.

Referenced by activate(), finalize(), initialize(), SqVM(), and ~SqVM().

SqVM::ScriptOutput ParCompMark::SqVM::mScriptOutput = SqVM::LOG [static, protected]

Script output.

Remarks:
This is own attribute of this class.

Definition at line 209 of file PCMSqVM.h.

Referenced by printFunction().

Script container.

Dynamic script can be also stored here when they have a proper name.

Remarks:
This is own attribute of this class.

Definition at line 262 of file PCMSqVM.h.

Referenced by findOrAddScript(), findScript(), and SqVM().

SquirrelVMSys* ParCompMark::SqVM::mSquirrelVMSys [protected]

Squirrel virtual machine.

Remarks:
This attribute references an attribute.

Definition at line 241 of file PCMSqVM.h.

Referenced by activate(), finalize(), initialize(), and SqVM().

char ParCompMark::SqVM::mStringBuffer = "" [static, protected]

Common C style string buffer of printFunction.

Remarks:
This is own attribute of this class.

Definition at line 216 of file PCMSqVM.h.

Referenced by printFunction().

const u32 ParCompMark::SqVM::mStringBufferSize = 32768 [static, protected]

Size of mStringBuffer.

Remarks:
This is own attribute of this class.

Definition at line 176 of file PCMSqVM.h.

Smart pointer on this object.

Remarks:
This is own attribute of this class.

Definition at line 234 of file PCMSqVM.h.

Referenced by activate().

const std::string ParCompMark::SqVM::NOMAINMETHOD = "null" [static]

Constant for indicating that no main method are defined for a script.

Remarks:
This is own attribute of this class.

Definition at line 167 of file PCMSqVM.h.

Referenced by ParCompMark::Application::commanderOperation(), compileAndExecuteScript(), ParCompMark::Application::createVirtualMachines(), ParCompMark::Application::executeUserCommand(), ParCompMark::Host::initialize(), and ParCompMark::Process::threadInitialize().


The documentation for this class was generated from the following files: