Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

attr.H

Go to the documentation of this file.
00001 /*----------------------------------------------------------------
00002  *   Name:        attr.h
00003  *
00004  *   Designer:    Willie Glover
00005  *
00006  *   Created:     4/02/96
00007  *
00008  *   Description: This file contains the LEGO header file which
00009  *                defines the attr structure of the LEGO IR.
00010  *
00011  *   Location:    /ncsu/tinker/LEGO/src/base/attr.h
00012  *
00013  *
00014  * 4/02/96 WTG:  Added structure for attrs. Used by op and graph.
00015  * 8/10/96 WTG:  Added support for operands and list of values.
00016  * 8/18/96 WTG:  Added support for writing REBEL.
00017  * 12/3/96 WAH:  Added copy constructors.
00018  * 2/26/97 WAH:  Fixed ~attrs to delete nextLcEntryPtr.
00019  * 3/20/97 WAH:  Renamed SetValue SetValid (was a mistake).
00020  * 4/7/97 WAH:   Filled in intList destructor.
00021  * 9/5/97 WAH:   Switched to enums in globals.H.
00022  * 10/10/97 WAH: Added support for legoOprd::parentPtr.
00023  * 1/9/98 WAH:   Fixed SetAttrString to handle NULL.
00024  * 1/27/98 WAH:  Fixed destructor to delete operand & intList.
00025  * 4/22/98 WAH:  Updated legoOprd::parentPtr; added legoOp *
00026  *               parameter to copy constructor.
00027  *---------------------------------------------------------------*/
00028 
00029 #ifndef ATTR_H
00030 #define ATTR_H
00031 
00032 //class legoOprd;
00033 #include "legoOprd.H"
00034 #include "globals.H"
00035 
00036 class intList {
00037    int      attrValue;        // attribute value
00038    int      valid;            // 0=invalid
00039    intList* nextIntListPtr;   // ptr to next item
00040 public:
00041   intList()
00042   {
00043     //    fprintf(stderr,"Creating INTLIST %p\n", this);
00044     attrValue = 0;
00045     valid = 0;
00046     nextIntListPtr = NULL;
00047   }
00048   intList (const intList &orig)
00049   {
00050     attrValue = orig.attrValue;
00051     valid = orig.valid;
00052     if (orig.nextIntListPtr != NULL)
00053       nextIntListPtr = new intList (*(orig.nextIntListPtr));
00054     else
00055       nextIntListPtr = NULL;
00056     //    fprintf(stderr,"Creating INTLIST %p\n", this);
00057   } // end copy constructor
00058   ~intList()
00059   {
00060     intList *tmpIntListPtr = NULL;
00061     while (nextIntListPtr != NULL)
00062       {
00063         tmpIntListPtr = nextIntListPtr;
00064         nextIntListPtr = tmpIntListPtr->nextIntListPtr;
00065         tmpIntListPtr->nextIntListPtr = NULL;
00066         delete tmpIntListPtr;
00067       } // end while
00068     //    fprintf(stderr,"Deleting ATTRS %p\n", this);
00069   } // end destructor
00070 
00071 /*--------------------------------------------------------
00072  * Get attrValue
00073  *--------------------------------------------------------*/
00074 int     GetAttrValue(void) { return attrValue; }
00075 
00076 /*--------------------------------------------------------
00077  * Get valid
00078  *--------------------------------------------------------*/
00079 int     GetValid(void) { return valid; }
00080 
00081 /*--------------------------------------------------------
00082  * Get nextIntListPtr
00083  *--------------------------------------------------------*/
00084 intList  *GetNextIntListPtr(void) { return nextIntListPtr; }
00085 
00086 /*---------------------------------------------------------
00087  * Set attrValue
00088  *-------------------------------------------------------*/
00089 void    SetAttrValue(unsigned newValue) {attrValue = newValue; }
00090 
00091 /*---------------------------------------------------------
00092  * Set valid
00093  *-------------------------------------------------------*/
00094 void    SetValid(unsigned newValid) {valid = newValid; }
00095 
00096 /*---------------------------------------------------------
00097  * Set nextIntListPtr
00098  *-------------------------------------------------------*/
00099 void    SetNextIntListPtr(intList *newPtr) {nextIntListPtr = newPtr; }
00100 
00101 };
00102 
00103 class attrs {
00104    enum attrTypes attrType;  // See enumeration below (globals.H)
00105    int attrId;            // current index value in REBEL dictionary
00106    int oldAttrId;         // original index in REBEL dictionary
00107    intList *attrValPtr;   // NULL unless attrType is bb_id or freq
00108                           //  note that bb_id takes only 1 value
00109    char* attrString;      // ptr to attr string
00110                           // NULL if attrType is not lc
00111    attrs *nextLcEntryPtr; // Use this pointer to build list of string/oprd
00112                           //  when the attrType = lc and there is more than
00113                           //  one parameter.
00114    legoOprd *attrOprdPtr; // ptr to list of operands
00115                           // NULL if attrType is not live or lc
00116    attrs *nextAttrPtr;    // pointer to next attr entry
00117 
00118 public:
00119 
00120        attrs(void)
00121        {
00122          //      fprintf(stderr,"Creating ATTRS %p\n", this);
00123          attrType = ATTR_UNDEF;  // undefined
00124          attrId = 0;           // undefined
00125          oldAttrId = 0;        // undefined
00126          attrValPtr = NULL;
00127          attrString = NULL;
00128          nextLcEntryPtr = NULL;
00129          attrOprdPtr = NULL;
00130          nextAttrPtr = NULL;
00131        }
00132 
00133   attrs(attrs &orig, legoOp *op, int newId = -1)
00134   {
00135     //    fprintf(stderr,"Creating ATTRS %p\n", this);
00136     attrType = orig.attrType;
00137     if (newId == -1)
00138       attrId = orig.attrId;  // id will be changed anyway
00139     else
00140       attrId = newId;
00141     oldAttrId = orig.oldAttrId;
00142     if (orig.attrValPtr != NULL)
00143       attrValPtr = new intList (*(orig.attrValPtr));
00144     else
00145       attrValPtr = NULL;
00146     if (orig.attrString != NULL)
00147       {
00148         attrString = new char [strlen (orig.attrString) + 1];
00149         strcpy (attrString, orig.attrString);
00150       } // end if
00151     else
00152       attrString = NULL;
00153     if (orig.nextLcEntryPtr != NULL)
00154       nextLcEntryPtr = new attrs (*(orig.nextLcEntryPtr), op, newId);
00155     else
00156       nextLcEntryPtr = NULL;
00157     if (orig.attrOprdPtr != NULL)
00158       {
00159         attrOprdPtr = new legoOprd (*(orig.attrOprdPtr));
00160         attrOprdPtr->SetParentOpPtr (op);
00161         attrOprdPtr->SetParentAttrPtr (this);
00162       } // end if
00163     else
00164       attrOprdPtr = NULL;
00165     nextAttrPtr = NULL;  // don't duplicate (dictionary;will be changed anyway)
00166   } // end copy constructor
00167 
00168   ~attrs(void)
00169   {
00170     delete[] attrString;
00171     delete attrOprdPtr;
00172     delete attrValPtr;
00173     /*
00174      * Remove storage associated with all attributes linked
00175      * as lcode attributes.
00176      */
00177     attrs *tmpAttrPtr = NULL;
00178     while (nextLcEntryPtr != NULL) {
00179       tmpAttrPtr = nextLcEntryPtr;
00180       nextLcEntryPtr = tmpAttrPtr->nextLcEntryPtr;
00181       tmpAttrPtr->nextLcEntryPtr = NULL;
00182       delete tmpAttrPtr;
00183     }
00184     /*
00185      * Remove storage associated with all attributes linked
00186      * in this chain.
00187      */
00188     while (nextAttrPtr != NULL) {
00189       tmpAttrPtr = nextAttrPtr;
00190       nextAttrPtr = tmpAttrPtr->nextAttrPtr;
00191       tmpAttrPtr->nextAttrPtr = NULL;
00192       delete tmpAttrPtr;
00193     }
00194     //    fprintf(stderr,"Deleting ATTRS %p\n", this);
00195   } // end destructor
00196 
00197 /*---------------------------------------------------------
00198  * Get attribute type
00199  *-------------------------------------------------------*/
00200 enum attrTypes GetAttrType(void) { return attrType; }
00201 
00202 /*---------------------------------------------------------
00203  * Get attribute index
00204  *-------------------------------------------------------*/
00205 int GetAttrId(void) { return attrId; }
00206 
00207 /*---------------------------------------------------------
00208  * Get original REBEL file library index
00209  *-------------------------------------------------------*/
00210 int GetOldAttrId(void) { return oldAttrId; }
00211 
00212 /*---------------------------------------------------------
00213  * Get pointer to value of freq attribute or bb_id attribute.
00214  * Undefined for other attributes.
00215  *-------------------------------------------------------*/
00216 intList  *GetAttrValPtr(void) { return attrValPtr; }
00217 
00218 /*---------------------------------------------------------
00219  * Get string associated with lc attributes
00220  *-------------------------------------------------------*/
00221 char *GetAttrString(void) { return attrString; }
00222 
00223 /*---------------------------------------------------------
00224  * Get pointer to next lc parameter of this attribute.
00225  * NULL for other attribute types.
00226  *-------------------------------------------------------*/
00227 attrs  *GetNextLcEntryPtr(void) { return nextLcEntryPtr; }
00228 
00229 /*---------------------------------------------------------
00230  * Get operand list associated with live and lc attributes
00231  *-------------------------------------------------------*/
00232 legoOprd *GetAttrOprdPtr(void) { return attrOprdPtr; }
00233 
00234 /*---------------------------------------------------------
00235  * Get pointer to next attribute
00236  *-------------------------------------------------------*/
00237 attrs *GetNextAttrPtr(void) { return nextAttrPtr; }
00238 
00239 /*---------------------------------------------------------
00240  * Update attribute type
00241  *-------------------------------------------------------*/
00242 void SetAttrType(enum attrTypes newType) {attrType = newType; }
00243 
00244 /*---------------------------------------------------------
00245  * Update attribute index.
00246  *-------------------------------------------------------*/
00247 void SetAttrId(unsigned newIndex) {attrId = newIndex; }
00248 
00249 /*---------------------------------------------------------
00250  * Update original REBEL file library index.
00251  * This method should only be used by the REBEL parser.
00252  *-------------------------------------------------------*/
00253 void SetOldAttrId(unsigned newIndex) {oldAttrId = newIndex; }
00254 
00255 /*---------------------------------------------------------------
00256  * Updtae pointer to value of freq attribute or bb_id attribute.
00257  *--------------------------------------------------------------*/
00258 void SetAttrValPtr(intList *newValPtr) {attrValPtr = newValPtr; }
00259 
00260 /*---------------------------------------------------------
00261  * Update string associated with lc attributes
00262  *-------------------------------------------------------*/
00263 void SetAttrString(char *newString)
00264   {
00265     delete[] attrString;
00266     if (newString != NULL)
00267       {
00268         attrString = new char[strlen(newString)+1];
00269         (void)strcpy(attrString,newString);
00270       } // end if
00271     else attrString = NULL;
00272   }
00273 
00274 /*---------------------------------------------------------
00275  * Update pointer to next lc parameter of this attribute.
00276  * This operation is undefined for other attribute types.
00277  *-------------------------------------------------------*/
00278 void SetNextLcEntryPtr(attrs *newEntryPtr)
00279   { nextLcEntryPtr = newEntryPtr; }
00280 
00281 /*---------------------------------------------------------
00282  * Update pointer to operand list for live and lc attributes
00283  *-------------------------------------------------------*/
00284 void SetAttrOprdPtr(legoOprd *newOprdPtr)
00285   {attrOprdPtr = newOprdPtr; }
00286 
00287 /*---------------------------------------------------------
00288  * Update pointer to next attribute
00289  *-------------------------------------------------------*/
00290 void SetNextAttrPtr(attrs *newPtr) {nextAttrPtr = newPtr; }
00291 
00292 };
00293 //--------------------------------------------------------------
00294 //  attribute type
00295 //   0 = ATTR_UNDEF
00296 //   1 = ATTR_LC
00297 //   2 = ATTR_MS     *** not implemented ***
00298 //   3 = ATTR_BBID
00299 //   4 = ATTR_FREQ
00300 //   5 = ATTR_LIVE
00301 //--------------------------------------------------------------
00302 #endif

Generated on Mon Jul 21 20:23:59 2003 for TINKER LEGO DOC by doxygen 1.3.2