mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
LibGUI: Add GVariant class and use it for table model data.
This commit is contained in:
parent
c1f5f2694b
commit
75fabef57b
8 changed files with 152 additions and 6 deletions
70
LibGUI/GVariant.h
Normal file
70
LibGUI/GVariant.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/AKString.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
|
||||
class GVariant {
|
||||
public:
|
||||
GVariant();
|
||||
GVariant(bool);
|
||||
GVariant(float);
|
||||
GVariant(int);
|
||||
GVariant(const String&);
|
||||
GVariant(const GraphicsBitmap&);
|
||||
~GVariant();
|
||||
|
||||
enum class Type {
|
||||
Invalid,
|
||||
Bool,
|
||||
Int,
|
||||
Float,
|
||||
String,
|
||||
Bitmap,
|
||||
};
|
||||
|
||||
bool is_valid() const { return m_type != Type::Invalid; }
|
||||
Type type() const { return m_type; }
|
||||
|
||||
bool as_bool() const
|
||||
{
|
||||
ASSERT(type() == Type::Bool);
|
||||
return m_value.as_bool;
|
||||
}
|
||||
|
||||
int as_int() const
|
||||
{
|
||||
ASSERT(type() == Type::Int);
|
||||
return m_value.as_int;
|
||||
}
|
||||
|
||||
float as_float() const
|
||||
{
|
||||
ASSERT(type() == Type::Float);
|
||||
return m_value.as_float;
|
||||
}
|
||||
|
||||
String as_string() const
|
||||
{
|
||||
ASSERT(type() == Type::String);
|
||||
return *m_value.as_string;
|
||||
}
|
||||
|
||||
const GraphicsBitmap& as_bitmap() const
|
||||
{
|
||||
ASSERT(type() == Type::Bitmap);
|
||||
return *m_value.as_bitmap;
|
||||
}
|
||||
|
||||
String to_string() const;
|
||||
|
||||
private:
|
||||
union {
|
||||
StringImpl* as_string;
|
||||
GraphicsBitmap* as_bitmap;
|
||||
bool as_bool;
|
||||
int as_int;
|
||||
float as_float;
|
||||
} m_value;
|
||||
|
||||
Type m_type { Type::Invalid };
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue