Xorn
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Functions
object.cc File Reference
#include "internal.h"
#include <stdlib.h>
#include <algorithm>
#include "key_iterator.h"

Go to the source code of this file.

Functions

bool xorn_object_exists_in_revision (xorn_revision_t rev, xorn_object_t ob)
 Return whether an object exists in a revision. More...
 
xorn_obtype_t xorn_get_object_type (xorn_revision_t rev, xorn_object_t ob)
 Get the type of an object in a given revision. More...
 
void const * xorn_get_object_data (xorn_revision_t rev, xorn_object_t ob, xorn_obtype_t type)
 Get a pointer to an object's data in a given revision. More...
 
int xorn_get_object_location (xorn_revision_t rev, xorn_object_t ob, xorn_object_t *attached_to_return, unsigned int *position_return)
 Get the location of an object in the object structure. More...
 
int xorn_get_objects (xorn_revision_t rev, xorn_object_t **objects_return, size_t *count_return)
 Return a list of all objects in a revision. More...
 
int xorn_get_objects_attached_to (xorn_revision_t rev, xorn_object_t ob, xorn_object_t **objects_return, size_t *count_return)
 Return a list of objects in a revision which are attached to a certain object. More...
 
int xorn_get_selected_objects (xorn_revision_t rev, xorn_selection_t sel, xorn_object_t **objects_return, size_t *count_return)
 Return a list of objects which are in a revision as well as in a selection. More...
 
int xorn_get_added_objects (xorn_revision_t from_rev, xorn_revision_t to_rev, xorn_object_t **objects_return, size_t *count_return)
 Return a list of objects which are in a revision but not in another. More...
 
int xorn_get_removed_objects (xorn_revision_t from_rev, xorn_revision_t to_rev, xorn_object_t **objects_return, size_t *count_return)
 Return a list of objects which are in a revision but not in another. More...
 
int xorn_get_modified_objects (xorn_revision_t from_rev, xorn_revision_t to_rev, xorn_object_t **objects_return, size_t *count_return)
 Return a list of objects which exist in two revisions but have different type or data. More...
 

Function Documentation

int xorn_get_added_objects ( xorn_revision_t  from_rev,
xorn_revision_t  to_rev,
xorn_object_t **  objects_return,
size_t *  count_return 
)

Return a list of objects which are in a revision but not in another.

The returned list contains all objects in to_rev which are not in from_rev. They are not necessarily returned in a meaningful order.

The same semantics apply as in xorn_get_objects. See there for a more detailed description.

Definition at line 246 of file object.cc.

int xorn_get_modified_objects ( xorn_revision_t  from_rev,
xorn_revision_t  to_rev,
xorn_object_t **  objects_return,
size_t *  count_return 
)

Return a list of objects which exist in two revisions but have different type or data.

The objects are not necessarily returned in a meaningful order.

The same semantics apply as in xorn_get_objects. See there for a more detailed description.

Definition at line 307 of file object.cc.

void const* xorn_get_object_data ( xorn_revision_t  rev,
xorn_object_t  ob,
xorn_obtype_t  type 
)

Get a pointer to an object's data in a given revision.

The returned data structure (including referenced strings) must not be changed by the caller; use xorn_set_object_data or its type-safe equivalents to change the object.

Returns
Returns a pointer to a data structure matching type (e.g., if type is xornsch_obtype_net, returns a pointer to a xornsch_net structure). If the object doesn't exist in rev, or type doesn't match its type, returns NULL.

Example:

const struct xornsch_line *data;
if (data == NULL)
/* ob doesn't exist or isn't a line */;
Note
Try not to use this function. There are type-specific functions available (xornsch_get_net_data etc.) which offer the same functionality but are type-safe.

Definition at line 64 of file object.cc.

int xorn_get_object_location ( xorn_revision_t  rev,
xorn_object_t  ob,
xorn_object_t attached_to_return,
unsigned int *  position_return 
)

Get the location of an object in the object structure.

Parameters
revRevision to examine
obObject whose location to return
attached_to_returnPointer to a variable where to write the object to which ob is attached
position_returnPointer to a variable where to write the index of ob relative to its sibling objects

Both pointer arguments may be NULL to indicate that the caller isn't interested in the return value.

Returns
Returns 0 and writes the appropriate values to attached_to_return and position_return if ob exists in rev. Otherwise, doesn't touch the values and returns -1.

Definition at line 93 of file object.cc.

xorn_obtype_t xorn_get_object_type ( xorn_revision_t  rev,
xorn_object_t  ob 
)

Get the type of an object in a given revision.

Returns xorn_obtype_none if the object doesn't exist in the revision.

Definition at line 35 of file object.cc.

int xorn_get_objects ( xorn_revision_t  rev,
xorn_object_t **  objects_return,
size_t *  count_return 
)

Return a list of all objects in a revision.

A list of xorn_object_t values is allocated and written to, and its location is written to the variable pointed to by objects_return. The number of objects is written to the variable pointed to by count_return. If the list is empty or there is not enough memory, *objects_return may be set to NULL.

The objects are returned in their actual order. Attached objects are listed after the object they are attached to.

Returns
Returns 0 on success and -1 if there is not enough memory.
Note
You should free the returned list using free(3).

Example:

xorn_object_t *objects;
size_t count;
unsigned int i;
if (xorn_get_objects(rev, &objects, &count) == -1)
/* handle error */;
for (i = 0; i < count; i++)
/* do something with objects[i] */;
free(objects);

Definition at line 149 of file object.cc.

int xorn_get_objects_attached_to ( xorn_revision_t  rev,
xorn_object_t  ob,
xorn_object_t **  objects_return,
size_t *  count_return 
)

Return a list of objects in a revision which are attached to a certain object.

If ob is NULL, return all objects in the revision which are not attached. The objects are returned in their actual order. Objects attached to the returned objects are not returned.

objects_return may be NULL to indicate that the caller is only interested in the object count. In this case, the object list isn't created, and the function cannot run out of memory. Otherwise, the same semantics apply as in xorn_get_objects. See there for a more detailed description.

Definition at line 176 of file object.cc.

int xorn_get_removed_objects ( xorn_revision_t  from_rev,
xorn_revision_t  to_rev,
xorn_object_t **  objects_return,
size_t *  count_return 
)

Return a list of objects which are in a revision but not in another.

The returned list contains all objects in from_rev which are not in to_rev. They are not necessarily returned in a meaningful order.

The same semantics apply as in xorn_get_objects. See there for a more detailed description.

Definition at line 277 of file object.cc.

int xorn_get_selected_objects ( xorn_revision_t  rev,
xorn_selection_t  sel,
xorn_object_t **  objects_return,
size_t *  count_return 
)

Return a list of objects which are in a revision as well as in a selection.

The objects are not necessarily returned in a meaningful order.

The same semantics apply as in xorn_get_objects. See there for a more detailed description.

Definition at line 215 of file object.cc.

bool xorn_object_exists_in_revision ( xorn_revision_t  rev,
xorn_object_t  ob 
)

Return whether an object exists in a revision.

Definition at line 25 of file object.cc.