Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Tools/Debugging/Trace.h

Go to the documentation of this file.

    00001 /**
    00002 * @file Tools/Debugging/Trace.h
    00003 *
    00004 * A class representing a trace.
    00005 *
    00006 * @author Thomas Röfer
    00007 */
    00008 #ifndef __Trace_h_
    00009 #define __Trace_h_
    00010
    00011 #include "Tools/Streams/InOut.h"
    00012 #include "Tools/RingBuffer.h"
    00013
    00014 class Trace;
    00015
    00016 /**
    00017  * Streaming operator that reads a trace from a stream.
    00018  * @param stream The stream from which is read.
    00019  * @param currentLine The trace.
    00020  * @return The stream.
    00021  */
    00022 In& operator>>(In& stream, Trace& trace);
    00023
    00024 /**
    00025  * Streaming operator that writes a robot pose to a stream.
    00026  * @param stream The stream to write on.
    00027  * @param currentLine The current line.
    00028  * @return The stream.
    00029  */
    00030 Out& operator<<(Out& stream, const Trace& trace);
    00031
    00032 class Trace
    00033 {
    00034 private:
    00035   /**
    00036   * The class represents single trace points.
    00037   */
    00038   class Line
    00039   {
    00040   public:
    00041     char file[256]; /**< The name of the source file a passed trace point is located in. */
    00042     int line; /**< The line a passed trace point is located in. */
    00043
    00044     /**
    00045     * Constructor.
    00046     * @param f The name of the source file a passed trace point is located in.
    00047     * @param l The line a passed trace point is located in.
    00048     */
    00049     Line(const char* f = "", int l = 0);
    00050   };
    00051
    00052   RingBuffer<Line, 10> buffer; /**< A buffer for the last 10 passed trace points. */
    00053
    00054 public:
    00055   /**
    00056   * The function adds a new entry to the list of passed trace points.
    00057   * @param file The name of the source file a passed trace point is located in.
    00058   * @param line The line a passed trace point is located in.
    00059   */
    00060   void setCurrentLine(const char* file, int line);
    00061
    00062   friend In& operator>>(In& stream, Trace& trace);
    00063   friend Out& operator<<(Out& stream, const Trace& trace);
    00064 };
    00065
    00066 /**
    00067 * The function returns a reference to the shared trace object.
    00068 * @return The reference to the shared trace object.
    00069 */
    00070 Trace& getTrace();
    00071
    00072 /**
    00073 * The function sets the reference to the shared trace object.
    00074 * @param t The reference to the shared trace object.
    00075 */
    00076 void setTrace(Trace& t);
    00077
    00078 #ifdef _WIN32 // On Windows, no trace points are generated
    00079 #define GT_TRACE
    00080 #else
    00081 #ifdef NDEBUG // Neither in the release configuration
    00082 #define GT_TRACE
    00083 #else // But in debug configurations on the robot
    00084 #define GT_TRACE getTrace().setCurrentLine(__FILE__, __LINE__);
    00085 #endif
    00086 #endif
    00087
    00088 #endif