home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / aplusplus-1.01-src.lha / GNU / src / amiga / APlusPlus-1.01 / libsource / AttrList.cxx < prev    next >
C/C++ Source or Header  |  1994-05-09  |  6KB  |  206 lines

  1. /******************************************************************************
  2.  **
  3.  **    C++ Class Library for the Amiga© system software.
  4.  **
  5.  **    Copyright (C) 1994 by Armin Vogt  **  EMail: armin@uni-paderborn.de
  6.  **    All Rights Reserved.
  7.  **
  8.  **    $Source: apphome:APlusPlus/RCS/libsource/AttrList.cxx,v $
  9.  **    $Revision: 1.5 $
  10.  **    $Date: 1994/05/09 21:17:52 $
  11.  **    $Author: Armin_Vogt $
  12.  **
  13.  ******************************************************************************/
  14.  
  15.  
  16. #include <APlusPlus/utility/AttrList.h>
  17.  
  18.  
  19. volatile static char rcs_id[] = "$Id: AttrList.cxx,v 1.5 1994/05/09 21:17:52 Armin_Vogt Exp Armin_Vogt $";
  20.  
  21.  
  22. struct TagItem *AttrList::tmp = NULL;
  23. AttrList *AttrList::tmpUser = NULL; 
  24. int AttrList::tmpMaxLength = 0;
  25.  
  26.  
  27. AttrList::AttrList(struct TagItem *tl) 
  28.     taglist = tl!=NULL?CloneTagItems(tl):NULL; 
  29. }
  30.  
  31. AttrList::AttrList(LONG tag1Type,...) 
  32.     taglist = CloneTagItems((struct TagItem*)&tag1Type);
  33. }
  34.  
  35. AttrList::AttrList(const AttrList& from) 
  36.     taglist = from.taglist!=NULL?CloneTagItems(from.taglist):NULL; 
  37. }
  38.         
  39. struct TagItem *AttrList::copyTagItems(struct TagItem *tlist)
  40. {
  41.     return CloneTagItems(tlist);
  42. }
  43.  
  44. void AttrList::freeTagItems(struct TagItem *tlist)
  45. {
  46.     FreeTagItems(taglist);
  47. }
  48.  
  49. AttrList::~AttrList() 
  50.     freeTagItems(taglist); 
  51. }
  52.  
  53. AttrList& AttrList::operator=(const AttrList& from) // assignment is copying
  54. {
  55.     if (this != &from)
  56.     {
  57.         freeTagItems(taglist);   
  58.         taglist = from.taglist!=NULL?CloneTagItems(from.taglist):NULL; 
  59.     }
  60.     return *this; 
  61. }        
  62.  
  63. BOOL AttrList::addAttrs(const AttrList& attrs)
  64.    /* Enhance the IntuiObject's attribute taglist with additional tags from the given
  65.       taglist in a way, that not already present tags will be added, while already
  66.       present remain untouched.
  67.       The new tags will be added at the head of the attribute taglist and initialised
  68.       to zero.
  69.       Note that setting the attributes is only possible by using public method
  70.       setAttributes() or protected method setAttrs() which both will involve the
  71.       ITransponder notification mechanism.
  72.    */
  73. {
  74.    /** Set tags in the modifying taglist that are already present in the attribute taglist 
  75.     ** to TAG_IGNORE. The remaining tags are added to the attribute taglist and set to 0.
  76.     **/
  77.     _dout("AttrList::addAttrs("<<attrs<<")\n"); 
  78.     if (taglist==NULL)
  79.     { 
  80.         taglist = CloneTagItems(attrs);    
  81.         _dout("addAttrs to null list.\n");
  82.         return TRUE; 
  83.     }    // for an empty AttrList only copy additional tags to this.
  84.      
  85.    if (FilterTagItems(taglist,(Tag*)attrs.taglist,TAGFILTER_NOT)>0)
  86.    {
  87.       // get the end of the taglist
  88.       struct TagItem *tag = attrs.taglist;
  89.       while (tag->ti_Tag != TAG_END)
  90.          tag++;
  91.         
  92.         // concatenate additional taglist to attribute taglist    
  93.       tag->ti_Tag = TAG_MORE;
  94.       tag->ti_Data = (ULONG)taglist;
  95.         
  96.         // copy concatenated taglist to a private memory (removes TAG_MORE)
  97.         struct TagItem *newTL;
  98.       if (NULL != (newTL = CloneTagItems(attrs.taglist)) )
  99.       {                
  100.          // free old private attribute taglist copy
  101.          freeTagItems(taglist);
  102.              
  103.          taglist = newTL;     // set to new concatenated attribute taglist.
  104.          _dout("IntuiObject has now attr: "<<*this<<") done.\n");
  105.          return TRUE;
  106.       }
  107.         else cerr << "OUT_OF_MEMORY";
  108.    }
  109.     else _dout("no additional tags found\n");
  110.     
  111.    return FALSE;
  112. }
  113.  
  114. BOOL AttrList::updateAttrs(const AttrList& attrlist)
  115.     /* updates the tag data in 'this' of tags present in both 'this' and 'attrlist'
  116.         with the corresponding tag data in attrlist.
  117.     */
  118. {
  119.     BOOL changed = FALSE;   // any changes done
  120.     AttrManipulator next(*this);
  121.     AttrIterator read(attrlist);
  122.     
  123.     _dout("IntuiObject::writeTags : ");
  124.    while (read())
  125.    {
  126.       if (next.findTagItem(read.tag()) )
  127.       {
  128.          if (read.data() != next.data())
  129.          {
  130.             next.writeData(read.data());
  131.             changed = TRUE;
  132.          }
  133.       }
  134.    }    
  135.     if (!changed) 
  136.     {
  137.         _dout(" no changes.\n"); 
  138.     }        
  139.     else
  140.     { 
  141.         _dout("\n");
  142.     }
  143.     return changed;  
  144. }
  145.  
  146. ULONG AttrList::mapAttrs(AttrList& mapAt)
  147.     /* Maps taglist according to mapAt. All tags that are not appearing
  148.       in the mapAt list are being deleted (set to TAG_IGNORE). Still remaining
  149.       valid tags will be mapped to the new tag identifiers in the mapAt list.
  150.    */
  151. {
  152.    MapTags(taglist,mapAt.taglist,FALSE);
  153.    // include miss is FALSE, so unmatched tags are being deleted.
  154.     // ERROR: MapTags() does NOT remove unmatched tags!!!!
  155.     // Bug fix: use subsequent FilterTagItems().
  156.     return filterAttrs(mapAt);
  157.    //return 1L;
  158. }
  159. ULONG AttrList::mapAttrs(struct TagItem *mapList)
  160. {
  161.     MapTags(taglist,mapList,FALSE);
  162.     return filterAttrs(mapList);
  163. }
  164.  
  165. ULONG AttrList::filterAttrs(AttrList& filterAt)
  166.    /* Filters taglist according to filterTags. All tags that are not appearing
  167.       in the filterTags array are deleted (set to TAG_IGNORE).
  168.       The number of tags that are not set to TAG_IGNORE is returned.
  169.    */
  170. {
  171.    return FilterTagItems(taglist,(Tag*)filterAt.taglist,TAGFILTER_AND);
  172. }
  173. ULONG AttrList::filterAttrs(struct TagItem *filterList)
  174. {
  175.     return FilterTagItems(taglist,(Tag*)filterList,TAGFILTER_AND);
  176.  
  177. }
  178.  
  179.  
  180. //------------------- AttrIterator methods ----------------------------------------
  181.  
  182. BOOL AttrIterator::findTagItem(Tag tagVal)
  183.     /** This method assumes that NextTagItem() keeps track of the scanned taglist with 
  184.      ** the 'tstate' pointer referencing to the next tag item to be fetched with NextTagItem().
  185.      ** Since NextTagItem() does not return TAG_MORE ,TAG_SKIP and TAG_END the found tag item 
  186.      ** must be a user tag thus the following tag item is at the successing (TagItem*) address.
  187.      **/
  188.     if (NULL != (atTag = FindTagItem(tagVal,tstate)))
  189.     {
  190.         tstate = atTag+1;    // set NextTagItem() internal track to next tag item
  191.         return TRUE;
  192.     }
  193.     else return FALSE;
  194. }
  195.               
  196. ostream& operator << (ostream& OS,const AttrList& attrlist)
  197. {
  198.     OS <<"<"<< attrlist.taglist <<">"<<endl;
  199.     return OS ;          
  200. }
  201.