BRL-CAD
|
#include "common.h"
#include <stdio.h>
#include "vmath.h"
#include "bu/avs.h"
#include "rt/db5.h"
#include "rt/defines.h"
Go to the source code of this file.
Macros | |
#define | db_ident(a, b, c) +++error+++ |
Ensure that the on-disk database has been completely written out of the operating system's cache.
De-register a client of this database instance, if provided, and close out the instance.
Check if a specified path is a .g database file, based on identification (or not) of a valid .g file header. Returns the dbi_version if the file has a valid header, and -1 otherwise.
Note that this routine does NOT do the endian-flipping tests to spot big-endian v4 .g files in the case where a valid header is not found - files are assumed to be either v5 or little endian v4 formatted. Codes willing to take the performance vs robustness tradeoff of the endian flipping check (which will do more file reading than this basic check) should use db_open.
Dump a full copy of one database into another. This is a good way of committing a ".inmem" database to a ".g" file. The input is a database instance, the output is a LIBWDB object, which could be a disk file or another database instance.
Returns - -1 error 0 success
Obtain an additional instance of this same database. A new client is registered at the same time if one is specified.
Create a v5 database "free" object of the specified size, and place it at the indicated location in the database.
There are two interesting cases:
|
extern |
Change the size of a v5 database object.
If the object is getting smaller, break it into two pieces, and write out free objects for both. The caller is expected to re-write new data on the first one.
If the object is getting larger, seek a suitable "hole" large enough to hold it, throwing back any surplus, properly marked.
If the object is getting larger and there is no suitable "hole" in the database, extend the file, write a free object in the new space, and write a free object in the old space.
There is no point to trying to extend in place, that would require two searches through the memory map, and doesn't save any disk I/O.
Returns - 0 OK -1 Failure
|
extern |
A routine for merging together the three optional parts of an object into the final on-disk format. Results in extra data copies, but serves as a starting point for testing. Any of name, attrib, and body may be null.
|
extern |
The attributes are taken from ip->idb_avs
If present, convert attributes to on-disk format. This must happen after exporting the body, in case the ft_export5() method happened to extend the attribute set. Combinations are one "solid" which does this.
The internal representation is NOT freed, that's the caller's job.
The 'ext' pointer is accepted in uninitialized form, and an initialized structure is always returned, so that the caller may free it even when an error return is given.
Returns - 0 OK -1 FAIL
|
extern |
|
extern |
Given an external representation of a database object, convert it into its internal representation.
Returns - <0 On error id On success.
|
extern |
Get an object from the database, and convert it into its internal representation.
Applications and middleware shouldn't call this directly, they should use the generic interface "rt_db_get_internal()".
Returns - <0 On error id On success.
|
extern |
Convert the internal representation of a solid to the external one, and write it into the database.
Applications and middleware shouldn't call this directly, they should use the version-generic interface "rt_db_put_internal()".
The internal representation is always freed. (Not the pointer, just the contents).
Returns - <0 error 0 success
|
extern |
Make only the front (header) portion of a free object. This is used when operating on very large contiguous free objects in the database (e.g. 50 MBytes).
|
extern |
Make a complete, zero-filled, free object. Note that free objects can sometimes get quite large.
Given a variable-width length field character pointer (cp) in network order (XDR), store it in *lenp.
Format is typically expected to be one of: DB5HDR_WIDTHCODE_8BIT DB5HDR_WIDTHCODE_16BIT DB5HDR_WIDTHCODE_32BIT DB5HDR_WIDTHCODE_64BIT
Returns - The number of bytes of input that were decoded.
Given a variable-width length field in network order (XDR), store it in *lenp.
This routine processes unsigned values.
Returns - The number of bytes of input that were decoded.
|
extern |
Given a number to encode, decide which is the smallest encoding format which will contain it.
Given a value and a variable-width format spec, store it in network order.
Returns - pointer to next available byte.
|
extern |
Given a pointer to the memory for a serialized database object, get a raw internal representation.
Returns - on success, pointer to next unused byte in 'ip' after object got; NULL, on error.
|
extern |
Given a file pointer to an open geometry database positioned on a serialized object, get a raw internal representation.
Returns - 0 on success -1 on EOF -2 on error
Verify that this is a valid header for a BRL-CAD v5 database.
Returns - 0 Not valid v5 header 1 Valid v5 header
write an ident header (title and units) to the provided file pointer.
Returns - 0 Success -1 Error
|
extern |
Given that caller already has an external representation of the database object, update it to have a new name (taken from dp->d_namep) in that external representation, and write the new object into the database, obtaining different storage if the size has changed.
Changing the name on a v5 object is a relatively expensive operation.
Caller is responsible for freeing memory of external representation, using bu_free_external().
This routine is used to efficiently support MGED's "cp" and "keep" commands, which don't need to import and decompress objects just to rename and copy them.
Returns - -1 error 0 success
|
extern |
As the v4 database does not really have the notion of "wrapping", this function writes the object name into the proper place (a standard location in all granules).
|
extern |
Add name from dp->d_namep to external representation of solid, and write it into a file.
Caller is responsible for freeing memory of external representation, using bu_free_external().
The 'name' field of the external representation is modified to contain the desired name. The 'ep' parameter cannot be const.
THIS ROUTINE ONLY SUPPORTS WRITING V4 GEOMETRY.
Returns - <0 error 0 OK
NOTE: Callers of this should be using wdb_export_external() instead.
Retrieve all records in the database pertaining to an object, and place them in malloc()'ed storage, which the caller is responsible for free()'ing.
This loads the combination into a local record buffer. This is in external v4 format.
Returns - union record * - OK (union record *)0 - FAILURE
|
extern |
Retrieve 'len' records from the database, "offset" granules into this entry.
Returns - 0 OK -1 FAILURE
|
extern |
Store 'len' records to the database, "offset" granules into this entry.
Returns: 0 OK non-0 FAILURE
|
extern |
Obtains a object from the database, leaving it in external (on-disk) format.
The bu_external structure represented by 'ep' is initialized here, the caller need not pre-initialize it. On error, 'ep' is left un-initialized and need not be freed, to simplify error recovery. On success, the caller is responsible for calling bu_free_external(ep);
Returns - -1 error 0 success
|
extern |
Given that caller already has an external representation of the database object, update it to have a new name (taken from dp->d_namep) in that external representation, and write the new object into the database, obtaining different storage if the size has changed.
Caller is responsible for freeing memory of external representation, using bu_free_external().
This routine is used to efficiently support MGED's "cp" and "keep" commands, which don't need to import objects just to rename and copy them.
Returns - <0 error 0 success
|
extern |
Update the _GLOBAL object, which in v5 serves the place of the "ident" header record in v4 as the place to stash global information. Since every database will have one of these things, it's no problem to update it.
Returns - 0 Success -1 Fatal Error
Create a header for a v5 database.
This routine has the same calling sequence as db_fwrite_ident() which makes a v4 database header.
In the v5 database, two database objects must be created to match the semantics of what was in the v4 header:
First, a database header object.
Second, create a specially named attribute-only object which contains the attributes "title=" and "units=" with the values of title and local2mm respectively.
Note that the current working units are specified as a conversion factor to millimeters because database dimensional values are always stored as millimeters (mm). The units conversion factor only affects the display and conversion of input values. This helps prevent error accumulation and improves numerical stability when calculations are made.
This routine should only be used by db_create(). Everyone else should use db5_update_ident().
Returns - 0 Success -1 Fatal Error
Initialize conversion factors given the v4 database unit
|
extern |
A generic routine to determine the type of the database, (v4 or v5) and to invoke the appropriate db_scan()-like routine to build the in-memory directory.
It is the caller's responsibility to close the database in case of error.
Called from rt_dirbuild() and other places directly where a raytrace instance is not required.
Returns - 0 OK -1 failure
|
extern |
|
extern |
Scan a v5 database, sending each object off to a handler.
Returns - 0 Success -1 Fatal Error
|
extern |
Obtain the database version for a given database instance.
Returns 4 or 5 accordingly for v4 or v5 geometry database files. Returns -1 if dbip is invalid.
|
extern |
Detect whether a given geometry database file seems to be corrupt or invalid due to flipped endianness. Only relevant for v4 geometry files that are binary-incompatible with the runtime platform.
Returns true if flipping the endian type fixes all combination member matrices.
|
extern |
Transmogrify an existing directory entry to be an in-memory-only one, stealing the external representation from 'ext'.
Return the number of "struct directory" nodes in the given database.
For debugging, ensure that all the linked-lists for the directory structure are intact.
Returns - 0 if the in-memory directory is empty 1 if the in-memory directory has entries, which implies that a db_scan() has already been performed.
Returns a hash index for a given string that corresponds with the head of that string's hash chain.
|
extern |
This routine ensures that ret_name is not already in the directory. If it is, it tries a fixed number of times to modify ret_name before giving up. Note - most of the time, the hash for ret_name is computed once.
Inputs - dbip database instance pointer ret_name the original name noisy to blather or not
Outputs - ret_name the name to use headp pointer to the first (struct directory *) in the bucket
Returns - 0 success <0 fail
This routine takes a path or a name and returns the current directory pointer (if any) associated with the object.
If given an object name, it will look up the object name in the directory table. If the name is present, a pointer to the directory struct element is returned, otherwise NULL is returned.
If given a path, it will validate that the path is a valid path in the current database. If it is, a pointer to the current directory in the path (i.e. the leaf object on the path) is returned, otherwise NULL is returned.
If noisy is non-zero, a print occurs, else only the return code indicates failure.
Returns - struct directory if name is found RT_DIR_NULL on failure
|
extern |
Add an entry to the directory. Try to make the regular path through the code as fast as possible, to speed up building the table of contents.
dbip is a pointer to a valid/opened database instance
name is the string name of the object being added
laddr is the offset into the file to the object
len is the length of the object, number of db granules used
flags are defined in raytrace.h (RT_DIR_SOLID, RT_DIR_COMB, RT_DIR_REGION, RT_DIR_INMEM, etc.) for db version 5, ptr is the minor_type (non-null pointer to valid unsigned char code)
an laddr of RT_DIR_PHONY_ADDR means that database storage has not been allocated yet.
|
extern |
Given a pointer to a directory entry, remove it from the linked list, and free the associated memory.
It is the responsibility of the caller to have released whatever structures have been hung on the d_use_hd bu_list, first.
Returns - 0 on success non-0 on failure
For debugging, print the entire contents of the database directory.
Change the name string of a directory entry. Because of the hashing function, this takes some extra work.
Returns - 0 on success non-0 on failure
Updates the d_nref fields (which count the number of times a given entry is referenced by a COMBination in the database).
|
extern |
Given the internal form of a database object, return the appropriate 'flags' word for stashing in the in-memory directory of objects.
|
extern |
Given a database object in "raw" internal form, return the appropriate 'flags' word for stashing in the in-memory directory of objects.
This routine is called by the RT_GET_DIRECTORY macro when the freelist is exhausted. Rather than simply getting one additional structure, we get a whole batch, saving overhead.
This routine is called by the GET_SEG macro when the freelist is exhausted. Rather than simply getting one additional structure, we get a whole batch, saving overhead. When this routine is called, the seg resource must already be locked. malloc() locking is done in bu_malloc.
Read named MGED db, build toc.
|
extern |