Otawa  0.10
Trace.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * Trace class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2008, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef OTAWA_UTIL_TRACE_H
23 #define OTAWA_UTIL_TRACE_H
24 
25 #include <elm/string.h>
26 #include <elm/io/OutStream.h>
27 #include <elm/io/Output.h>
28 #include <elm/io.h>
29 
30 namespace otawa {
31 
32 class Level;
33 
34 extern const Level L1;
35 extern const Level L2;
36 extern const Level L3;
37 extern const Level L4;
38 extern const Level L5;
39 extern const Level L6;
40 extern const Level L7;
41 extern const Level L8;
42 extern const Level L9;
43 
44 
45 class Level {
46 public:
47  inline Level(int l)
48  : _level(l) { }
49  int _level;
50 };
51 
53  virtual int write (const char *buffer, int size) { return 0;}
54  int flush (void) { return 0; }
55  };
56 
57 extern NullStream null_stream;
58 
59 class Trace : public elm::io::Output {
60  int _level;
63 
64 public:
65  Trace (elm::io::OutStream& stream, int level, elm::String module_name)
66  : _level(level), _module_name(module_name), _stream(stream) {
67 #ifndef OTAWA_NOTRACE
68  setStream(_stream);
69 #else
70  setStream(elm::io::OutStream::null);
71 #endif
72  }
73  inline void checkLevel(int level) {
74 #ifndef OTAWA_NOTRACE
75  if (level <= _level)
76  setStream(_stream);
77  else
78  setStream(null_stream);
79 #endif
80  }
81 };
82 
83 inline Trace& operator<<(Trace& trace, const Level& level) {
84  trace.checkLevel(level._level);
85  return trace;
86 }
87 
88 }
89 
90 #endif // OTAWA_UTIL_TRACE_H
elm::io::OutStream & _stream
Definition: Trace.h:62
elm::io::Output & operator<<(elm::io::Output &out, Address addr)
Definition: base.cpp:188
NullStream null_stream
Definition: util_Trace.cpp:36
const Level L9
uint32 size
Definition: Trace.h:52
Trace(elm::io::OutStream &stream, int level, elm::String module_name)
Definition: Trace.h:65
const Level L4
const Level L6
Level(int l)
Definition: Trace.h:47
Definition: Trace.h:59
const Level L2
const Level L8
elm::String _module_name
Definition: Trace.h:61
int _level
Definition: Trace.h:60
virtual int write(const char *buffer, int size)
Definition: Trace.h:53
int _level
Definition: Trace.h:49
const Level L1
Definition: Trace.h:45
void checkLevel(int level)
Definition: Trace.h:73
const Level L5
const Level L3
const Level L7
int flush(void)
Definition: Trace.h:54