KDbMessageGuard

Search for usage in LXR

#include <KDbMessageHandler.h>

Public Member Functions

 KDbMessageGuard (const KDbResult &result, KDbMessageHandler *handler)
 
 KDbMessageGuard (KDbResultable *resultable)
 

Protected Attributes

Private *const d
 

Detailed Description

A guard class for transmitting messages based on KDbResult.

It's intended use is for top-level public methods in applications that have to display messages. Create it's instance on stack; at the end of the block, on KDbMessageGuard's destruction result will be checked. If it's not empty, error is passed to the associated message handler. The example below emits error message if result is not empty before .

class MyClass : ... public KDbResultable {
[..]
MyClass(KDbMessageHandler *handler) {
setMessageHandler(handler); // need ...
}
bool connectToProject() {
KDbMessageGuard mg(this); // MyClass is KDbResultable so this easy notation is possible
if (... something failed ...) {
m_result = KDbResult(tr("Operation failed."));
return false; // ~KDbMessageGuard called here, m_result is passed to messageHandler()
}
// ...
return true; // ~KDbMessageGuard called here is a no-op because there's no error in m_result
}
};
A guard class for transmitting messages based on KDbResult.
Interface for classes providing a result.
void setMessageHandler(KDbMessageHandler *handler)
Sets message handler to handler.

There are two equivalent variants of usage:

Definition at line 65 of file KDbMessageHandler.h.

Constructor & Destructor Documentation

◆ KDbMessageGuard() [1/2]

KDbMessageGuard::KDbMessageGuard ( KDbResultable * resultable)
explicit

Builds a guard in the current code block using resultable Infromation from resultable will be used in ~KDbMessageGuard() to pass message to the resultable->messageHandler() handler if the handler is present and resultable->result().isError() == true.

Note
resultable is required

Definition at line 35 of file KDbMessageHandler.cpp.

◆ KDbMessageGuard() [2/2]

KDbMessageGuard::KDbMessageGuard ( const KDbResult & result,
KDbMessageHandler * handler )

Builds a guard in the current code block using a reference to result and handler These will be used in ~KDbMessageGuard() is result.isError() == true.

Note
handler is required

Definition at line 43 of file KDbMessageHandler.cpp.

◆ ~KDbMessageGuard()

KDbMessageGuard::~KDbMessageGuard ( )

Definition at line 51 of file KDbMessageHandler.cpp.

Member Data Documentation

◆ d

Private* const KDbMessageGuard::d
protected

Definition at line 85 of file KDbMessageHandler.h.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 1 2024 18:50:28 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.