Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::cAppConsole Class Reference

#include <cAppConsole.h>

Inheritance diagram for Gray::cAppConsole:
Gray::cSingleton< cAppConsole > Gray::cStreamOutput Gray::cSingletonStatic< TYPE > Gray::cSingletonRegister Gray::cStreamBase Gray::CObject Gray::cHeapObject Gray::IHeapObject

Public Member Functions

virtual ~cAppConsole ()
 
bool HasConsoleParent () noexcept
 
AppCon_TYPE get_ConsoleMode () noexcept
 
bool isConsoleMode () noexcept
 
bool AttachOrAllocConsole (bool bAttachElseAlloc=true)
 make printf() go to the console. create console if needed. More...
 
void ReleaseConsole ()
 
HRESULT WriteStrErr (const char *pszText)
 
HRESULT WriteStrOut (const char *pszText)
 
HRESULT SetKeyModes (bool bEchoMode=true, bool bEnterMode=true)
 
int get_KeyReadQty () const
 
int ReadKeyWait ()
 Get a single char. -1 = block/wait for char failed. More...
 
int ReadKey ()
 Get a single char. -1 = none avail. non blocking,. More...
 
HRESULT WriteString (const char *pszStr) override
 
HRESULT WriteString (const wchar_t *pszStr) override
 
const void * get_HeapPtr () const noexcept override
 Get the top level (outermost, freeable) class pointer. I can delete get_HeapPtr(). More...
 
- Public Member Functions inherited from Gray::CObject
virtual ~CObject ()
 
virtual bool isValidCheck () const noexcept
 < memory allocation and structure definitions are valid. More...
 
virtual void AssertValid () const
 < memory allocation and structure definitions are valid. More...
 
virtual void Serialize (cArchive &a)
 
- Public Member Functions inherited from Gray::cHeapObject
 cHeapObject ()
 
virtual ~cHeapObject ()
 
bool IsValidInsideN (INT_PTR index) const
 
bool IsValidInsidePtr (void const *pTest) const
 
virtual size_t GetHeapStatsThis (OUT ITERATE_t &iAllocCount) const
 
virtual bool isValidCheck () const noexcept
 
- Public Member Functions inherited from Gray::cStreamOutput
 cStreamOutput () noexcept
 
virtual ~cStreamOutput ()
 
virtual HRESULT WriteX (const void *pData, size_t nDataSize)
 
HRESULT WriteT (const void *pVal, size_t nDataSize)
 
template<typename TYPE >
HRESULT WriteT (TYPE val)
 
HRESULT WriteSize (size_t nSize)
 
HRESULT WriteHashCode (HASHCODE_t nHashCode)
 
HRESULT WriteN (const void *pBuffer, size_t nSize)
 
template<typename _CH >
HRESULT WriteStringN (const _CH *pszStr)
 
template<typename _CH >
HRESULT WriteCharRepeat (_CH nChar, int nCount=1)
 
StrLen_t VPrintf (const char *pszFormat, va_list args)
 
StrLen_t VPrintf (const wchar_t *pszFormat, va_list args)
 
StrLen_t _cdecl Printf (const char *pszFormat,...)
 
StrLen_t _cdecl Printf (const wchar_t *pszFormat,...)
 
HRESULT WriteStream (cStreamInput &sInp, STREAM_POS_t nSizeMax=k_FILE_BLOCK_SIZE, IStreamProgressCallback *pProgress=nullptr, TIMESYSD_t nTimeout=0)
 Copy cStreamInput to this stream. More...
 
virtual HRESULT FlushX ()
 
- Public Member Functions inherited from Gray::cStreamBase
virtual ~cStreamBase ()
 
virtual STREAM_SEEKRET_t Seek (STREAM_OFFSET_t iOffset, SEEK_ORIGIN_TYPE eSeekOrigin=SEEK_Set)
 
void SeekToBegin ()
 
STREAM_POS_t SeekToEnd ()
 
virtual STREAM_POS_t GetPosition () const
 
virtual STREAM_POS_t GetLength () const
 

Static Public Attributes

