hoa_script::WriteScriptDescriptor Class Reference

Provides a simplistic interface for writing data to a new Lua file. More...

#include <script_write.h>

Inheritance diagram for hoa_script::WriteScriptDescriptor:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ~WriteScriptDescriptor ()
Comment Write Functions
Writes comments into a Lua file

Parameters:
comment The comment to write to the file.


void BeginCommentBlock ()
 After this function is invoked, all other data written will be a comment.
void EndCommentBlock ()
 Ends a comment block.
void InsertNewLine ()
 Inserts a blank line into the text.
void WriteComment (const std::string &comment)
 Writes a string of text and prepends it with a comment. This is equivalent to the `// comment` in C++.
void WriteLine (const std::string &comment, bool new_line=true)
 Writes an unaltered string to the file.
Table Write Functions
These functions write the beginning and ends of Lua tables

Parameters:
key The name of the table to write.
Note:
If you begin a new table and then begin another when you haven't ended the first one, the new table will become a key to the first. A table will only become global when there are no other write tables open.


void BeginTable (int32 key)
void BeginTable (const std::string &key)
void EndTable ()
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)
Variable Write Functions
These functions will write a single variable and its value to a Lua file.

Parameters:
*key The name of the Lua variable to write.
value The value of the new global variable to write.
Note:
If no write tables are open when these calls are made, the variables become global in the Lua file. Otherwise, they become keys of the most recently opened table.


void WriteBool (const int32 key, bool value)
void WriteBool (const std::string &key, bool value)
void WriteFloat (const int32 key, float value)
void WriteFloat (const std::string &key, float value)
void WriteInt (const int32 key, int32 value)
void WriteInt (const std::string &key, int32 value)
void WriteString (const int32 key, const std::string &value)
void WriteString (const std::string &key, const std::string &value)
void WriteUInt (const int32 key, uint32 value)
void WriteUInt (const std::string &key, uint32 value)
void WriteUString (const int32 key, const std::string &value)
void WriteUString (const std::string &key, const std::string &value)
Vector Write Functions
These functions write a vector of data to a Lua file.

Parameters:
key The name of the table to use in the Lua file to represent the data.
&vect A reference to the vector of elements to write.


void WriteBoolVector (const int32 key, std::vector< bool > &vect)
void WriteBoolVector (const std::string &key, std::vector< bool > &vect)
void WriteFloatVector (const int32 key, std::vector< float > &vect)
void WriteFloatVector (const std::string &key, std::vector< float > &vect)
void WriteIntVector (const int32 key, std::vector< int32 > &vect)
void WriteIntVector (const std::string &key, std::vector< int32 > &vect)
void WriteStringVector (const int32 key, std::vector< std::string > &vect)
void WriteStringVector (const std::string &key, std::vector< std::string > &vect)
void WriteUIntVector (const int32 key, std::vector< int32 > &vect)
void WriteUIntVector (const std::string &key, std::vector< int32 > &vect)
void WriteUStringVector (const int32 key, std::vector< std::string > &vect)
void WriteUStringVector (const std::string &key, std::vector< std::string > &vect)

Private Member Functions

void _WriteTablePath ()
 Writes the pathname of all open tables (i.e., table1[table2][table3]).
Variable Write Templates
These template functions are called by the public WriteTYPE functions of this class.

Parameters:
key The name or numeric identifier of the Lua variable to write.
value The value to write for the new variable
Note:
The integer keys are only valid for variables stored in a table, not for global variables.


template<class T>
void _WriteData (const int32 key, T value)
template<class T>
void _WriteData (const std::string &key, T value)
Vector Read Templates
These template functions are called by the public ReadTYPEVector functions of this class.

Parameters:
key The name or numeric identifier of the Lua variable to access.
vect A reference to the vector where the read variables should be store
Note:
Integer keys are only valid for variables stored in a table, not for global variables.


