3#include <CesiumUtility/Library.h>
9#include <unordered_map>
59struct CESIUMUTILITY_API Credit {
65 return this->_id == rhs._id && this->_generation == rhs._generation;
72 Credit(uint32_t
id, uint32_t generation) noexcept
73 : _id(
id), _generation(generation) {}
75 friend class CreditSystem;
76 friend class CreditReferencer;
109 CreditSource(
const std::shared_ptr<CreditSystem>& pCreditSystem)
noexcept;
127 void notifyCreditSystemDestroyed() noexcept;
129 CreditSystem* _pCreditSystem;
131 friend class CreditSystem;
179 const CreditSource& source,
181 bool showOnScreen = false);
185 const CreditSource& source,
186 const
std::
string& html,
187 bool showOnScreen = false);
282 struct CreditRecord {
284 bool showOnScreen{
false};
285 int32_t referenceCount{0};
286 bool shownLastSnapshot{0};
287 uint32_t generation{0};
288 const CreditSource* pSource{
nullptr};
289 uint32_t previousCreditWithSameHtml{INVALID_CREDIT_INDEX};
290 uint32_t nextCreditWithSameHtml{INVALID_CREDIT_INDEX};
293 void addBulkReferences(
294 const std::vector<int32_t>& references,
295 const std::vector<uint32_t>& generations)
noexcept;
296 void releaseBulkReferences(
297 const std::vector<int32_t>& references,
298 const std::vector<uint32_t>& generations)
noexcept;
300 void createCreditSource(
CreditSource& creditSource)
noexcept;
301 void destroyCreditSource(
CreditSource& creditSource)
noexcept;
303 uint32_t filterCreditForSnapshot(
305 const CreditRecord& record)
noexcept;
307 const std::string INVALID_CREDIT_MESSAGE =
308 "Error: Invalid Credit, cannot get HTML string.";
310 static const uint32_t INVALID_CREDIT_INDEX{
311 std::numeric_limits<uint32_t>::max()};
313 std::vector<CreditSource*> _creditSources;
314 std::vector<CreditRecord> _credits;
315 CreditsSnapshot _snapshot;
316 std::vector<int32_t> _referenceCountScratch;
321 std::vector<Credit> _shownCreditsDestroyed;
325 std::vector<size_t> _unusedCreditRecords;
327 CreditSource _defaultCreditSource{*
this};
329 friend class CreditReferencer;
330 friend class CreditSource;
Represents a source of credits, such as a tileset or raster overlay, provided to a CreditSystem.
CreditSystem * getCreditSystem() noexcept
Gets the CreditSystem associated with this source.
CreditSource(CreditSystem &creditSystem) noexcept
Constructs a new credit source associated with a given credit system.
CreditSource(const std::shared_ptr< CreditSystem > &pCreditSystem) noexcept
Constructs a new credit source associated with a given credit system.
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.
const CreditSource * getCreditSource(Credit credit) const noexcept
Gets the source of this credit.
bool addCreditReference(Credit credit)
Adds a reference to a credit, incrementing its reference count. The referenced credit will be shown u...
const CreditSource & getDefaultCreditSource() const noexcept
Gets the default credit source used when no other source is specified.
CreditSystem() noexcept=default
Constructs a new instance.
const CreditsSnapshot & getSnapshot(CreditFilteringMode filteringMode=CreditFilteringMode::UniqueHtml) 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.
bool removeCreditReference(Credit credit)
Removes a reference from a credit, decrementing its reference count. When the reference count goes to...
Credit createCredit(const CreditSource &source, std::string &&html, bool showOnScreen=false)
Inserts a credit string.
const std::string & getHtml(Credit credit) const noexcept
Get the HTML string for this credit.
Utility classes for Cesium.
CreditFilteringMode
Specifies how credit system snapshots should handle multiple credits with the same HTML string.
@ None
No filtering is performed. Each unique Credit is reported.
@ UniqueHtmlAndShowOnScreen
Credits are filtered so that each reported credit has a combination of HTML string and CreditSystem::...
@ UniqueHtml
Credits with identical HTML strings are reported as one Credit even if they have a different CreditSo...
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.