JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwScopedConnection Class Reference

A RAII-style scoped database connection. More...

#include <QwDatabase.h>

+ Collaboration diagram for QwScopedConnection:

Public Member Functions

 QwScopedConnection (QwDatabase *db)
 
 ~QwScopedConnection ()
 
 QwScopedConnection (const QwScopedConnection &)=delete
 
QwScopedConnectionoperator= (const QwScopedConnection &)=delete
 
 QwScopedConnection (QwScopedConnection &&other) noexcept
 
QwScopedConnectionoperator= (QwScopedConnection &&other) noexcept
 
QwDatabaseoperator-> ()
 
const QwDatabaseoperator-> () const
 
QwDatabaseoperator* ()
 
const QwDatabaseoperator* () const
 
bool IsConnected () const
 

Private Attributes

QwDatabasefDatabase
 
bool fConnected
 

Detailed Description

A RAII-style scoped database connection.

This class provides automatic connection management using RAII principles. The connection is established when the object is created and automatically disconnected when the object goes out of scope.

Definition at line 83 of file QwDatabase.h.

Constructor & Destructor Documentation

◆ QwScopedConnection() [1/3]

QwScopedConnection::QwScopedConnection ( QwDatabase * db)
explicit

Definition at line 28 of file QwDatabase.cc.

29 : fDatabase(db), fConnected(false) {
30 if (fDatabase) {
31 fConnected = fDatabase->Connect();
32 if (!fConnected) {
33 QwError << "QwScopedConnection: Failed to establish database connection" << QwLog::endl;
34 }
35 }
36}
#define QwError
Predefined log drain for errors.
Definition QwLog.h:39
QwDatabase * fDatabase
Definition QwDatabase.h:85
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297

References QwLog::endl(), fConnected, fDatabase, and QwError.

Referenced by operator=(), operator=(), QwScopedConnection(), and QwScopedConnection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ~QwScopedConnection()

QwScopedConnection::~QwScopedConnection ( )

Definition at line 38 of file QwDatabase.cc.

38 {
39 if (fDatabase && fConnected) {
40 fDatabase->Disconnect();
41 fConnected = false;
42 }
43}

References fConnected, and fDatabase.

◆ QwScopedConnection() [2/3]

QwScopedConnection::QwScopedConnection ( const QwScopedConnection & )
delete

References QwScopedConnection().

+ Here is the call graph for this function:

◆ QwScopedConnection() [3/3]

QwScopedConnection::QwScopedConnection ( QwScopedConnection && other)
noexcept

Definition at line 45 of file QwDatabase.cc.

46 : fDatabase(other.fDatabase), fConnected(other.fConnected) {
47 other.fDatabase = nullptr;
48 other.fConnected = false;
49}

References fConnected, fDatabase, and QwScopedConnection().

+ Here is the call graph for this function:

Member Function Documentation

◆ IsConnected()

bool QwScopedConnection::IsConnected ( ) const

Definition at line 69 of file QwDatabase.cc.

69 {
70 return fConnected && fDatabase && fDatabase->Connected();
71}

References fConnected, and fDatabase.

◆ operator*() [1/2]

QwDatabase & QwScopedConnection::operator* ( )
inline

Definition at line 103 of file QwDatabase.h.

103{ return *fDatabase; }

References fDatabase.

◆ operator*() [2/2]

const QwDatabase & QwScopedConnection::operator* ( ) const
inline

Definition at line 104 of file QwDatabase.h.

104{ return *fDatabase; }

References fDatabase.

◆ operator->() [1/2]

QwDatabase * QwScopedConnection::operator-> ( )
inline

Definition at line 101 of file QwDatabase.h.

101{ return fDatabase; }

References fDatabase.

◆ operator->() [2/2]

const QwDatabase * QwScopedConnection::operator-> ( ) const
inline

Definition at line 102 of file QwDatabase.h.

102{ return fDatabase; }

References fDatabase.

◆ operator=() [1/2]

QwScopedConnection & QwScopedConnection::operator= ( const QwScopedConnection & )
delete

References QwScopedConnection().

+ Here is the call graph for this function:

◆ operator=() [2/2]

QwScopedConnection & QwScopedConnection::operator= ( QwScopedConnection && other)
noexcept

Definition at line 51 of file QwDatabase.cc.

51 {
52 if (this != &other) {
53 // Clean up current connection
54 if (fDatabase && fConnected) {
55 fDatabase->Disconnect();
56 }
57
58 // Move from other
59 fDatabase = other.fDatabase;
60 fConnected = other.fConnected;
61
62 // Clear other
63 other.fDatabase = nullptr;
64 other.fConnected = false;
65 }
66 return *this;
67}

References fConnected, fDatabase, and QwScopedConnection().

+ Here is the call graph for this function:

Field Documentation

◆ fConnected

bool QwScopedConnection::fConnected
private

◆ fDatabase

QwDatabase* QwScopedConnection::fDatabase
private

The documentation for this class was generated from the following files: