mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
Add guid type
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "kutil/coord.h"
|
||||
#include "kutil/guid.h"
|
||||
#include "kutil/memory.h"
|
||||
#include "console.h"
|
||||
#include "font.h"
|
||||
@@ -334,6 +335,23 @@ void console::vprintf(const char *fmt, va_list args)
|
||||
done = true;
|
||||
break;
|
||||
|
||||
case 'G': {
|
||||
// Special: GUID type
|
||||
kutil::guid g = va_arg(args, kutil::guid);
|
||||
put_hex<uint32_t>(g.a, 8, '0');
|
||||
putc('-');
|
||||
put_hex<uint16_t>((g.a >> 32) & 0xffff, 4, '0');
|
||||
putc('-');
|
||||
put_hex<uint16_t>((g.a >> 48) & 0xffff, 4, '0');
|
||||
putc('-');
|
||||
put_hex<uint16_t>((kutil::byteswap(g.b) >> 16) & 0xffff, 4, '0');
|
||||
putc('-');
|
||||
put_hex<uint16_t>(kutil::byteswap(g.b) & 0xffff, 4, '0');
|
||||
put_hex<uint32_t>(kutil::byteswap(g.b >> 32), 8, '0');
|
||||
}
|
||||
done = true;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
switch (*r++) {
|
||||
case 'x': put_hex<uint64_t>(va_arg(args, uint64_t), right ? width : -width, pad); done = true; break;
|
||||
|
||||
38
src/modules/kutil/guid.h
Normal file
38
src/modules/kutil/guid.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
/// \file guid.h
|
||||
/// Definition of the guid type and related functions
|
||||
#include <stdint.h>
|
||||
#include "kutil/misc.h"
|
||||
|
||||
namespace kutil {
|
||||
|
||||
|
||||
/// A GUID
|
||||
struct guid
|
||||
{
|
||||
uint64_t a, b;
|
||||
};
|
||||
|
||||
/// Make a GUID by writing it naturally-ordered in code:
|
||||
/// AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE becomes:
|
||||
/// make_guid(0xAAAAAAAA, 0xBBBB, 0xCCCC, 0xDDDD, 0xEEEEEEEEEEEE);
|
||||
/// \returns The guid object
|
||||
inline constexpr guid make_guid(uint32_t a, uint16_t b, uint16_t c, uint16_t d, uint64_t e)
|
||||
{
|
||||
const uint64_t h =
|
||||
static_cast<uint64_t>(c) << 48 |
|
||||
static_cast<uint64_t>(b) << 32 |
|
||||
a;
|
||||
|
||||
const uint64_t l =
|
||||
static_cast<uint64_t>(byteswap(e & 0xffffffff)) << 32 |
|
||||
(byteswap(e >> 32) & 0xffff0000) |
|
||||
((d << 8) & 0xff00) | ((d >> 8) & 0xff);
|
||||
|
||||
return {h, l};
|
||||
}
|
||||
|
||||
} // namespace kutil
|
||||
|
||||
|
||||
inline bool operator==(const kutil::guid &a, const kutil::guid &b) { return a.a == b.a && a.b == b.b; }
|
||||
Reference in New Issue
Block a user