Skip to content

Commit

Permalink
Base: replace calls of printf() with Console().DeveloperWarning()
Browse files Browse the repository at this point in the history
and remove the assert(0) statement as this is an indication of a problem in the code but not serious enough to crash the application
  • Loading branch information
wwmayer committed Oct 5, 2023
1 parent 579d427 commit 95f1e3c
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/Base/Observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ class Observer
* @param rcReason
* \todo undocumented parameter 2
*/
virtual void OnChange(Subject<_MessageType>& rCaller,_MessageType rcReason)=0;
virtual void OnChange(Subject<_MessageType>& rCaller, _MessageType rcReason) = 0;

/**
* This method need to be reimplemented from the concrete Observer
* and get called by the observed class
* @param rCaller a reference to the calling object
*/
virtual void OnDestroy(Subject<_MessageType> & rCaller) {
virtual void OnDestroy(Subject<_MessageType>& rCaller) {
(void)rCaller;
}

Expand All @@ -85,7 +85,9 @@ class Observer
* and returns the name of the observer. Needed to use the Get
* Method of the Subject.
*/
virtual const char *Name(){return nullptr;}
virtual const char *Name() {
return nullptr;
}
};

/** Subject class
Expand Down Expand Up @@ -118,8 +120,8 @@ class Subject
{
if (_ObserverSet.size() > 0)
{
printf("Not detached all observers yet\n");
assert(0);
Base::Console().DeveloperWarning(std::string("~Subject()"),
"Not detached all observers yet\n");
}
}

Expand All @@ -133,10 +135,12 @@ class Subject
{
#ifdef FC_DEBUG
size_t count = _ObserverSet.size();
//printf("Attach observer %p\n", ToObserv);
_ObserverSet.insert(ToObserv);
if ( _ObserverSet.size() == count )
printf("Observer %p already attached\n", static_cast<void*>(ToObserv));
if ( _ObserverSet.size() == count ) {
Base::Console().DeveloperWarning(std::string("Subject::Attach"),
"Observer %p already attached\n",
static_cast<void*>(ToObserv));
}
#else
_ObserverSet.insert(ToObserv);
#endif
Expand All @@ -152,10 +156,12 @@ class Subject
{
#ifdef FC_DEBUG
size_t count = _ObserverSet.size();
//printf("Detach observer %p\n", ToObserv);
_ObserverSet.erase(ToObserv);
if ( _ObserverSet.size() == count )
printf("Observer %p already detached\n", static_cast<void*>(ToObserv));
if (_ObserverSet.size() == count) {
Base::Console().DeveloperWarning(std::string("Subject::Detach"),
"Observer %p already detached\n",
static_cast<void*>(ToObserv));
}
#else
_ObserverSet.erase(ToObserv);
#endif
Expand Down

0 comments on commit 95f1e3c

Please sign in to comment.