aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/tourist/trace/src/types.cpp
blob: 7327b34f3fa3074f18387a04d90408a3aadae7a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <foundation/types.h>
#include <foundation/buffer.h>
#include <trace/detail/type.h>

#include "constants.h"

//------------------------------------------------------------------------------
uint32 Type::Field::get_type_info() const
{
    return type_info;
}

//------------------------------------------------------------------------------
uint32 Type::Field::get_offset() const
{
    return _offset;
}

//------------------------------------------------------------------------------
uint32 Type::Field::get_size() const
{
    return (type_info & TYPE_INFO_CAT_ARRAY) ? 0 : 1 << (type_info & 0003);
}

//------------------------------------------------------------------------------
uint32 Type::get_uid() const
{
    return _uid;
}

//------------------------------------------------------------------------------
uint32 Type::get_field_count() const
{
    return _field_count;
}

//------------------------------------------------------------------------------
Type::Field Type::get_field(uint32 index) const
{
    return get_field_info(index).field;
}

//------------------------------------------------------------------------------
bool Type::has_flag(uint32 flag) const
{
    return !!(_flags & flag);
}

//------------------------------------------------------------------------------
Type::TypeName Type::get_name() const
{
    const auto* base = (const char*)(_fields + _field_count);
    StringView logger_name(base, _logger_name_len);
    base += _logger_name_len;
    StringView event_name(base, _event_name_len);
    return { logger_name, event_name };
}

//------------------------------------------------------------------------------
Type::FieldInfo Type::get_field_info(uint32 index) const
{
    Field field = _fields[index];

    // :(
    const auto* base = (const char*)(_fields + _field_count);
    base += _logger_name_len + _event_name_len;
    for (const Field* cursor = _fields; index-- > 0; ++cursor)
        base += cursor->name_size;

    StringView name(base, field.name_size);
    return { name, field };
}

//------------------------------------------------------------------------------
void Type::patch()
{
    for (uint32 i = 0; i < get_field_count(); ++i)
    {
        Field* field = const_cast<Field*>(_fields + i);
        if (field->_internal_type == FIELD_INTERNAL_VALUE)
            continue;

        if ((field->type_info & TYPE_INFO_SPECIAL_MASK) != 0)
            fatal("unexpected special value in type");

        if (field->_internal_type == FIELD_INTERNAL_REF)
        {
            field->type_info |= TYPE_INFO_SPECIAL_REF;
            continue;
        }

        field->type_info = field->name_size;
        field->type_info |= TYPE_INFO_SPECIAL_DEF_ID;
        field->name_size = 0;
    }
}