Graphviz 12.0.1~dev.20240715.2254
Loading...
Searching...
No Matches
cgraph.h File Reference

abstract graph C library, Cgraph API More...

#include "cdt.h"
#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
Include dependency graph for cgraph.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Agrec_s
 implementation of Agrec_t More...
 
struct  Agtag_s
 tag in Agobj_s for graphs, nodes, and edges. More...
 
struct  Agobj_s
 a generic header of Agraph_s, Agnode_s and Agedge_s More...
 
struct  Agsubnode_s
 This is the node struct allocated per graph (or subgraph). More...
 
struct  Agnode_s
 
struct  Agedge_s
 
struct  Agedgepair_s
 
struct  Agdesc_s
 graph descriptor More...
 
struct  Agiddisc_s
 object ID allocator discipline More...
 
struct  Agiodisc_s
 IO services. More...
 
struct  Agdisc_s
 user's discipline More...
 
struct  Agdstate_s
 client state (closures) More...
 
struct  Agcbdisc_s
 client event callbacks, used in Agcbstack_s More...
 
struct  Agcbstack_s
 object event callbacks More...
 
struct  Agclos_s
 shared resources for Agraph_s More...
 
struct  Agraph_s
 graph or subgraph More...
 
struct  Agattr_s
 string attribute container More...
 
struct  Agsym_s
 string attribute descriptor symbol in Agattr_s.dict More...
 
struct  Agdatadict_s
 
struct  graphviz_acyclic_options_t
 options for passing to graphviz_acyclic More...
 
struct  graphviz_tred_options_t
 options for passing to graphviz_tred More...
 
struct  graphviz_unflatten_options_t
 options for passing to graphviz_unflatten More...
 

Macros

#define AGTAG(obj)   (((Agobj_t *)(obj))->tag)
 
#define AGTYPE(obj)   (AGTAG(obj).objtype)
 returns AGRAPH, AGNODE, or AGEDGE depending on the type of the object
 
#define AGID(obj)   (AGTAG(obj).id)
 returns the unique integer ID associated with the object
 
#define AGSEQ(obj)   (AGTAG(obj).seq)
 
#define AGATTRWF(obj)   (AGTAG(obj).attrwf)
 
#define AGDATA(obj)   (((Agobj_t *)(obj))->data)
 returns Agrec_t
 
#define agnew(g, t)   ((t *)agalloc(g, sizeof(t)))
 
#define agnnew(g, n, t)   ((t *)agalloc(g, (n) * sizeof(t)))
 
#define AGIN2OUT(inedge)   ((inedge) - 1)
 Agedgepair_s.in -> Agedgepair_s.out.
 
