SpreadRPC Values

SpreadRPC Values — Functions about the values/parameters for methods

Synopsis

typedef             SPRpcValue;
enum                SPRpcTypeValue;
SPRpcValue*         sp_rpc_value_new                    (void);
void                sp_rpc_value_ref                    (SPRpcValue *value);
void                sp_rpc_value_unref                  (SPRpcValue *value);
void                sp_rpc_value_set_type               (SPRpcValue *value,
                                                         SPRpcTypeValue type);
SPRpcTypeValue      sp_rpc_value_get_type               (SPRpcValue *value);
gdouble             sp_rpc_value_get_number             (SPRpcValue *value);
void                sp_rpc_value_set_number             (SPRpcValue *value,
                                                         gdouble v_number);
void                sp_rpc_value_set_boolean            (SPRpcValue *value,
                                                         gboolean v_boolean);
gboolean            sp_rpc_value_get_boolean            (SPRpcValue *value);
void                sp_rpc_value_set_string             (SPRpcValue *value,
                                                         gchar *v_string);
void                sp_rpc_value_set_string_printf      (SPRpcValue *value,
                                                         gchar *format,
                                                         ...);
gchar*              sp_rpc_value_get_string             (SPRpcValue *value);
guint               sp_rpc_value_array_length           (SPRpcValue *varray);
SPRpcValue*         sp_rpc_value_array_get              (SPRpcValue *varray,
                                                         guint id);
gint                sp_rpc_value_array_get_id_by_value  (SPRpcValue *varray,
                                                         SPRpcValue *v);
void                sp_rpc_value_array_set              (SPRpcValue *varray,
                                                         SPRpcValue *v);
void                sp_rpc_value_array_set_new          (SPRpcValue *varray,
                                                         SPRpcValue **v);
void                sp_rpc_value_array_set_before       (SPRpcValue *varray,
                                                         SPRpcValue *v,
                                                         SPRpcValue *sibling);
void                sp_rpc_value_array_set_before_new   (SPRpcValue *varray,
                                                         SPRpcValue **v,
                                                         SPRpcValue *sibling);
void                sp_rpc_value_array_set_position     (SPRpcValue *varray,
                                                         SPRpcValue *v,
                                                         gint position);
void                sp_rpc_value_array_set_position_new (SPRpcValue *varray,
                                                         SPRpcValue **v,
                                                         gint position);
void                sp_rpc_value_array_remove           (SPRpcValue *varray,
                                                         SPRpcValue *v);
void                sp_rpc_value_array_remove_by_id     (SPRpcValue *varray,
                                                         guint id);
gboolean            sp_rpc_value_struct_has_key         (SPRpcValue *vstruct,
                                                         const gchar *key);
SPRpcValue*         sp_rpc_value_struct_get_key         (SPRpcValue *vstruct,
                                                         const gchar *key);
const gchar*        sp_rpc_value_struct_get_key_by_value
                                                        (SPRpcValue *vstruct,
                                                         SPRpcValue *v);
gchar**             sp_rpc_value_struct_get_keys        (SPRpcValue *vstruct,
                                                         guint *length);
void                sp_rpc_value_struct_set_key         (SPRpcValue *vstruct,
                                                         const gchar *key,
                                                         SPRpcValue *v);
void                sp_rpc_value_struct_set_key_new     (SPRpcValue *vstruct,
                                                         const gchar *key,
                                                         SPRpcValue **v);
void                sp_rpc_value_struct_remove_key      (SPRpcValue *vstruct,
                                                         const gchar *key);
void                sp_rpc_value_struct_iter_init       (SPRpcValue *vstruct,
                                                         SPRpcIter *iter);
gboolean            sp_rpc_value_struct_iter_next       (SPRpcIter *iter,
                                                         gchar **key,
                                                         SPRpcValue **value);
void                sp_rpc_value_struct_iter_remove     (SPRpcIter *iter);

Description

Functions about the values/parameters for methods

Details

