Sorting Network Verify and Draw
Check Whether Comparator Networks Sort and Draw Them
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CMain Class Reference

The main class. More...

#include <CMain.h>

Public Member Functions

 CMain (const HWND)
 Constructor. More...
 
 ~CMain ()
 Destructor. More...
 
template<class t >
void GeneratePowerOf2 ()
 Generate sorting network. More...
 
template<class t >
void Generate ()
 Generate sorting network. More...
 
void Read ()
 Read comparator network from file. More...
 
void Draw ()
 Draw comparator network to bitmap. More...
 
bool Verify ()
 Verify that comparator network sorts. More...
 
void OnPaint ()
 Paint the client area of the window. More...
 
Gdiplus::Bitmap * GetBitmap ()
 Get pointer to bitmap. More...
 
void SetDrawStyle (const eDrawStyle)
 Set drawing style. More...
 
HRESULT Export (const eExport)
 Export image file. More...
 

Private Member Functions

void CreateMenus ()
 Create menus. More...
 
void EnableMenus ()
 Enable menus. More...
 

Private Attributes

HWND m_hWnd = nullptr
 Window handle.
More...
 
ULONG_PTR m_gdiplusToken = 0
 GDI+ token. More...
 
HMENU m_hMenuBar = nullptr
 Handle to the menu bar. More...
 
std::wstring m_wstrName = L"Default"
 File name. More...
 
eDrawStyle m_eDrawStyle = eDrawStyle::Horizontal
 Drawing style. More...
 
CSortingNetworkm_pSortingNetwork = nullptr
 Pointer to the sorting network. More...
 

Detailed Description

The interface between I/O from Windows (input from the drop-down menus, output to the client area of the window) and the GDI+ graphics interface.

Definition at line 38 of file CMain.h.

Constructor & Destructor Documentation

◆ CMain()

CMain::CMain ( const HWND  hwnd)

Initialize GDI+, create and initialize the menus.

Parameters
hwndWindow handle.

Definition at line 46 of file CMain.cpp.

◆ ~CMain()

CMain::~CMain ( )

Delete the sorting network and shut down GDI+.

Definition at line 57 of file CMain.cpp.

Member Function Documentation

◆ CreateMenus()

void CMain::CreateMenus ( )
private

Add the menus to the menu bar. Store handles to the ones that have entries that are initially grayed out to prevent the user from selecting them when there is no comparator network loaded.

Definition at line 130 of file CMain.cpp.

◆ Draw()

void CMain::Draw ( )

If a comparator network exists, then draw it to a new bitmap of the appropriate width and depth. Put a pointer to the bitmap into m_pBitmap.

Definition at line 237 of file CMain.cpp.

◆ EnableMenus()

void CMain::EnableMenus ( )
private

Enable the menu items that were initially grayed out to prevent the user from selecting them when there was no comparator network loaded.

Definition at line 144 of file CMain.cpp.

◆ Export()

HRESULT CMain::Export ( const eExport  t)

Export an image of the comparator network.

Parameters
tExport file type.
Returns
S_OK for success, E_FAIL for failure.

Definition at line 246 of file CMain.cpp.

◆ Generate()

template<class t >
template void CMain::Generate< CBubbleSort > ( )

Generate bubblesort.

Generate max-bubblesort.

Generate min-bubblesort.

Pop up a custom dialog box asking for the number of inputs. If successful and in range, then generate a sorting network with that number of inputs.

Template Parameters
tClass of sorting network to generate.

Definition at line 191 of file CMain.cpp.

◆ GeneratePowerOf2()

template<class t >
template void CMain::GeneratePowerOf2< CPairwiseSort > ( )

Generate pairwise.

Generate bitonic.

Generate odd-even.

Pop up a custom dialog box asking for the number of inputs. If successful and in range, then round the number of inputs up to the closest power of 2, generate a sorting network of that size, then prune away unneeded channels and comparators.

Template Parameters
tClass of sorting network to generate.

Definition at line 215 of file CMain.cpp.

◆ GetBitmap()

Gdiplus::Bitmap * CMain::GetBitmap ( )

Reader function for the bitmap pointer m_pBitmap.

Returns
The bitmap pointer m_pBitmap.

Definition at line 159 of file CMain.cpp.

◆ OnPaint()

void CMain::OnPaint ( )

If we have a comparator network loaded or generated, then draw its bitmap to the window client area, scaled as necessary using GDI+. This function should only be called from the Window procedure in response to a WM_PAINT message.

Definition at line 74 of file CMain.cpp.

◆ Read()

void CMain::Read ( )

Attempt to read a comparator network from a file into a new instance of CSortingNetwork and put a pointer to it in m_pSortingNetwork. If successful, then enable the menu items that are grayed out by default until a comparator network is successully loaded. Otherwise set m_pSortingNetwork to nullptr.

Definition at line 169 of file CMain.cpp.

◆ SetDrawStyle()

void CMain::SetDrawStyle ( const eDrawStyle  d)

Set the draw style and put a checkmark next to the corresponding menu item.

Parameters
dDraw style enumerated type.

Definition at line 339 of file CMain.cpp.

◆ Verify()

bool CMain::Verify ( )

Pop up a message box that tells the user information about the comparator network and whether or not it is a sorting network. The latter will take time exponential in the number of inputs, which is probably the best we can do because sorting network verification is Co-NP-complete even for shallow sorting networks (see the following paper).

‍I. Parberry. "Single-exception sorting networks and the computational complexity of optimal sorting network verification", Mathematical Systems Theory, Vol. 23, No. 1, pp. 81–93, 1990.

If the number of inputs to the sorting network is 30 or larger, the user is given the option of whether or not to proceed with verification via a Yes/No dialog box.

Returns
true if redundant comparators detected (for redraw).

Definition at line 266 of file CMain.cpp.

Member Data Documentation

◆ m_eDrawStyle

eDrawStyle CMain::m_eDrawStyle = eDrawStyle::Horizontal
private

Definition at line 46 of file CMain.h.

◆ m_gdiplusToken

ULONG_PTR CMain::m_gdiplusToken = 0
private

Definition at line 41 of file CMain.h.

◆ m_hMenuBar

HMENU CMain::m_hMenuBar = nullptr
private

Definition at line 42 of file CMain.h.

◆ m_hWnd

HWND CMain::m_hWnd = nullptr
private

Definition at line 40 of file CMain.h.

◆ m_pSortingNetwork

CSortingNetwork* CMain::m_pSortingNetwork = nullptr
private

Definition at line 48 of file CMain.h.

◆ m_wstrName

std::wstring CMain::m_wstrName = L"Default"
private

Definition at line 44 of file CMain.h.