Coverage Report

Created: 2026-10-19 14:15

src/zserio/IWalkObserver.h
Line
Count
Source
1
#ifndef ZSERIO_I_WALK_OBSERVER_H_INC
2
#define ZSERIO_I_WALK_OBSERVER_H_INC
3
4
#include "zserio/IReflectable.h"
5
#include "zserio/ITypeInfo.h"
6
#include "zserio/Types.h"
7
#include "zserio/WalkerConst.h"
8
9
namespace zserio
10
{
11
12
/**
13
 * Interface for observers which are called by the walker.
14
 */
15
template <typename ALLOC = std::allocator<uint8_t>>
16
class IBasicWalkObserver
17
{
18
public:
19
    /** Destructor. */
20
89
    virtual ~IBasicWalkObserver() = default;
21
22
    /**
23
     * Called for the root compound zserio object which is to be walked-through.
24
     *
25
     * \param compound Reflectable root compound zserio object.
26
     */
27
    virtual void beginRoot(const IBasicReflectableConstPtr<ALLOC>& compound) = 0;
28
29
    /**
30
     * Called at the end of just walked root compound zserio object.
31
     *
32
     * \param compound Reflectable root compound zserio object.
33
     */
34
    virtual void endRoot(const IBasicReflectableConstPtr<ALLOC>& compound) = 0;
35
36
    /**
37
     * Called at the beginning of an array.
38
     *
39
     * Note that for unset arrays (i.e. non-present optionals) the visitValue method with nullptr is called
40
     * instead!
41
     *
42
     * \param array Reflectable zserio array.
43
     * \param fieldInfo Array field info.
44
     */
45
    virtual void beginArray(
46
            const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) = 0;
47
48
    /**
49
     * Called at the end of an array.
50
     *
51
     * \param array Reflectable zserio array.
52
     * \param fieldInfo Array field info.
53
     */
54
    virtual void endArray(
55
            const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) = 0;
56
57
    /**
58
     * Called at the beginning of an compound field object.
59
     *
60
     * Note that for unset compounds (i.e. non-present optionals) the visitValue method with nullptr is called
61
     * instead!
62
     *
63
     * \param compound Reflectable compound zserio object.
64
     * \param fieldInfo Compound field info.
65
     * \param elementIndex Element index in array or WALKER_NOT_ELEMENT if the compound is not in array.
66
     */
67
    virtual void beginCompound(const IBasicReflectableConstPtr<ALLOC>& compound,
68
            const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) = 0;
69
70
    /**
71
     * Called at the end of just walked compound object.
72
     *
73
     * \param compound Reflectable compound zserio object.
74
     * \param fieldInfo Compound field info.
75
     * \param elementIndex Element index in array or WALKER_NOT_ELEMENT if the compound is not in array.
76
     */
77
    virtual void endCompound(const IBasicReflectableConstPtr<ALLOC>& compound,
78
            const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) = 0;
79
80
    /**
81
     * Called when a simple (or an unset compound or array - i.e. nullptr) value is reached.
82
     *
83
     * \param value Reflectable simple value.
84
     * \param fieldInfo Field info.
85
     * \param elementIndex Element index in array or WALKER_NOT_ELEMENT if the value is not in array.
86
     */
87
    virtual void visitValue(const IBasicReflectableConstPtr<ALLOC>& value,
88
            const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) = 0;
89
};
90
91
/** Typedefs to walk observer interface provided for convenience - using default std::allocator<uint8_t>. */
92
/** \{ */
93
using IWalkObserver = IBasicWalkObserver<>;
94
/** \} */
95
96
} // namespace zserio
97
98
#endif // ZSERIO_I_WALK_OBSERVER_H_INC