Program Listing for File reflection/struct.h

Return to documentation for file (include\reflection\struct.h)

/******************************************************************************
© Intel Corporation.

This software and the related documents are Intel copyrighted materials,
and your use of them is governed by the express license under which they
were provided to you ("License"). Unless the License provides otherwise,
you may not use, modify, copy, publish, distribute, disclose or transmit
this software or the related documents without Intel's prior written
permission.


 This software and the related documents are provided as is, with no express
or implied warranties, other than those that are expressly stated in the
License.

******************************************************************************/

#pragma once

#include <cstdint>
#include <cstddef>
#include <map>

namespace gpa {
namespace serialization {

class Field;
class Union;

struct UnionBinding
{
    std::map<uint64_t, Field const*> selectorValueMap;
    Field const* selector;
};

class Struct
{
public:
    Struct();

    Struct(char const* name, Field const* fields, uint64_t fieldCount, size_t size);
    ~Struct();

    char const* Name() const;

    uint64_t FieldCount() const;

    Field const* GetField(uint64_t index) const;

    Field const* GetFieldByName(char const* name) const;

    void AddUnionFieldSelectorValue(uint64_t selectorValue, char const* unionFieldName, uint64_t unionIndex);

    void SetUnionFieldSelector(uint64_t index, uint64_t unionIndex);

    Field const* GetValidField(void const* structBase, uint64_t unionIndex) const;

    UnionBinding const* GetUnionBinding(uint64_t unionIndex) const;

    size_t Size() const;

private:
    char const* mName{};
    Field const* mFields{};
    uint64_t mFieldCount{};
    size_t mSize{};
    std::map<Union const*, UnionBinding> mUnionFieldSelectorMap;
    bool IndexIsValid(uint64_t unionIndex) const;
    void AddUnionBindingIfNoneExist(Union const* unionMember);
};

}  // namespace serialization
}  // namespace gpa