|
9 | 9 |
|
10 | 10 | namespace hgraph |
11 | 11 | { |
| 12 | + /** |
| 13 | + * @brief Type tag enum for fast runtime type identification without RTTI. |
| 14 | + * |
| 15 | + * Used to avoid dynamic_cast overhead in hot paths like is_same_type() and copy operations. |
| 16 | + * Each concrete time series type has a unique kind value. |
| 17 | + */ |
| 18 | + /** |
| 19 | + * @brief Type tag using bit flags for fast runtime type identification. |
| 20 | + * |
| 21 | + * Each flag represents a type trait that can be combined: |
| 22 | + * - Direction: Output, Input |
| 23 | + * - Base types: Value, Bundle, List, Dict, Set, Reference, Window |
| 24 | + * - Modifiers: Indexed, Signal, etc. |
| 25 | + * |
| 26 | + * Examples: |
| 27 | + * - ListOutput: List | Output |
| 28 | + * - ListInput: List | Input |
| 29 | + * - IndexedListOutput: Indexed | List | Output |
| 30 | + */ |
| 31 | + enum class TimeSeriesKind : uint32_t { |
| 32 | + None = 0, |
| 33 | + |
| 34 | + // Direction flags (mutually exclusive) |
| 35 | + Output = 1 << 0, |
| 36 | + Input = 1 << 1, |
| 37 | + |
| 38 | + // Base type flags |
| 39 | + Value = 1 << 2, |
| 40 | + Bundle = 1 << 3, |
| 41 | + List = 1 << 4, |
| 42 | + Dict = 1 << 5, |
| 43 | + Set = 1 << 6, |
| 44 | + Reference = 1 << 7, |
| 45 | + Window = 1 << 8, |
| 46 | + |
| 47 | + // Modifier flags (can be combined with base types) |
| 48 | + Indexed = 1 << 9, |
| 49 | + Signal = 1 << 10, |
| 50 | + FixedWindow = 1 << 11, |
| 51 | + TimeWindow = 1 << 12, |
| 52 | + }; |
| 53 | + |
| 54 | + // Bitwise operators for combining flags |
| 55 | + constexpr TimeSeriesKind operator|(TimeSeriesKind a, TimeSeriesKind b) { |
| 56 | + return static_cast<TimeSeriesKind>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b)); |
| 57 | + } |
| 58 | + |
| 59 | + constexpr TimeSeriesKind operator&(TimeSeriesKind a, TimeSeriesKind b) { |
| 60 | + return static_cast<TimeSeriesKind>(static_cast<uint32_t>(a) & static_cast<uint32_t>(b)); |
| 61 | + } |
| 62 | + |
| 63 | + constexpr bool operator!(TimeSeriesKind k) { |
| 64 | + return static_cast<uint32_t>(k) == 0; |
| 65 | + } |
| 66 | + |
| 67 | + // Helper to check if all flags in 'required' are present in 'kind' |
| 68 | + constexpr bool has_flags(TimeSeriesKind kind, TimeSeriesKind required) { |
| 69 | + return (kind & required) == required; |
| 70 | + } |
12 | 71 |
|
13 | 72 | struct TimeSeriesVisitor; |
14 | 73 |
|
@@ -105,6 +164,14 @@ namespace hgraph |
105 | 164 | [[nodiscard]] virtual bool is_reference() const = 0; |
106 | 165 | [[nodiscard]] virtual bool has_reference() const = 0; |
107 | 166 |
|
| 167 | + /** |
| 168 | + * @brief Returns the runtime type tag for this time series. |
| 169 | + * |
| 170 | + * Used for fast type identification without RTTI overhead. |
| 171 | + * Default implementation returns None; concrete classes override with their specific kind. |
| 172 | + */ |
| 173 | + [[nodiscard]] virtual TimeSeriesKind kind() const { return TimeSeriesKind::None; } |
| 174 | + |
108 | 175 | static inline time_series_type_s_ptr null_ptr{}; |
109 | 176 | }; |
110 | 177 |
|
|
0 commit comments