home *** CD-ROM | disk | FTP | other *** search
- // %PARAMETERS = "CH19LIST C:\UT2004"
- //Identifies the package
- //Script.uc
-
- //#1
- //Class preconditions:
- //This class depends on the Element class.
- //The test driver for this class is CH19_03LIST
-
- class Script extends Commandlet;
-
- //#2 Class attributes
- var private Array<Element> rgElements;
- var private int iLen;
-
- //#3
- //------------------------getElement---------------------
- public function Element getElement(int elNum){
- local Element locElement;
- local int iCtr;
- //if it does not exit, return a zero item
- locElement = new class'Element';
- locElement.setElementNum(0);
- //Verify the number of items in the array
- iLen = rgElements.Length;
- iCtr = 0;
- while(iCtr < iLen){
- if(elNum == rgElements[iCtr].getElementNum()){
- locElement = rgElements[iCtr];
- break;
- }//end if
- iCtr++;
- }//end while
- return locElement;
- }//end getElement
-
- //#4
- //-------------------addElement------------------------
- public function addElement(Element elToAdd){
-
- //insert element at end of array
- iLen = rgElements.Length;
- if(elToAdd.getElementNum() != 0){
- rgElements.Insert(iLen, 1);
- //insert the new element
- iLen = rgElements.Length;
- rgElements[iLen - 1] = elToAdd;
- }else{
- Log(" Cannot add an element with no identifier number.");
- }
- }//end addElement
-
-
- //#5
- //--------------------logElementInfo-------------------
- //Print the basic contents of an element
- private function logElementInfo(Element elToLog){
- //Do not try to access an element tha does not exist
- if(elToLog.getElementNum() != 0){
- Log(" " $ elToLog.getElementNum() );
- Log(" " $ elToLog.getElementName() );
- Log(" [" $ elToLog.getDirection() $ "]");
- Log(" " $ elToLog.getSpeech() );
- }else{
- Log(" Element not found");
- }
- }
-
- //#6
- //--------------------showBasicElement------------------
- //Use the number of an element to show it for display
- public function showBasicElement(int elNum){
- logElementInfo(getElement( elNum));
- }//end getElement
-
- //#7
- //--------------------getLength------------------
- //Obtain the length of the Script Elements array
- public function int getLength(){
- return iLen;
- }
-
- //#8
- //--------------------removeElement------------------
- public function removeElement(int elNum){
- //Delete the element with the specified identifer
- local int iCtr;
- //confirm current length;
- iLen = rgElements.Length;
- iCtr = 0;
- if( getElement(elNum).getElementNum() != 0){
- while(iCtr <= iLen){
- //when you find the number
- if(elNum == rgElements[iCtr].getElementNum()){
- Log(" Deleting: " $ rgElements[iCtr].getElementNum());
- rgElements.Remove(iCtr, 1);
- break;
- }//end if
- iCtr++;
- }//end while
- }//end if
- iLen = rgElements.Length;
- }
-