template<class T>
void _WriteDataVector (const int32 key, std::vector< T > &vect)
template<class T>
void _WriteDataVector (const std::string &key, std::vector< T > &vect)

Private Attributes

bool _inside_comment_block
 Set to true after a comment block begins and false after the comment block ends.
std::ofstream _outfile
 The output file stream to write to for when the file is opened in write mode.

Friends

class GameScript

Detailed Description

Provides a simplistic interface for writing data to a new Lua file.

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

This class does not actually involve Lua in any way. Rather, it provides an interface with which to write a Lua file from scratch. One area of the code base which uses this class graciously is the Allacrost editor when it saves new map files. Be cautious when using this class, as it can overwrite existing Lua files. This class is primarily for writing data, not code, although it is indeed possible to write script code using this class.

Note:
With the exception of the open/close file functions, all methods of this class assume that the file is open and do not check otherwise. If you try to invoke these functions with an unopened file, you will generate a segmentation fault.

Except where noted in the function's comments, all methods automatically insert a new line into the file after they write their requested contents.

Todo:
Implement the WriteUString methods that will automatically insert the gettext call to retrieve the translated value of the string.
Todo:
Allow the user to automatically compile the newly written file and possibly also delete the plain text version when this is done.

Definition at line 52 of file script_write.h.


Constructor & Destructor Documentation

hoa_script::WriteScriptDescriptor::~WriteScriptDescriptor (  ) 

Definition at line 30 of file script_write.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::WriteScriptDescriptor::_WriteData ( const int32  key,
value 
) [private]

Definition at line 231 of file script_write.h.

References hoa_script::ScriptDescriptor::_error_messages, hoa_script::ScriptDescriptor::_open_tables, _outfile, and _WriteTablePath().

Here is the call graph for this function:

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

Definition at line 220 of file script_write.h.

References hoa_script::ScriptDescriptor::_open_tables, _outfile, and _WriteTablePath().

Referenced by WriteFloat(), WriteInt(), and WriteUInt().

Here is the call graph for this function:

template<class T>
void hoa_script::WriteScriptDescriptor::_WriteDataVector ( const int32  key,
std::vector< T > &  vect 
) [private]

Definition at line 268 of file script_write.h.

References hoa_script::ScriptDescriptor::_error_messages, hoa_script::ScriptDescriptor::_open_tables, _outfile, and _WriteTablePath().

Here is the call graph for this function:

template<class T>
void hoa_script::WriteScriptDescriptor::_WriteDataVector ( const std::string &  key,
std::vector< T > &  vect 
) [private]

Definition at line 244 of file script_write.h.

References hoa_script::ScriptDescriptor::_error_messages, hoa_script::ScriptDescriptor::_open_tables, _outfile, and _WriteTablePath().

Referenced by WriteFloatVector(), WriteIntVector(), and WriteUIntVector().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::_WriteTablePath (  )  [private]

Writes the pathname of all open tables (i.e., table1[table2][table3]).

Definition at line 413 of file script_write.cpp.

References hoa_script::ScriptDescriptor::_error_messages, hoa_script::ScriptDescriptor::_open_tables, and _outfile.

Referenced by _WriteData(), _WriteDataVector(), BeginTable(), WriteBool(), and WriteBoolVector().

void hoa_script::WriteScriptDescriptor::BeginCommentBlock (  ) 

After this function is invoked, all other data written will be a comment.

Definition at line 133 of file script_write.cpp.

References hoa_script::ScriptDescriptor::_error_messages, _inside_comment_block, and _outfile.

void hoa_script::WriteScriptDescriptor::BeginTable ( int32  key  ) 

Definition at line 386 of file script_write.cpp.

References hoa_script::ScriptDescriptor::_open_tables, _outfile, and _WriteTablePath().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::BeginTable ( const std::string &  key  ) 

Referenced by hoa_script::ModifyScriptDescriptor::_CommitTable(), and hoa_editor::Grid::SaveMap().

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

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

Implements hoa_script::ScriptDescriptor.

