]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/tools/build/src/engine/variable.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / tools / build / src / engine / variable.h
index 948ac3432adb2a86b084acd3d1c44d5c66c74b3d..082f677c52ba14a59a0e278cc306779f717453b4 100644 (file)
@@ -14,6 +14,9 @@
 #include "config.h"
 #include "lists.h"
 #include "object.h"
+#include "modules.h"
+
+#include <string>
 
 
 struct module_t;
@@ -32,4 +35,72 @@ void   var_done( struct module_t * );
 #define VAR_APPEND   1   /* append to previous value */
 #define VAR_DEFAULT  2   /* set only if no previous value */
 
+namespace b2 { namespace jam {
+    struct variable
+    {
+        inline variable(const variable &v)
+            : var_module(v.var_module), var_symbol(object_copy(v.var_symbol)) {}
+        inline variable(struct module_t *m, const char *v)
+            : var_module(m), var_symbol(object_new(v)) {}
+        inline variable(const char *m, const char *v)
+            : variable(bindmodule(object_new(m)), v) {}
+        inline variable(const std::string &m, const std::string &v)
+            : variable(bindmodule(object_new(m.c_str())), v.c_str()) {}
+        inline explicit variable(const char *v) : variable(root_module(), v) {}
+        inline explicit variable(const std::string &v) : variable(v.c_str()) {}
+        inline ~variable()
+        {
+            if (var_symbol) object_free(var_symbol);
+        }
+
+        inline operator list() const { return list{var_get(var_module, var_symbol)}; }
+
+        inline variable & operator=(list && v)
+        {
+            var_set(var_module, var_symbol, v.release(), VAR_SET);
+            return *this;
+        }
+        inline variable & operator=(const list & v) { return *this = list{v}; }
+        inline variable & operator=(const char *v) { return *this = list{object{v}}; }
+        inline variable & operator=(const std::string &v) { return *this = list{object{v}}; }
+
+        inline variable & operator+=(list & v)
+        {
+            var_set(var_module, var_symbol, v.release(), VAR_APPEND);
+            return *this;
+        }
+        inline variable & operator+=(list && v)
+        {
+            var_set(var_module, var_symbol, v.release(), VAR_APPEND);
+            return *this;
+        }
+        inline variable & operator+=(const char *v) { return *this += list{object{v}}; }
+        inline variable & operator+=(const std::string &v) { return *this += list{object{v}}; }
+
+        inline variable & operator|=(list & v)
+        {
+            var_set(var_module, var_symbol, v.release(), VAR_DEFAULT);
+            return *this;
+        }
+        inline variable & operator|=(list && v)
+        {
+            var_set(var_module, var_symbol, v.release(), VAR_DEFAULT);
+            return *this;
+        }
+        inline variable & operator|=(const char *v) { return *this |= list{object{v}}; }
+        inline variable & operator|=(const std::string &v) { return *this |= list{object{v}}; }
+
+        inline operator bool() const
+        {
+            LIST * l = var_get(var_module, var_symbol);
+            return (!list_empty(l)) && (list_length(l) > 0);
+        }
+
+        private:
+
+        struct module_t * var_module = nullptr;
+        OBJECT * var_symbol = nullptr;
+    };
+}}
+
 #endif