SPRpcValue

typedef struct sp_rpc_value_t SPRpcValue;


enum SPRpcTypeValue

typedef enum
{
  SP_RPC_TYPE_NULL,

  SP_RPC_TYPE_NUMBER,
  SP_RPC_TYPE_BOOLEAN,
  
  SP_RPC_TYPE_STRING,

  SP_RPC_TYPE_ARRAY,
  SP_RPC_TYPE_STRUCT
} SPRpcTypeValue;

The types for a SPRpcValue

SP_RPC_TYPE_NULL

a null value

SP_RPC_TYPE_NUMBER

a number (double)

SP_RPC_TYPE_BOOLEAN

boolean value

SP_RPC_TYPE_STRING

a string

SP_RPC_TYPE_ARRAY

a list of SPRpcValue

SP_RPC_TYPE_STRUCT

a struct key/SPRpcValue

sp_rpc_value_new ()

SPRpcValue*         sp_rpc_value_new                    (void);

Creates a new SPRpcValue with type SP_RPC_TYPE_NULL.

Returns :

a new SPRpcValue with a reference count of 1

sp_rpc_value_ref ()

void                sp_rpc_value_ref                    (SPRpcValue *value);

Increases the reference count of a SPRpcValue.

value :

a SPRpcValue

sp_rpc_value_unref ()

void                sp_rpc_value_unref                  (SPRpcValue *value);

Decreases the reference count of a SPRpcValue. When its reference count drops to 0, the SPRpcValue is finalized.

value :

a SPRpcValue

sp_rpc_value_set_type ()

void                sp_rpc_value_set_type               (SPRpcValue *value,
                                                         SPRpcTypeValue type);

Changes the type of a SPRpcValue. It removes the previous value of the SPRpcValue.

value :

a SPRpcValue

type :

the type

sp_rpc_value_get_type ()

SPRpcTypeValue      sp_rpc_value_get_type               (SPRpcValue *value);

Returns the type of a SPRpcValue

value :

a SPRpcValue

Returns :

the type of the SPRpcValue

sp_rpc_value_get_number ()

gdouble             sp_rpc_value_get_number             (SPRpcValue *value);

Returns the value of SPRpcValue if its type is SP_RPC_TYPE_NUMBER.

value :

a SPRpcValue

Returns :

the value of the SPRpcValue

sp_rpc_value_set_number ()

void                sp_rpc_value_set_number             (SPRpcValue *value,
                                                         gdouble v_number);

Sets the v_number into a SPRpcValue if its type is SP_RPC_TYPE_NUMBER.

value :

a SPRpcValue

v_number :

the number of the SPRpcValue

sp_rpc_value_set_boolean ()

void                sp_rpc_value_set_boolean            (SPRpcValue *value,
                                                         gboolean v_boolean);

Sets a boolean value into a SPRpcValue if its type is SP_RPC_TYPE_BOOLEAN.

value :

a SPRpcValue

v_boolean :

a boolean value

sp_rpc_value_get_boolean ()

gboolean            sp_rpc_value_get_boolean            (SPRpcValue *value);

Returns the value of SPRpcValue if its type is SP_RPC_TYPE_BOOLEAN.

value :

a SPRpcValue

Returns :

the value of the SPRpcValue

sp_rpc_value_set_string ()

void                sp_rpc_value_set_string             (SPRpcValue *value,
                                                         gchar *v_string);

Sets a string into a SPRpcValue if its type is SP_RPC_TYPE_STRING.

value :

a SPRpcValue

v_string :

a string

sp_rpc_value_set_string_printf ()

void                sp_rpc_value_set_string_printf      (SPRpcValue *value,
                                                         gchar *format,
                                                         ...);

Sets a string from a format string into a SPRpcValue if its type is SP_RPC_TYPE_STRING.

value :

a SPRpcValue

format :

a format string

... :

arguments of the format string

sp_rpc_value_get_string ()

gchar*              sp_rpc_value_get_string             (SPRpcValue *value);

