[vlc-devel] commit: var_GetAndSet: implement OR and NAND, return new value ( Rémi Denis-Courmont )

git version control git at videolan.org
Tue Feb 9 20:22:30 CET 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Feb  9 19:53:28 2010 +0200| [7e6c2325f169cfe06a8562b55a0832c26580c503] | committer: Rémi Denis-Courmont 

var_GetAndSet: implement OR and NAND, return new value

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7e6c2325f169cfe06a8562b55a0832c26580c503
---

 include/vlc_variables.h |   54 +++++++++++++++++++++++++++++++---------------
 src/misc/variables.c    |   18 ++++++++++++---
 2 files changed, 50 insertions(+), 22 deletions(-)

diff --git a/include/vlc_variables.h b/include/vlc_variables.h
index 24be87f..3dbeaf1 100644
--- a/include/vlc_variables.h
+++ b/include/vlc_variables.h
@@ -117,16 +117,12 @@
  * These are the different actions that can be used with var_GetAndSet()
  * @{
  */
-/**
- * Toggle the value of this boolean
- * \param val Unused
- */
-#define VLC_VAR_TOGGLE_BOOL         0x0010
-/**
- * Increment or decrement an integer of a given value
- * \param val the value
- */
-#define VLC_VAR_INTEGER_INCDEC      0x0020
+enum {
+    VLC_VAR_BOOL_TOGGLE, /**< Invert a boolean value (param ignored) */
+    VLC_VAR_INTEGER_ADD, /**< Add parameter to an integer value */
+    VLC_VAR_INTEGER_OR,  /**< Binary OR over an integer bits field */
+    VLC_VAR_INTEGER_NAND,/**< Binary NAND over an integer bits field */
+};
 /**@}*/
 
 /*****************************************************************************
@@ -152,8 +148,7 @@ VLC_EXPORT( int, var_Get, ( vlc_object_t *, const char *, vlc_value_t * ) );
 
 VLC_EXPORT( int, var_SetChecked, ( vlc_object_t *, const char *, int, vlc_value_t ) );
 VLC_EXPORT( int, var_GetChecked, ( vlc_object_t *, const char *, int, vlc_value_t * ) );
-VLC_EXPORT( int, var_GetAndSet, ( vlc_object_t *, const char *, int, vlc_value_t ) );
-#define var_GetAndSet(a,b,c,d) var_GetAndSet(VLC_OBJECT(a), b, c, d)
+VLC_EXPORT( int, var_GetAndSet, ( vlc_object_t *, const char *, int, vlc_value_t * ) );
 
 VLC_EXPORT( int, var_Inherit, ( vlc_object_t *, const char *, int, vlc_value_t * ) );
 
@@ -385,11 +380,12 @@ static inline void *var_GetAddress( vlc_object_t *p_obj, const char *psz_name )
  * \param p_obj the object that holds the variable
  * \param psz_name the name of the variable
  */
-static inline void var_IncInteger( vlc_object_t *p_obj, const char *psz_name )
+static inline int var_IncInteger( vlc_object_t *p_obj, const char *psz_name )
 {
     vlc_value_t val;
     val.i_int = 1;
-    var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_INCDEC, val );
+    var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_ADD, &val );
+    return val.i_int;
 }
 #define var_IncInteger(a,b) var_IncInteger( VLC_OBJECT(a), b )
 
@@ -398,14 +394,35 @@ static inline void var_IncInteger( vlc_object_t *p_obj, const char *psz_name )
  * \param p_obj the object that holds the variable
  * \param psz_name the name of the variable
  */
-static inline void var_DecInteger( vlc_object_t *p_obj, const char *psz_name )
+static inline int var_DecInteger( vlc_object_t *p_obj, const char *psz_name )
 {
     vlc_value_t val;
     val.i_int = -1;
-    var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_INCDEC, val );
+    var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_ADD, &val );
+    return val.i_int;
 }
 #define var_DecInteger(a,b) var_DecInteger( VLC_OBJECT(a), b )
 
