gdata
Loading...
Searching...
No Matches
gFrameHeader.h
Go to the documentation of this file.
1#pragma once
2
26#include "glogger.h"
27#include <atomic>
28#include <string>
29
31{
32public:
46 GFrameHeader(long int frameID_, double frameDuration_, std::shared_ptr<GLogger> logger)
47 : frameID(frameID_), frameDuration(frameDuration_), log(logger) {
48 log->debug(CONSTRUCTOR, "GFrameHeader id ", frameID);
49 }
50
57 ~GFrameHeader() { if (log) log->debug(DESTRUCTOR, "GFrameHeader id ", frameID); }
58
72 static std::unique_ptr<GFrameHeader> create(std::shared_ptr<GLogger> logger) {
73 double fd = 33.33; // Example frame duration (units could be ms or other)
74 int frameNo = globalFrameCounter.fetch_add(1, std::memory_order_relaxed);
75 return std::make_unique<GFrameHeader>(frameNo, fd, logger);
76 }
77
82 [[nodiscard]] inline long int getFrameID() const { return frameID; }
83
97 [[nodiscard]] inline long int getTime() const { return time_ns(); }
98
99private:
100 long int frameID;
101 double frameDuration;
102 std::shared_ptr<GLogger> log{};
103
112 [[nodiscard]] long int time_ns() const { return frameID * frameDuration; }
113
115 static std::atomic<int> globalFrameCounter;
116};
static std::unique_ptr< GFrameHeader > create(std::shared_ptr< GLogger > logger)
Test/example factory: create a header with a unique frame ID.
GFrameHeader(long int frameID_, double frameDuration_, std::shared_ptr< GLogger > logger)
Construct a frame header.
~GFrameHeader()
Destructor (logs for debug builds/configurations).
long int getFrameID() const
Get the frame identifier.
long int getTime() const
Get a deterministic time coordinate for the frame.
void debug(debug_type type, Args &&... args) const
CONSTRUCTOR
DESTRUCTOR