Developer Documentation
Tracing.hh
1/*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40\*===========================================================================*/
41
42
43
44
45
46
47//=============================================================================
48//
49// CLASS Tracing
50//
51//=============================================================================
52
53
54#ifndef ACG_TRACING_HH
55#define ACG_TRACING_HH
56
57
58//== INCLUDES =================================================================
59
60#include "StopWatch.hh"
61#include <iostream>
62#include <string>
63#include "../Config/ACGDefines.hh"
64
65
66//== NAMESPACES ===============================================================
67
68namespace ACG {
69
70
71//== HELPER MACROS ============================================================
72
73
74#define ACG_TRACE(_text) ACG::Tracing acg_tracer__(_text)
75#define ACG_TRACE_CMD(_text, _cmd) { ACG_TRACE(_text); cmd; }
76
77#define ACG_TIMED_TRACE(_text) ACG::TimedTracing acg_tracer__(_text)
78#define ACG_TIMED_TRACE_CMD(_text, _cmd) { ACG_TIMED_TRACE(_text); _cmd; }
79
80#define ACG_TRACE_PROGRESS acg_tracer__.progress()
81
82
83//== CLASS DEFINITION =========================================================
84
85
119class ACGDLLEXPORT Tracing
120{
121public:
122
124 Tracing(const std::string& _text,
125 std::ostream& _os = std::cerr)
126 : os_(_os)
127 { os_ << _text << " " << std::flush; }
128
129
131 ~Tracing() { os_ << "finished.\n" << std::flush; }
132
133
136 void progress() {
137 os_ << progress_[((++idx_)&=0x3)] << "\b" << std::flush;
138 }
139
140
141protected:
142
143 std::ostream& os_;
144 static char progress_[4];
145 static unsigned char idx_;
146};
147
148
149//== CLASS DEFINITION =========================================================
150
151
152
182class ACGDLLEXPORT TimedTracing : public Tracing
183{
184public:
185
187 TimedTracing( const std::string& _text,
188 std::ostream& _os = std::cerr )
189 : Tracing(_text, _os)
190 { timer_.start(); }
191
192
195 {
196 os_ << timer_.stop()*0.001 << " secs, ";
197 }
198
199private:
200
201 StopWatch timer_;
202};
203
204
205
206//=============================================================================
207} // namespace ACG
208//=============================================================================
209#endif // ACG_TRACING_HH defined
210//=============================================================================
211
TimedTracing(const std::string &_text, std::ostream &_os=std::cerr)
default constructor
Definition: Tracing.hh:187
~TimedTracing()
destructor
Definition: Tracing.hh:194
void progress()
Definition: Tracing.hh:136
~Tracing()
Destructor.
Definition: Tracing.hh:131
Tracing(const std::string &_text, std::ostream &_os=std::cerr)
Constructor.
Definition: Tracing.hh:124
Namespace providing different geometric functions concerning angles.