Skip to content
Snippets Groups Projects
Commit ae1cca7e authored by Cédric Traizet's avatar Cédric Traizet
Browse files

STYLE: run clang-format on the python logger classes

parent a87ee3ff
Branches
Tags
No related merge requests found
...@@ -47,8 +47,7 @@ Logger * Logger::CreateInstance() ...@@ -47,8 +47,7 @@ Logger * Logger::CreateInstance()
Logger * logger = new Logger; Logger * logger = new Logger;
// By default redirect logs to std::cout // By default redirect logs to std::cout
itk::StdStreamLogOutput::Pointer defaultOutput = itk::StdStreamLogOutput::Pointer defaultOutput = itk::StdStreamLogOutput::New();
itk::StdStreamLogOutput::New();
defaultOutput->SetStream(std::cout); defaultOutput->SetStream(std::cout);
logger->AddLogOutput(defaultOutput); logger->AddLogOutput(defaultOutput);
......
...@@ -43,12 +43,12 @@ typedef otb::Wrapper::ComplexInputImageParameter ComplexInputImageParame ...@@ -43,12 +43,12 @@ typedef otb::Wrapper::ComplexInputImageParameter ComplexInputImageParame
typedef otb::Wrapper::ImageBaseType ImageBaseType; typedef otb::Wrapper::ImageBaseType ImageBaseType;
typedef otb::Logger Logger; typedef otb::Logger Logger;
typedef otb::Logger::Pointer Logger_Pointer; typedef otb::Logger::Pointer Logger_Pointer;
typedef otb::LogOutputCallback LogOutputCallback; typedef otb::LogOutputCallback LogOutputCallback;
typedef otb::PythonLogOutput PythonLogOutput; typedef otb::PythonLogOutput PythonLogOutput;
typedef otb::PythonLogOutput::Pointer PythonLogOutput_Pointer; typedef otb::PythonLogOutput::Pointer PythonLogOutput_Pointer;
typedef otb::ProgressReporterManager ProgressReporterManager; typedef otb::ProgressReporterManager ProgressReporterManager;
typedef otb::ProgressReporterManager::Pointer ProgressReporterManager_Pointer; typedef otb::ProgressReporterManager::Pointer ProgressReporterManager_Pointer;
#endif #endif
...@@ -24,104 +24,78 @@ ...@@ -24,104 +24,78 @@
namespace otb namespace otb
{ {
CallbackProgressReporter CallbackProgressReporter::CallbackProgressReporter()
::CallbackProgressReporter()
{ {
} }
CallbackProgressReporter CallbackProgressReporter::CallbackProgressReporter(itk::ProcessObject* process, const char* comment)
::CallbackProgressReporter(itk::ProcessObject* process, : FilterWatcherBase(process, comment), m_StarsCount(50), m_CurrentNbStars(-1)
const char *comment)
: FilterWatcherBase(process, comment),
m_StarsCount(50),
m_CurrentNbStars(-1)
{ {
} }
CallbackProgressReporter CallbackProgressReporter::CallbackProgressReporter(itk::ProcessObject* process, const std::string& comment)
::CallbackProgressReporter(itk::ProcessObject* process, : FilterWatcherBase(process, comment.c_str()), m_StarsCount(50), m_CurrentNbStars(-1)
const std::string& comment)
: FilterWatcherBase(process, comment.c_str()),
m_StarsCount(50),
m_CurrentNbStars(-1)
{ {
} }
void void CallbackProgressReporter::ShowProgress()
CallbackProgressReporter
::ShowProgress()
{ {
if (m_Process) if (m_Process)
{ {
int progressPercent = static_cast<int>(m_Process->GetProgress() * 100); int progressPercent = static_cast<int>(m_Process->GetProgress() * 100);
int nbStars = static_cast<int>(m_Process->GetProgress() * m_StarsCount); int nbStars = static_cast<int>(m_Process->GetProgress() * m_StarsCount);
int nbBlanks = m_StarsCount - nbStars; int nbBlanks = m_StarsCount - nbStars;
if (nbBlanks < 0) if (nbBlanks < 0)
{ {
nbBlanks = 0; nbBlanks = 0;
} }
if (nbStars > m_StarsCount) if (nbStars > m_StarsCount)
{ {
nbStars = m_StarsCount; nbStars = m_StarsCount;
} }
if (progressPercent > 100) if (progressPercent > 100)
{ {
progressPercent = 100; progressPercent = 100;
} }
if (nbStars > m_CurrentNbStars) if (nbStars > m_CurrentNbStars)
{ {
std::string stars(nbStars, '*'); std::string stars(nbStars, '*');
std::string blanks(nbBlanks, ' '); std::string blanks(nbBlanks, ' ');
if (m_Callback->Isatty()) if (m_Callback->Isatty())
{ {
m_Callback->Call("\r" m_Callback->Call("\r" + m_Comment + ": " + std::to_string(progressPercent) + "% [" + stars + blanks + "]");
+m_Comment
+": "
+std::to_string(progressPercent)
+"% ["
+stars
+blanks
+"]");
m_Callback->Flush(); m_Callback->Flush();
} }
else else
{ {
m_Buffer= "\r"+m_Comment+": "+std::to_string(progressPercent) m_Buffer = "\r" + m_Comment + ": " + std::to_string(progressPercent) + "% [" + stars + blanks + "]";
+"% ["+stars+blanks+"]";
}
} }
}
m_CurrentNbStars = nbStars; m_CurrentNbStars = nbStars;
} }
} }
void void CallbackProgressReporter::StartFilter()
CallbackProgressReporter
::StartFilter()
{ {
m_Stopwatch.Start(); m_Stopwatch.Start();
} }
void void CallbackProgressReporter::EndFilter()
CallbackProgressReporter
::EndFilter()
{ {
m_Stopwatch.Stop(); m_Stopwatch.Stop();
if (m_Process && !(m_Callback->Isatty())) if (m_Process && !(m_Callback->Isatty()))
{ {
m_Callback->Call(m_Buffer); m_Callback->Call(m_Buffer);
m_Buffer = std::string(""); m_Buffer = std::string("");
} }
m_Callback->Call(" (" m_Callback->Call(" (" + m_Stopwatch.GetElapsedHumanReadableTime() + ")\n");
+m_Stopwatch.GetElapsedHumanReadableTime()
+")\n");
} }
} }
...@@ -34,17 +34,15 @@ namespace otb ...@@ -34,17 +34,15 @@ namespace otb
* the LogOutputCallback. The LogOutputCallback is also used to determine * the LogOutputCallback. The LogOutputCallback is also used to determine
* if the output is interactive. * if the output is interactive.
*/ */
class CallbackProgressReporter : public FilterWatcherBase class CallbackProgressReporter : public FilterWatcherBase
{ {
public: public:
/** Constructor. Takes a ProcessObject to monitor and an optional /** Constructor. Takes a ProcessObject to monitor and an optional
* comment string that is prepended to each event message. */ * comment string that is prepended to each event message. */
CallbackProgressReporter(itk::ProcessObject* process, CallbackProgressReporter(itk::ProcessObject* process, const char* comment = "");
const char *comment = "");
CallbackProgressReporter(itk::ProcessObject* process, CallbackProgressReporter(itk::ProcessObject* process, const std::string& comment = "");
const std::string& comment = "");
/** Default constructor */ /** Default constructor */
CallbackProgressReporter(); CallbackProgressReporter();
...@@ -53,13 +51,13 @@ public: ...@@ -53,13 +51,13 @@ public:
virtual ~CallbackProgressReporter() = default; virtual ~CallbackProgressReporter() = default;
typedef LogOutputCallback CallbackType; typedef LogOutputCallback CallbackType;
/** Set the callback method */ /** Set the callback method */
void SetCallback(CallbackType * callback) void SetCallback(CallbackType* callback)
{ {
m_Callback = callback; m_Callback = callback;
} }
protected: protected:
/** Callback method to show the ProgressEvent */ /** Callback method to show the ProgressEvent */
virtual void ShowProgress() override; virtual void ShowProgress() override;
...@@ -71,19 +69,18 @@ protected: ...@@ -71,19 +69,18 @@ protected:
virtual void EndFilter() override; virtual void EndFilter() override;
private: private:
/** Total number of stars in the progress bar */ /** Total number of stars in the progress bar */
int m_StarsCount; int m_StarsCount;
/** Current number of stars in the progress bar */ /** Current number of stars in the progress bar */
int m_CurrentNbStars; int m_CurrentNbStars;
/** The Callback used for printing */ /** The Callback used for printing */
CallbackType * m_Callback; CallbackType* m_Callback;
/** buffer used when sys.stdout.isatty() == false */ /** buffer used when sys.stdout.isatty() == false */
std::string m_Buffer; std::string m_Buffer;
}; };
} }
#endif //otbCallbackProgressReporter_h #endif // otbCallbackProgressReporter_h
...@@ -33,27 +33,29 @@ namespace otb ...@@ -33,27 +33,29 @@ namespace otb
* class PythonLogOutputCallback, that uses Swig directors to override these * class PythonLogOutputCallback, that uses Swig directors to override these
* methods. * methods.
*/ */
class LogOutputCallback class LogOutputCallback
{ {
public: public:
/** Constructor */ /** Constructor */
LogOutputCallback() = default; LogOutputCallback() = default;
/** Destructor */ /** Destructor */
virtual ~LogOutputCallback() = default; virtual ~LogOutputCallback() = default;
/** Write a string to a buffer */ /** Write a string to a buffer */
virtual void Call(std::string const &) {}; virtual void Call(std::string const&){};
/** Flush the buffer */ /** Flush the buffer */
virtual void Flush() {}; virtual void Flush(){};
/** Determine if the bufer is interactive */ /** Determine if the bufer is interactive */
virtual bool Isatty() {return false;}; virtual bool Isatty()
{
return false;
};
}; };
} // namespace otb } // namespace otb
#endif // otbPythonLogOutputCallback_h #endif // otbPythonLogOutputCallback_h
...@@ -23,27 +23,23 @@ ...@@ -23,27 +23,23 @@
namespace otb namespace otb
{ {
ProgressReporterManager ProgressReporterManager::ProgressReporterManager()
::ProgressReporterManager()
{ {
// Add the callback to be added when a AddProcessToWatch event is invoked // Add the callback to be added when a AddProcessToWatch event is invoked
m_AddProcessCommand = AddProcessCommandType::New(); m_AddProcessCommand = AddProcessCommandType::New();
m_AddProcessCommand->SetCallbackFunction(this, &ProgressReporterManager::LinkWatchers); m_AddProcessCommand->SetCallbackFunction(this, &ProgressReporterManager::LinkWatchers);
} }
void ProgressReporterManager::LinkWatchers(itk::Object * itkNotUsed(caller), const itk::EventObject & event) void ProgressReporterManager::LinkWatchers(itk::Object* itkNotUsed(caller), const itk::EventObject& event)
{ {
if (typeid(otb::Wrapper::AddProcessToWatchEvent) == typeid( event )) if (typeid(otb::Wrapper::AddProcessToWatchEvent) == typeid(event))
{ {
const Wrapper::AddProcessToWatchEvent* eventToWatch = dynamic_cast<const Wrapper::AddProcessToWatchEvent*> (&event); const Wrapper::AddProcessToWatchEvent* eventToWatch = dynamic_cast<const Wrapper::AddProcessToWatchEvent*>(&event);
CallbackProgressReporter * watch = new CallbackProgressReporter(eventToWatch->GetProcess(), CallbackProgressReporter* watch = new CallbackProgressReporter(eventToWatch->GetProcess(), eventToWatch->GetProcessDescription());
eventToWatch->GetProcessDescription());
watch->SetCallback(m_Callback); watch->SetCallback(m_Callback);
m_WatcherList.push_back(watch); m_WatcherList.push_back(watch);
} }
} }
} }
...@@ -41,37 +41,36 @@ class ProgressReporterManager : public itk::Object ...@@ -41,37 +41,36 @@ class ProgressReporterManager : public itk::Object
{ {
public: public:
/** Standard class typedefs. */ /** Standard class typedefs. */
typedef ProgressReporterManager Self; typedef ProgressReporterManager Self;
typedef itk::Object Superclass; typedef itk::Object Superclass;
typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer; typedef itk::SmartPointer<const Self> ConstPointer;
itkTypeMacro(ProgressReporterManager, itk::Object); itkTypeMacro(ProgressReporterManager, itk::Object);
itkNewMacro(ProgressReporterManager); itkNewMacro(ProgressReporterManager);
typedef LogOutputCallback CallbackType; typedef LogOutputCallback CallbackType;
/** Command Member */ /** Command Member */
typedef itk::MemberCommand< Self > AddProcessCommandType; typedef itk::MemberCommand<Self> AddProcessCommandType;
/** Filter watcher list type */ /** Filter watcher list type */
typedef std::vector<CallbackProgressReporter *> WatcherListType; typedef std::vector<CallbackProgressReporter*> WatcherListType;
/** Set the logger callback function */ /** Set the logger callback function */
void SetLogOutputCallback(CallbackType * callback) void SetLogOutputCallback(CallbackType* callback)
{ {
m_Callback = callback; m_Callback = callback;
this->Modified(); this->Modified();
} }
/** Getter to AddProcessCommand */ /** Getter to AddProcessCommand */
AddProcessCommandType* GetAddProcessCommand() AddProcessCommandType* GetAddProcessCommand()
{ {
return m_AddProcessCommand.GetPointer(); return m_AddProcessCommand.GetPointer();
} }
protected:
protected:
/** Default constructor */ /** Default constructor */
ProgressReporterManager(); ProgressReporterManager();
...@@ -79,19 +78,18 @@ protected: ...@@ -79,19 +78,18 @@ protected:
virtual ~ProgressReporterManager() = default; virtual ~ProgressReporterManager() = default;
/** Load the watchers for internal progress and writing progress report. */ /** Load the watchers for internal progress and writing progress report. */
void LinkWatchers(itk::Object * caller, const itk::EventObject & event); void LinkWatchers(itk::Object* caller, const itk::EventObject& event);
private: private:
/** The LogOutputCallback used for printing */ /** The LogOutputCallback used for printing */
CallbackType * m_Callback; CallbackType* m_Callback;
/** Command associated to the LinkWatchers command */ /** Command associated to the LinkWatchers command */
AddProcessCommandType::Pointer m_AddProcessCommand; AddProcessCommandType::Pointer m_AddProcessCommand;
/** container storing all the watchers (CallbackProgressReporter) */ /** container storing all the watchers (CallbackProgressReporter) */
WatcherListType m_WatcherList; WatcherListType m_WatcherList;
}; };
} }
#endif //otbProgressReporterManager_h #endif // otbProgressReporterManager_h
...@@ -32,17 +32,17 @@ void PythonLogOutput::Write(double timestamp) ...@@ -32,17 +32,17 @@ void PythonLogOutput::Write(double timestamp)
m_Callback->Call(std::to_string(timestamp)); m_Callback->Call(std::to_string(timestamp));
} }
void PythonLogOutput::Write(std::string const & content) void PythonLogOutput::Write(std::string const& content)
{ {
m_Callback->Call(content); m_Callback->Call(content);
} }
void PythonLogOutput::Write(std::string const & content, double timestamp) void PythonLogOutput::Write(std::string const& content, double timestamp)
{ {
m_Callback->Call(std::to_string(timestamp) + " : " + content); m_Callback->Call(std::to_string(timestamp) + " : " + content);
} }
void PythonLogOutput::PrintSelf(std::ostream & os, itk::Indent indent) const void PythonLogOutput::PrintSelf(std::ostream& os, itk::Indent indent) const
{ {
Superclass::PrintSelf(os, indent); Superclass::PrintSelf(os, indent);
} }
......
...@@ -35,10 +35,10 @@ namespace otb ...@@ -35,10 +35,10 @@ namespace otb
class PythonLogOutput : public itk::LogOutput class PythonLogOutput : public itk::LogOutput
{ {
public: public:
typedef PythonLogOutput Self; typedef PythonLogOutput Self;
typedef itk::LogOutput Superclass; typedef itk::LogOutput Superclass;
typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer< const Self > ConstPointer; typedef itk::SmartPointer<const Self> ConstPointer;
typedef LogOutputCallback CallbackType; typedef LogOutputCallback CallbackType;
itkTypeMacro(PythonLogOutput, itk::LogOutput); itkTypeMacro(PythonLogOutput, itk::LogOutput);
...@@ -46,12 +46,12 @@ public: ...@@ -46,12 +46,12 @@ public:
itkNewMacro(PythonLogOutput); itkNewMacro(PythonLogOutput);
/** Set the callback method */ /** Set the callback method */
void SetCallback(CallbackType * callback) void SetCallback(CallbackType* callback)
{ {
m_Callback = callback; m_Callback = callback;
this->Modified(); this->Modified();
} }
/** flush a buffer */ /** flush a buffer */
virtual void Flush() override; virtual void Flush() override;
...@@ -59,10 +59,10 @@ public: ...@@ -59,10 +59,10 @@ public:
virtual void Write(double timestamp) override; virtual void Write(double timestamp) override;
/** Write to a buffer */ /** Write to a buffer */
virtual void Write(std::string const & content) override; virtual void Write(std::string const& content) override;
/** Write to a buffer */ /** Write to a buffer */
virtual void Write(std::string const & content, double timestamp) override; virtual void Write(std::string const& content, double timestamp) override;
protected: protected:
/** Constructor */ /** Constructor */
...@@ -71,10 +71,10 @@ protected: ...@@ -71,10 +71,10 @@ protected:
/** Destructor */ /** Destructor */
virtual ~PythonLogOutput() override = default; virtual ~PythonLogOutput() override = default;
virtual void PrintSelf(std::ostream & os, itk::Indent indent) const override; virtual void PrintSelf(std::ostream& os, itk::Indent indent) const override;
private: private:
CallbackType * m_Callback; CallbackType* m_Callback;
}; };
} // namespace otb } // namespace otb
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment