luacommandwriter.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  ***************************************************************************/
00009 
00010 #include "luacommandwriter.h"
00011 
00012 #include <boost/regex.hpp>
00013 #include <boost/algorithm/string/split.hpp>
00014 #include <boost/algorithm/string/classification.hpp>
00015 
00016 void LuaCommandWriter :: splitString( const ASCString& string ) 
00017 {
00018    typedef vector< ASCString > Split_vector_type;
00019 
00020    Split_vector_type splitVec; // #2: Search for tokens
00021    boost::algorithm::split( splitVec, string, boost::algorithm::is_any_of("\n") ); // SplitVec == { "hello abc","ABC","aBc goodbye" }
00022       
00023    for ( Split_vector_type::iterator i = splitVec.begin(); i != splitVec.end(); ++i ) {
00024       printCommand( *i );  
00025    }
00026 }
00027       
00028 void LuaCommandWriter :: writeHeader()  {
00029    outputLine("-- get handle to active map \n");
00030    outputLine("map = asc.getActiveMap() \n");
00031 }
00032       
00033 LuaCommandWriter :: LuaCommandWriter ( ) : commandCounter(0) {
00034 }
00035 
00036 void LuaCommandWriter :: printCommand( const ASCString& command ) {
00037    if ( command.find('\n') != ASCString::npos ) {
00038       splitString(command);
00039    } else {
00040       outputLine("r = asc." + command + "\n" );
00041       outputLine("if r:successful()==false then asc.displayActionError(r, \"command " + ASCString::toString(++commandCounter) + "\") end \n" );
00042    }
00043 };
00044 
00045 void LuaCommandWriter :: printComment( const ASCString& comment ) {
00046    outputLine("\n--" + comment + "\n" );
00047 };
00048 
00049 
00050 
00051 LuaCommandFileWriter :: LuaCommandFileWriter ( const ASCString& filename ) : stream ( filename, tnstream::writing ) 
00052 {
00053    writeHeader();
00054 }
00055 
00056 void LuaCommandFileWriter :: outputLine( const ASCString& line )
00057 {
00058    stream.writeString( line, false );
00059 }
00060 

Generated on Mon May 21 01:26:34 2012 for Advanced Strategic Command by  doxygen 1.5.1