Returns the value of SPRpcValue if its type is SP_RPC_TYPE_STRING. This string must be freed with g_free().

value :

a SPRpcValue

Returns :

a new allocated string

sp_rpc_value_array_length ()

guint               sp_rpc_value_array_length           (SPRpcValue *varray);

Returns the number of items of an array if the varray is a SP_RPC_TYPE_ARRAY.

varray :

a SPRpcValue

Returns :

the number of items of an array

sp_rpc_value_array_get ()

SPRpcValue*         sp_rpc_value_array_get              (SPRpcValue *varray,
                                                         guint id);

Returns an item of an array if the varray is a SP_RPC_TYPE_ARRAY.

varray :

a SPRpcValue

id :

the position of the item

Returns :

a SPRpcValue in the position id

sp_rpc_value_array_get_id_by_value ()

gint                sp_rpc_value_array_get_id_by_value  (SPRpcValue *varray,
                                                         SPRpcValue *v);

Returns the position of the value v into the varray or -1 if it is not into the array.

varray :

a SPRpcValue

v :

a SPRpcValue

Returns :

the position of the value v into the array, or -1

sp_rpc_value_array_set ()

void                sp_rpc_value_array_set              (SPRpcValue *varray,
                                                         SPRpcValue *v);

Inserts a new value into the varray. The count references of the value will be increased.

varray :

a SPRpcValue

v :

a SPRpcValue

sp_rpc_value_array_set_new ()

void                sp_rpc_value_array_set_new          (SPRpcValue *varray,
                                                         SPRpcValue **v);

Creates and inserts a value into an varray.

varray :

a SPRpcValue

v :

the location of a SPRpcValue

sp_rpc_value_array_set_before ()

void                sp_rpc_value_array_set_before       (SPRpcValue *varray,
                                                         SPRpcValue *v,
                                                         SPRpcValue *sibling);

Inserts a new value into the array before the given position.

varray :

a SPRpcValue

v :

a SPRpcValue

sibling :

the array item before which the new value is inserted or NULL to insert at the end of the array;

sp_rpc_value_array_set_before_new ()

void                sp_rpc_value_array_set_before_new   (SPRpcValue *varray,
                                                         SPRpcValue **v,
                                                         SPRpcValue *sibling);

Creates and inserts a new value into the array before the given position.

varray :

a SPRpcValue

v :

the location of a SPRpcValue

sibling :

the array item before which the new value is inserted or NULL to insert at the end of the array;

sp_rpc_value_array_set_position ()

void                sp_rpc_value_array_set_position     (SPRpcValue *varray,
                                                         SPRpcValue *v,
                                                         gint position);

Inserts a new value into the varray at the given position.

varray :

a SPRpcValue

v :

a SPRpcValue

position :

the position to insert the element. If this is negative, or is larger than the number of elements in the array, the new element is added on to the end of the array.

sp_rpc_value_array_set_position_new ()

void                sp_rpc_value_array_set_position_new (SPRpcValue *varray,
                                                         SPRpcValue **v,
                                                         gint position);

Creates and inserts a new value into the array at the given position.

varray :

a SPRpcValue

v :

the location of a SPRpcValue

position :

the position to insert the element. If this is negative, or is larger than the number of elements in the array, the new element is added on to the end of the array.

sp_rpc_value_array_remove ()

void                sp_rpc_value_array_remove           (SPRpcValue *varray,
                                                         SPRpcValue *v);

Removes a value from the array and decreases its reference count.

varray :

a SPRpcValue

v :

a SPRpcValue

sp_rpc_value_array_remove_by_id ()

void                sp_rpc_value_array_remove_by_id     (SPRpcValue *varray,
                                                         guint id);

Removes a value by its position from the array and decreases its reference count.

varray :

a SPRpcValue

id :

the position

sp_rpc_value_struct_has_key ()

gboolean            sp_rpc_value_struct_has_key         (SPRpcValue *vstruct,
                                                         const gchar *key);

