[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4. Support Classes

Implementation of defined UNITs uses several support classes. Support classes are general library regardless of inside or outside ISIS.

Now, the following support classes are implemented.

4.1 root_object class  
4.2 c_array class  
4.3 bitvector class  
4.4 cyclic_queue class  
4.5 limited_counter class  
4.6 argument_parser class  
4.7 gdb_port class  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1 root_object class

root_object class is an abstract class which directs to its derived classes interface for copying objects, transferring streams, and checking invariant equations. Using this class as a root of hierarchy, a unique interface can be used in the hierarchy. Hardware units in ISIS often copies objects and transfers stream through the interface supported by root_object class.

root_object class is an abstract class, and it has pure virtual functions and virtual functions. Derived classes are required to give a definition of all pure virtual functions. Definition can be given to all other virtual functions if required.

int check_invariant(void) const
Checks the legality of object invariant equations. If invariant equations are legal, true is returned. By giving a new definition to the virtual function in derived classes which has data member, the check function of invariant equations can be re-defined.

root_object* new_object(void) const
Generates the same type object and returns its pointer. It is a pure virtual function. Using this function, same type objects can be generated without recognition of their type. For using this function, define the default constructor in the derived class, and define follows:

 
derived_class : public root_object
{
public:
    virtual root_object* new_object(void) const;
};

root_object* derived_class::new_object(void) const
{
    return new derived_class;
}

root_object* clone_object(void) const
Generates the same type object, copies the value of itself, and returns its pointer. It is a pure virtual function. Using this function, same type and same value objects can be generated without recognition of their type. For using this function, define the default constructor in the derived class, and define follows:

 
derived_class : public root_object
{
public:
    virtual root_object* new_object(void) const;
};

root_object* derived_class::new_object(void) const
{
    return new derived_class(*this);
}

void input(istream&)
Inputs data from the input-stream to the object. Since input operation function from input-stream is actually implemented by calling this virtual function, a new definition of this function modifies the implementation of stream input.

void output(ostream&) const
Outputs data to output-stream. Since output operation function to output-stream is actually implemented by calling this virtual function, a new definition of this function modifies the implementation of stream output.

If root_object is used as a virtual base class, new_object function and clone_object function cannot be used.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2 c_array class

c_array class is a container class which holds an array of specified typed objects. The interface is almost the same as STL vector class except that the size of array is fixed. The cost of execution time is the same as that of integrated array.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.3 bitvector class

bitvector is a container class which holds a boolean array. The interface is almost the same as STL bitset class except that the size of array can be changed.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4 cyclic_queue class

cyclic_queue class is a container class which holds a queue of specified type objects. The interface is almost the same as STL queue class.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5 limited_counter class

limited_counter class represents a counter for a limited range. It is a template class with its value as a parameter. Increment and decrement are allowed as an operation. The minimum value is 0, and as the maximum value, arbitrary integer value can be specified. If not specified, it becomes 1. Operations of ++ and -- are supported.

value_type max(void) const
Returns the maximum value of the counter.

value_type value(void) const
Returns the current value of the counter.

bool is_max(void) const
Checks whether the value is maximum or not.

const limited_counter& increment(void)
Increments the counter. If the value is at the maximum, nothing is done. It returns the value after the operation.

const limited_counter& decrement(void)
Decrements the counter. If the value is 0, nothing is done. It returns the value after the operation.

void clear(void)
Sets counter to 0.

void set_max(value_type)
Sets counter to the maximum value, and returns the maximum value.

bool check_invariant(void) const
Checks invariant equations.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.6 argument_parser class

argument_parser class interprets a command line parameter, and generates a database for reference. It supports four option forms: `-<char>', `-<char><value>', `--<str>' and `--<str>=<value>'. Option and non-option can be specified in any order. All options are registered in the database, and non-option is registered as a string array similar to the second parameter of main function. As an exception, when -- is specified in the command line, following options are treated as non-options.

`-<char>' and `--<str>' have a boolean value true or false, and `-<char><value>' and `--<str>=<value>' hold string. For checking the boolean true or not, defined member function is used, and for referring the string value, operator [] is used. For referring `-<char>' value, character is given as a key, and for `--<str>', string is given. defined function returns true or false. [] operation returns string if the value is defined, otherwise, NULL is returned.

For giving the parameter of the command line input, constructor parameter or set member function is used. Usually, the second parameter of main function argv plus one should be given. With this method, command line parameters other than the program itself can be stored in the database.

The following is a simple example. In this example, the output of number of total clocks is specified with `-c', the number of processors with `-p<n>', verbose output parameters with `--verbose', and the standard output file with `--stdout=<file>', respectively.

 
int main(int, char** argv)
{
    bool clock_flag = false, verbose_flag = false, punum = true;
    char* stdout_filename = NULL;
    argument_parser arg(argv + 1);
    if (arg.defined('c')) clock_flag = true;
    if (arg['p'] != NULL) punum = atoi(arg['p']);
    if (arg.defined("verbose")) verbose_flag = true;
    if (arg["stdout"] != NULL) stdout_filename = arg["stdout"];
    /* ... */
}

void set(const char* const)
Sets command line parameters.

void clear(void)
Removes the specified command line parameters.

bool defined(char) const
Returns true if `-<char>' is set on specified character.

bool defined(const char*) const
Returns true if `--<string>' is set on specified string.

const char* operator[](char) const
Returns the value of specified character in `-<char><value>' form.

const char* operator[](const char*) const
Returns the value of specified string in `--<string>=<value>' form.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.7 gdb_port class

gdb port class manages the communication between a simulator and gdb. It supports communication using TCP and UDP, and packet encoding. Communication is done only by send and receive member function. The receiving of acknowledge of packet sending and the sending of acknowledge of packet receiving are done automatically.

  1. The protocol is set with use_tcp or use_udp to TCP or UDP.

  2. The port number is set by set_port.

  3. Initialization is done with setup. If successful, true is returned.

  4. When TCP is used, connect waits the connection from client.

  5. send and receive are used for communication.

  6. When TCP is used, disconnect terminates the connection.

  7. shutdown terminates the communication.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Masaki WAKABAYASHI on September, 3 2003 using texi2html