Definition at line 96 of file script_write.cpp.

References hoa_script::ScriptDescriptor::_access_mode, hoa_script::ScriptDescriptor::_error_messages, hoa_script::ScriptDescriptor::_filename, hoa_script::ScriptDescriptor::_open_tables, _outfile, 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 hoa_script::ModifyScriptDescriptor::CommitChanges(), hoa_editor::Grid::SaveMap(), and ~WriteScriptDescriptor().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::EndCommentBlock (  ) 

Ends a comment block.

Definition at line 146 of file script_write.cpp.

References hoa_script::ScriptDescriptor::_error_messages, _inside_comment_block, and _outfile.

void hoa_script::WriteScriptDescriptor::EndTable (  ) 

Definition at line 399 of file script_write.cpp.

References hoa_script::ScriptDescriptor::_error_messages, and hoa_script::ScriptDescriptor::_open_tables.

Referenced by hoa_script::ModifyScriptDescriptor::_CommitTable(), and hoa_editor::Grid::SaveMap().

void hoa_script::WriteScriptDescriptor::InsertNewLine (  ) 

Inserts a blank line into the text.

Definition at line 121 of file script_write.cpp.

References _outfile.

Referenced by hoa_global::GameGlobal::_SaveCharacter(), hoa_global::GameGlobal::_SaveInventory(), and hoa_editor::Grid::SaveMap().

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

Opens the file named by the classes' _filename member.

Returns:
False on failure, true on success.

Implements hoa_script::ScriptDescriptor.

Definition at line 83 of file script_write.cpp.

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

bool hoa_script::WriteScriptDescriptor::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.

Implements hoa_script::ScriptDescriptor.

Referenced by hoa_script::ModifyScriptDescriptor::CommitChanges(), and hoa_editor::Grid::SaveMap().

void hoa_script::WriteScriptDescriptor::WriteBool ( const int32  key,
bool  value 
)

Definition at line 191 of file script_write.cpp.

References hoa_script::ScriptDescriptor::_error_messages, hoa_script::ScriptDescriptor::_open_tables, _outfile, and _WriteTablePath().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::WriteBool ( const std::string &  key,
bool  value 
)

Referenced by hoa_script::ModifyScriptDescriptor::_CommitTable().

void hoa_script::WriteScriptDescriptor::WriteBoolVector ( const int32  key,
std::vector< bool > &  vect 
)

Definition at line 281 of file script_write.cpp.

References hoa_script::ScriptDescriptor::_error_messages, hoa_script::ScriptDescriptor::_open_tables, _outfile, and _WriteTablePath().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::WriteBoolVector ( const std::string &  key,
std::vector< bool > &  vect 
)

void hoa_script::WriteScriptDescriptor::WriteComment ( const std::string &  comment  ) 

Writes a string of text and prepends it with a comment. This is equivalent to the `// comment` in C++.

Referenced by hoa_editor::Grid::SaveMap().

void hoa_script::WriteScriptDescriptor::WriteFloat ( const int32  key,
float  value 
) [inline]

Definition at line 122 of file script_write.h.

References _WriteData().

Here is the call graph for this function:

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

Definition at line 119 of file script_write.h.

References _WriteData().

Referenced by hoa_script::ModifyScriptDescriptor::_CommitTable().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::WriteFloatVector ( const int32  key,
std::vector< float > &  vect 
) [inline]

Definition at line 161 of file script_write.h.

References _WriteDataVector().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::WriteFloatVector ( const std::string &  key,
std::vector< float > &  vect 
) [inline]

Definition at line 158 of file script_write.h.

References _WriteDataVector().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::WriteInt ( const int32  key,
int32  value 
) [inline]

Definition at line 110 of file script_write.h.

References _WriteData().

Here is the call graph for this function:

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

Definition at line 107 of file script_write.h.

References _WriteData().