static const COUNT_t k_MAX_CONSOLE_LINES = 500
 arbitrary max lines shown at once. More...
 
- Static Public Attributes inherited from Gray::cSingletonRegister
static cThreadLockFast sm_LockSingle
 common lock for all cSingleton. More...
 
- Static Public Attributes inherited from Gray::cStreamBase
static const BYTE k_SIZE_MASK = 0x80
 Used for WriteSize() More...
 
static const size_t k_FILE_BLOCK_SIZE = (32 * 1024)
 default arbitrary transfer block size. more than this is NOT more efficient. More...
 

Protected Member Functions

 cAppConsole ()
 
void CheckConsoleMode () noexcept
 
bool AttachConsoleSync ()
 
- Protected Member Functions inherited from Gray::cSingleton< cAppConsole >
 cSingleton (cAppConsole *pObject, const TYPEINFO_t &rAddrCode=typeid(cAppConsole)) noexcept
 
virtual ~cSingleton ()
 
- Protected Member Functions inherited from Gray::cSingletonStatic< TYPE >
 cSingletonStatic (TYPE *pObject) noexcept
 
virtual ~cSingletonStatic () noexcept
 
- Protected Member Functions inherited from Gray::cSingletonRegister
 cSingletonRegister (const TYPEINFO_t &rAddrCode) noexcept
 
virtual ~cSingletonRegister ()
 
void RegisterSingleton ()
 
- Protected Member Functions inherited from Gray::cHeapObject
const void * get_HeapPtr () const noexcept override
 Get the top level (outermost, freeable) class pointer. I can delete get_HeapPtr(). More...
 

Friends

class cSingleton< cAppConsole >
 
class cAppConsoleTests
 

Additional Inherited Members

- Static Public Member Functions inherited from Gray::cSingleton< cAppConsole >
static cAppConsole *__stdcall get_Single ()
 
static TYPE2 *__stdcall get_SingleT ()
 
static cAppConsole &__stdcall I ()
 
- Static Public Member Functions inherited from Gray::cSingletonStatic< TYPE >
static bool isSingleCreated () noexcept
 
static TYPEget_SingleU () noexcept
 
static TYPEget_Single ()
 
template<class TYPE2 >
static TYPE2 *__stdcall get_SingleCast ()
 
static TYPEI () noexcept
 
- Static Public Member Functions inherited from Gray::cSingletonRegister
static void __stdcall ReleaseModule (HMODULE hMod)
 
- Protected Attributes inherited from Gray::cSingletonRegister
HMODULE m_hModuleLoaded
 What modules loaded this ? So singletons can be destroyed if DLL/SO unloads. More...
 
- Static Protected Attributes inherited from Gray::cSingletonStatic< TYPE >
static TYPEsm_pThe = nullptr
 pointer to the one and only object of this TYPE. ASSUME automatically init to = nullptr. More...
 

Detailed Description

Singleton to Manage console output/input for this app. use of printf() etc This allows apps not compiled in _CONSOLE mode to attach to a console if they are started in one (or create one if not).

Constructor & Destructor Documentation

◆ cAppConsole()

Gray::cAppConsole::cAppConsole ( )
protected

◆ ~cAppConsole()

Gray::cAppConsole::~cAppConsole ( )
virtual

Member Function Documentation

◆ AttachConsoleSync()

bool Gray::cAppConsole::AttachConsoleSync ( )
protected

Synchronize the C std* buffers (needs USE_CRT) with _WIN32 Console. NOTE: Not sure why this isn't just handled by AllocConsole() Similar to std::ios::sync_with_stdio()

◆ AttachOrAllocConsole()

bool Gray::cAppConsole::AttachOrAllocConsole ( bool  bAttachElseAlloc = true)

make printf() go to the console. create console if needed.

  1. Do i already have a console. use it. if _CONSOLE app.
  2. Attach to my parents console if there is one.
  3. allocate a new console for this app. http://stackoverflow.com/questions/493536/can-one-executable-be-both-a-console-and-gui-application/494000#494000 https://www.tillett.info/2013/05/13/how-to-create-a-windows-program-that-works-as-both-as-a-gui-and-console-application/