+static inline unsigned var_OrInteger( vlc_object_t *obj, const char *name,
+                                      unsigned v )
+{
+    vlc_value_t val;
+    val.i_int = v;
+    var_GetAndSet( obj, name, VLC_VAR_INTEGER_OR, &val );
+    return val.i_int;
+}
+#define var_OrInteger(a,b,c) var_OrInteger(VLC_OBJECT(a),b,c)
+
+static inline unsigned var_NAndInteger( vlc_object_t *obj, const char *name,
+                                        unsigned v )
+{
+    vlc_value_t val;
+    val.i_int = v;
+    var_GetAndSet( obj, name, VLC_VAR_INTEGER_NAND, &val );
+    return val.i_int;
+}
+#define var_NAndInteger(a,b,c) var_NAndInteger(VLC_OBJECT(a),b,c)
+
 /**
  * Create a integer variable with inherit and get its value.
  *
@@ -600,10 +617,11 @@ static inline int var_CountChoices( vlc_object_t *p_obj, const char *psz_name )
 #define var_CountChoices(a,b) var_CountChoices( VLC_OBJECT(a),b)
 
 
-static inline int var_ToggleBool( vlc_object_t *p_obj, const char *psz_name )
+static inline bool var_ToggleBool( vlc_object_t *p_obj, const char *psz_name )
 {
     vlc_value_t val;
-    return var_GetAndSet( p_obj, psz_name, VLC_VAR_TOGGLE_BOOL, val );
+    var_GetAndSet( p_obj, psz_name, VLC_VAR_BOOL_TOGGLE, &val );
+    return val.b_bool;
 }
 #define var_ToggleBool(a,b) var_ToggleBool( VLC_OBJECT(a),b )
 
diff --git a/src/misc/variables.c b/src/misc/variables.c
index f227041..7f142f8 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -634,13 +634,14 @@ int var_Change( vlc_object_t *p_this, const char *psz_name,
  * \return vlc error codes
  */
 int var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action,
-                   vlc_value_t val )
+                   vlc_value_t *p_val )
 {
     int i_ret;
     variable_t *p_var;
     vlc_value_t oldval;
 
     assert( p_this );
+    assert( p_val );
 
     vlc_object_internals_t *p_priv = vlc_internals( p_this );
 
@@ -663,13 +664,21 @@ int var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action,
     /* depending of the action requiered */
     switch( i_action )
     {
-    case VLC_VAR_TOGGLE_BOOL:
+    case VLC_VAR_BOOL_TOGGLE:
         assert( ( p_var->i_type & VLC_VAR_BOOL ) == VLC_VAR_BOOL );
         p_var->val.b_bool = !p_var->val.b_bool;
         break;
-    case VLC_VAR_INTEGER_INCDEC:
+    case VLC_VAR_INTEGER_ADD:
         assert( ( p_var->i_type & VLC_VAR_INTEGER ) == VLC_VAR_INTEGER );
-        p_var->val.i_int += val.i_int;
+        p_var->val.i_int += p_val->i_int;
+        break;
+    case VLC_VAR_INTEGER_OR:
+        assert( ( p_var->i_type & VLC_VAR_INTEGER ) == VLC_VAR_INTEGER );
+        p_var->val.i_int |= p_val->i_int;
+        break;
+    case VLC_VAR_INTEGER_NAND:
+        assert( ( p_var->i_type & VLC_VAR_INTEGER ) == VLC_VAR_INTEGER );
+        p_var->val.i_int &= ~p_val->i_int;
         break;
     default:
         vlc_mutex_unlock( &p_priv->var_lock );
@@ -678,6 +687,7 @@ int var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action,
 
     /*  Check boundaries */
     CheckValue( p_var, &p_var->val );
+    *p_val = p_var->val;
 
     /* Deal with callbacks.*/
     i_ret = TriggerCallback( p_this, p_var, psz_name, oldval );




More information about the vlc-devel mailing list