gdata
Loading...
Searching...
No Matches
gFrameHeader.h
Go to the documentation of this file.
1#pragma once
2
27#include "glogger.h"
28#include <atomic>
29#include <string>
30
45{
46public:
60 GFrameHeader(long int frameID_, double frameDuration_, std::shared_ptr<GLogger> logger)
61 : frameID(frameID_), frameDuration(frameDuration_), log(logger) {
62 log->debug(CONSTRUCTOR, "GFrameHeader id ", frameID);
63 }
64
72 ~GFrameHeader() { if (log) log->debug(DESTRUCTOR, "GFrameHeader id ", frameID); }
73
87 static std::unique_ptr<GFrameHeader> create(std::shared_ptr<GLogger> logger) {
88 double fd = 33.33; // Example frame duration (units could be ms or other).
89 int frameNo = globalFrameCounter.fetch_add(1, std::memory_order_relaxed);
90 return std::make_unique<GFrameHeader>(frameNo, fd, logger);
91 }
92
98 [[nodiscard]] inline long int getFrameID() const { return frameID; }
99
113 [[nodiscard]] inline long int getTime() const { return time_ns(); }
114
115private:
116 long int frameID;
117 double frameDuration;
118 std::shared_ptr<GLogger> log{};
119
128 [[nodiscard]] long int time_ns() const { return frameID * frameDuration; }
129
131 static std::atomic<int> globalFrameCounter;
132};
Stores minimal metadata for one frame-style time window.
static std::unique_ptr< GFrameHeader > create(std::shared_ptr< GLogger > logger)
Test/example factory creating a header with a unique frame ID.
GFrameHeader(long int frameID_, double frameDuration_, std::shared_ptr< GLogger > logger)
Construct a frame header.
~GFrameHeader()
Destructor.
long int getFrameID() const
Returns the frame identifier.
long int getTime() const
Returns a deterministic time coordinate for the frame.
void debug(debug_type type, Args &&... args) const
CONSTRUCTOR
DESTRUCTOR