# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

script_debug_source.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "nel/ai/script/script_debug_source.h"
00027 
00028 
00029 namespace NLAISCRIPT {
00030 
00031 //*********************
00032 //IScriptDebugSource
00033 //*********************
00034 
00035 /*
00036  * Constructor
00037  */
00038 IScriptDebugSource::IScriptDebugSource(const char* sourceName):
00039 _SourceName(sourceName)
00040 {
00041 }
00042 
00044 std::string IScriptDebugSource::getSourceName () const
00045 {
00046         return _SourceName;
00047 }
00048 
00049 //*********************
00050 //CScriptDebugSourceFile
00051 //*********************
00052 
00053 /*
00054  * Constructor
00055  */
00056 CScriptDebugSourceFile::CScriptDebugSourceFile(const char* sourceName, bool file): 
00057         IScriptDebugSource((file) ? sourceName : "memoryScript"), isMemory(!file)
00058 {
00059         if(!file) MemoryScript = sourceName;
00060 }
00061 
00063 std::string CScriptDebugSourceFile::getSourceBuffer() const
00064 {
00065         if(!isMemory)
00066         {
00067                 FILE* f;
00068                 sint32 size;
00069                 char* buf;
00070                 std::string ret;
00071 
00072                 // Read the file
00073                 f = fopen(_SourceName.c_str(),"rb");
00074                 fseek(f,0,SEEK_END);
00075                 size = ftell(f);
00076                 rewind(f);
00077                 buf = new char [size + 4];
00078                 fread(buf+1, sizeof( char ), size, f);
00079                 fclose(f);
00080                 buf[0] = ' ';
00081                 buf[size+1] = '\n';
00082                 buf[size+2] = 0;
00083 
00084                 ret = buf;
00085                 delete[] buf;
00086                 
00087                 return ret;
00088         }
00089         else return MemoryScript;
00090 }
00091 
00093 void CScriptDebugSourceFile::save(NLMISC::IStream &os)
00094 {
00095         os.serial(_SourceName);
00096 }
00097 
00099 void CScriptDebugSourceFile::load(NLMISC::IStream &is)
00100 {
00101         is.serial(_SourceName);
00102 }
00103 
00104 const NLAIC::CIdentType& CScriptDebugSourceFile::getType() const
00105 {               
00106         return IdScriptDebugSourceFile;
00107 }
00108 
00109 const NLAIC::IBasicType* CScriptDebugSourceFile::clone() const 
00110 {
00111         NLAIC::IBasicType *x = new CScriptDebugSourceFile(*this);
00112         return x;
00113 }
00114 
00115 const NLAIC::IBasicType *CScriptDebugSourceFile::newInstance() const 
00116 {
00117         NLAIC::IBasicType *x = new CScriptDebugSourceFile("");
00118         return x;
00119 }
00120 
00121 void CScriptDebugSourceFile::getDebugString(std::string &text) const
00122 {
00123         text += "CScriptDebugSourceFile<";
00124         text += _SourceName;
00125         text += ">";
00126 }
00127 
00128 //*********************
00129 //CScriptDebugSourceMemory
00130 //*********************
00131 
00132 /*
00133  * Constructor
00134  */
00135 CScriptDebugSourceMemory::CScriptDebugSourceMemory(const char* sourceName, const char* code):
00136 IScriptDebugSource(sourceName)
00137 {
00138         _Code = code;
00139 }
00140 
00142 std::string CScriptDebugSourceMemory::getSourceBuffer() const
00143 {
00144         return _Code;
00145 }
00146 
00148 void CScriptDebugSourceMemory::save(NLMISC::IStream &os)
00149 {
00150         os.serial(_SourceName);
00151         os.serial(_Code);
00152 }
00153 
00155 void CScriptDebugSourceMemory::load(NLMISC::IStream &is)
00156 {
00157         is.serial(_SourceName);
00158         is.serial(_Code);
00159 }
00160 
00161 const NLAIC::CIdentType& CScriptDebugSourceMemory::getType() const
00162 {               
00163         return IdScriptDebugSourceMemory;
00164 }
00165 
00166 const NLAIC::IBasicType* CScriptDebugSourceMemory::clone() const 
00167 {
00168         NLAIC::IBasicType *x = new CScriptDebugSourceMemory(*this);
00169         return x;
00170 }
00171 
00172 const NLAIC::IBasicType *CScriptDebugSourceMemory::newInstance() const 
00173 {
00174         NLAIC::IBasicType *x = new CScriptDebugSourceMemory("","");
00175         return x;
00176 }
00177 
00178 void CScriptDebugSourceMemory::getDebugString(std::string &text) const
00179 {
00180         text += "CScriptDebugSourceMemory<";
00181         text += _SourceName;
00182         text += ">";
00183         text += "\nValue : ";
00184         text += _Code;
00185 }
00186 
00187 } // NLAISCRIPT