hoa_script::ModifyScriptDescriptor Class Reference

Represents a Lua file opened with read, execute, and modify permissions. More...

#include <script_modify.h>

Inheritance diagram for hoa_script::ModifyScriptDescriptor:

Inheritance graph
[legend]
Collaboration diagram for hoa_script::ModifyScriptDescriptor:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void CommitChanges (bool leave_closed=false)
 Commits all modified changes to the Lua file for permanent retention.
 ~ModifyScriptDescriptor ()
Data Addition Functions
These functions allow the addition of new key/value pairs

Parameters:
key The string or integer key of the variable to add
value The value to set the new variable to
Note:
If the key already exists in the active scope when these methods are called, the value of that key will be overwritten with the new value. There will be no indication that this type of overwrite operation took place, so be cautious.


void AddNewBool (int32 key, bool value)
void AddNewBool (const std::string &key, bool value)
void AddNewFloat (int32 key, float value)
void AddNewFloat (const std::string &key, float value)
void AddNewInt (int32 key, int32 value)
void AddNewInt (const std::string &key, int32 value)
void AddNewString (int32 key, const std::string &value)
void AddNewString (const std::string &key, const std::string &value)
void AddNewUInt (int32 key, uint32 value)
void AddNewUInt (const std::string &key, uint32 value)
File Access Functions
Note:
These are derived from ScriptDescriptor, refer to the comments for these methods in the header file for that class.


void CloseFile ()
 Closes the script file and sets the _access_mode member to SCRIPT_CLOSED.
bool OpenFile ()
 Opens the file named by the classes' _filename member.
bool OpenFile (const std::string &file_name)
Data Modifier Functions
These functions allow the modification of primitive data types

Parameters:
key The string or integer key of the variable to change
value The value to change the variable to
Note:
If the key could not be found in the active scope, no change will occur and an error message will be logged.


void ModifyBool (int32 key, bool value)
void ModifyBool (const std::string &key, bool value)
void ModifyFloat (int32 key, float value)
void ModifyFloat (const std::string &key, float value)
void ModifyInt (int32 key, int32 value)
void ModifyInt (const std::string &key, int32 value)
void ModifyString (int32 key, const std::string &value)
void ModifyString (const std::string &key, const std::string &value)
void ModifyUInt (int32 key, uint32 value)
void ModifyUInt (const std::string &key, uint32 value)

Private Member Functions

void _CommitTable (WriteScriptDescriptor &file, const luabind::object &table)
 A helper function to CommitChanges() that writes out the contents of a table to the file.
template<class T>
void _AddNewData (int32 key, T value)
template<class T>
void _AddNewData (const std::string &key, T value)
 Template functions which add a new key, value pair to the most recently opened scope.
template<class T>
void _ModifyData (int32 key, T value)
template<class T>
void _ModifyData (const std::string &key, T value)
 Template functions that update the key, value pair for the most recently opened table, or in the global scope.

Friends

class GameScript

Detailed Description

Represents a Lua file opened with read, execute, and modify permissions.

****************************************************************************

