ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | List of all members
RecencyTracker< Entity, KeyExtractor, TimestampExtractor > Class Template Reference

Tracks recently-modified records for recency highlighting. More...

#include <RecencyTracker.hpp>

Collaboration diagram for RecencyTracker< Entity, KeyExtractor, TimestampExtractor >:
Collaboration graph

Public Member Functions

 RecencyTracker (KeyExtractor key_extractor)
 Construct a RecencyTracker with custom key extractor.
 
 RecencyTracker (KeyExtractor key_extractor, TimestampExtractor timestamp_extractor)
 Construct a RecencyTracker with custom key and timestamp extractors.
 
template<typename Container >
bool update (const Container &entities)
 Update the set of recent records by comparing timestamps.
 
bool is_recent (const std::string &key) const
 Check if a record with the given key is recent.
 
std::size_t recent_count () const
 Get the number of recent records.
 
bool has_recent () const
 Check if there are any recent records.
 
void clear ()
 Clear the recent records set.
 
void reset ()
 Reset the tracker completely.
 

Detailed Description

template<typename Entity, typename KeyExtractor, typename TimestampExtractor = default_timestamp_extractor<Entity>>
class ores::qt::RecencyTracker< Entity, KeyExtractor, TimestampExtractor >

Tracks recently-modified records for recency highlighting.

This template class provides a reusable way to detect which records have been modified since the last reload. It compares each record's recorded_at timestamp against the last reload time and tracks their identifiers.

Template Parameters
EntityThe entity type (e.g., catalog, currency)
KeyExtractorA callable that extracts the identifier from an entity. Signature: std::string(const Entity&)
TimestampExtractorA callable that extracts the recorded_at timestamp. Signature: std::chrono::system_clock::time_point(const Entity&) Defaults to accessing .recorded_at member.

Usage:

// Define extractor
auto keyFn = [](const auto& e) { return e.name; };
// Create tracker (uses default recorded_at extractor)
RecencyTracker<Catalog, decltype(keyFn)> tracker(keyFn);
// After loading data
tracker.update(catalogs);
// In data() method
if (tracker.is_recent(catalog.name) && pulseManager_->is_pulse_on()) {
}
static const QColor stale_indicator
Color for indicating stale/changed data that needs attention.
Definition ColorConstants.hpp:40
Tracks recently-modified records for recency highlighting.
Definition RecencyTracker.hpp:75

Constructor & Destructor Documentation

◆ RecencyTracker() [1/2]

template<typename Entity , typename KeyExtractor , typename TimestampExtractor = default_timestamp_extractor<Entity>>
RecencyTracker ( KeyExtractor  key_extractor)
explicit

Construct a RecencyTracker with custom key extractor.

Uses the default timestamp extractor (entity.recorded_at).

Parameters
key_extractorCallable to extract identifier from entity

◆ RecencyTracker() [2/2]

template<typename Entity , typename KeyExtractor , typename TimestampExtractor = default_timestamp_extractor<Entity>>
RecencyTracker ( KeyExtractor  key_extractor,
TimestampExtractor  timestamp_extractor 
)

Construct a RecencyTracker with custom key and timestamp extractors.

Parameters
key_extractorCallable to extract identifier from entity
timestamp_extractorCallable to extract recorded_at from entity

Member Function Documentation

◆ update()

template<typename Entity , typename KeyExtractor , typename TimestampExtractor = default_timestamp_extractor<Entity>>
template<typename Container >
bool update ( const Container &  entities)

Update the set of recent records by comparing timestamps.

Compares each entity's recorded_at against the last reload time. On first call, sets the baseline timestamp without marking anything recent.

Parameters
entitiesThe collection of entities to check
Returns
true if any recent records were found, false otherwise

◆ is_recent()

template<typename Entity , typename KeyExtractor , typename TimestampExtractor = default_timestamp_extractor<Entity>>
bool is_recent ( const std::string &  key) const

Check if a record with the given key is recent.

Parameters
keyThe identifier to check
Returns
true if the record is in the recent set

◆ clear()

template<typename Entity , typename KeyExtractor , typename TimestampExtractor = default_timestamp_extractor<Entity>>
void clear ( )

Clear the recent records set.

Call this when pulsing completes.

◆ reset()

template<typename Entity , typename KeyExtractor , typename TimestampExtractor = default_timestamp_extractor<Entity>>
void reset ( )

Reset the tracker completely.

Clears recent keys and resets the last reload time.