Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

dev.cpp

Go to the documentation of this file.
00001 //============================================================================= 
00002 //
00003 // XDFLengine library
00004 //
00005 //----------------------------------------------------------------------------- 
00006 //  dev.cpp
00007 //----------------------------------------------------------------------------- 
00013 //_____________________________________________________________________________
00014 //
00015 //  Copyright (C) 2003 Guillaume Baurand. All Rights Reserved.
00016 //
00017 //  This file is part of the XDFLengine project.
00018 //
00019 //  The XDFLengine is free software; you can redistribute it and/or modify
00020 //  it under the terms of the GNU General Public License as published by
00021 //  the Free Software Foundation; either version 2 of the License, or
00022 //  (at your option) any later version.
00023 //
00024 //  This program is distributed in the hope that it will be useful,
00025 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00026 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00027 //  GNU General Public License for more details.
00028 //
00029 //  You should have received a copy of the GNU General Public License
00030 //  along with this program; if not, write to the Free Software
00031 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
00032 //  USA.
00033 //
00034 //  For more information, 
00035 //      contact  : guillaume@baurand.net 
00036 //      or visit : http://xdflengine.sourceforge.net
00037 //
00038 //=============================================================================
00039 
00040 #include "dev.hpp"
00041 #include "config/config.hpp"
00042 #include "utils/vaarray.hpp"
00043 #include <time.h>
00044 #ifdef PLATFORM_WIN32_MSVC
00045 #   ifdef _DEBUG
00046 #       include "crtdbg.h"
00047 #   endif
00048 #endif
00049 
00050 
00051 #define         TRACEFILE "C:\\XDFLenginetrace.TXT"
00052 //#define           TRACEPAUSE
00053 
00054 #if TRACE_DEBUG==0
00055 #   undef TRACEPAUSE
00056 #endif
00057 
00058 #if TRACE_DEBUG==1
00059     int             debug_intObjectsCreated;
00060     int             debug_intObjectsDeleted;
00061     XDFLengine::VAarray<int>    debug_obj;
00062     XDFLengine::VAarray<int>    debug_functions;
00063 #endif
00064 
00065 
00066 //============================================================================= 
00067 
00068 void debug_init()
00069 {
00070 #if TRACE_DEBUG==1
00071     debug_intObjectsCreated = 0;
00072     debug_intObjectsDeleted = 0;
00073 
00074     #if defined(TRACEFILE)
00075         traceout.log_set( TRACEFILE);
00076     #else
00077         traceout.log_set( XMLPROCESSOR_LOGFILESTD);
00078     #endif
00079     /*
00080     traceout << "|  date   |   mem   |  diff   |?|\n";
00081     traceout << "|==============================|=|\n";*/
00082     traceout << "\n=====================================================================\n";
00083 
00084 #endif
00085 }
00086 
00087 void debug_end()
00088 {
00089 #if TRACE_DEBUG==1
00090     /*traceout <<   "|==============================|=|\n";*/
00091     traceout << "\n=====================================================================\n";
00092     traceout << "Objects created : " << debug_intObjectsCreated << "\n";
00093     traceout << "Objects deleted : " << debug_intObjectsDeleted << "\n";
00094     traceout << "Objects remaining : \n" ;
00095     while(!debug_obj.empty())
00096     {
00097         traceout << "\t" << debug_obj.getKey(0) << ":" << debug_obj.get((int)0) << "\n";
00098         debug_obj.remove((int)0);
00099     }
00100 
00101     traceout << "\nFunction calls non returned : \n" ;
00102     while(!debug_functions.empty())
00103     {
00104 
00105         traceout << "\t" << debug_functions.getKey(0) << ":" << debug_functions.get((int)0) << "\n";
00106         debug_functions.remove((int)0);
00107     }
00108 #endif
00109 
00110 }
00111 
00112 void debug_indent(int offset)
00113 {
00114 #if TRACE_DEBUG==1
00115     static int debug_indent=0;
00116 
00117     debug_indent+=offset;
00118 
00119     if(offset==0){
00120         for (int i=0;i<debug_indent;i++){
00121             traceout << "\t" ;
00122         }
00123     }
00124 #endif
00125 }
00126 
00127 void debug_startLogLine(const char* c){
00128 
00129 #if TRACE_DEBUG==1
00130     static char temp[100];
00131     /*
00132     static int intSize1=0;
00133     int intSize2;
00134     int diff;
00135     const char* rk;
00136     
00137     
00138     intSize2=0;
00139 
00140     if(intSize2>intSize1) { rk="+"; diff=intSize2-intSize1 ;}
00141     if(intSize2<intSize1) { rk="-"; diff=intSize1-intSize2 ;}
00142     if(intSize2==intSize1) { rk=" "; diff=0; }
00143 
00144     intSize1=intSize2;
00145     sprintf(temp,"| %7d | %8d |%s%7d |%s|",clock(),intSize2,rk,diff,c);
00146 */
00147     sprintf(temp,"| %7d | %8d |",clock(),debug_intObjectsCreated-debug_intObjectsDeleted);
00148     traceout << temp  ;
00149 #endif
00150     
00151 }
00152 
00153 void debug_in(const char* func)
00154 {
00155 #if TRACE_DEBUG==1
00156     if( debug_functions.count(func)==0 ) 
00157     {
00158         debug_functions.add(1, func);
00159     }
00160     else
00161     {
00162         debug_functions.add( debug_functions.remove(func)+1, func );
00163     }
00164 #endif
00165 }
00166 
00167 void debug_out(const char* func)
00168 {
00169 #if TRACE_DEBUG==1
00170     int c;
00171 
00172     if( debug_functions.count(func)==0 ) 
00173     {
00174         debug_functions.add(-1, func);
00175     }
00176     else
00177     {
00178         c=debug_functions.remove(func)-1;
00179         if(c>0) debug_functions.add( c, func );
00180     }
00181 #endif
00182 }
00183 
00184 void debug_create(const char* obj)
00185 {
00186 #if TRACE_DEBUG==1
00187     debug_intObjectsCreated ++;
00188     if( debug_obj.count(obj)==0 ) 
00189     {
00190         debug_obj.add(1, obj);
00191     }
00192     else
00193     {
00194         debug_obj.add( debug_obj.remove(obj)+1, obj );
00195     }
00196 #endif
00197 }
00198 
00199 void debug_del(const char* obj)
00200 {
00201 #if TRACE_DEBUG==1
00202     int c;
00203     debug_intObjectsDeleted ++;
00204     if( debug_obj.count(obj)==0 ) 
00205     {
00206         debug_obj.add(-1, obj);
00207     }
00208     else
00209     {
00210         c=debug_obj.remove(obj)-1;
00211         if(c>0) debug_obj.add( c, obj );
00212     }
00213 #endif
00214 }
00215 
00216 //============================================================================= 
00217 
00218 
00219 
00220 
00221 
00222 logstream::logstream()
00223 {
00224     m_logout=0;
00225 }
00226 
00227 logstream::~logstream()
00228 {}
00229 
00230 void logstream::log_set( const char* p_pszLogDest)
00231 {
00232     bool l_boolOK=false;
00233 
00234     if(p_pszLogDest)
00235     {
00236         // Set log file 
00237         if( strlen( p_pszLogDest)>0)
00238         {
00239             if( strcmp(p_pszLogDest,XMLPROCESSOR_LOGFILESTD) == 0) m_logout = stdout;
00240             else m_logout=fopen(p_pszLogDest,"w");
00241 
00242             l_boolOK = true;
00243         }
00244     }
00245     if(!l_boolOK)
00246     {
00247         if(m_logout && (m_logout!=stdout)) fclose(m_logout);
00248         m_logout = 0;
00249     }
00250 }
00251 
00252 FILE* logstream::log_get()
00253 {
00254     return m_logout;
00255 }
00256 
00257 logstream & logstream::operator<< ( const char* cContent)
00258 {
00259     if(m_logout) 
00260     {
00261         fprintf( m_logout, "%s", cContent);
00262         fflush(m_logout);
00263     }
00264     return * this;
00265 }
00266 
00267 logstream & logstream::operator<< ( long lContent)
00268 {
00269     if(m_logout) 
00270     {
00271         fprintf( m_logout, "%d", lContent);
00272         fflush(m_logout);;
00273     }
00274     return * this;
00275 }
00276 
00277 
00278 void logstream::display_version( char* cLibTag, char* cLibName, char* cLibVersion, char* cLibComment)
00279 {
00280     static char m_logCreds[4096];
00281     char        m_logTag[255];
00282     
00283     #ifdef SHOW_VERSION_INFO
00284 
00285     m_logTag[0]=',';
00286     strcpy( ((char*)&m_logTag)+1, cLibTag);
00287     strcat((char*) & m_logTag,",");
00288     
00289 
00290     if( !strstr((char*) & m_logCreds,(char*) &  m_logTag))  
00291     {
00292         strcat((char*) & m_logCreds,",");
00293         strcat((char*) & m_logCreds,cLibTag); 
00294         strcat((char*) & m_logCreds,",");
00295 
00296         
00297         (*this) << (char*)cLibName;
00298         (*this) << (char*) " ";
00299         (*this) << (char*) cLibVersion;
00300         (*this) << (char*) "\n\t";
00301         (*this) << (char*)cLibComment;
00302         (*this) << (char*)"\n";
00303     }
00304 
00305     
00306     #endif  
00307     
00308     
00309 }
00310 
00311 void logstream::display_version( char* cLibTag, char* cLibName, int iLibVersion, char* cLibComment)
00312 {
00313     char cLibVersion[50];
00314     sprintf((char*)(&cLibVersion),"%d",iLibVersion);
00315     display_version( cLibTag, cLibName, cLibVersion,  cLibComment);
00316 }
00317 //============================================================================= 

Generated on Sat Oct 4 13:19:58 2003 for XDFLengine by doxygen1.3-rc2