datanode.c File Reference

Implementation for path-based string data storage. More...

Include dependency graph for datanode.c:

Go to the source code of this file.

Functions

void datanode_copy (struct datanode *dest, struct datanode *src, int overwrite)
 Copies values at and beneath a source node to a destination, optionally overwriting.
void datanode_destroy (struct datanode *node)
 Frees memory allocated for all node beneath a given node.
int datanode_exists (struct datanode *node, const char *path)
 Tests whether any values exists at or beneath a node.
void datanode_init (struct datanode *node, const char *key)
 Initializes a blank datanode.
struct datanodedatanode_lookup (struct datanode *node, const char *path, int create)
 Obtains a node beneath a given node, pathing through child nodes as appropriate.
struct datanodedatanode_lookup_expert (struct datanode *node, char *path, int create)
 The same as datanode_lookup, except that the input path is destructively modified (slashes replaced with '').
void datanode_read (struct datanode *node, FILE *stream, const char *type_char, int overwrite)
 Reads nodes from a file stream into a given node.
void datanode_write (struct datanode *node, FILE *stream, const char *type_char)
 Prints all value-containing nodes beneath a given node in LRU (least recently used) order.

Detailed Description

Implementation for path-based string data storage.

Definition in file datanode.c.


Function Documentation

void datanode_copy ( struct datanode dest,
struct datanode src,
int  overwrite 
)

Copies values at and beneath a source node to a destination, optionally overwriting.

The destination must already have been initialized via datanode_init or obtained via datanode_lookup.

This function also copies mod_type, val_type, and meta even from source nodes that do not have values, but only if overwiting or if the destination has no value. Further, this function does not copy val if val_type is negative (assumed to be non-string).

Parameters:
dest the node to receive copied values
src the node to be copied
overwrite whether to overwite existing values
See also:
datanode_lookup, datanode_init

Definition at line 192 of file datanode.c.

References datanode_lookup_expert(), datanode::first_child, datanode::key, datanode::meta, datanode::mod_type, datanode::next, datanode::val, and datanode::val_type.

Referenced by fx_copy_module().

void datanode_destroy ( struct datanode node  ) 

Frees memory allocated for all node beneath a given node.

Parameters:
node the node to destruct
See also:
datanode_init

Definition at line 66 of file datanode.c.

References datanode::first_child, datanode::key, datanode::next, and datanode::val.

Referenced by fx_done().

int datanode_exists ( struct datanode node,
const char *  path 
)

Tests whether any values exists at or beneath a node.

This is a somewhat awkward definition of "exists", but reflects the fact that valueless node may be created for metadata purposes only. It is equivalent to asking whether a node's key will occur with a value or in a path when printing.

Parameters:
node the containing node of the node to check for
path the path of the node to chedk for
Returns:
whether the node was found
See also:
datanode_lookup

Definition at line 185 of file datanode.c.

References datanode_lookup().

void datanode_init ( struct datanode node,
const char *  key 
)

Initializes a blank datanode.

Parameters:
node a freshly constructed datanode
key the name of the datanode; e.g. "" for root
See also:
datanode_destruct, datanode_lookup, struct datanode

Definition at line 60 of file datanode.c.

References datanode::key.

struct datanode* datanode_lookup ( struct datanode node,
const char *  path,
int  create 
) [read]

Obtains a node beneath a given node, pathing through child nodes as appropriate.

The key passed to this function may be a slash-delimited path as in UNIX. Child nodes are (optionally) created if they do not exist, and both found and created entries are moved to the ends of their containing lists. This causes nodes to be printed in LRU order.

It is never your responsibility to allocate or free memory for entire nodes, though when modifying a node's value, you must free the old value and provide a new one that may later be freed; i.e. do not use string constants, but instead strdup them first.

Parameters:
node the containing node of the node to find
path the path of the node to find
create whether to create the node if it does not exist
Returns:
the found/created node, or NULL if not found
See also:
datanode_lookup_expert, datanode_exists, datanode_init

Definition at line 156 of file datanode.c.

References datanode_lookup_expert().

Referenced by datanode_exists().

struct datanode* datanode_lookup_expert ( struct datanode node,
char *  path,
int  create 
) [read]

The same as datanode_lookup, except that the input path is destructively modified (slashes replaced with '').

Parameters:
node the containing node of the node to find
path the path to the node to find; destructively modified
create whether to create the node if it does not exist
Returns:
the found/created node, or NULL if not found
See also:
datanode_lookup

Definition at line 87 of file datanode.c.

References datanode::first_child, datanode::key, datanode::last_child, datanode::next, and datanode::parent.

Referenced by datanode_copy(), datanode_lookup(), and datanode_read().

void datanode_read ( struct datanode node,
FILE *  stream,
const char *  type_char,
int  overwrite 
)

Reads nodes from a file stream into a given node.

Input format is identical to the output format for datanode_write. The ":type" segment is optional, with type set to 0 if emitted and left unchanged if type_chars is NULL (it still defaults to 0 for newly created nodes). Type is set via strchr(type_char, c) .

Parameters:
node the node to be filled
stream the input stream
type_char a string of characters indexed by node->type, or NULL if types should be ignored
overwrite whether to overwerite existing values
See also:
fx_module_write, struct fx_module, fx_type_marker

Definition at line 246 of file datanode.c.

References datanode_lookup_expert(), datanode::key, datanode::mod_type, unhex_in_place(), and datanode::val.

void datanode_write ( struct datanode node,
FILE *  stream,
const char *  type_char 
)

Prints all value-containing nodes beneath a given node in LRU (least recently used) order.

Node are printed in the format:

   /path/from/root/key:type value

Type is given by character type_char[node->type] if type_char is non-NULL; otherwise, it and its preceding colon are omitted. Nodes with negative val_type are not printed.

Due to conflicts with certain valid characters in keys and values (e.g. colons, spaces, and newlines), non-alphanumeric characters other than "_+,-.[]" are converted to 'XX', where XX is the hexadecimal ASCII value.

Parameters:
node the node to print
stream the output stream
type_char a string of characters indexed by node->type, or NULL if types should not be printed
See also:
fx_module_read, struct datanode

Definition at line 226 of file datanode.c.

References datanode::first_child, hex_to_stream(), datanode::mod_type, datanode::next, datanode::val, and datanode::val_type.

Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3