Возвращение экземпляров синглтонов по ссылке
This commit is contained in:
parent
7ec97f8f19
commit
e160b83c45
@ -19,18 +19,18 @@ int main( int argc, char** argv )
|
|||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
QCoreApplication::setApplicationName( QStringLiteral( CMLIB_PROJECT_NAME ) );
|
QCoreApplication::setApplicationName( QStringLiteral( CMLIB_PROJECT_NAME ) );
|
||||||
MF::PathsMT* pathsMT = MF::PathsMT::instance();
|
MF::PathsMT& pathsMT = MF::PathsMT::instance();
|
||||||
MF::Paths* paths = MF::Paths::instance();
|
MF::Paths& paths = MF::Paths::instance();
|
||||||
|
|
||||||
pathsMT->init( QStringLiteral( CMLIB_PROJECT_NAME ), QStringLiteral( "conf" ) );
|
pathsMT.init( QStringLiteral( CMLIB_PROJECT_NAME ), QStringLiteral( "conf" ) );
|
||||||
pathsMT->findConfigFile( QStringLiteral( "test" ) );
|
pathsMT.findConfigFile( QStringLiteral( "test" ) );
|
||||||
qDebug() << pathsMT->systemLogDirectory();
|
qDebug() << pathsMT.systemLogDirectory();
|
||||||
qDebug() << pathsMT->systemConfigDirectory();
|
qDebug() << pathsMT.systemConfigDirectory();
|
||||||
|
|
||||||
paths->init( QStringLiteral( CMLIB_PROJECT_NAME ), QStringLiteral( "conf" ) );
|
paths.init( QStringLiteral( CMLIB_PROJECT_NAME ), QStringLiteral( "conf" ) );
|
||||||
paths->findConfigFile( QStringLiteral( "test" ) );
|
paths.findConfigFile( QStringLiteral( "test" ) );
|
||||||
qDebug() << paths->systemConstDataDirectory();
|
qDebug() << paths.systemConstDataDirectory();
|
||||||
qDebug() << paths->configFileName();
|
qDebug() << paths.configFileName();
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
@ -85,10 +85,10 @@ public:
|
|||||||
* @brief getInstance
|
* @brief getInstance
|
||||||
* @return Уникальный экземпляр класса Paths
|
* @return Уникальный экземпляр класса Paths
|
||||||
*/
|
*/
|
||||||
static Paths* instance()
|
static Paths& instance()
|
||||||
{
|
{
|
||||||
static Paths p;
|
static Paths p;
|
||||||
return( &p );
|
return( p );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ namespace filesystem {
|
|||||||
|
|
||||||
PathsMT::PathsMT() = default;
|
PathsMT::PathsMT() = default;
|
||||||
|
|
||||||
PathsMT* PathsMT::instance()
|
PathsMT& PathsMT::instance()
|
||||||
{
|
{
|
||||||
volatile PathsMT* localInstance = mInstance.load( std::memory_order_acquire );
|
volatile PathsMT* localInstance = mInstance.load( std::memory_order_acquire );
|
||||||
if ( localInstance == nullptr )
|
if ( localInstance == nullptr )
|
||||||
@ -26,7 +26,7 @@ PathsMT* PathsMT::instance()
|
|||||||
mInstance.store( const_cast< PathsMT* >( localInstance ), std::memory_order_release ); // NOLINT
|
mInstance.store( const_cast< PathsMT* >( localInstance ), std::memory_order_release ); // NOLINT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return( const_cast< PathsMT* >( localInstance ) ); // NOLINT
|
return( const_cast< PathsMT& >( *localInstance ) ); // NOLINT
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace filesystem
|
} // namespace filesystem
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
* @brief getInstance
|
* @brief getInstance
|
||||||
* @return Уникальный экземпляр класса PathsMT
|
* @return Уникальный экземпляр класса PathsMT
|
||||||
*/
|
*/
|
||||||
static PathsMT* instance();
|
static PathsMT& instance();
|
||||||
}; // class PathsMT
|
}; // class PathsMT
|
||||||
|
|
||||||
} // namespace filesystem
|
} // namespace filesystem
|
||||||
|
Loading…
x
Reference in New Issue
Block a user