]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
pluginlib: Add common smart class templates.
authorRadosław Korzeniewski <radekk@inteos.pl>
Wed, 23 Dec 2020 10:25:51 +0000 (11:25 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:00 +0000 (09:03 +0100)
bacula/src/plugins/fd/pluginlib/smartalist.h [new file with mode: 0644]
bacula/src/plugins/fd/pluginlib/smartptr.h [new file with mode: 0644]

diff --git a/bacula/src/plugins/fd/pluginlib/smartalist.h b/bacula/src/plugins/fd/pluginlib/smartalist.h
new file mode 100644 (file)
index 0000000..adb5ad8
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2020 Kern Sibbald
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
+*/
+/**
+ * @file commctx.h
+ * @author Radosław Korzeniewski (radoslaw@korzeniewski.net)
+ * @brief This is a simple smart array list (alist) resource guard conceptually based on C++11 - RAII.
+ * @version 1.1.0
+ * @date 2020-12-23
+ *
+ * @copyright Copyright (c) 2020 All rights reserved. IP transferred to Bacula Systems according to agreement.
+ */
+
+#ifndef _SMARTALIST_H_
+#define _SMARTALIST_H_
+
+
+/**
+ * @brief This is a simple smart array list (alist) resource guard conceptually based on C++11 - RAII.
+ *
+ * @tparam T is a type for a pointer to allocate on smart_alist.
+ */
+template <typename T>
+class smart_alist : public alist
+{
+public:
+   smart_alist(int num = 10) : alist(num, not_owned_by_alist) {};
+   ~smart_alist()
+   {
+      T * it;
+      if (items) {
+         for (int i = 0; i < max_items; i++) {
+            if (items[i]) {
+               it = (T*)items[i];
+               items[i] = NULL;
+               delete it;
+            }
+         }
+      }
+   };
+};
+
+#endif   /* _SMARTALIST_H_ */
diff --git a/bacula/src/plugins/fd/pluginlib/smartptr.h b/bacula/src/plugins/fd/pluginlib/smartptr.h
new file mode 100644 (file)
index 0000000..a08cfdf
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2020 Kern Sibbald
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
+*/
+/**
+ * @file commctx.h
+ * @author Radosław Korzeniewski (radoslaw@korzeniewski.net)
+ * @brief This is a simple smart pointer guard conceptually based on C++11 smart pointers - unique_ptr.
+ * @version 1.1.0
+ * @date 2020-12-23
+ *
+ * @copyright Copyright (c) 2020 All rights reserved. IP transferred to Bacula Systems according to agreement.
+ */
+
+#ifndef _SMARTPTR_H_
+#define _SMARTPTR_H_
+
+/**
+ * @brief This is a simple smart pointer based conceptually on C++11 smart unique pointer.
+ *
+ * @tparam T is a type for a pointer to guard
+ */
+template <typename T>
+class smart_ptr
+{
+   T * _ptr;
+public:
+   smart_ptr(T *ptr) : _ptr(ptr) {};
+   ~smart_ptr()
+   {
+      if (_ptr != NULL){
+         delete _ptr;
+         _ptr = NULL;
+      }
+   };
+
+   T * get() { return _ptr; };
+};
+
+#endif   /* _SMARTPTR_H_ */