debug.cpp 2.9 KB
Newer Older
Thomas Moulard's avatar
Thomas Moulard committed
1
2
3
4
/*
 * Copyright 2010,
 * François Bleibel,
 * Olivier Stasse,
5
 *
Thomas Moulard's avatar
Thomas Moulard committed
6
 * CNRS/AIST
7
 *
Thomas Moulard's avatar
Thomas Moulard committed
8
 * This file is part of dynamic-graph.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 * dynamic-graph is free software:
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Thomas Moulard's avatar
Thomas Moulard committed
30
 */
31

32
#include <dynamic-graph/debug.h>
33
34
35
36
37
38
#include <fstream>
#include <ios>

using namespace dynamicgraph;

#ifdef WIN32
39
const char * DebugTrace::DEBUG_FILENAME_DEFAULT = "c:/tmp/dynamic-graph-traces.txt";
40
#else	/*WIN32*/
41
const char * DebugTrace::DEBUG_FILENAME_DEFAULT = "/tmp/dynamic-graph-traces.txt";
42
43
44
45
46
47
#endif	/*WIN32*/



#ifdef VP_DEBUG
 #ifdef WIN32
48
  std::ofstream dg_debugfile( "C:/tmp/dynamic-graph-traces.txt", std::ios::trunc&std::ios::out );
49
 #else	/*WIN32*/
50
  std::ofstream dg_debugfile( "/tmp/dynamic-graph-traces.txt", std::ios::trunc&std::ios::out );
51
52
53
#endif	/*WIN32*/
#else
std::ofstream dg_debugfile; //( "/dev/null", std::ios::trunc&std::ios::out );
54
 class dgDebug_init
55
56
 {
 public:
Thomas Moulard's avatar
Thomas Moulard committed
57
58
   dgDebug_init  ()
     { dg_debugfile.setstate( std::ios::failbit ) ; /* dg_debugfile.close (); */ }
59
 };
60
 dgDebug_init dgDebug_initialisator;
61
62
63

#endif

64
65
66
67
namespace dynamicgraph {
	DebugTrace dgDEBUGFLOW(dg_debugfile);
	DebugTrace dgERRORFLOW(dg_debugfile);
}
68
69
70

void DebugTrace::openFile( const char * filename )
{
Thomas Moulard's avatar
Thomas Moulard committed
71
72
  if( dg_debugfile.good ()&&dg_debugfile.is_open () ) dg_debugfile.close ();
  dg_debugfile.clear ();
73
  dg_debugfile.open( filename, std::ios::trunc&std::ios::out );
Thomas Moulard's avatar
Thomas Moulard committed
74
  //std::cout << filename << dg_debugfile.good () << dg_debugfile.is_open () << std::endl;
75
76
}

77
void DebugTrace::closeFile(const char *)
78
{
Thomas Moulard's avatar
Thomas Moulard committed
79
  if( dg_debugfile.good ()&&dg_debugfile.is_open () ) { dg_debugfile.close (); }
80
81
82
83
84
85
86
  dg_debugfile.setstate( std::ios::failbit ) ;
}


//DebugTrace dgDebugFLOW(std::cout);
//DebugTrace dgERRORFLOW(std::cerr);