Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » unsigned long / uint64 from Value type (Same issue different decade)
Re: unsigned long / uint64 from Value type [message #60516 is a reply to message #60439] Sat, 16 March 2024 16:59 Go to previous message
mirek is currently offline  mirek
Messages: 14267
Registered: November 2005
Ultimate Member
Hi,

I suppose this is one-off case, so adding this to U++ or even .usc is not worth it. I would to this:


#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct U64Convert : Convert {
	Value Format(const Value& q) const override {
		return FormatUInt64((uint64)(int64)q);
	}
	
	Value Scan(const Value& text) const override {
		uint64 x;
		bool overflow = false;
		String s = ~text;
		if(ScanUint<char, byte, uint64, 10>(x, s))
			return (int64)x;
		return ErrorValue("Invalid number");
	}
	int Filter(int chr) const override {
		return CharFilterDigit(chr);
	}
};

GUI_APP_MAIN
{
	TopWindow win;
	EditField h;
	h.SetConvert(Single<U64Convert>());
	win << h.HSizePos().TopPos(0);
	uint64 x = UINT64_MAX;
	h <<= (int64)x;
	win.Run();
	x = (int64)~h;
	DDUMP(x);
}

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: plugin/Zip issue with UTF-8
Next Topic: Performance comparison of mmap+MemStream to FileIn
Goto Forum:
  


Current Time: Sun Aug 03 01:19:28 CEST 2025

Total time taken to generate the page: 0.07690 seconds