From df33da9a910a831bf1c34b0f5b38657650fbe178 Mon Sep 17 00:00:00 2001 From: Arvin Schnell Date: Wed, 6 Aug 2025 09:30:21 +0200 Subject: [PATCH] - updated examples --- examples/c++-lib/CmpDirs.cc | 2 +- examples/c++-lib/Create.cc | 11 ++++------- examples/c++-lib/CreateNumber.cc | 4 +--- examples/c++-lib/CreateTimeline.cc | 4 +--- examples/c++-lib/List.cc | 14 ++++++-------- examples/c++-lib/ListAll.cc | 19 +++++++++---------- 6 files changed, 22 insertions(+), 32 deletions(-) diff --git a/examples/c++-lib/CmpDirs.cc b/examples/c++-lib/CmpDirs.cc index 69519ea1..76c9b7dd 100644 --- a/examples/c++-lib/CmpDirs.cc +++ b/examples/c++-lib/CmpDirs.cc @@ -1,5 +1,5 @@ -#include +#include #include #include diff --git a/examples/c++-lib/Create.cc b/examples/c++-lib/Create.cc index 7e3bfbf5..ccd34374 100644 --- a/examples/c++-lib/Create.cc +++ b/examples/c++-lib/Create.cc @@ -1,7 +1,5 @@ -#include -#include -#include +#include #include #include @@ -9,10 +7,11 @@ using namespace snapper; using namespace std; + int main(int argc, char** argv) { - Snapper* sh = new Snapper("root", "/"); + Snapper snapper("root", "/"); SCD scd; scd.uid = getuid(); @@ -21,9 +20,7 @@ main(int argc, char** argv) Plugins::Report report; - sh->createSingleSnapshot(scd, report); - - delete sh; + snapper.createSingleSnapshot(scd, report); exit(EXIT_SUCCESS); } diff --git a/examples/c++-lib/CreateNumber.cc b/examples/c++-lib/CreateNumber.cc index a8149f2f..b3675410 100644 --- a/examples/c++-lib/CreateNumber.cc +++ b/examples/c++-lib/CreateNumber.cc @@ -1,7 +1,5 @@ -#include -#include -#include +#include #include #include diff --git a/examples/c++-lib/CreateTimeline.cc b/examples/c++-lib/CreateTimeline.cc index b5d3a753..5424a9e1 100644 --- a/examples/c++-lib/CreateTimeline.cc +++ b/examples/c++-lib/CreateTimeline.cc @@ -1,7 +1,5 @@ -#include -#include -#include +#include #include #include diff --git a/examples/c++-lib/List.cc b/examples/c++-lib/List.cc index 0272d747..0c0f2755 100644 --- a/examples/c++-lib/List.cc +++ b/examples/c++-lib/List.cc @@ -1,5 +1,5 @@ -#include +#include #include #include @@ -7,18 +7,16 @@ using namespace snapper; using namespace std; + int main(int argc, char** argv) { - Snapper* sh = new Snapper("root", "/"); + Snapper snapper("root", "/"); - const Snapshots& snapshots = sh->getSnapshots(); - for (Snapshots::const_iterator it = snapshots.begin(); it != snapshots.end(); ++it) - { - cout << *it << endl; - } + const Snapshots& snapshots = snapper.getSnapshots(); - delete sh; + for (const Snapshot& snapshot : snapshots) + cout << snapshot << '\n'; exit(EXIT_SUCCESS); } diff --git a/examples/c++-lib/ListAll.cc b/examples/c++-lib/ListAll.cc index 8ee8fdad..0f19b09e 100644 --- a/examples/c++-lib/ListAll.cc +++ b/examples/c++-lib/ListAll.cc @@ -1,28 +1,27 @@ -#include +#include #include +#include #include using namespace snapper; using namespace std; + int main(int argc, char** argv) { list config_infos = Snapper::getConfigs("/"); - list sh; - - for (list::const_iterator it = config_infos.begin(); it != config_infos.end(); ++it) - sh.push_back(new Snapper(it->get_config_name(), "/")); + list> snappers; - for (list::const_iterator it = sh.begin(); it != sh.end(); ++it) - cout << (*it)->configName() << " " << (*it)->subvolumeDir() << " " - << (*it)->getSnapshots().size() << endl; + for (const ConfigInfo& config_info : config_infos) + snappers.push_back(make_unique(config_info.get_config_name(), "/")); - for (list::const_iterator it = sh.begin(); it != sh.end(); ++it) - delete *it; + for (const unique_ptr& snapper : snappers) + cout << snapper->configName() << " " << snapper->subvolumeDir() << " " + << snapper->getSnapshots().size() << endl; exit(EXIT_SUCCESS); } -- 2.47.3