Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 02:21

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Time Converter

Discussion on Time Converter within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 225
Join Date: Sep 2014
Posts: 334
Received Thanks: 460
Time Converter

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
Cyrex' is offline  
Thanks
2 Users
Reply


Similar Threads Similar Threads
[Converter] Free Music Converter
07/19/2010 - Music - 1 Replies
Moin, ich hab für euch mal einen kleinen Musik Converter gemacht! Mit dem Converter könnt ihr die standart files convetieren, wie *.mp3 , *.wav , *.wma und noch mehr! hier ein pic: http://i30.tinypic.com/dy9mqe.png
DID ANYONE TRY HACK TIME CONVERTER ?
01/11/2010 - 12Sky2 - 1 Replies
i mean hack the time with we spend in the game, some how make the time run faster than normally we spend or just hack the points taken from that time spend in the game ?



All times are GMT +1. The time now is 02:21.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.