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

# Tools/Debugging/DebugRequest.h

Go to the documentation of this file.

    00001 /**
    00002 * @file DebugRequest.h
    00003 * Declaration of class DebugRequest
    00004 *
    00005 * @author Matthias Jüngel
    00006 */
    00007
    00008 #ifndef __DebugRequest_h__
    00009 #define __DebugRequest_h__
    00010
    00011 #include <string.h>
    00012 #include "Tools/Streams/InOut.h"
    00013
    00014 class DebugRequest
    00015 {
    00016 public:
    00017   /** Constructor, resets the table */
    00018   DebugRequest();
    00019   DebugRequest(const char* description, bool enable = true, bool once = false);
    00020
    00021   /** the == operator */
    00022   char description[80];
    00023   bool enable;
    00024   bool once;
    00025 };
    00026
    00027 /**
    00028 * Streaming operator that reads a DebugRequest from a stream.
    00029 * @param stream The stream from which is read.
    00030 * @param debugRequest The DebugRequest object.
    00031 * @return The stream.
    00032 */
    00033 In& operator>>(In& stream,DebugRequest& debugRequest);
    00034
    00035 /**
    00036 * Streaming operator that writes a DebugRequest to a stream.
    00037 * @param stream The stream to write on.
    00038 * @param debugRequest The DebugRequest object.
    00039 * @return The stream.
    00040 */
    00041 Out& operator<<(Out& stream, const DebugRequest& debugRequest);
    00042
    00043 class DebugRequestTable
    00044 {
    00045 private:
    00046   enum { maxNumberOfDebugRequests = 1000 };
    00047
    00048 public:
    00049   /**
    00050   * The Debug Key Table
    00051   */
    00052   DebugRequest debugRequests[maxNumberOfDebugRequests];
    00053   int currentNumberOfDebugRequests;
    00054
    00055   /** Constructor, resets the table */
    00056   DebugRequestTable();
    00057
    00058   /** */
    00059   void addRequest(const DebugRequest& debugRequest);
    00060
    00061   /** */
    00062   void removeRequest(const char* description);
    00063
    00064   /** */
    00065   bool isActive (const char* name) const
    00066   {
    00067     if(name == lastName)
    00068       return lastIndex < currentNumberOfDebugRequests && debugRequests[lastIndex].enable;
    00069     else if(name == prevLastName)
    00070     {
    00071       const char* t1 = prevLastName;
    00072       prevLastName = lastName;
    00073       lastName = t1;
    00074       int t2 = prevLastIndex;
    00075       prevLastIndex = lastIndex;
    00076       lastIndex = t2;
    00077       return lastIndex < currentNumberOfDebugRequests && debugRequests[lastIndex].enable;
    00078     }
    00079     else
    00080     {
    00081       prevLastName = lastName;
    00082       lastName = name;
    00083       prevLastIndex = lastIndex;
    00084       for(lastIndex = 0; lastIndex < currentNumberOfDebugRequests; ++lastIndex)
    00085         if(strcmp(name, debugRequests[lastIndex].description) == 0)
    00086           return debugRequests[lastIndex].enable;
    00087       return false;
    00088     }
    00089   }
    00090
    00091   /** */
    00092   bool once (const char* name) const
    00093   {
    00094     if(name == lastName)
    00095       return lastIndex < currentNumberOfDebugRequests && debugRequests[lastIndex].once;
    00096     else if(name == prevLastName)
    00097     {
    00098       const char* t1 = prevLastName;
    00099       prevLastName = lastName;
    00100       lastName = t1;
    00101       int t2 = prevLastIndex;
    00102       prevLastIndex = lastIndex;
    00103       lastIndex = t2;
    00104       return lastIndex < currentNumberOfDebugRequests && debugRequests[lastIndex].once;
    00105     }
    00106     else
    00107     {
    00108       prevLastName = lastName;
    00109       lastName = name;
    00110       prevLastIndex = lastIndex;
    00111       for(lastIndex = 0; lastIndex < currentNumberOfDebugRequests; ++lastIndex)
    00112         if(strcmp(name, debugRequests[lastIndex].description) == 0)
    00113           return debugRequests[lastIndex].once;
    00114       return false;
    00115     }
    00116   }
    00117
    00118   /** */
    00119   void disable (const char* name);
    00120
    00121   /** */
    00122   bool notYetPolled(const char* name);
    00123
    00124   /** */
    00125   void removeAllRequests()
    00126   {
    00127     currentNumberOfDebugRequests = 0;
    00128   }
    00129
    00130   /** */
    00131   bool poll;
    00132
    00133   int pollCounter;
    00134
    00135   const char* alreadyPolledDebugRequests[maxNumberOfDebugRequests];
    00136   int alreadyPolledDebugRequestCounter;
    00137   mutable const char* lastName,
    00138                     * prevLastName;
    00139   mutable int lastIndex,
    00140               prevLastIndex;
    00141 };
    00142
    00143 #endif //__DebugRequest_h__