summaryrefslogtreecommitdiffhomepage
path: root/StarsEx
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-12 18:53:54 +0200
committerAki <please@ignore.pl>2022-04-12 18:53:54 +0200
commitcbc7d648a83274c87a2d3796a2877adc8c48cb42 (patch)
tree12a981594d8c084464048b86c63a6a9fc0d25457 /StarsEx
parent9c1439b0e5e1c90723c0f2f6e22a24a935623542 (diff)
downloadstarshatter-cbc7d648a83274c87a2d3796a2877adc8c48cb42.zip
starshatter-cbc7d648a83274c87a2d3796a2877adc8c48cb42.tar.gz
starshatter-cbc7d648a83274c87a2d3796a2877adc8c48cb42.tar.bz2
Added a way to weak reference sources without any dependencies
Diffstat (limited to 'StarsEx')
-rw-r--r--StarsEx/DataLoader.cpp14
-rw-r--r--StarsEx/DataLoader.h4
-rw-r--r--StarsEx/DataSource.cpp13
-rw-r--r--StarsEx/DataSource.h3
4 files changed, 26 insertions, 8 deletions
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<DataSource> 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;
};