◆ CheckConsoleMode()

void Gray::cAppConsole::CheckConsoleMode ( )
protectednoexcept

Is the process already running from a console window? _CONSOLE Was process started by a console ? e.g. Linux applications started from GNOME desktop have no console window.

Note
printf() might not work until i call RedirectIOToConsole()
"GetConsoleWindow();" returns null if Windows 10 and i was a windows app started in console.

◆ get_ConsoleMode()

AppCon_TYPE Gray::cAppConsole::get_ConsoleMode ( )
inlinenoexcept

◆ get_HeapPtr()

const void* Gray::cAppConsole::get_HeapPtr ( ) const
inlineoverridevirtualnoexcept

Get the top level (outermost, freeable) class pointer. I can delete get_HeapPtr().

Implements Gray::IHeapObject.

◆ get_KeyReadQty()

◆ HasConsoleParent()

bool Gray::cAppConsole::HasConsoleParent ( )
inlinenoexcept

started from command line ? Call AllocConsole to start using console.

◆ isConsoleMode()

bool Gray::cAppConsole::isConsoleMode ( )
inlinenoexcept

Is the app already running in console mode? can i use printf() ?

  1. I am _CONSOLE app, 2. I attached to my parent. 3. I created a console.

◆ ReadKey()

int Gray::cAppConsole::ReadKey ( )

Get a single char. -1 = none avail. non blocking,.

Get ASCII_TYPE Key char produced by possibly multiple keys pressed (shift). Don't wait. similar to INPUTKEY_TYPE and VK_TYPE -> VK_ESCAPE = INPUTKEY_ESCAPE

Returns
-1 = no char is available. else ASCII_TYPE character produced by key or keys pressed.

◆ ReadKeyWait()

int Gray::cAppConsole::ReadKeyWait ( )

Get a single char. -1 = block/wait for char failed.

Read a single key from conio stdin. block/wait for char. Arrows and escape key are sometimes special purpose here.

Returns
-1 = failed. no char is available. else ASCII key. (like enum VK_TYPE)

◆ ReleaseConsole()

void Gray::cAppConsole::ReleaseConsole ( )

◆ SetKeyModes()

HRESULT Gray::cAppConsole::SetKeyModes ( bool  bEchoMode = true,
bool  bEnterMode = true 
)
  • bEchoMode = default true = auto echo for input keys input on/off
  • bEnterMode = default true = Wait for a enter to be pressed first ? false = get all keys as they come in.
    Note
    The effects are persistent for the console in Linux. remember to undo your changes before exit.

◆ WriteStrErr()

HRESULT Gray::cAppConsole::WriteStrErr ( const char *  pszText)

Does not support UNICODE ?

Returns
EOF = (-1) error >=0 = success

◆ WriteString() [1/2]

HRESULT Gray::cAppConsole::WriteString ( const char *  pszStr)
inlineoverridevirtual

support cStreamOutput Do not assume line termination with

Reimplemented from Gray::cStreamOutput.

◆ WriteString() [2/2]

HRESULT Gray::cAppConsole::WriteString ( const wchar_t *  pszStr)
inlineoverridevirtual

support cStreamOutput Do not assume line termination with

Reimplemented from Gray::cStreamOutput.

◆ WriteStrOut()

HRESULT Gray::cAppConsole::WriteStrOut ( const char *  pszText)

Write to console. Does not support UNICODE ?

Returns
HRESULT_WIN32_C(ERROR_HANDLE_DISK_FULL) >=0 = success
Note
_WIN32 could probably use the m_h directly.

Friends And Related Function Documentation

◆ cAppConsoleTests

friend class cAppConsoleTests
friend

◆ cSingleton< cAppConsole >

friend class cSingleton< cAppConsole >
friend

Member Data Documentation

◆ k_MAX_CONSOLE_LINES

const COUNT_t Gray::cAppConsole::k_MAX_CONSOLE_LINES = 500
static

arbitrary max lines shown at once.


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