#define AGOUT2IN(outedge)    ((outedge) + 1)
 Agedgepair_s.out -> Agedgepair_s.in/*#end#*‍/.
 
#define AGOPP(e)   ((AGTYPE(e) == AGINEDGE) ? AGIN2OUT(e) : AGOUT2IN(e))
 
#define AGMKOUT(e)   (AGTYPE(e) == AGOUTEDGE ? (e) : AGIN2OUT(e))
 
#define AGMKIN(e)   (AGTYPE(e) == AGINEDGE ? (e) : AGOUT2IN(e))
 
#define AGTAIL(e)   (AGMKIN(e)->node)
 
#define AGHEAD(e)   (AGMKOUT(e)->node)
 
#define AGEQEDGE(e, f)   (AGMKOUT(e) == AGMKOUT(f))
 
#define agtail(e)   AGTAIL(e)
 
#define aghead(e)   AGHEAD(e)
 
#define agopp(e)    AGOPP(e)
 opposite edge: flip Agedgepair_s.outAgedgepair_s.in/*#end#*‍/
 
#define ageqedge(e, f)   AGEQEDGE(e, f)
 edges are equal
 
#define TAILPORT_ID   "tailport"
 
#define HEADPORT_ID   "headport"
 
#define AGSNMAIN(sn)   ((sn) == (&((sn)->node->mainsub)))
 
#define EDGEOF(sn, rep)
 

Typedefs

typedef uint64_t IDTYPE
 unique per main graph ID
 
typedef struct Agtag_s Agtag_t
 
typedef struct Agobj_s Agobj_t
 generic object header
 
typedef struct Agraph_s Agraph_t
 graph, subgraph (or hyperedge)
 
typedef struct Agdesc_s Agdesc_t
 graph descriptor
 
typedef struct Agdstate_s Agdstate_t
 client state (closures)
 
typedef struct Agclos_s Agclos_t
 common fields for graph/subgs
 
typedef struct Agnode_s Agnode_t
 node (atom)
 
typedef struct Agsubnode_s Agsubnode_t
 
typedef struct Agedge_s Agedge_t
 node pair
 
typedef struct Agedgepair_s Agedgepair_t
 the edge object
 
typedef struct Agiddisc_s Agiddisc_t
 object ID allocator
 
typedef struct Agiodisc_s Agiodisc_t
 IO services.
 
typedef struct Agdisc_s Agdisc_t
 union of client discipline methods
 
typedef struct Agcbdisc_s Agcbdisc_t
 client event callbacks
 
typedef struct Agcbstack_s Agcbstack_t
 enclosing state for Agcbdisc_t
 
typedef struct Agsym_s Agsym_t
 string attribute descriptors
 
typedef struct Agattr_s Agattr_t
 string attribute container
 
typedef struct Agdatadict_s Agdatadict_t
 set of dictionaries per graph
 
typedef struct Agrec_s Agrec_t
 generic header of Agattr_s, Agdatadict_s and user records
 
typedef void(* agobjfn_t) (Agraph_t *g, Agobj_t *obj, void *arg)
 
typedef void(* agobjupdfn_t) (Agraph_t *g, Agobj_t *obj, void *arg, Agsym_t *sym)
 
typedef int(* agusererrf) (char *)
 

Enumerations

enum  {
  AGRAPH , AGNODE , AGEDGE , AGOUTEDGE = AGEDGE ,
  AGINEDGE
}
 Object tags. Can't exceed 2 bits. See Agtag_s. More...
 
enum  agerrlevel_t { AGWARN , AGERR , AGMAX , AGPREV }
 

Functions

void agpushdisc (Agraph_t *g, Agcbdisc_t *disc, void *state)
 
int agpopdisc (Agraph_t *g, Agcbdisc_t *disc)
 
Agraph_tagopen (char *name, Agdesc_t desc, Agdisc_t *disc)
 creates a new graph with the given name and kind
 
int agclose (Agraph_t *g)
 deletes a graph, freeing its associated storage
 
Agraph_tagread (void *chan, Agdisc_t *disc)
 constructs a new graph
 
Agraph_tagmemread (const char *cp)
 reads a graph from the input string
 
Agraph_tagmemconcat (Agraph_t *g, const char *cp)
 
void agreadline (int)
 sets input line number for subsequent error reporting
 
void agsetfile (const char *)
 sets the current file name for subsequent error reporting
 
Agraph_tagconcat (Agraph_t *g, void *chan, Agdisc_t *disc)
 merges the file contents with a pre-existing graph
 
int agwrite (Agraph_t *g, void *chan)
 Return 0 on success, EOF on failure.
 
int agisdirected (Agraph_t *g)
 
int agisundirected (Agraph_t *g)
 
int agisstrict (Agraph_t *g)
 
int agissimple (Agraph_t *g)
 
Agnode_tagnode (Agraph_t *g, char *name, int createflag)
 
Agnode_tagidnode (Agraph_t *g, IDTYPE id, int createflag)
 
Agnode_tagsubnode (Agraph_t *g, Agnode_t *n, int createflag)
 
Agnode_tagfstnode (Agraph_t *g)
 
Agnode_tagnxtnode (Agraph_t *g, Agnode_t *n)
 
Agnode_taglstnode (Agraph_t *g)
 
Agnode_tagprvnode (Agraph_t *g, Agnode_t *n)
 
Agsubnode_tagsubrep (Agraph_t *g, Agnode_t *n)
 
int agnodebefore (Agnode_t *u, Agnode_t *v)
 
int agdelnode (Agraph_t *g, Agnode_t *arg_n)
 removes a node from a graph or subgraph.
 
int agrelabel_node (Agnode_t *n, char *newname)
 
Agedge_tagedge (Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
 
Agedge_tagidedge (Agraph_t *g, Agnode_t *t, Agnode_t *h, IDTYPE id, int createflag)
 
Agedge_tagsubedge (Agraph_t *g, Agedge_t *e, int createflag)
 
Agedge_tagfstin (Agraph_t *g, Agnode_t *n)
 
Agedge_tagnxtin (Agraph_t *g, Agedge_t *e)
 
Agedge_tagfstout (Agraph_t *g, Agnode_t *n)
 
Agedge_tagnxtout (Agraph_t *g, Agedge_t *e)
 
Agedge_tagfstedge (Agraph_t *g, Agnode_t *n)
 
Agedge_tagnxtedge (Agraph_t *g, Agedge_t *e, Agnode_t *n)
 
int agdeledge (Agraph_t *g, Agedge_t *arg_e)
 
Agraph_tagraphof (void *obj)
 
Agraph_tagroot (void *obj)
 
int agcontains (Agraph_t *, void *obj)
 returns non-zero if obj is a member of (sub)graph
 
char * agnameof (void *)
 returns a string descriptor for the object.
 
int agdelete (Agraph_t *g, void *obj)
 deletes object. Equivalent to agclose, agdelnode, and agdeledge for obj being a graph, node or edge, respectively.
 
int agobjkind (void *obj)
 
char * agstrdup (Agraph_t *, const char *)
 returns a pointer to a reference-counted copy of the argument string, creating one if necessary
 
char * agstrdup_html (Agraph_t *, const char *)
 
int aghtmlstr (const char *)
 
char * agstrbind (Agraph_t *g, const char *)
 
int agstrfree (Agraph_t *, const char *)
 
char * agcanon (char *str, int html)
 
char * agstrcanon (char *, char *)
 
char * agcanonStr (char *str)
 
Agsym_tagattr (Agraph_t *g, int kind, char *name, const char *value)
 creates or looks up attributes of a graph
 
Agsym_tagattrsym (void *obj, char *name)
 looks up a string attribute for a graph object given as an argument
 
Agsym_tagnxtattr (Agraph_t *g, int kind, Agsym_t *attr)
 permits traversing the list of attributes of a given type
 
int agcopyattr (void *oldobj, void *newobj)
 copies all of the attributes from one object to another
 
void * agbindrec (void *obj, const char *name, unsigned int recsize, int move_to_front)
 attaches a new record of the given size to the object
 
Agrec_taggetrec (void *obj, const char *name, int move_to_front)
 find record in circular list and do optional move-to-front and lock
 
int agdelrec (void *obj, const char *name)
 deletes a named record from one object
 
void aginit (Agraph_t *g, int kind, const char *rec_name, int rec_size, int move_to_front)
 attach new records to objects of specified kind
 
void agclean (Agraph_t *g, int kind, char *rec_name)
 calls agdelrec for all objects of the same class in an entire graph
 
char * agget (void *obj, char *name)
 
char * agxget (void *obj, Agsym_t *sym)
 
int agset (void *obj, char *name, const char *value)
 
int agxset (void *obj, Agsym_t *sym, const char *value)
 
int agsafeset (void *obj, char *name, const char *value, const char *def)
 ensures the given attribute is declared before setting it locally on an object
 
Agraph_tagsubg (Agraph_t *g, char *name, int cflag)
 
Agraph_tagidsubg (Agraph_t *g, IDTYPE id, int cflag)
 
Agraph_tagfstsubg (Agraph_t *g)
 
Agraph_tagnxtsubg (Agraph_t *subg)
 
Agraph_tagparent (Agraph_t *g)
 
int agdelsubg (Agraph_t *g, Agraph_t *sub)
 
int agnnodes (Agraph_t *g)
 
int agnedges (Agraph_t *g)
 
int agnsubg (Agraph_t *g)
 
int agdegree (Agraph_t *g, Agnode_t *n, int in, int out)
 
int agcountuniqedges (Agraph_t *g, Agnode_t *n, int in, int out)
 
void * agalloc (Agraph_t *g, size_t size)
 
void * agrealloc (Agraph_t *g, void *ptr, size_t oldsize, size_t size)
 
void agfree (Agraph_t *g, void *ptr)
 
void aginternalmapclearlocalnames (Agraph_t *g)
 
agerrlevel_t agseterr (agerrlevel_t)
 
char * aglasterr (void)
 
int agerr (agerrlevel_t level, const char *fmt,...)
 
void agerrorf (const char *fmt,...)
 
void agwarningf (const char *fmt,...)
 
int agerrors (void)
 
int agreseterrors (void)
 
agusererrf agseterrf (agusererrf)
 
bool graphviz_acyclic (Agraph_t *g, const graphviz_acyclic_options_t *opts, size_t *num_rev)
 
void graphviz_tred (Agraph_t *g, const graphviz_tred_options_t *opts)
 programmatic access to tred - transitive reduction
 
void graphviz_unflatten (Agraph_t *g, const graphviz_unflatten_options_t *opts)
 
size_t graphviz_node_induce (Agraph_t *g, Agraph_t *edgeset)
 

Variables

Agiddisc_t AgIdDisc
 
Agiodisc_t AgIoDisc
 
Agdisc_t AgDefaultDisc
 
Agdesc_t Agdirected
 directed
 
Agdesc_t Agstrictdirected
 strict directed. A strict graph cannot have multi-edges or self-arcs.
 
Agdesc_t Agundirected
 undirected
 
Agdesc_t Agstrictundirected
 strict undirected
 

Detailed Description

Libcgraph supports graph programming by maintaining graphs in memory and reading and writing graph files. Graphs are composed of nodes, edges, and nested subgraphs. These graph objects may be attributed with string name-value pairs and programmer-defined records (see Attributes). All of Libcgraph’s global symbols have the prefix ag (case varying). In the following, if a function has a parameter int createflag and the object does not exist, the function will create the specified object if createflag is non-zero; otherwise, it will return NULL.

man 3 cgraph

Definition in file cgraph.h.