Add "warn_deprecated" function

This function can be used for issuing runtime deprecation warnings
This commit is contained in:
Ray Speth 2013-05-31 15:56:06 +00:00
parent f90d136232
commit c1cfdffccc
4 changed files with 29 additions and 0 deletions

View file

@ -177,6 +177,9 @@ void writelogendl();
//! @copydoc Application::Messages::logerror
void error(const std::string& msg);
//! @copydoc Application::warn_deprecated
void warn_deprecated(const std::string& method, const std::string& extra="");
//! @copydoc Application::Messages::setLogger
void setLogger(Logger* logwriter);

View file

@ -366,6 +366,17 @@ void Application::ApplicationDestroy()
}
}
void Application::warn_deprecated(const std::string& method,
const std::string& extra)
{
if (warnings.count(method)) {
return;
}
warnings.insert(method);
writelog("WARNING: '" + method + "' is deprecated. " + extra);
writelogendl();
}
void Application::thread_complete()
{
#if defined(THREAD_SAFE_CANTERA)

View file

@ -6,6 +6,7 @@
#include "cantera/base/logger.h"
#include <map>
#include <set>
#include <memory>
#include <string>
#include <vector>
@ -435,6 +436,12 @@ public:
pMessenger->logerror(msg);
}
//! Print a warning indicating that *method* is deprecated. Additional
//! information (removal version, alternatives) can be specified in
//! *extra*. Deprecation warnings are printed once per method per
//! invocation of the application.
void warn_deprecated(const std::string& method, const std::string& extra="");
//! @copydoc Messages::setLogger
void setLogger(Logger* logwriter) {
pMessenger->setLogger(logwriter);
@ -535,6 +542,9 @@ protected:
std::string tmp_dir;
//! Current vector of xml file trees that have been previously parsed
std::map<std::string, XML_Node*> xmlfiles;
//! Vector of deprecation warnings that have been emitted (to suppress duplicates)
std::set<std::string> warnings;
//! Current pointer to the logwriter
//Logger* logwriter;
#ifdef WITH_HTML_LOGS

View file

@ -72,6 +72,11 @@ void error(const std::string& msg)
app()->logerror(msg);
}
void warn_deprecated(const std::string& method, const std::string& extra)
{
app()->warn_deprecated(method, extra);
}
// **************** HTML Logging ****************
#ifdef WITH_HTML_LOGS