This class features all the functionality found in the ReadScriptDescriptor class, plus the additional ability to modify existing Lua data and save it back to the file. An object of this class should only be created if the user intends to modify the Lua data in the file at some point (i.e. don't use this class over the ReadScriptDescriptor simply because it has more functionality available).

In order to permanently (and irreversibly) change Lua data in the file, the user must call the CommitChanges function after making one or several ModifyData calls.

Note:
This class and is features are still highly experimental and incomplete.
Todo:
Add ability to modify tables and their data

Definition at line 46 of file script_modify.h.


Constructor & Destructor Documentation

hoa_script::ModifyScriptDescriptor::~ModifyScriptDescriptor (  ) 

Definition at line 29 of file script_modify.cpp.

References hoa_script::ScriptDescriptor::_access_mode, hoa_script::ScriptDescriptor::_error_messages, hoa_script::ScriptDescriptor::_filename, hoa_script::ScriptDescriptor::_open_tables, CloseFile(), hoa_script::ScriptDescriptor::IsFileOpen(), hoa_script::SCRIPT_CLOSED, and hoa_script::SCRIPT_DEBUG.

Here is the call graph for this function:


Member Function Documentation

template<class T>
void hoa_script::ModifyScriptDescriptor::_AddNewData ( int32  key,
value 
) [private]

Definition at line 285 of file script_modify.h.

References hoa_script::ScriptDescriptor::_error_messages, hoa_script::ReadScriptDescriptor::_lstack, hoa_script::ScriptDescriptor::_open_tables, and hoa_script::private_script::STACK_TOP.

template<class T>
void hoa_script::ModifyScriptDescriptor::_AddNewData ( const std::string &  key,
value 
) [private]

Template functions which add a new key, value pair to the most recently opened scope.

Parameters:
key The key name of the variable to add
value The value to set for the new variable

Definition at line 264 of file script_modify.h.

References hoa_script::ScriptDescriptor::_error_messages, hoa_script::ReadScriptDescriptor::_lstack, hoa_script::ScriptDescriptor::_open_tables, and hoa_script::private_script::STACK_TOP.

Referenced by AddNewBool(), AddNewFloat(), AddNewInt(), AddNewString(), and AddNewUInt().

void hoa_script::ModifyScriptDescriptor::_CommitTable ( WriteScriptDescriptor file,
const luabind::object &  table 
) [private]

A helper function to CommitChanges() that writes out the contents of a table to the file.

Parameters:
file A reference to the open file to write the table to
table A reference to the valid luabind::object that contains the table's contents

Definition at line 145 of file script_modify.cpp.

References hoa_script::ScriptDescriptor::_error_messages, hoa_script::WriteScriptDescriptor::BeginTable(), hoa_script::WriteScriptDescriptor::EndTable(), hoa_script::SCRIPT_DEBUG, hoa_script::WriteScriptDescriptor::WriteBool(), hoa_script::WriteScriptDescriptor::WriteFloat(), hoa_script::WriteScriptDescriptor::WriteInt(), and hoa_script::WriteScriptDescriptor::WriteString().

Referenced by CommitChanges().

Here is the call graph for this function:

template<class T>
void hoa_script::ModifyScriptDescriptor::_ModifyData ( int32  key,
value 
) [private]

Definition at line 227 of file script_modify.h.

References hoa_script::ScriptDescriptor::_error_messages, hoa_script::ReadScriptDescriptor::_lstack, hoa_script::ScriptDescriptor::_open_tables, hoa_script::private_script::STACK_TOP, and hoa_script::private_script::TABLE_END.

template<class T>
void hoa_script::ModifyScriptDescriptor::_ModifyData ( const std::string &  key,
value 
) [private]

Template functions that update the key, value pair for the most recently opened table, or in the global scope.

Parameters:
key The key name of the variable to be change
value The new value to set the key

Definition at line 189 of file script_modify.h.

References hoa_script::ScriptDescriptor::_error_messages, hoa_script::ReadScriptDescriptor::_lstack, hoa_script::ScriptDescriptor::_open_tables, hoa_script::private_script::STACK_TOP, and hoa_script::private_script::TABLE_END.

Referenced by ModifyBool(), ModifyFloat(), ModifyInt(), ModifyString(), and ModifyUInt().

void hoa_script::ModifyScriptDescriptor::AddNewBool ( int32  key,
bool  value 
) [inline]

Definition at line 113 of file script_modify.h.

References _AddNewData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::AddNewBool ( const std::string &  key,
bool  value 
) [inline]

Definition at line 110 of file script_modify.h.

References _AddNewData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::AddNewFloat ( int32  key,
float  value 
) [inline]

Definition at line 131 of file script_modify.h.

References _AddNewData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::AddNewFloat ( const std::string &  key,
float  value 
) [inline]

Definition at line 128 of file script_modify.h.

References _AddNewData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::AddNewInt ( int32  key,
int32  value 
) [inline]

Definition at line 119 of file script_modify.h.

References _AddNewData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::AddNewInt ( const std::string &  key,
int32  value 
) [inline]

Definition at line 116 of file script_modify.h.

References _AddNewData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::AddNewString ( int32  key,
const std::string &  value 
) [inline]

Definition at line 137 of file script_modify.h.

References _AddNewData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::AddNewString ( const std::string &  key,
const std::string &  value 
) [inline]

Definition at line 134 of file script_modify.h.

References _AddNewData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::AddNewUInt ( int32  key,
uint32  value 
) [inline]

Definition at line 125 of file script_modify.h.

References _AddNewData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::AddNewUInt ( const std::string &  key,
uint32  value 
) [inline]

Definition at line 122 of file script_modify.h.

References _AddNewData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::CloseFile (  )  [virtual]

Closes the script file and sets the _access_mode member to SCRIPT_CLOSED.

Reimplemented from hoa_script::ReadScriptDescriptor.

Definition at line 88 of file script_modify.cpp.

References hoa_script::ScriptDescriptor::_access_mode, hoa_script::ScriptDescriptor::_error_messages, hoa_script::ScriptDescriptor::_filename, hoa_script::ReadScriptDescriptor::_lstack, hoa_script::ScriptDescriptor::_open_tables, hoa_script::GameScript::_RemoveOpenFile(), hoa_script::ScriptDescriptor::IsErrorDetected(), hoa_script::ScriptDescriptor::IsFileOpen(), hoa_script::SCRIPT_CLOSED, hoa_script::SCRIPT_DEBUG, and hoa_script::ScriptManager.

Referenced by CommitChanges(), and ~ModifyScriptDescriptor().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::CommitChanges ( bool  leave_closed = false  ) 

Commits all modified changes to the Lua file for permanent retention.

Parameters:
leave_closed If set to true this file will be left closed once the function finishes (re-opens fileby default)
This is a heavy-weight function because it has to write out the entire Lua state to a file, regardless of whether one piece of data was modified or one hundred were. Therefore, you should only call this function when all data modifications are done and you need to save the result back to the hard-disk. Because the file referenced by this class is modified, the file is closed and optionally re-opened before the function returns.

Todo:
Spawn off this function in a seperate thread?

Definition at line 113 of file script_modify.cpp.

References _CommitTable(), hoa_script::ScriptDescriptor::_error_messages, hoa_script::ScriptDescriptor::_filename, hoa_script::ReadScriptDescriptor::_lstack, CloseFile(), hoa_script::WriteScriptDescriptor::CloseFile(), hoa_utils::MoveFile(), OpenFile(), hoa_script::WriteScriptDescriptor::OpenFile(), and hoa_script::SCRIPT_DEBUG.

Referenced by hoa_boot::BootMode::_SaveSettingsFile().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::ModifyBool ( int32  key,
bool  value 
) [inline]

Definition at line 72 of file script_modify.h.

References _ModifyData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::ModifyBool ( const std::string &  key,
bool  value 
) [inline]

Definition at line 69 of file script_modify.h.

References _ModifyData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::ModifyFloat ( int32  key,
float  value 
) [inline]

Definition at line 90 of file script_modify.h.

References _ModifyData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::ModifyFloat ( const std::string &  key,
float  value 
) [inline]

Definition at line 87 of file script_modify.h.

References _ModifyData().

Referenced by hoa_boot::BootMode::_SaveSettingsFile().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::ModifyInt ( int32  key,
int32  value 
) [inline]

Definition at line 78 of file script_modify.h.

References _ModifyData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::ModifyInt ( const std::string &  key,
int32  value 
) [inline]

Definition at line 75 of file script_modify.h.

References _ModifyData().

Referenced by hoa_boot::BootMode::_SaveSettingsFile().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::ModifyString ( int32  key,
const std::string &  value 
) [inline]

Definition at line 96 of file script_modify.h.

References _ModifyData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::ModifyString ( const std::string &  key,
const std::string &  value 
) [inline]

Definition at line 93 of file script_modify.h.

References _ModifyData().

Referenced by hoa_boot::BootMode::_SaveSettingsFile().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::ModifyUInt ( int32  key,
uint32  value 
) [inline]

Definition at line 84 of file script_modify.h.

References _ModifyData().

Here is the call graph for this function:

void hoa_script::ModifyScriptDescriptor::ModifyUInt ( const std::string &  key,
uint32  value 
) [inline]

Definition at line 81 of file script_modify.h.

References _ModifyData().

Here is the call graph for this function:

bool hoa_script::ModifyScriptDescriptor::OpenFile (  )  [virtual]

Opens the file named by the classes' _filename member.

Returns:
False on failure, true on success.

Reimplemented from hoa_script::ReadScriptDescriptor.

Definition at line 75 of file script_modify.cpp.

References hoa_script::ScriptDescriptor::_filename, and hoa_script::SCRIPT_DEBUG.

Referenced by CommitChanges().

bool hoa_script::ModifyScriptDescriptor::OpenFile ( const std::string &  file_name  )  [virtual]

Parameters:
file_name The name of the Lua file to be opened.
Returns:
False on failure or true on success.
Note:
This is the only function that uses explicit error checking. An error in this function call will not change the return value of the GetErrors() function.

Reimplemented from hoa_script::ReadScriptDescriptor.

Definition at line 47 of file script_modify.cpp.

References hoa_script::ScriptDescriptor::_access_mode, hoa_script::GameScript::_AddOpenFile(), hoa_script::ScriptDescriptor::_filename, hoa_script::ReadScriptDescriptor::_lstack, hoa_script::GameScript::GetGlobalState(), hoa_script::GameScript::IsFileOpen(), hoa_script::SCRIPT_CLOSED, hoa_script::SCRIPT_DEBUG, hoa_script::SCRIPT_READ, and hoa_script::ScriptManager.

Referenced by hoa_boot::BootMode::_SaveSettingsFile().

Here is the call graph for this function:


Friends And Related Function Documentation

friend class GameScript [friend]

Reimplemented from hoa_script::ReadScriptDescriptor.

Definition at line 47 of file script_modify.h.


The documentation for this class was generated from the following files:
Generated on Fri Jul 6 23:15:44 2007 for Hero of Allacrost by  doxygen 1.5.1