move ConsoleWriterFactory implementation in util.cpp
This commit is contained in:
parent
feaea570f2
commit
3348056253
3 changed files with 42 additions and 42 deletions
37
src/main.cpp
37
src/main.cpp
|
@ -31,45 +31,16 @@
|
|||
#include "serverdlg.h"
|
||||
#include "settings.h"
|
||||
#include "testbench.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
|
||||
/******************************************************************************\
|
||||
* Console logging *
|
||||
\******************************************************************************/
|
||||
// Try for a portable console --------------------------------------------------
|
||||
|
||||
QTextStream* ConsoleWriterFactory::get()
|
||||
{
|
||||
if ( ptsConsole == nullptr )
|
||||
{
|
||||
#if _WIN32
|
||||
if ( !AttachConsole ( ATTACH_PARENT_PROCESS ) )
|
||||
{
|
||||
// Not run from console, dump logging to nowhere
|
||||
static QString conout;
|
||||
ptsConsole = new QTextStream ( &conout );
|
||||
}
|
||||
else
|
||||
{
|
||||
freopen ( "CONOUT$", "w", stdout );
|
||||
ptsConsole = new QTextStream ( stdout );
|
||||
}
|
||||
#else
|
||||
ptsConsole = new QTextStream ( stdout );
|
||||
#endif
|
||||
}
|
||||
return ptsConsole;
|
||||
}
|
||||
|
||||
// Implementation **************************************************************
|
||||
|
||||
int main ( int argc, char** argv )
|
||||
{
|
||||
QTextStream& tsConsole = *((new ConsoleWriterFactory())->get());
|
||||
|
||||
QString strArgument;
|
||||
double rDbleArgument;
|
||||
QTextStream& tsConsole = *( ( new ConsoleWriterFactory() )->get() );
|
||||
QString strArgument;
|
||||
double rDbleArgument;
|
||||
|
||||
// initialize all flags and string which might be changed by command line
|
||||
// arguments
|
||||
|
|
25
src/util.cpp
25
src/util.cpp
|
@ -1209,6 +1209,31 @@ QString CCountyFlagIcons::GetResourceReference ( const QLocale::Country eCountry
|
|||
}
|
||||
|
||||
|
||||
// Console writer factory ------------------------------------------------------
|
||||
QTextStream* ConsoleWriterFactory::get()
|
||||
{
|
||||
if ( ptsConsole == nullptr )
|
||||
{
|
||||
#if _WIN32
|
||||
if ( !AttachConsole ( ATTACH_PARENT_PROCESS ) )
|
||||
{
|
||||
// Not run from console, dump logging to nowhere
|
||||
static QString conout;
|
||||
ptsConsole = new QTextStream ( &conout );
|
||||
}
|
||||
else
|
||||
{
|
||||
freopen ( "CONOUT$", "w", stdout );
|
||||
ptsConsole = new QTextStream ( stdout );
|
||||
}
|
||||
#else
|
||||
ptsConsole = new QTextStream ( stdout );
|
||||
#endif
|
||||
}
|
||||
return ptsConsole;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************\
|
||||
* Global Functions Implementation *
|
||||
\******************************************************************************/
|
||||
|
|
22
src/util.h
22
src/util.h
|
@ -482,6 +482,19 @@ public slots:
|
|||
};
|
||||
|
||||
|
||||
// Console writer factory ------------------------------------------------------
|
||||
// this class was written by pljones
|
||||
class ConsoleWriterFactory
|
||||
{
|
||||
public:
|
||||
ConsoleWriterFactory() : ptsConsole ( nullptr ) { }
|
||||
QTextStream* get();
|
||||
|
||||
private:
|
||||
QTextStream* ptsConsole;
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************\
|
||||
* Other Classes/Enums *
|
||||
\******************************************************************************/
|
||||
|
@ -1275,13 +1288,4 @@ protected:
|
|||
bool bPreviousState;
|
||||
};
|
||||
|
||||
class ConsoleWriterFactory
|
||||
{
|
||||
public:
|
||||
ConsoleWriterFactory() : ptsConsole ( nullptr ) { }
|
||||
QTextStream* get();
|
||||
private:
|
||||
QTextStream* ptsConsole;
|
||||
};
|
||||
|
||||
#endif /* !defined ( UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */
|
||||
|
|
Loading…
Reference in a new issue