Referenced by hoa_script::ModifyScriptDescriptor::_CommitTable(), and hoa_editor::Grid::SaveMap().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::WriteIntVector ( const int32  key,
std::vector< int32 > &  vect 
) [inline]

Definition at line 149 of file script_write.h.

References _WriteDataVector().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::WriteIntVector ( const std::string &  key,
std::vector< int32 > &  vect 
) [inline]

Definition at line 146 of file script_write.h.

References _WriteDataVector().

Referenced by hoa_editor::Grid::SaveMap().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::WriteLine ( const std::string &  comment,
bool  new_line = true 
)

Writes an unaltered string to the file.

Parameters:
comment The string of text to write to the file
new_line If true, automatically appends a new line (enabled by default)
Note:
Typically, you should really try to avoid using this function unless you know what you are doing. It is, however, safe to use it between the beginning and end of a comment block (just don't write the syntax that ends the block, which is `--]]`).

Referenced by hoa_global::GameGlobal::_SaveCharacter(), hoa_global::GameGlobal::_SaveEvents(), hoa_global::GameGlobal::_SaveInventory(), and hoa_editor::Grid::SaveMap().

void hoa_script::WriteScriptDescriptor::WriteString ( const int32  key,
const std::string &  value 
)

void hoa_script::WriteScriptDescriptor::WriteString ( const std::string &  key,
const std::string &  value 
)

Referenced by hoa_script::ModifyScriptDescriptor::_CommitTable(), and hoa_editor::Grid::SaveMap().

void hoa_script::WriteScriptDescriptor::WriteStringVector ( const int32  key,
std::vector< std::string > &  vect 
)

void hoa_script::WriteScriptDescriptor::WriteStringVector ( const std::string &  key,
std::vector< std::string > &  vect 
)

void hoa_script::WriteScriptDescriptor::WriteUInt ( const int32  key,
uint32  value 
) [inline]

Definition at line 116 of file script_write.h.

References _WriteData().

Here is the call graph for this function:

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

Definition at line 113 of file script_write.h.

References _WriteData().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::WriteUIntVector ( const int32  key,
std::vector< int32 > &  vect 
) [inline]

Definition at line 155 of file script_write.h.

References _WriteDataVector().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::WriteUIntVector ( const std::string &  key,
std::vector< int32 > &  vect 
) [inline]

Definition at line 152 of file script_write.h.

References _WriteDataVector().

Here is the call graph for this function:

void hoa_script::WriteScriptDescriptor::WriteUString ( const int32  key,
const std::string &  value 
)

void hoa_script::WriteScriptDescriptor::WriteUString ( const std::string &  key,
const std::string &  value 
)

The WriteUString functions actually take standard strings, not ustrings, for their value. What these methods do is write the string to the Lua file with the gettext translation code attached so that when the value is retrieved, the appropriate string translation is returned from gettext instead of the actual base string contained in the file.

void hoa_script::WriteScriptDescriptor::WriteUStringVector ( const int32  key,
std::vector< std::string > &  vect 
)

void hoa_script::WriteScriptDescriptor::WriteUStringVector ( const std::string &  key,
std::vector< std::string > &  vect 
)


Friends And Related Function Documentation

friend class GameScript [friend]

Reimplemented from hoa_script::ScriptDescriptor.

Definition at line 53 of file script_write.h.


Member Data Documentation

bool hoa_script::WriteScriptDescriptor::_inside_comment_block [private]

Set to true after a comment block begins and false after the comment block ends.

Definition at line 188 of file script_write.h.

Referenced by BeginCommentBlock(), and EndCommentBlock().

std::ofstream hoa_script::WriteScriptDescriptor::_outfile [private]

The output file stream to write to for when the file is opened in write mode.

Definition at line 185 of file script_write.h.

Referenced by _WriteData(), _WriteDataVector(), _WriteTablePath(), BeginCommentBlock(), BeginTable(), CloseFile(), EndCommentBlock(), InsertNewLine(), WriteBool(), and WriteBoolVector().


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