csutil/callstack.h
Go to the documentation of this file.
00001 /* 00002 Call stack creation helper 00003 Copyright (C) 2004 by Jorrit Tyberghein 00004 (C) 2004 by Frank Richter 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public 00017 License along with this library; if not, write to the Free 00018 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 #ifndef __CS_UTIL_CALLSTACK_H__ 00021 #define __CS_UTIL_CALLSTACK_H__ 00022 00027 #include "csextern.h" 00028 #include "csutil/csstring.h" 00029 #include "csutil/refcount.h" 00030 00032 class CS_CRYSTALSPACE_EXPORT csCallStack : public csRefCount 00033 { 00034 protected: 00035 virtual ~csCallStack() {} 00036 public: 00040 virtual void Free() = 0; 00041 00043 virtual size_t GetEntryCount () = 0; 00044 //{@ 00050 virtual bool GetFunctionName (size_t num, char*& str) = 0; 00051 bool GetFunctionName (size_t num, csString& str) 00052 { 00053 char* cstr; 00054 if (GetFunctionName (num, cstr)) 00055 { 00056 str = cstr; 00057 free (cstr); 00058 return true; 00059 } 00060 return false; 00061 } 00063 //{@ 00069 virtual bool GetLineNumber (size_t num, char*& str) = 0; 00070 bool GetLineNumber (size_t num, csString& str) 00071 { 00072 char* cstr; 00073 if (GetLineNumber (num, cstr)) 00074 { 00075 str = cstr; 00076 free (cstr); 00077 return true; 00078 } 00079 return false; 00080 } 00082 //{@ 00087 virtual bool GetParameters (size_t num, char*& str) = 0; 00088 bool GetParameters (size_t num, csString& str) 00089 { 00090 char* cstr; 00091 if (GetParameters (num, cstr)) 00092 { 00093 str = cstr; 00094 free (cstr); 00095 return true; 00096 } 00097 return false; 00098 } 00100 00105 void Print (FILE* f = stdout, bool brief = false) 00106 { 00107 for (size_t i = 0; i < GetEntryCount(); i++) 00108 { 00109 char* s; 00110 bool hasFunc = GetFunctionName (i, s); 00111 fprintf (f, "%s", hasFunc ? (const char*)s : "<unknown>"); 00112 if (hasFunc) free (s); 00113 if (!brief && (GetLineNumber (i, s))) 00114 { 00115 fprintf (f, " @%s", (const char*)s); 00116 free (s); 00117 } 00118 if (!brief && (GetParameters (i, s))) 00119 { 00120 fprintf (f, " (%s)", (const char*)s); 00121 free (s); 00122 } 00123 fprintf (f, "\n"); 00124 } 00125 fflush (f); 00126 } 00132 csString GetEntryAll (size_t i, bool brief = false) 00133 { 00134 csString line; 00135 char* s; 00136 bool hasFunc = GetFunctionName (i, s); 00137 line << (hasFunc ? (const char*)s : "<unknown>"); 00138 if (hasFunc) free (s); 00139 if (!brief && GetLineNumber (i, s)) 00140 { 00141 line << " @" << s; 00142 free (s); 00143 } 00144 if (!brief && GetParameters (i, s)) 00145 { 00146 line << " (" << s << ")"; 00147 free (s); 00148 } 00149 return line; 00150 } 00151 }; 00152 00154 class CS_CRYSTALSPACE_EXPORT csCallStackHelper 00155 { 00156 public: 00168 static csCallStack* CreateCallStack (int skip = 0, bool fast = false); 00169 }; 00170 00171 #endif // __CS_UTIL_CALLSTACK_H__
Generated for Crystal Space 1.4.1 by doxygen 1.7.1