From cbc7d648a83274c87a2d3796a2877adc8c48cb42 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Apr 2022 18:53:54 +0200 Subject: Added a way to weak reference sources without any dependencies --- StarsEx/DataLoader.cpp | 14 +++++++++----- StarsEx/DataLoader.h | 4 ++-- StarsEx/DataSource.cpp | 13 ++++++++++++- StarsEx/DataSource.h | 3 +++ 4 files changed, 26 insertions(+), 8 deletions(-) (limited to 'StarsEx') diff --git a/StarsEx/DataLoader.cpp b/StarsEx/DataLoader.cpp index 12a6c67..95e8444 100644 --- a/StarsEx/DataLoader.cpp +++ b/StarsEx/DataLoader.cpp @@ -104,7 +104,7 @@ DataLoader::EnableMedia(bool enable) // +--------------------------------------------------------------------+ int -DataLoader::InsertDatafile(const char* name, Group group, int pos) +DataLoader::MountDatafile(const char* name, Group group, int pos) { FILE* f = fopen(name, "rb"); if (!f) { @@ -123,17 +123,21 @@ DataLoader::InsertDatafile(const char* name, Group group, int pos) sources.append(source); else sources.insert(source, pos); - return 0; + return source->Id(); } -void -DataLoader::ClearSources() +int +DataLoader::UnmountSource(int src) { ListIter iter = sources; while (++iter) { - if (iter.value()->GetGroup() != Group::BASE) + if (iter.value()->Id() == src) { delete iter.removeItem(); + return src; + } } + last_error = Text::format("Source with id is not mounted: %d", src); + return FAILED; } // +--------------------------------------------------------------------+ diff --git a/StarsEx/DataLoader.h b/StarsEx/DataLoader.h index 6d83e2f..4cc526d 100644 --- a/StarsEx/DataLoader.h +++ b/StarsEx/DataLoader.h @@ -46,8 +46,8 @@ public: void UseVideo(Video* v); void EnableMedia(bool enable=true); - int InsertDatafile(const char* name, Group group=Group::DEFAULT, int pos=-1); - void ClearSources(); + int MountDatafile(const char* name, Group group=Group::DEFAULT, int pos=-1); + int UnmountSource(int src); int EnableDatafile(const char* name); int DisableDatafile(const char* name); diff --git a/StarsEx/DataSource.cpp b/StarsEx/DataSource.cpp index 06c7658..1618171 100644 --- a/StarsEx/DataSource.cpp +++ b/StarsEx/DataSource.cpp @@ -18,9 +18,13 @@ using Group = DataSource::Group; +int DataSource::s_next_id {0}; + + DataSource::DataSource(Group group) : m_prefix {""}, - m_group {group} + m_group {group}, + m_id {s_next_id++} { } @@ -30,6 +34,13 @@ DataSource::~DataSource() } +int +DataSource::Id() const +{ + return m_id; +} + + Group DataSource::GetGroup() const { diff --git a/StarsEx/DataSource.h b/StarsEx/DataSource.h index 5dbc1d7..cc69870 100644 --- a/StarsEx/DataSource.h +++ b/StarsEx/DataSource.h @@ -24,6 +24,7 @@ public: explicit DataSource(Group group=Group::DEFAULT); virtual ~DataSource(); + int Id() const; Group GetGroup() const; void SetPrefix(const char* prefix=nullptr); @@ -34,6 +35,8 @@ public: protected: Text m_prefix; Group m_group; + const int m_id; + static int s_next_id; }; -- cgit v1.1