next up previous contents
Next: Display objects Up: Function and Class Previous: Utility functions

Utility objects

 

The following objects are useful utility objects used throughout the program. Items which have a specific section listed for them are explained in detail in that section.

  
Table 6.1: VMD utility objects.

DLinkList

 

Description

A template class implementing a doubly linked list. This can be used to provide an arbitrary linked list of any type, which also has a built-in iterator.

Constructors

Internal data structures

Nonvirtual member functions

Method of use

This is a template, so a new linked list is created as follows: DLinkList<int> intLinkedList; Once created, new items can be added or removed, and the list may be iterated through by the use of reset, get, next, and prev routines.

Inform

 

Description

A streams-like utility object used to format messages for display at the console or other selectable ostream object. Messages are given to an Inform object via insertion operators ( <<), and the messages are printed out to a provided ostream device, prefixed by a certain string. A special manipulator `sendmsg' is used to signal when a mesage should be printed.

Each Inform object has a current `message level', which is also indicated when the messages are printed out. Routines are provided to set the current level of the Inform object, so that only messages with a level smaller than or equal to the current output level are printed. Levels range from 1 (most likely to be printed) to 10 (very unlikely to be printed). The main use of this feature in VMD is in conjunction with debugging messages, where the level of debugging information can be changed via text commands.

There are four global instances of Inform which are available to the entire program (as long as they include the file Inform.h):

Constructors

Enumerations, lists or character name arrays

Inform contains several manipulators used to determine how the message is printed or to do actions. They are:

Internal data structures

Nonvirtual member functions

Method of use

As stated, there are four global instances of Inform which should be used for printing all messages in VMD . They are used just like a stream, except the manipulator sendmsg is used instead of endl to signal that the string should be printed. An example: msgWarn << level3 << "This is a level-3 warning." << sendmsg; In this case, if msgWarn is on, and it's output level is greater than or equal to 3, then this message will be printed, otherwise it will be ignored.

For debugging messages (printed to msgDebug), make sure to use the MSGDEBUG macro, so that these debugging messages can be conditionally excluded from the executable.

Suggestions for future changes/additions

Right now, only the debug Inform object takes advantage of the message level facility, all other messages (information, warning, or error) are all level-1 messages. More messages should be printed out by VMD , but at different levels of verbosity and content, and text commands should be put in to control the current output level of msgInfo, msgWarn, and msgErr.

Text commands should be added to allow the message text to be sent to a file, or to the console (right now, they are always sent to the console). This would not be very difficult, a new text command would need to be added which would open a file, and call the destination routine with the respective ostream pointer.

NameList

 

Description

This is a template class which implements a simple associative array. A NameList consists of N items, where each item has a name, an index, and an associated data value (the type of which is determined by the type given to the template).

Constructors

Internal data structures

Nonvirtual member functions

Method of use

This is a template used to associate sets of data of any type with character strings (names). Names and data are added with add_name, and the other routines are used to query info about these names. Many objects in VMD use NameList s, for example the colors are all stored this way.

ResizeArray

 

Description

A template class which implements a dynamically-growing, automatically resizing array of data of a given type. Elements in the array may be accessed via the [] operator. When new data is added to the end of an array, the size of the array is automatically increased if necessary.

A ResizeArray has two sizes that are important:

Constructors

Internal data structures

Nonvirtual member functions

Method of use

A ResizeArray is created by specifying the type of data to store, i.e. ResizeArray<char *> stringArray; Once created, it looks just like an array, and you can use the [] operator to get and set data. For example: stringArray[3] = "Some text."; or cout << stringArray[3] << endl;

Stack

 

Description

A template class which implements a simple stack of arbitrary data. Items are pushed onto and popped off of the stack, or may just be copied from the stack.

Constructors

Internal data structures

Nonvirtual member functions

Method of use

You instantiate a stack by telling it how large it can grow, and then just push and pop data on/off the stack. If the stack gets too large or small, warning messagea are printed.

Timer

 

Description

The Timer class is used for timing various aspects of VMD . It is modeled after the CMMD_node_timers implemented on the CM5. Each Timer object is an accumulator that accumulates time whenever started. A Timer can be started and stopped multiple times, accumulating the total time from each cycle. Timer 's can also be cleared to set the accumulated time to zero. Each Timer tracks clock time, user cpu time, system cpu time, and total cpu time.

On the HPs and SGIs, these functions are based on the library routines times() and gettimeofday().

Constructors

Nonvirtual member functions

Method of use

The functions start(), stop(), and clear() are used to start, stop and clear a Timer . The functions clock_time(), cpu_time(), user_time(), and system_time() are used to report the current values of a Timer .

As example, to time both the total time to complete a loop and each iteration of the loop, the following code could be used:

 
 		  Timer total_time;

Timer iter_time;

total_time.start();

while ( . . .)

{

iter_time.start();

. . .

iter_time.stop();

printf("ITERATION TOOK %f secondsn", iter_time.clock_time());

iter_time.clear();

}

total_time.stop();

printf("TOTAL TIME %f secondsn", total_time.clock_time());



next up previous contents
Next: Display objects Up: Function and Class Previous: Utility functions



Andrew Dalke
Wed May 15 02:25:03 CDT 1996