inkcpp
Loading...
Searching...
No Matches
types.h
1
/* Copyright (c) 2024 Julian Benda
2
*
3
* This file is part of inkCPP which is released under MIT license.
4
* See file LICENSE.txt or go to
5
* https://github.com/JBenda/inkcpp for full license details.
6
*/
7
#pragma once
8
9
#include "list.h"
10
#include "story_ptr.h"
11
#include "system.h"
12
13
namespace
ink::runtime
14
{
15
class
globals_interface;
16
class
runner_interface;
17
class
snapshot;
18
20
using
globals
=
story_ptr<globals_interface>
;
22
using
runner
=
story_ptr<runner_interface>
;
24
using
list
=
list_interface
*;
25
36
struct
value
{
37
private
:
38
union
{
39
bool
v_bool;
40
uint32_t
v_uint32;
41
int32_t v_int32;
42
const
char
* v_string;
43
float
v_float;
44
list
v_list;
45
};
46
47
public
:
49
enum class
Type
{
50
Bool
,
51
Uint32
,
52
Int32
,
53
String
,
54
Float
,
55
List
56
}
type
;
57
58
value
()
59
: v_int32{0}
60
,
type
{
Type
::
Int32
}
61
{
62
}
63
65
66
value
(
bool
v)
67
: v_bool{v}
68
,
type
{
Type
::
Bool
}
69
{
70
}
71
72
value
(
uint32_t
v)
73
: v_uint32{v}
74
,
type
{
Type
::
Uint32
}
75
{
76
}
77
78
value
(int32_t v)
79
: v_int32{v}
80
,
type
{
Type
::
Int32
}
81
{
82
}
83
84
value
(
const
char
* v)
85
: v_string{v}
86
,
type
{
Type
::
String
}
87
{
88
}
89
90
value
(
float
v)
91
: v_float{v}
92
,
type
{
Type
::
Float
}
93
{
94
}
95
96
value
(
list_interface
*
list
)
97
: v_list{
list
}
98
,
type
{
Type
::
List
}
99
{
100
}
101
102
value
(
const
value
& v)
103
:
type
{v.
type
}
104
{
105
switch
(
type
) {
106
case
Type::Bool
: v_bool = v.v_bool;
break
;
107
case
Type::Uint32
: v_uint32 = v.v_uint32;
break
;
108
case
Type::Int32
: v_int32 = v.v_int32;
break
;
109
case
Type::String
: v_string = v.v_string;
break
;
110
case
Type::Float
: v_float = v.v_float;
break
;
111
case
Type::List
: v_list = v.v_list;
break
;
112
}
113
}
114
116
121
template
<Type Ty>
122
const
auto
&
get
()
const
123
{
124
static_assert
(Ty != Ty,
"No value getter for the selected type"
);
125
}
126
};
127
129
template
<>
130
inline
const
auto
& value::get<value::Type::Bool>()
const
131
{
132
return
v_bool;
133
}
134
136
template
<>
137
inline
const
auto
& value::get<value::Type::Uint32>()
const
138
{
139
return
v_uint32;
140
}
141
143
template
<>
144
inline
const
auto
& value::get<value::Type::Int32>()
const
145
{
146
return
v_int32;
147
}
148
150
template
<>
151
inline
const
auto
& value::get<value::Type::String>()
const
152
{
153
return
v_string;
154
}
155
157
template
<>
158
inline
const
auto
& value::get<value::Type::Float>()
const
159
{
160
return
v_float;
161
}
162
164
template
<>
165
inline
const
auto
& value::get<value::Type::List>()
const
166
{
167
return
v_list;
168
}
169
}
// namespace ink::runtime
ink::runtime::list_interface
Interface for accessing a Ink list.
Definition
list.h:43
ink::runtime::story_ptr
Pointer wrapper to an object whose lifetime is tied to a story object.
Definition
story_ptr.h:85
ink::runtime
Contaning all modules and classes used for the inkles ink runtime.
Definition
choice.h:13
ink::uint32_t
unsigned int uint32_t
define basic numeric type
Definition
system.h:47
ink::runtime::value
A Ink variable.
Definition
types.h:36
ink::runtime::value::value
value(const value &v)
Construct value from corresponding type.
Definition
types.h:102
ink::runtime::value::value
value(bool v)
Construct value from corresponding type.
Definition
types.h:66
ink::runtime::value::value
value(uint32_t v)
Construct value from corresponding type.
Definition
types.h:72
ink::runtime::value::Type
Type
Type labels for ink::runtime::value
Definition
types.h:49
ink::runtime::value::Type::Float
@ Float
containing a float
ink::runtime::value::Type::String
@ String
contaning a const char*
ink::runtime::value::Type::Uint32
@ Uint32
containing uint32_t
ink::runtime::value::Type::List
@ List
containing a list_interface
ink::runtime::value::Type::Int32
@ Int32
containing int32_t
ink::runtime::value::Type::Bool
@ Bool
containing bool
ink::runtime::value::value
value(list_interface *list)
Construct value from corresponding type.
Definition
types.h:96
ink::runtime::value::type
enum ink::runtime::value::Type type
Label of type currently contained in value.
ink::runtime::value::value
value(const char *v)
Construct value from corresponding type.
Definition
types.h:84
ink::runtime::value::get
const auto & get() const
Get value to corresponding type.
Definition
types.h:122
ink::runtime::value::value
value(int32_t v)
Construct value from corresponding type.
Definition
types.h:78
ink::runtime::value::value
value(float v)
Construct value from corresponding type.
Definition
types.h:90
inkcpp
include
types.h
Generated by
1.10.0