ScriptRobot
 All Classes Functions Typedefs Enumerations Enumerator
ScriptPackage Class Reference

ScriptPackage class. More...

#include <ScriptPackage.h>

Public Types

enum   Error {
  NoError = 0, NotLoaded = -1, NotBuilt = -2, EngineIsNull = -3,
  CouldNotOpenFile = -4, NotAScriptPackage = -5, ErrorParsingConfig = -6, MissingProjectConfig = -7,
  MissingRobotConfig = -8, CouldNotRegisterProperty = -10, CouldNotBuildScript = -9
}
  Error enum. More...
 
typedef enum ScriptPackage::Error  Error
  Error enum. More...
 

Public Member Functions

  ScriptPackage ()
  ScriptPackage constructor. More...
 
  ~ScriptPackage ()
  ScriptPackage destructor calls unload() on the ScriptPackage releasing all angelscript objects created by the ScriptPackage. More...
 
ScriptPackage::Error  getLastError ()
  Returns the last error set. More...
 
std::string  getLastErrorMessage ()
  Returns the last error message set. More...
 
bool  isValid ()
  Returns true if a ScriptPackage is ready for use. More...
 
ScriptPackage::Error  load (std::string path)
  Loads a ScriptPackage from the path. More...
 
void  unload ()
  Unloads a ScriptPackage from memory. More...
 
ScriptPackage::Error  build (asIScriptEngine *engine)
  Builds a ScriptPackage. More...
 
void  release ()
  Releases all angelscript objects. More...
 
ScriptPackage::Error  write (std::string path)
  Writes the ScriptPackage to a file. More...
 
std::string  getPath ()
  Returns the last set path. More...
 
std::string  getProjectConfig ()
  Returns the project config file as a string. More...
 
std::string  getRobotConfig ()
  Returns the robot config file as a string. More...
 
void  addSection (std::string name, std::string file)
  Adds a section to a ScriptPackage. More...
 
void  remSection (std::string name)
  Removes a section from a ScriptPackage. More...
 
PackageSection getSection (std::string name)
  Returns a section. More...
 
void  addRoutine (std::string name, ScriptRoutine::Type type, std::vector< std::string > scripts)
  Adds a routine to a ScriptPakcage. More...
 
void  remRoutine (std::string name)
  Removes a routine from a ScriptPackage. More...
 
ScriptRoutine getRoutine (std::string name)
  Returns a routine. More...
 
ScriptRoutine getInitRoutine ()
  Returns the init routine. More...
 
std::string  getDefaultDisabledRoutine ()
  Returns the default disabled routine. More...
 
std::string  getDefaultAutonomousRoutine ()
  Returns the default autonomous routine. More...
 
std::string  getOperatorControlRoutine ()
  Returns the default operator control routine. More...
 
std::string  getTestRoutine ()
  Returns the default test routine. More...
 
void  addProperty (std::string definition, std::string type, std::string name, void *ptr)
  Adds a property to a ScriptPakcage. More...
 
void  remProperty (std::string name)
  Removes a property from a ScriptPackage. More...
 
GlobalProperty getProperty (std::string name)
  Returns a property. More...
 

Static Public Member Functions

static std::string  addExstension (std::string path)
  Adds .scpkg to the end of the file path if isn't already there. More...
 
static bool  isScript (std::string name)
  Returns true if the file name ends in .as. More...
 
static bool  isConfig (std::string name)
  Returns true if the file name ends in .cfg. More...
 

Detailed Description

ScriptPackage class.

The ScriptPackage class loads and writes ScriptPackage files (.scpkg) A ScriptPackage file is a binary file that archives scripts and configs. Into PackageSections containing the file and original file path. The ScriptPackage once successfully loaded is configured and built using a project.cfg and a robot.cfg. robot.cfg contains info about the robots devices and their ports and the project.cfg contains info about ScriptRoutines for the robot to execute. TODO: make this more consice

Member Typedef Documentation

Error enum.

Used to characterize the an error caused while calling load, unload, build, release or write.

Member Enumeration Documentation

Error enum.

Used to characterize the an error caused while calling load, unload, build, release or write.

Enumerator
NoError 

The ScriptPackage is ready for use.

NotLoaded 

The ScriptPackage hasn't been loaded yet.

NotBuilt 

The ScriptPackage hasn't been built yet.

EngineIsNull 

The Engine used to build was null.

CouldNotOpenFile 

A file path couldn't be opened.

NotAScriptPackage 

The file loaded wasn't a ScriptPackage.

ErrorParsingConfig 

There was an error while parsing a config.

MissingProjectConfig 

project.cfg is missing.

MissingRobotConfig 

robot.cfg is missing.

CouldNotRegisterProperty 

There was an error while registering a property.

CouldNotBuildScript 

There was an error while building a script.

Constructor & Destructor Documentation

ScriptPackage::ScriptPackage ( )

ScriptPackage constructor.

Creates an empty instance of a ScriptPackage class with the angelscript engine set to NULL.

ScriptPackage::~ScriptPackage ( )

ScriptPackage destructor calls unload() on the ScriptPackage releasing all angelscript objects created by the ScriptPackage.

See Also
unload()

Member Function Documentation

std::string ScriptPackage::addExstension ( std::string  path )
static

Adds .scpkg to the end of the file path if isn't already there.

Parameters
path a path.
void ScriptPackage::addProperty ( std::string  definition,
std::string  type,
std::string  name,
void *  ptr 
)

Adds a property to a ScriptPakcage.

If the property already existed it is overwritten.

Parameters
definition the line used to generate the property from a config.
type the property type as used in angelscript.
name the name of the property as to be used in angelscript code.
ptr the pointer to the property.
void ScriptPackage::addRoutine ( std::string  name,
ScriptRoutine::Type  type,
std::vector< std::string >  scripts 
)

Adds a routine to a ScriptPakcage.

If the routine already existed it is overwritten.

Parameters
name the name of the routine.
type the routine type.
scripts the scripts utilized by the routine.
void ScriptPackage::addSection ( std::string  name,
std::string  file 
)

Adds a section to a ScriptPackage.

If the section already existed it is overwritten.

Parameters
name the file name of section.
file the file as a string.
ScriptPackage::Error ScriptPackage::build ( asIScriptEngine *  engine )

Builds a ScriptPackage.

Registers all GlobalProperties. And Builds all scripts. Then fetches all hooks for ScriptRoutines. If building was not successful release() is called on the ScriptPackage.

Parameters
engine a fully registered angelscript engine.
Returns
< 0 if an error occurred while building.
std::string ScriptPackage::getDefaultAutonomousRoutine ( )

Returns the default autonomous routine.

Returns
the default autonomous routine.
std::string ScriptPackage::getDefaultDisabledRoutine ( )

Returns the default disabled routine.

Returns
the default disabled routine.
ScriptRoutine * ScriptPackage::getInitRoutine ( )

Returns the init routine.

Returns
the init routine.
ScriptPackage::Error ScriptPackage::getLastError ( )

Returns the last error set.

Returns
the last error set.
std::string ScriptPackage::getLastErrorMessage ( )

Returns the last error message set.

Returns
the last error set.
std::string ScriptPackage::getOperatorControlRoutine ( )

Returns the default operator control routine.

Returns
the default operator control routine.
std::string ScriptPackage::getPath ( )

Returns the last set path.

The path is set when write or load is called.

Returns
the path to the current package.
std::string ScriptPackage::getProjectConfig ( )

Returns the project config file as a string.

Returns
the project config file as a string.
GlobalProperty * ScriptPackage::getProperty ( std::string  name )

Returns a property.

Parameters
name the name of the property to fetch.
Returns
NULL if the property didn't exist.
std::string ScriptPackage::getRobotConfig ( )

Returns the robot config file as a string.

Returns
the robot config file as a string.
ScriptRoutine * ScriptPackage::getRoutine ( std::string  name )

Returns a routine.

Parameters
name the name of the routine to fetch.
Returns
NULL if the routine didn't exist.
PackageSection * ScriptPackage::getSection ( std::string  name )

Returns a section.

Parameters
name the name of the section to fetch.
Returns
NULL if the section didn't exist.
std::string ScriptPackage::getTestRoutine ( )

Returns the default test routine.

Returns
the default test routine.
bool ScriptPackage::isConfig ( std::string  name )
static

Returns true if the file name ends in .cfg.

Parameters
name the name of a file to test.
Returns
true if the file name ends in .cfg
bool ScriptPackage::isScript ( std::string  name )
static

Returns true if the file name ends in .as.

Parameters
param the name of a file to test.
Returns
true if the file name ends in .as
bool ScriptPackage::isValid ( )

Returns true if a ScriptPackage is ready for use.

The ScriptPackage will only be valid if it has been loaded and built successfully.

Returns
true if the ScriptPackage is ready for use.
ScriptPackage::Error ScriptPackage::load ( std::string  path )

Loads a ScriptPackage from the path.

Loads a .scpkg file into memory and prepares the ScriptPackage to be built. If the ScriptPackage is unsuccessfully loaded unload() is called on it.

See Also
unload()
Parameters
path the full path to a .scpkg file.
Returns
ScriptPackage::Error::NotBuilt on success.
void ScriptPackage::release ( )

Releases all angelscript objects.

All angelscript objects owned by the ScriptPackage will be released. The ScriptPackage will no longer be valid if it previously was.

void ScriptPackage::remProperty ( std::string  name )

Removes a property from a ScriptPackage.

The ScriptPackage will no longer be valid if it previously was.

Parameters
name the name of the property to remove.
void ScriptPackage::remRoutine ( std::string  name )

Removes a routine from a ScriptPackage.

The ScriptPackage will no longer be valid if it previously was.

Parameters
name the name of the routine to remove.
void ScriptPackage::remSection ( std::string  name )

Removes a section from a ScriptPackage.

The ScriptPackage will no longer be valid if it previously was.

Parameters
name the name of the section to remove.
void ScriptPackage::unload ( )

Unloads a ScriptPackage from memory.

Calls release() on the ScriptPackage releasing all angelscript objects created by the ScriptPackage. The ScriptPackage will no longer be valid if it previously was.

See Also
release()
ScriptPackage::Error ScriptPackage::write ( std::string  path )

Writes the ScriptPackage to a file.

Only writes objects created using add functions.

Parameters
path the full path to a .scpkg file.
Returns
ScriptPackage::Error::CouldNotOpenFile on error.

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