00001 00002 // Name: wxGuiTest/ProvokedWarningRegistry.cpp 00003 // Author: Reinhold Fuereder 00004 // Created: 2004 00005 // Copyright: (c) 2005 Reinhold Fuereder 00006 // Modifications: John Ralls, 2007-2008 00007 // Modifications Copyright: (c) 2008 John Ralls 00008 // Licence: wxWindows licence 00009 // 00010 // $Id$ 00012 00013 #ifdef __GNUG__ 00014 #pragma implementation "ProvokedWarningRegistry.h" 00015 #endif 00016 00017 #include <wxGuiTest/ProvokedWarningRegistry.h> 00018 00019 using namespace wxTst; 00020 00021 00022 // Init single instance: 00023 ProvokedWarningRegistry *ProvokedWarningRegistry::ms_instance = NULL; 00024 00025 00026 ProvokedWarningRegistry::ProvokedWarningRegistry () 00027 { 00028 // Nothing to do 00029 } 00030 00031 00032 ProvokedWarningRegistry::~ProvokedWarningRegistry () 00033 { 00034 ProvokedWarningMap::iterator it = warnings.begin (); 00035 while (it != warnings.end ()) { 00036 00037 this->UnregisterWarning (*((*it++).first)); 00038 } 00039 warnings.clear (); 00040 } 00041 00042 00043 ProvokedWarningRegistry & ProvokedWarningRegistry::GetInstance () 00044 { 00045 if (ms_instance == NULL) { 00046 00047 ms_instance = new ProvokedWarningRegistry (); 00048 } 00049 return *ms_instance; 00050 } 00051 00052 00053 void ProvokedWarningRegistry::Destroy () 00054 { 00055 if (ms_instance != NULL) { 00056 00057 delete ms_instance; 00058 ms_instance = NULL; 00059 } 00060 } 00061 00062 00063 void ProvokedWarningRegistry::RegisterWarning ( 00064 const ProvokedWarning &warning) 00065 { 00066 wxASSERT (warnings.end () == warnings.find (&warning)); 00067 warnings.insert (std::make_pair (&warning, false)); 00068 } 00069 00070 00071 void ProvokedWarningRegistry::UnregisterWarning ( 00072 const ProvokedWarning &warning) 00073 { 00074 wxASSERT (warnings.end () != warnings.find (&warning)); 00075 warnings.erase (&warning); 00076 } 00077 00078 00079 bool ProvokedWarningRegistry::IsRegisteredAndInTime ( 00080 const ProvokedWarning& warning) const 00081 { 00082 ProvokedWarningMap::const_iterator it; 00083 it = warnings.find (&warning); 00084 00085 if (it == warnings.end ()) { 00086 00087 return false; 00088 00089 } else { 00090 00091 const ProvokedWarning* newwarning = (*it).first; 00092 wxDateTime now = wxDateTime::Now(); 00093 if (now.IsLaterThan (newwarning->GetTimeout ())) { 00094 00095 return false; 00096 00097 } else { 00098 00099 return true; 00100 } 00101 } 00102 } 00103 00104 00105 bool ProvokedWarningRegistry::WasDetected ( 00106 const ProvokedWarning &warning) const 00107 { 00108 ProvokedWarningMap::const_iterator it; 00109 it = warnings.find (&warning); 00110 00111 if (it == warnings.end ()) { 00112 00113 return false; 00114 00115 } else { 00116 00117 return ((*it).second); 00118 } 00119 } 00120 00121 00122 void ProvokedWarningRegistry::SetWarningAsDetected ( 00123 const ProvokedWarning &warning) 00124 { 00125 wxASSERT (warnings.end () != warnings.find (&warning)); 00126 ProvokedWarningMap::iterator it; 00127 it = warnings.find (&warning); 00128 (*it).second = true; 00129 } 00130 00131 00132 const ProvokedWarning * 00133 ProvokedWarningRegistry::FindRegisteredWarning (const wxString &caption, 00134 const wxString &message) 00135 const 00136 { 00137 for (ProvokedWarningMap::const_iterator it = warnings.begin (); 00138 it != warnings.end(); it++) { 00139 00140 const ProvokedWarning *warning = it->first; 00141 if (warning->GetCaption () == caption && 00142 (message.empty() || warning->GetMessage() == message)) 00143 return it->first; 00144 } 00145 return NULL; 00146 } 00147 00148