move ConsoleWriterFactory implementation in util.cpp
This commit is contained in:
parent
feaea570f2
commit
3348056253
3 changed files with 42 additions and 42 deletions
31
src/main.cpp
31
src/main.cpp
|
@ -31,43 +31,14 @@
|
||||||
#include "serverdlg.h"
|
#include "serverdlg.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "testbench.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 **************************************************************
|
// Implementation **************************************************************
|
||||||
|
|
||||||
int main ( int argc, char** argv )
|
int main ( int argc, char** argv )
|
||||||
{
|
{
|
||||||
QTextStream& tsConsole = *( ( new ConsoleWriterFactory() )->get() );
|
QTextStream& tsConsole = *( ( new ConsoleWriterFactory() )->get() );
|
||||||
|
|
||||||
QString strArgument;
|
QString strArgument;
|
||||||
double rDbleArgument;
|
double rDbleArgument;
|
||||||
|
|
||||||
|
|
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 *
|
* 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 *
|
* Other Classes/Enums *
|
||||||
\******************************************************************************/
|
\******************************************************************************/
|
||||||
|
@ -1275,13 +1288,4 @@ protected:
|
||||||
bool bPreviousState;
|
bool bPreviousState;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConsoleWriterFactory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ConsoleWriterFactory() : ptsConsole ( nullptr ) { }
|
|
||||||
QTextStream* get();
|
|
||||||
private:
|
|
||||||
QTextStream* ptsConsole;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* !defined ( UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */
|
#endif /* !defined ( UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */
|
||||||
|
|
Loading…
Reference in a new issue