00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "nel/ai/script/script_debug_source.h"
00027
00028
00029 namespace NLAISCRIPT {
00030
00031
00032
00033
00034
00035
00036
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
00051
00052
00053
00054
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
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
00130
00131
00132
00133
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 }