mirror of
https://github.com/alexhopeoconnor/DFTE.git
synced 2026-10-03 22:21:59 +10:00
102 lines
3.2 KiB
C++
102 lines
3.2 KiB
C++
#ifndef DEVICEFRAMEWORK_TEMPLATE_CONTEXT_H
|
|
#define DEVICEFRAMEWORK_TEMPLATE_CONTEXT_H
|
|
|
|
#include <Arduino.h>
|
|
#include "DeviceFrameworkTemplateTypes.h"
|
|
|
|
// Fallback defaults when DeviceFrameworkConfig is not available (standalone usage)
|
|
// Always use internal macro names (DFTE_*) to avoid conflicts with DeviceFrameworkConfig extern declarations
|
|
// When DeviceFrameworkConfig is included, extern variables are declared with CONFIG_* names
|
|
// We use DFTE_* internal names for compile-time constants (constexpr) and array sizes
|
|
#ifndef DFTE_MAX_STACK_DEPTH_DEFAULT
|
|
#define DFTE_MAX_STACK_DEPTH_DEFAULT 16
|
|
#endif
|
|
|
|
#ifndef DFTE_BUFFER_SIZE_DEFAULT
|
|
#define DFTE_BUFFER_SIZE_DEFAULT 512
|
|
#endif
|
|
|
|
#ifndef DFTE_PLACEHOLDER_NAME_SIZE_DEFAULT
|
|
#define DFTE_PLACEHOLDER_NAME_SIZE_DEFAULT 24
|
|
#endif
|
|
|
|
// Layout-affecting settings must be supplied through build-wide DFTE_* flags.
|
|
#ifndef DFTE_MAX_STACK_DEPTH
|
|
#define DFTE_MAX_STACK_DEPTH DFTE_MAX_STACK_DEPTH_DEFAULT
|
|
#endif
|
|
|
|
#ifndef DFTE_BUFFER_SIZE
|
|
#define DFTE_BUFFER_SIZE DFTE_BUFFER_SIZE_DEFAULT
|
|
#endif
|
|
|
|
// Forward declaration
|
|
class DeviceFrameworkPlaceholderRegistry;
|
|
|
|
/**
|
|
* Template rendering context
|
|
* Maintains state for chunked streaming rendering with nested template support
|
|
*/
|
|
class DeviceFrameworkTemplateContext {
|
|
public:
|
|
using State = TemplateRenderState;
|
|
|
|
// Context state
|
|
State state;
|
|
|
|
// Unified rendering stack
|
|
static constexpr int MAX_RENDERING_DEPTH = DFTE_MAX_STACK_DEPTH;
|
|
RenderingContext renderingStack[MAX_RENDERING_DEPTH];
|
|
int renderingDepth;
|
|
|
|
// Current placeholder being built (only valid during BUILDING_PLACEHOLDER state)
|
|
// Allocated to configured size - matches CONFIG_templatePlaceholderNameSize when DeviceFramework is present
|
|
char placeholderName[DFTE_PLACEHOLDER_NAME_SIZE];
|
|
size_t placeholderPos;
|
|
|
|
// Centralized buffer management
|
|
// Allocated to configured size - matches CONFIG_templateBufferSize when DeviceFramework is present
|
|
static const size_t BUFFER_SIZE = DFTE_BUFFER_SIZE;
|
|
uint8_t readBuffer[BUFFER_SIZE];
|
|
size_t bufferPos;
|
|
size_t bufferLen;
|
|
size_t bufferOffset;
|
|
|
|
// Placeholder registry (injected, not owned)
|
|
DeviceFrameworkPlaceholderRegistry* registry;
|
|
|
|
// Statistics
|
|
size_t totalBytesProcessed;
|
|
unsigned long startTime;
|
|
|
|
DeviceFrameworkTemplateContext();
|
|
~DeviceFrameworkTemplateContext();
|
|
void reset();
|
|
|
|
// Unified stack management methods
|
|
bool pushContext(RenderingContextType type, const char* name);
|
|
void popContext();
|
|
RenderingContext* getCurrentContext();
|
|
RenderingContext* getContext(int depth);
|
|
bool isRenderingTemplate() const;
|
|
bool isRenderingPlaceholder() const;
|
|
RenderingContextType getCurrentContextType() const;
|
|
|
|
bool isComplete() const;
|
|
bool hasError() const;
|
|
String getStateString() const;
|
|
String getStackTrace() const;
|
|
|
|
// Set the registry to use for placeholder lookups
|
|
void setRegistry(DeviceFrameworkPlaceholderRegistry* reg) { registry = reg; }
|
|
|
|
// Unified buffer management
|
|
bool refillBuffer();
|
|
char getNextChar();
|
|
size_t getAvailableBytes() const;
|
|
bool hasMoreData() const;
|
|
void resetPlaceholder();
|
|
};
|
|
|
|
#endif // DEVICEFRAMEWORK_TEMPLATE_CONTEXT_H
|
|
|