summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-02-02 20:48:48 +0100
committerCarl Hetherington <cth@carlh.net>2025-02-02 21:24:31 +0100
commit676be00ff2d50c399eeeef3802099ec6a5065f52 (patch)
tree9677c1869955104880b6347de8acb120d2c19bf6 /src
parent4d2cc8cf69cdbc35675ffbf6911ac83564418f43 (diff)
Add SPL::insert().
Diffstat (limited to 'src')
-rw-r--r--src/lib/spl.cc18
-rw-r--r--src/lib/spl.h2
2 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/spl.cc b/src/lib/spl.cc
index 615dd916a..3897709db 100644
--- a/src/lib/spl.cc
+++ b/src/lib/spl.cc
@@ -33,6 +33,7 @@ LIBDCP_ENABLE_WARNINGS
using std::cout;
using std::string;
using std::shared_ptr;
+using boost::optional;
void
@@ -67,3 +68,20 @@ SPL::write (boost::filesystem::path path) const
}
doc.write_to_file_formatted (path.string());
}
+
+
+void
+SPL::insert(SPLEntry entry, optional<string> before_id)
+{
+ if (before_id) {
+ auto iter = std::find_if(_spl.begin(), _spl.end(), [before_id](SPLEntry const& e) {
+ return e.id == before_id;
+ });
+ if (iter != _spl.end()) {
+ _spl.insert(iter, entry);
+ }
+ } else {
+ _spl.push_back(entry);
+ }
+}
+
diff --git a/src/lib/spl.h b/src/lib/spl.h
index f55a9fe1f..76fb77020 100644
--- a/src/lib/spl.h
+++ b/src/lib/spl.h
@@ -55,6 +55,8 @@ public:
_spl.erase (_spl.begin() + index);
}
+ void insert(SPLEntry entry, boost::optional<std::string> before_id);
+
std::vector<SPLEntry> const & get () const {
return _spl;
}