cesium-native 0.47.0
Loading...
Searching...
No Matches
CreditSystem.h
1#pragma once
2
3#include <CesiumUtility/Library.h>
4
5#include <cstdint>
6#include <string>
7#include <unordered_map>
8#include <utility>
9#include <vector>
10
11namespace CesiumUtility {
12
18struct CESIUMUTILITY_API Credit {
19public:
23 bool operator==(const Credit& rhs) const noexcept {
24 return this->id == rhs.id;
25 }
26
27private:
28 size_t id;
29
30 Credit(size_t id_) noexcept : id(id_) {}
31
32 friend class CreditSystem;
33 friend class CreditReferencer;
34};
35
43 std::vector<Credit> currentCredits;
44
49 std::vector<Credit> removedCredits;
50};
51
57class CESIUMUTILITY_API CreditSystem final {
58public:
65 Credit createCredit(std::string&& html, bool showOnScreen = false);
66
73 Credit createCredit(const std::string& html, bool showOnScreen = false);
74
78 bool shouldBeShownOnScreen(Credit credit) const noexcept;
79
83 void setShowOnScreen(Credit credit, bool showOnScreen) noexcept;
84
88 const std::string& getHtml(Credit credit) const noexcept;
89
98
106
115 const CreditsSnapshot& getSnapshot() noexcept;
116
117private:
118 void addBulkReferences(const std::vector<int32_t>& references) noexcept;
119 void releaseBulkReferences(const std::vector<int32_t>& references) noexcept;
120
121 const std::string INVALID_CREDIT_MESSAGE =
122 "Error: Invalid Credit, cannot get HTML string.";
123
124 struct CreditRecord {
125 std::string html;
126 bool showOnScreen;
127 int32_t referenceCount;
128 bool shownLastSnapshot;
129 };
130
131 std::vector<CreditRecord> _credits;
132 std::vector<Credit> _creditsToNoLongerShowThisSnapshot;
133 CreditsSnapshot _snapshot;
134
135 friend class CreditReferencer;
136};
137} // namespace CesiumUtility
Provides a way to reference a set of credits in a CreditSystem so that the references can easily be r...
Creates and manages Credit objects. Avoids repetitions and tracks which credits should be shown and w...
bool shouldBeShownOnScreen(Credit credit) const noexcept
Gets whether or not the credit should be shown on screen.
Credit createCredit(std::string &&html, bool showOnScreen=false)
Inserts a credit string.
const CreditsSnapshot & getSnapshot() noexcept
Gets a snapshot of the credits. The returned instance is only valid until the next call to this metho...
void setShowOnScreen(Credit credit, bool showOnScreen) noexcept
Sets whether or not the credit should be shown on screen.
Credit createCredit(const std::string &html, bool showOnScreen=false)
Inserts a credit string.
void addCreditReference(Credit credit)
Adds a reference to a credit, incrementing its reference count. The referenced credit will be shown u...
void removeCreditReference(Credit credit)
Removes a reference from a credit, decrementing its reference count. When the reference count goes to...
const std::string & getHtml(Credit credit) const noexcept
Get the HTML string for this credit.
Utility classes for Cesium.
STL namespace.
Represents an HTML string that should be shown on screen to attribute third parties for used data,...
bool operator==(const Credit &rhs) const noexcept
Returns true if two credit objects have the same ID.
A snapshot of the credits currently active in a CreditSystem.
std::vector< Credit > currentCredits
The credits that are currently active.
std::vector< Credit > removedCredits
The credits that were removed since the last call to CreditSystem::getSnapshot.