Looks whether the struct has the key key.

vstruct :

a SPRpcValue

key :

the key

Returns :

TRUE if key is a part of the struct, FALSE otherwise.

sp_rpc_value_struct_get_key ()

SPRpcValue*         sp_rpc_value_struct_get_key         (SPRpcValue *vstruct,
                                                         const gchar *key);

returns the value of a key

vstruct :

a SPRpcValue

key :

the key

Returns :

the value of a key

sp_rpc_value_struct_get_key_by_value ()

const gchar*        sp_rpc_value_struct_get_key_by_value
                                                        (SPRpcValue *vstruct,
                                                         SPRpcValue *v);

Returns the key of a value, or NULL if the value v is not into the struct. The string is internal and you should not free it.

vstruct :

a SPRpcValue

v :

a SPRpcValue

Returns :

the key of a value

sp_rpc_value_struct_get_keys ()

gchar**             sp_rpc_value_struct_get_keys        (SPRpcValue *vstruct,
                                                         guint *length);

creates an array of the keys of a struct. Use g_strfreev() after the usage.

vstruct :

a SPRpcValue

length :

the location of the length of the array of keys, or NULL

Returns :

a new allocated array of the keys

sp_rpc_value_struct_set_key ()

void                sp_rpc_value_struct_set_key         (SPRpcValue *vstruct,
                                                         const gchar *key,
                                                         SPRpcValue *v);

Inserts a new key and value into a struct.

If the key already exists into the struct, its current value is replaced with the new value and the old value will be unreferenced.

The count reference of the v will be increased.

vstruct :

a SPRpcValue

key :

the key of the new struct

v :

a SPRpcValue

sp_rpc_value_struct_set_key_new ()

void                sp_rpc_value_struct_set_key_new     (SPRpcValue *vstruct,
                                                         const gchar *key,
                                                         SPRpcValue **v);

Creates and inserts a new key and value into a struct. Read how the sp_rpc_value_struct_set_key() works.

vstruct :

a SPRpcValue

key :

the key of the new struct

v :

the location of the new SPRpcValue

sp_rpc_value_struct_remove_key ()

void                sp_rpc_value_struct_remove_key      (SPRpcValue *vstruct,
                                                         const gchar *key);

Removes a key and its associated value from a struct. The count reference of the value will be decreased.

vstruct :

a SPRpcValue

key :

the key

sp_rpc_value_struct_iter_init ()

void                sp_rpc_value_struct_iter_init       (SPRpcValue *vstruct,
                                                         SPRpcIter *iter);

Initializes a key/value pair iterator and associates it with the vstruct. Modifying the struct after calling this function invalidates the returned iterator.

gchar *key;
SPRpcValue *value;
SPRpcIter iter;

sp_rpc_value_struct_iter_init(vstruct, &iter);
while (sp_rpc_value_struct_iter_next(&iter, &key, &value)) 
  {
    /* do something with key and value */
  }

vstruct :

a SPRpcValue

iter :

an unitialized SPRpcIter

sp_rpc_value_struct_iter_next ()

gboolean            sp_rpc_value_struct_iter_next       (SPRpcIter *iter,
                                                         gchar **key,
                                                         SPRpcValue **value);

Advances iter and retrieves the key and/or value that are now pointed to as a result of this advancement. If FALSE is returned, key and value are not set, and the iterator becomes invalid.

iter :

an initialized SPRpcIter

key :

a location for the key, or NULL

value :

the location for the value, or NULL

Returns :

FALSE if the end of struct has been reached

sp_rpc_value_struct_iter_remove ()

void                sp_rpc_value_struct_iter_remove     (SPRpcIter *iter);

Removes the key/value pair currently pointed to by the iterator from its associated SPRpcValue. Can only be called after sp_rpc_value_struct_iter_next() returned TRUE, and cannot be called more than once for the same key/value pair.

The count reference of the removed value will be decreased.

iter :

an initialized SPRpcIter