Home Software Docs Tutorials Demos Databases Dictionaries Models Research Support Mailing Lists What's New
You are here: Standards / General / Tutorials / Software / Home  

 
  Method Files
black fading line


The ISIP Standard requires that class method file contain exactly one method definition. The standards for naming these files is shown on the filenaming page. In this section, we show a full definition of a class method file and then we explain each part of this file. Note that this page does not cover syntax in a detailed manner. For a discussion on style, see our page on programming style.

An example of a class method file is shown below.
// file: class/math/io/sof/sof_disp_0.cc
//

// isip include files
//
#include "sof.h"
#include "sof_constants.h"

// method: display_cc
//
// arguments:
//  FILE* fp: (input/output) file pointer to use for display
//
// return: a logical_1 value indicating status
//
// this method dumps the object index.
//
logical_1 Sof::display_cc(FILE* fp_a) {

// display a message
//
fprintf(fp_a, "object index for %ld objects:\n", num_objs_d);
if (num_objs_d == (int_4)0) {
return ISIP_TRUE;
}

// cycle through the list
//
for (int_4 n=0; n<num_objs_d; n++) {

// dump the object
//
fprintf(fp_a, "   object: %lu\n", (uint_4)n);
fprintf(fp_a, "\tname = %s\n", index_d[n].name);
fprintf(fp_a, "\ttag = %ld\n", index_d[n].tag);
fprintf(fp_a, "\tpos = %ld\n", index_d[n].pos);
fprintf(fp_a, "\tsize = %ld\n", index_d[n].size);
}

// exit gracefully
//
return ISIP_FALSE;
}
An item by item description follows:
// file: class/math/io/sof/sof_disp_0.cc
//
This section defines the filename according to the conventions set in the filenaming standards.


// isip include files
//
#include "sof.h"
#include "sof_constants.h"
These two include statements provide the class definition for the object to which this method belongs and contains a set of constants related to this class. It is not necessary to include the constants file header for each method if none of the constants are used. It is, however, necessary to include the class definition header. Note that these are in quotes so they refer to the local copy of the file, not necessarily the one pointed to in the include directory.

// method: display_cc
//
// arguments:
//  FILE* fp: (input/output) file pointer to use for display
//
// return: a logical_1 value indicating status
//
// this method dumps the object index.
//
This section is the standard comment block for any method written. It contains the method name, a description of the arguments, the return type and a brief synopsis of the method. This prototype must be strictly followed since this is often the only part of the method a person will look at when they are trying to re-use code.
The arguments are also designated as one of "input" or "output" or "input/output". This allows the user to easily determine the parameter passing arrangement for this method. Also notice that the "_a" is dropped from the parameter name in the comment block. If no arguments are necessary for this method then the proper form is:
// arguments: none // // return: a logical_1 value indicating
status
logical_1 Sof::display_cc(FILE*
fp_a) {
This is the method call line. By standard, the curly brace is placed at the end of the line followed by a blank line.

// display a message
//
fprintf(fp_a, "object index for %ld objects:\n", num_objs_d);
if (num_objs_d == (int_4)0) {
return ISIP_TRUE;
}

// cycle through the list
//
for (int_4 n=0; n<num_objs_d; n++) {

// dump the object
//
fprintf(fp_a, "   object: %lu\n", (uint_4)n);
fprintf(fp_a, "\tname = %s\n", index_d[n].name);
fprintf(fp_a, "\ttag = %ld\n", index_d[n].tag);
fprintf(fp_a, "\tpos = %ld\n", index_d[n].pos);
fprintf(fp_a, "\tsize = %ld\n", index_d[n].size);
}
The body of the method contains everything necessary to perform the desired function. Visit this link for pointers on style.

// exit gracefully
//
return ISIP_FALSE;
}
The final statement in the file is the return statement. It is a very rare occasion in our standard that a method will not have a return value. Most often the return value is a logical value indicating the status of the method; that is whether it succeeded or failed in its task - ISIP_TRUE or ISIP_FALSE respectively).
   
   
    Help / Support / Site Map / Contact Us / ISIP Home