|
Graphviz 14.0.5~dev.20251125.0222
|
Dynamically expanding string buffers. More...
#include <assert.h>#include <limits.h>#include <stdarg.h>#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <stdio.h>#include <string.h>#include <util/alloc.h>#include <util/unused.h>Go to the source code of this file.
Data Structures | |
| struct | agxbuf |
Macros | |
| #define | PRINTF_LIKE(index, first) /* nothing */ |
Enumerations | |
| enum | agxbuf_loc_t { AGXBUF_INLINE_SIZE_0 = 0 , AGXBUF_ON_HEAP = 255 } |
| a description of where a buffer is located More... | |
Functions | |
| static bool | agxbuf_is_inline (const agxbuf *xb) |
| static void | agxbfree (agxbuf *xb) |
| free any malloced resources | |
| static char * | agxbstart (agxbuf *xb) |
| return pointer to beginning of buffer | |
| static size_t | agxblen (const agxbuf *xb) |
| return number of characters currently stored | |
| static size_t | agxbsizeof (const agxbuf *xb) |
| static int | agxbpop (agxbuf *xb) |
| removes last character added, if any | |
| static void | agxbmore (agxbuf *xb, size_t ssz) |
| expand buffer to hold at least ssz more bytes | |
| static char * | agxbnext (agxbuf *xb) |
| next position for writing | |
| static int | vagxbprint (agxbuf *xb, const char *fmt, va_list ap) |
| vprintf-style output to an agxbuf | |
| static int | agxbprint (agxbuf *xb, const char *fmt,...) |
| Printf-style output to an agxbuf. | |
| static size_t | agxbput_n (agxbuf *xb, const char *s, size_t ssz) |
| append string s of length ssz into xb | |
| static size_t | agxbput (agxbuf *xb, const char *s) |
| append string s into xb | |
| static int | agxbputc (agxbuf *xb, char c) |
| add character to buffer | |
| static void | agxbclear (agxbuf *xb) |
| resets pointer to data | |
| static WUR char * | agxbuse (agxbuf *xb) |
| static char * | agxbdisown (agxbuf *xb) |
| static void | agxbuf_trim_zeros (agxbuf *xb) |
Incrementally constructing a string in C is not something easily available out-of-the-box. You either need to statically know the size of the string upfront or rely on non-standard APIs like asprintf and open_memstream.
This header implements a self-contained, reasonably efficient alternative. You can think of this as similar to C++’s std::ostringstream or Python’s io.StringIO.
agxbuf includes Short String Optimization (SSO), a technique to pack small strings into the bytes of the structure itself rather than an out-of-line heap buffer. The point of this is to save memory and/or runtime by avoiding allocator calls. In contrast to most other SSO implementations (e.g. those in the std::string implementations of many C++ standard libraries), agxbuf biases heavily towards saving memory over runtime performance. That is, the maximum length of string is eligible for SSO, at the expense of more runtime code branches. The thinking here (that should periodically be reconsidered) is that expensive Graphviz runs typically hit memory limits before runtime limits, and thus would benefit more from saving memory than running faster.
Definition in file agxbuf.h.
| enum agxbuf_loc_t |
|
inlinestatic |
Definition at line 312 of file agxbuf.h.
References AGXBUF_INLINE_SIZE_0, agxbuf_is_inline(), agxbuf::located, and agxbuf::size.
Referenced by addEdgeGraphics(), addEdgeGraphics(), addEdgeLabelGraphics(), addEdgeLabelGraphics(), addNodeGraphics(), addNodeGraphics(), addNodeLabelGraphics(), addNodeLabelGraphics(), agerr_va(), agxbuse(), extoken_fn(), and pango_textlayout().
|
inlinestatic |
Definition at line 345 of file agxbuf.h.
References agxblen(), agxbputc(), agxbuf_is_inline(), agxbuf::buf, gv_strndup(), and agxbuf::store.
Referenced by aglasterr(), appendFItemList(), appendFItemList(), buildBindings(), compile(), concat(), endstr(), endstr(), fmtquote(), gdk_set_mimedata_from_file(), getName(), getName(), gv_get_font(), gv_postprocess(), gvconfig(), gvpr_select(), htmlEntityUTF8(), latin1ToUTF8(), lexname(), make_simple_label(), pango_psfontResolve(), parseBracket(), parseString(), pov_color_as_str(), ps_string(), renderresult(), sprintXDot(), strdup_and_subst_obj0(), and utf8ToLatin1().
|
inlinestatic |
Definition at line 97 of file agxbuf.h.
References AGXBUF_ON_HEAP, agxbuf::buf, free(), and agxbuf::located.
Referenced by aagerror(), agconcat(), attach_attrs_and_arrows(), attach_edge_colors(), bboxPDF(), cairogen_begin_anchor(), cccomps(), ccomps(), clearHTMLlexer(), clone_graph(), cloneNode(), colorx(), colorxlate(), colorxlate(), concat(), concat(), concatPort(), concatPort(), createEdgeId(), createGraphId(), createNodeId(), createOneBlock(), deref(), Dot_SetClusterColor(), emit_begin_edge(), emit_edge(), emit_edge_graphics(), emit_edge_label(), emit_page(), expandPercentsEval(), exsub(), fig_bezier(), findCComp(), gdk_format(), get_font_mapping(), get_metrics_for_font_family(), getval(), global_def(), gml_to_gv(), gml_to_gv(), graph_init(), gvloadimage(), gvloadimage_process_surface(), gvplugin_graph(), gvplugin_library_load(), gvplugin_load(), gvprintf(), gvprintpointf(), gvrender_resolve_color(), initAnchor(), initObjMapData(), jsonXDot_Op(), lookup(), main(), make_html_label(), make_simple_label(), makeBlockGraph(), makeDotGraph(), mkBlock(), mkBlock(), mkStmts(), on_gvprbuttonload_clicked(), pango_textlayout(), parseCase(), parseHTML(), parseString(), pccomps(), plot_dot_map(), plot_dot_polygons(), pov_bezier(), pov_color_as_str(), pov_ellipse(), pov_textspan(), printdouble(), printFloat(), printint(), printPolyline(), printRect(), printXDot_Op(), process(), processClusterEdges(), processClusters(), put_escaping_backslashes(), readLine(), rec_attach_bb(), refval(), resolve(), resolveColor(), run_gvpr(), setcolor(), setval(), spanning_tree(), stringOf(), svg_size(), traverse(), vgpane(), writeHdr(), xdot_end_graph(), xdot_gradient_fillcolor(), and xdot_style().
|
inlinestatic |
Definition at line 108 of file agxbuf.h.
References AGXBUF_INLINE_SIZE_0, agxbuf_is_inline(), agxbuf::located, and agxbuf::size.
Referenced by aagerror(), addEdgePoint(), addEdgePoint(), agxbdisown(), agxbmore(), agxbnext(), agxbpop(), agxbput_n(), agxbputc(), agxbuf_trim_zeros(), agxbuse(), beginstr(), beginstr(), beginstr(), dgsprintxy(), htmllex(), make_simple_label(), parse_style(), renderresult(), vagxbprint(), xdot_end_edge(), xdot_end_graph(), and xdot_end_node().
|
inlinestatic |
Definition at line 150 of file agxbuf.h.
References agxblen(), agxbsizeof(), AGXBUF_ON_HEAP, agxbuf::buf, agxbuf::capacity, cnt(), gv_calloc(), gv_recalloc(), agxbuf::located, agxbuf::size, and agxbuf::store.
Referenced by agxbput_n(), agxbputc(), and vagxbprint().
|
inlinestatic |
Definition at line 175 of file agxbuf.h.
References agxblen(), agxbuf_is_inline(), agxbuf::buf, len(), and agxbuf::store.
Referenced by vagxbprint().
|
inlinestatic |
Definition at line 130 of file agxbuf.h.
References agxblen(), AGXBUF_INLINE_SIZE_0, agxbuf_is_inline(), agxbuf::buf, len(), agxbuf::located, agxbuf::size, and agxbuf::store.
Referenced by attach_attrs_and_arrows(), and xdot_gradient_fillcolor().
|
inlinestatic |
Definition at line 252 of file agxbuf.h.
References vagxbprint().
Referenced by aagerror(), addEdgeLabelGraphics(), addEdgeLabelGraphics(), addEdgePoint(), addEdgePoint(), addNodeGraphics(), addNodeGraphics(), attach_attrs_and_arrows(), auto_output_filename(), blockName(), buildBindings(), cairogen_begin_anchor(), cccomps(), ccomps(), chkGraphName(), clone_graph(), cloneNode(), clustNode(), color_string(), colorx(), colorxlate(), compile(), concat(), concat(), concat(), concatPort(), concatPort(), createEdgeId(), createGraphId(), createNodeId(), createOneBlock(), default_pencolor(), deparseAttr(), deparseAttr(), dgsprintxy(), emit_edge_label(), exdump(), expandPercentsEval(), fig_bezier(), findCComp(), findPath(), fullColor(), gdk_format(), gdk_set_mimedata_from_file(), gen(), get_avail_faces(), get_metrics_for_font_family(), getName(), getName(), getObjId(), graph_init(), gv_get_font(), gv_postprocess(), gvconfig(), gvloadimage(), gvloadimage_process_surface(), gvplugin_graph(), gvplugin_library_load(), gvplugin_list(), gvplugin_load(), gvpr_select(), gvrender_resolve_color(), hue2rgb(), initAnchor(), layerPagePrefix(), lexname(), LIST(), makeBlockGraph(), makeDotGraph(), mkBlock(), mkStmts(), nameOf(), pango_psfontResolve(), pango_textlayout(), pccomps(), pov_bezier(), pov_color_as_str(), pov_ellipse(), pov_textspan(), print(), printdouble(), printFloat(), printint(), printPolyline(), printRect(), process(), processClusters(), rec_attach_bb(), resolve(), rgb2hex(), run_gvpr(), scan(), scanEntity(), set_record_rects(), spanning_tree(), sprintXDot(), strdup_and_subst_obj0(), toGradString(), traverse(), vgpane(), writeHdr(), xdot_color_stop(), xdot_fmt_num(), xdot_points(), xdot_str_color_xbuf(), xdot_str_xbuf(), xdot_style(), and xdot_textspan().
|
inlinestatic |
Definition at line 288 of file agxbuf.h.
References agxbput_n().
|
inlinestatic |
Definition at line 268 of file agxbuf.h.
References agxblen(), agxbmore(), agxbsizeof(), agxbuf_is_inline(), agxbuf::buf, len(), agxbuf::located, agxbuf::size, and agxbuf::store.
Referenced by agxbput(), expandPercentsEval(), exsub(), global_def(), gv_string_writer(), parse_style(), replace(), resolve(), rgb2hex(), and storeFileName().
|
inlinestatic |
Definition at line 295 of file agxbuf.h.
References agxblen(), agxbmore(), agxbsizeof(), agxbuf_is_inline(), agxbuf::buf, len(), agxbuf::located, agxbuf::size, and agxbuf::store.
Referenced by aagerror(), addEdgeGraphics(), addEdgeGraphics(), addEdgeLabelGraphics(), addEdgeLabelGraphics(), addEdgePoint(), addEdgePoint(), addNodeGraphics(), addNodeGraphics(), addNodeLabelGraphics(), addNodeLabelGraphics(), agxbdisown(), agxbuse(), attach_attrs_and_arrows(), auto_output_filename(), canoncolor(), colorxlate(), colorxlate(), copyUpper(), cvtAndAppend(), deparseList(), deparseList(), dgsprintxy(), endBracket(), endString(), exdump(), expandPercentsEval(), extoken_fn(), gen(), getNum(), gv_get_font(), htmlEntityUTF8(), latin1ToUTF8(), make_simple_label(), nameOf(), parse_style(), parseString(), print(), ps_string(), put_escaping_backslashes(), readc(), readLine(), replace(), scan(), scanEntity(), strdup_and_subst_obj0(), svg_size(), toGradString(), utf8ToLatin1(), xdot_color_stop(), xdot_fmt_num(), xdot_gradient_fillcolor(), and xdot_style().
|
inlinestatic |
get the capacity of the backing memory of a buffer
In contrast to agxblen, this is the total number of usable bytes in the backing store, not the total number of currently stored bytes.
| xb | Buffer to operate on |
Definition at line 122 of file agxbuf.h.
References agxbuf_is_inline(), agxbuf::capacity, and agxbuf::store.
Referenced by agxbmore(), agxbput_n(), agxbputc(), and vagxbprint().
|
inlinestatic |
Definition at line 103 of file agxbuf.h.
References agxbuf_is_inline(), agxbuf::buf, and agxbuf::store.
Referenced by agxbuf_trim_zeros(), and agxbuse().
|
inlinestatic |
Definition at line 90 of file agxbuf.h.
References AGXBUF_ON_HEAP, agxbuf::located, and agxbuf::store.
Referenced by agxbclear(), agxbdisown(), agxblen(), agxbnext(), agxbpop(), agxbput_n(), agxbputc(), agxbsizeof(), agxbstart(), agxbuf_trim_zeros(), agxbuse(), and vagxbprint().
|
inlinestatic |
trim extraneous trailing information from a printed floating point value
tl;dr:
Printing a double or float via, for example, agxbprint("%.02f", 42.003) can result in output like “42.00”. If this data is destined for something that does generalized floating point parsing/decoding (e.g. SVG viewers) the “.00” is unnecessary. “42” would be interpreted identically. This function can be called after such a agxbprint to normalize data.
| xb | Buffer to operate on |
Definition at line 382 of file agxbuf.h.
References agxblen(), agxbstart(), AGXBUF_INLINE_SIZE_0, agxbuf_is_inline(), len(), agxbuf::located, agxbuf::size, and SIZE_MAX.
Definition at line 325 of file agxbuf.h.
References agxbclear(), agxblen(), agxbputc(), agxbstart(), AGXBUF_INLINE_SIZE_0, agxbuf_is_inline(), and agxbuf::store.
Referenced by aagerror(), addEdgeGraphics(), addEdgeGraphics(), addEdgeLabelGraphics(), addEdgeLabelGraphics(), addEdgePos(), addEdgePos(), addNodeGraphics(), addNodeGraphics(), addNodeLabelGraphics(), addNodeLabelGraphics(), attach_attrs_and_arrows(), attach_edge_colors(), auto_output_filename(), blockName(), cairogen_begin_anchor(), cccomps(), ccomps(), chkGraphName(), clone_graph(), cloneNode(), clustNode(), colorx(), colorxlate(), colorxlate(), concat(), concat(), concatPort(), concatPort(), createEdgeId(), createGraphId(), createNodeId(), createOneBlock(), default_pencolor(), deparse(), Dot_SetClusterColor(), emit_edge(), emit_edge_label(), emit_page(), endstr(), endstr_html(), expandPercentsEval(), exsub(), extoken_fn(), fig_bezier(), findCComp(), findPath(), fullColor(), gdk_format(), get_avail_faces(), get_metrics_for_font_family(), getNum(), getObjId(), global_def(), graph_init(), gvloadimage(), gvloadimage_process_surface(), gvplugin_graph(), gvplugin_library_load(), gvplugin_list(), gvplugin_load(), gvprintf(), gvprintpointf(), gvrender_resolve_color(), htmllex(), hue2rgb(), initAnchor(), jsonXDot_Op(), makeBlockGraph(), makeDotGraph(), mkBlock(), mkStmts(), nameOf(), nameOf(), nameOf(), on_gvprbuttonload_clicked(), pango_textlayout(), parse_style(), pccomps(), plot_dot_map(), plot_dot_polygons(), pov_bezier(), pov_color_as_str(), pov_ellipse(), pov_textspan(), printdouble(), printFloat(), printint(), printPolyline(), printRect(), printXDot_Op(), process(), processClusters(), put_escaping_backslashes(), readLine(), rec_attach_bb(), resolve(), run_gvpr(), setcolor(), spanning_tree(), storeFileName(), svg_size(), traverse(), unknown(), unknown(), vgpane(), writeHdr(), xdot_end_cluster(), xdot_end_edge(), xdot_end_graph(), xdot_end_node(), xdot_gradient_fillcolor(), xdot_style(), and yyparse().
|
inlinestatic |
Definition at line 181 of file agxbuf.h.
References agxblen(), agxbmore(), agxbnext(), agxbsizeof(), agxbuf_is_inline(), agxbuf::located, NULL, agxbuf::size, and agxbuf::store.
Referenced by agerr_va(), agxbprint(), and gvprintf().