McStas Readout Master 0.3.3
Loading...
Searching...
No Matches
TypeDescriptionParser.h
Go to the documentation of this file.
1// Copyright (C) 2026 European Spallation Source, ERIC. See LICENSE file
2//===----------------------------------------------------------------------===//
11//===----------------------------------------------------------------------===//
12#pragma once
13
14#include <string>
15#include <vector>
16#include <stdexcept>
17
18#ifdef WIN32
19// Export symbols if compile flags "READOUT_SHARED" and "READOUT_EXPORT" are set on Windows.
20 #ifdef READOUT_SHARED
21 #ifdef READOUT_EXPORT
22 #define RL_API __declspec(dllexport)
23 #else
24 #define RL_API __declspec(dllimport)
25 #endif
26 #else
27 // Disable definition if linking statically.
28 #define RL_API
29 #endif
30#else
31// Disable definition for non-Win32 systems.
32#define RL_API
33#endif
34
37 std::string name;
38 std::string type; // Canonical type name, e.g. "int32_t", "double"
39 size_t offset; // Byte offset within the struct
40 size_t element_size; // Size of one element in bytes
41 size_t array_count; // 0 = scalar, N = array of N elements
42 size_t alignment; // Required alignment for this type
43
45 size_t total_size() const { return element_size * (array_count > 0 ? array_count : 1); }
46};
47
50public:
51 std::vector<SchemaField> fields;
52 size_t total_size; // Computed total size including padding
53 std::string description; // Original description string
54
55 TypeSchema() : total_size(0) {}
56};
57
59class TypeDescriptionError : public std::runtime_error {
60public:
61 using std::runtime_error::runtime_error;
62};
63
82RL_API TypeSchema parse_type_description(const std::string& description);
RL_API TypeSchema parse_type_description(const std::string &description)
Parse a C struct type description string into a TypeSchema.
Exception thrown for parse errors.
Complete description of a parsed struct.
A single field in a parsed struct description.
size_t total_size() const
Total size of this field (element_size * max(array_count, 1))