Objects can be stored on disk in a system-independent way. The object-by-name routines are used to accomplish this. Files are written in big-endian byte order, no matter what byte order the computer uses. Many objects can be stored in one file. The objects are stored in reusable blocks and can be modified and deleted. Compression is optional. All objects have a label attached that is stored in a btree structure. This index is stored in the same file.
Open an object with the number object_id. All plotting commands that are given after this call are now stored in this object (= display-list). Calls to g_open_object() can be nested.
object_id - The object identifier ID. Can be any positive number.
If successfull object_id is returned. G_ERROR is returned if object_id already exists.
void TestColor(void)
{
char *colornames[] = {
"G_BLACK",
"G_BLUE",
"G_GREEN",
"G_CYAN",
"G_RED",
"G_MAGENTA",
"G_BROWN",
"G_LIGHTGRAY",
"G_DARKGRAY",
"G_LIGHTBLUE",
"G_LIGHTGREEN",
"G_LIGHTCYAN",
"G_LIGHTRED",
"G_LIGHTMAGENTA",
"G_YELLOW",
"G_WHITE"};
int i,id;
id = g_unique_object();
g_open_object(id);
g_set_linestyle(G_SOLID);
g_set_linewidth(3);
g_set_viewport(1, 0.0, 0.0, 1.0, 1.0);
g_set_world(1,0,0,100,100);
g_select_viewport(1);
for (i=0; i< g_get_palettesize(); i++) {
g_set_foreground(G_BLACK);
g_moveto(10,5*i + 11);
g_label(colornames[i]);
g_set_foreground(i);
g_moveto(10,5*i + 10);
g_lineto(90,5*i + 10);
}
g_close_object(id);
g_call_object(id);
}
Close the object with the number object_id. All plotting commands that are given after the last object has been closed are now executed directly.
object_id - The object identifier ID.
If successfull object_id is returned. G_ERROR is returned if object_id does not exists or is already closed.
Reopen an object with the number object_id. All plotting commands that are given after this call are now appended to this object.
object_id - The object identifier ID.
If successfull'object_id is returned. G_ERROR is returned if'object_id does not exists, or is already open.
Delete an object with the number'object_id. If the opject is open, it is closed before it is deleted.
object_id - The object identifier ID.
If successfull object_id is returned. G_ERROR is returned if object_id does not exists.
Determine if an object with the identifier object_id exists.
object_id - The object identifier ID.
If successfull object_id is returned. G_ERROR is returned if object_id does not exists.
Return an unused object number. It is good practice to use this call every time when a new object is created.
An unused object identifier.
Set the status of object object_id. If an object is awake, its list of plotting commands is executed when a call to g_call_object() is made. If an object sleeps, it will not execute its plotting commands.
object_id - The object identifier ID.status -
G_AWAKE - The object is active. This is the default.G_SLEEP - Sets the object to inactive. The object still exists, but will not been displayed.
If successfull G_OK is returned. G_ERROR is returned if object_id does not exists.
Display the object object_id (play back the display list). If the object status is G_SLEEP the object will not be displayed.
object_id - The object identifier ID.
If successfull object_id is returned. G_ERROR is returned if object_id does not exists.
Return the number of existing objects.
List the status of all the objects. The number of the objects is returned in the array id, and the status (G_SLEEP or G_AWAKE) in the array status. The user has to allocate the memory for the arrays. Use g_count_objects() to determine the size of the arrays.
id - Returns an array that contains the object_id of all the objects.status - Returns a corresponding array with the status G_SLEEP or G_AWAKE.
Open an object with the number object_id, and the namelabel. All plotting commands that are given after this call are now stored in this object (= display-list). Calls to g_open_object_byname() can be nested.
object_id - The object identifier ID. Can be any positive number. If object_id is 0, a unique id is generated.label - The object identifier label. Has up to 32 significant characters.
If successfull object_id is returned. G_ERROR is returned if object_id already exists.
Close the object with the name label. All plotting commands that are given after the last object has been closed are now executed directly.
label - The object identifier label. Has up to 32 significant characters.
If successfull object_id is returned. G_ERROR is returned if object_id does not exists or is already closed.
Reopen an object with the name label. All plotting commands that are given after this call are now appended to this object.
label - The object identifier label. Has up to 32 significant characters.
If successfull object_id is returned. G_ERROR is returned if object_id does not exists, or is already open.
Delete an object with the name label. If the opject is open, it is closed before it is deleted.
label - The object identifier label. Has up to 32 significant characters.
If successfull object_id is returned. G_ERROR is returned if object_id does not exists.
Set the status of object with the name label. If an object is awake, its list of plotting commands is executed when a call to g_call_object() is made. If an object sleeps, it will not execute its plotting commands.
label - The object identifier label. Has up to 32 significant characters.status -
G_AWAKE - The object is active. This is the default.G_SLEEP - Sets the object to inactive. The object still exists, but will not been displayed.
If successfull object_id is returned. G_ERROR is returned if object_id does not exists.
Display the object`label (play back the display list). If the object status is G_SLEEP the object will not be displayed.
label - The object identifier label. Has up to 32 significant characters.
If successfull object_id is returned. G_ERROR is returned if object_id does not exists.
Return the number of existing objects that have a label attached.
List the names of all the objects. The user has to allocate the memory for the list, BUT NOT FOR THE LABELS THAT WILL BE ATTACED TO LIST. The list contains pointers to the actual labels in the object management system. NEVER modify or free a member of the list. Use g_count_objects_byname() to determine the size of list.
list - Returns an array that contains the lables of all the objects that have a name.
Return the object ID that corresponds to the name label.
The identifier ID of the object, or G_ERROR if an error occurs.
Return the object label that corresponds to the object identifier ID id. This label is a pointer to the actual label in the object management system. NEVER modify or free this label.
A pointer to the label of the object, or NULL if the object has no label.
Create an object-file on disk with the name name. The file is written in big-endian byte order, no matter what byte order the program is in. The objects are stored in reusable blocks and have a label attached that is stored in a btree structure.
name - The name of the file on disk.ident - A 16 byte identifier, that can be used for version controll.
Open an object-file on disk with the name name.
name - The name of the file on disk.write_enabled - FALSE if the file is to be opened read-only, TRUE otherwise.
The file handle that is used to read or write to the file, and G_ERROR on error.
Close an object-file on disk.
file_id - the file_handle of the object_file.
Return the identifier string of the file file_id (16 bytes).
file_id - the file_handle of the object_file.
Read an object from disk by the name label and store it in an object with the name label, and the identifier ID obj_id. If obj_id is 0, an unique number will be generated. If`replace is TRUE and obj_id is 0, and an object with the name label does already exists, obj_id will get the old number.
file_id - The file handle of the object file.obj_id - The identifier ID for the new object.
label - The label of the object, as it is stored on disk. Has up to 32 significant characters.
with_children - If TRUE, objects that are called from object label, will also be loaded if present in the file file_id.
replace - If TRUE, objects that are already present will be overwritten by label if they have the same name as `label' (or its children).
G_OK on success and G_ERROR otherwise.
char *s, *list[100], label[33];
int fp, num_items = 0, result, obj_id;
s = g_popup_getfilename(win_id, "Get object file", "*.gp");
if (s) {
if ((fp = g_open_object_file(s, FALSE)) == G_ERROR)
return;
if (g_first_fileobject(fp, label)!= G_ERROR)
do {
printf("Object name is: %s\n",label);
list[num_items] = (char*) malloc(33);
strcpy(list[num_items], label);
num_items++;
if (num_items == 100)
break;
} while (g_next_fileobject(fp, label)!= G_ERROR);
if (num_items == 0) {
g_close_object_file(fp);
return;
}
result = g_popup_listbox(win_id,"Objects in File", "Select Object",
num_items, list, 1, 8);
if (result) {
obj_id = g_unique_object();
printf("Calling Object: %s id = %d\n",list[result-1], obj_id);
g_read_fileobject(fp, obj_id, list[result-1], TRUE, TRUE);
g_call_object(obj_id);
}
while (num_items) {
free(list[num_items-1]);
num_items--;
}
g_close_object_file(fp);
}
Write object label to disk.
file_id - The file handle of the object file.label - The label of the. Has up to 32 significant characters.
with_children - If TRUE, objects that are called from object `label', will also be stored on disk.
replace - If TRUE, objects that are already present in file_id will be overwritten by label if they have the same name as label (or its children).
G_OK on success and G_ERROR otherwise.
int num_items, j;
int do_compression = TRUE;
char *list[100];
num_items = g_count_objects_byname();
g_list_objects_byname(list);
for (j=0;j <num_items;j++)
printf("%s\n", list[j]);
result = g_popup_listbox(win_id,"Objects in File", "Select Object",
num_items, list, 1, 8);
if (result) {
int fp;
char *s;
s = g_popup_saveas(win_id, "Object File", "gna.gp");
if (s) {
printf("Writing Object: %s\n",list[result-1]);
if ((fp = g_open_object_file(s, TRUE)) == G_ERROR) {
g_create_object_file(s,"GENTEST", do_compression);
fp = g_open_object_file(s, TRUE);
}
g_write_fileobject(fp, list[result-1], TRUE, TRUE);
g_close_object_file(fp);
}
}
Delete an object from disk by the name label.
file_id - The file handle of the object file.label - The label of the object, as it is stored on disk. Has up to 32 significant characters.
G_OK on success and G_ERROR otherwise.
Returns the label of the first object in the file file_id.
file_id - The file handle of the object file.label - The label of the object, as it is stored on disk. There has to be room to store 33 characters. the user is resposible to allocate memory for label, before this function is called.
G_OK on success and G_ERROR otherwise.
Returns the label of the next object in the file file_id.
file_id - The file handle of the object file.label - The label of the object, as it is stored on disk. There has to be room to store 33 characters. the user is resposible to allocate memory for label, before this function is called.
G_OK on success and G_ERROR otherwise.
Returns the label of the previous object in the file file_id.
file_id - The file handle of the object file.label - The label of the object, as it is stored on disk. There has to be room to store 33 characters. the user is resposible to allocate memory for label, before this function is called.
G_OK on success and G_ERROR otherwise.
Returns the label of the last object in the file file_id.
file_id - The file handle of the object file.label - The label of the object, as it is stored on disk. There has to be room to store 33 characters. the user is resposible to allocate memory for label, before this function is called.
G_OK on success and G_ERROR otherwise.