00001 // ZenLib::Trace - To trace (in files) 00002 // Copyright (C) 2006-2011 MediaArea.net SARL, Info@MediaArea.net 00003 // 00004 // This software is provided 'as-is', without any express or implied 00005 // warranty. In no event will the authors be held liable for any damages 00006 // arising from the use of this software. 00007 // 00008 // Permission is granted to anyone to use this software for any purpose, 00009 // including commercial applications, and to alter it and redistribute it 00010 // freely, subject to the following restrictions: 00011 // 00012 // 1. The origin of this software must not be misrepresented; you must not 00013 // claim that you wrote the original software. If you use this software 00014 // in a product, an acknowledgment in the product documentation would be 00015 // appreciated but is not required. 00016 // 2. Altered source versions must be plainly marked as such, and must not be 00017 // misrepresented as being the original software. 00018 // 3. This notice may not be removed or altered from any source distribution. 00019 // 00020 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00021 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00022 // Trace 00023 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00024 // 00025 // Provide a direct to file trace 00026 // 00027 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00028 00029 //--------------------------------------------------------------------------- 00030 #ifndef ZenTraceH 00031 #define ZenTraceH 00032 //--------------------------------------------------------------------------- 00033 00034 //--------------------------------------------------------------------------- 00035 #include <fstream> 00036 #include "ZenLib/Ztring.h" 00037 //--------------------------------------------------------------------------- 00038 00039 namespace ZenLib 00040 { 00041 00042 //*************************************************************************** 00043 00044 static std::FILE* Trace_F; 00045 static ZenLib::Ztring Trace; 00046 static ZenLib::Ztring Trace2; 00047 00048 #ifdef TRACE 00049 #undef TRACE 00050 #endif //TRACE 00051 00052 #if 1 00053 #define TRACE(_TOAPPEND) 00054 #else 00055 #define TRACE(_TOAPPEND) \ 00056 Trace.clear(); \ 00057 Trace2.clear(); \ 00058 _TOAPPEND; \ 00059 if (!Trace2.empty()) \ 00060 { \ 00061 Trace+=_T(" - "); \ 00062 Trace+=Trace2; \ 00063 } \ 00064 Trace+=_T("\r\n"); \ 00065 Trace_F=std::fopen("Trace.txt", "a+t"); \ 00066 std::fwrite(Trace.To_Local().c_str(), Trace.size(), 1, Trace_F); \ 00067 std::fclose(Trace_F); 00068 #endif 00069 00070 //*************************************************************************** 00071 00072 00073 } //NameSpace 00074 00075 #endif // ZenTraceH 00076 00077