Time Converter

04/28/2016 21:50 Cyrex'#1
I honestly don't have a clue why I coded this.
However I share this with you lol.

You can place it in a header if you want.

Code:
#include <iostream>
#include <string>
#include <memory>
#include <Windows.h>

#define IsValidSTLPtr( x ) ( x && !IsBadReadPtr( x.get( ), sizeof( uintptr_t ) ) )
#define IsValidPtr( x ) ( x && !IsBadReadPtr( static_cast< const void* >( x ), sizeof( uintptr_t ) ) )

class TimeConverter
{
public:
	explicit TimeConverter( int seconds, bool makeStruct = false )
	{
		m_seconds = seconds;
		if ( makeStruct )
		{
			converted = std::make_shared<Converted_t>( );
			converted->days = toDays( );
			converted->hours = toHours( );
			converted->minutes = toMinutes( );
			converted->seconds = toSeconds( );
		}
	}

public:
	inline int toDays( ) const
	{
		return ( m_seconds / 60 / 60 / 24 );
	}

	inline int toHours( ) const
	{
		return ( m_seconds / 60 / 60 ) % 24;
	}

	inline int toMinutes( ) const
	{
		return ( m_seconds / 60 ) % 60;
	}

	inline int toSeconds( ) const
	{
		return ( m_seconds % 60 );
	}

public:
	struct Converted_t
	{
		int days, hours, minutes, seconds;
	};

	std::shared_ptr<Converted_t>& Get( )
	{
		if ( converted == nullptr || IsBadReadPtr( converted.get( ), sizeof( uintptr_t ) ) )
		{
			MessageBoxA( nullptr, "Instance ptr is not initialized as a result of passing false in the constructor!", "ATTENTION!", 0 );
			return converted;
		}

		return converted;
	}

private:
	int m_seconds;
	std::shared_ptr<Converted_t> converted;
};

int main( )
{
	int numSeconds;

	std::cout << "Number of seconds: ";
	std::cin >> numSeconds;

	TimeConverter converter( numSeconds, true );
	auto time = converter.Get( );

	if ( !IsValidSTLPtr( time ) )
	{
		std::cout << "ptr invalid." << std::endl;
		return 0;
	}

	std::cout << "Days: " << time->days << std::endl;
	std::cout << "Hours: " << time->hours << std::endl;
	std::cout << "Minutes: " << time->minutes << std::endl;
	std::cout << "Seconds: " << time->seconds << std::endl;
}
AND WHY ARE THE TABS SO FUCKING WIDE? q-q