"Fossies" - the Fresh Open Source Software Archive

Member "ivtools-ivtools-2.0.4/src/Attribute/attrlist.h" (9 Oct 2020, 10363 Bytes) of package /linux/misc/ivtools-ivtools-2.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "attrlist.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 2001 Scott E. Johnston
    3  * Copyright (c) 1996-1999 Vectaport Inc.
    4  *
    5  * Permission to use, copy, modify, distribute, and sell this software and
    6  * its documentation for any purpose is hereby granted without fee, provided
    7  * that the above copyright notice appear in all copies and that both that
    8  * copyright notice and this permission notice appear in supporting
    9  * documentation, and that the names of the copyright holders not be used in
   10  * advertising or publicity pertaining to distribution of the software
   11  * without specific, written prior permission.  The copyright holders make
   12  * no representations about the suitability of this software for any purpose.
   13  * It is provided "as is" without express or implied warranty.
   14  *
   15  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
   16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
   17  * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL,
   18  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
   19  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
   20  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
   21  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   22  * 
   23  */
   24 
   25 /*
   26  * AttributeList - a list of attributes
   27  */
   28 
   29 #ifndef attr_list_h
   30 #define attr_list_h
   31 
   32 #include <leakchecker.h>
   33 
   34 #include <OS/enter-scope.h>
   35 #include <InterViews/resource.h>
   36 #include <Attribute/classid.h>
   37 #include <Attribute/aliterator.h>
   38 
   39 #ifndef ALITERATOR
   40 #define ALIterator _lib_iv(Iterator)
   41 #define AList _lib_iv(UList)
   42 #endif
   43 
   44 class ALIterator;
   45 class AList;
   46 
   47 #include <iosfwd>
   48 
   49 class Attribute;
   50 class AttributeValue;
   51 class ParamStruct;
   52 
   53 //: list of Attribute objects, i.e. a property list.
   54 // An AttributeList is derived from Resource, so it is a reference-counted
   55 // object that can be freely shared between other objects.
   56 //
   57 // An AttributeList assumes responsibility for the memory of its member
   58 // Attribute objects, which in turn assume responsibility for the memory
   59 // of their member AttributeValue objects.
   60 class AttributeList : public Resource {
   61 public:
   62     AttributeList(AttributeList* = nil);
   63     // construct with optional AttributeList to copy.
   64     virtual ~AttributeList();
   65     // do not call directly.  Frees memory of associated Attribute objects.
   66 
   67     void add_attr(const char* name, AttributeValue& value); 
   68     // add attribute by making copy of an AttributeValue.
   69     void add_attr(const char* name, AttributeValue* value); 
   70     // add attribute by using pointer to AttributeValue, assuming responsibility
   71     void add_attr(int symid, AttributeValue& value); 
   72     // add attribute by making copy of an AttributeValue.
   73     void add_attr(int symid, AttributeValue* value); 
   74     // add attribute by using pointer to AttributeValue, assuming responsibility
   75     // for the memory.
   76 
   77     void add_attribute(Attribute* attr);
   78     // add complete Attribute object to the list, accepting responsibility
   79     // for the memory of the Attribute object. 
   80 
   81     void First(ALIterator&);
   82     // set iterator to point to first Attribute in list.
   83     void Last(ALIterator&);
   84     // set iterator to point to last Attribute in list.
   85     void Next(ALIterator&);
   86     // set iterator to point to next Attribute in list.
   87     void Prev(ALIterator&);
   88     // set iterator to point to previous Attribute in list.
   89     boolean Done(ALIterator);
   90     // return true if iterator is pointing off the end of the list.
   91     // works for forward and backward traversals.
   92     boolean IsEmpty();
   93     // true if no Attribute objects in list.
   94     int Number() const;
   95     // number of Attribute objects in list.
   96 
   97     Attribute* GetAttr(const char*);
   98     // get attribute by name.
   99     Attribute* GetAttr(int symid);
  100     // get attribute by symbol id.
  101     Attribute* GetAttr(ALIterator);
  102     // get attribute pointed to by iterator.
  103     void SetAttr(Attribute*, ALIterator&);
  104     // set attribute pointed to by iterator.
  105     boolean Includes(Attribute*);
  106     // check if list includes Attribute by pointer-comparison.
  107     void Remove(Attribute*);
  108     // remove Attribute from list, returning responsibility for freeing the
  109     // associated memory.
  110 
  111     AList* Elem(ALIterator);
  112     // return AList (UList) pointed to by ALIterator (Iterator).
  113     Attribute* Attr(AList*);
  114     // return attribute pointed to by AList (UList).
  115 
  116     AttributeList* merge(AttributeList*);
  117     // merge the contents of another AttributeList into this one,
  118     // replicating the AttributeValue as needed.
  119 
  120     static void print_attrlist(AttributeList* al);
  121     // print AttributeList to stdout
  122 
  123     static void print_attrlist(std::ostream& out, AttributeList* al);
  124     // print AttributeList to out
  125 
  126 protected:
  127     void Append(Attribute*);
  128     // append Attribute to end of list.  Could cause duplicates.
  129     void Prepend(Attribute*);
  130     // append Attribute to front of list.  Could cause duplicates.
  131     void InsertAfter(ALIterator, Attribute*);
  132     // append Attribute after position pointed by iterator.  Could cause duplicates.
  133     void InsertBefore(ALIterator, Attribute*);
  134     // append Attribute before position pointed by iterator.  Could cause duplicates.
  135     void Remove(ALIterator&);
  136     // remove Attribute pointed to by iterator from the list, 
  137     // returning responsibility for freeing the associated memory.
  138     // This requires saving a pointer to the Attribute before calling this method.
  139 
  140     void clear(); 
  141     // empty AttributeList, deleting all Attributes.
  142 
  143 
  144 public:
  145     friend ostream& operator << (ostream& s, const AttributeList&);
  146     // print list to ostream.
  147 
  148     void dump();
  149     // utility method to call ostream output method.
  150 
  151     AttributeValue* find(const char*);
  152     // find AttributeValue by symbol.
  153     AttributeValue* find(int symid);
  154     // find AttributeValue by symbol id.
  155 
  156 protected:
  157     int add_attr(Attribute* attr);
  158     // add attribute, returning 0 if new, -1 if it already existed.
  159     // When -1 is returned you need to clear the valueptr of 'attr' before 
  160     // deleting it.  That's why this is protected.
  161 
  162     AList* _alist;
  163     unsigned int _count;
  164 
  165     CLASS_SYMID("AttributeList");
  166 };
  167 
  168 //: list of AttributeValue objects.
  169 // An AttributeValueList is derived from Resource, so it is a reference-counted
  170 // object that can be freely shared between other objects.
  171 //
  172 // An AttributeValueList assumes responsibility for the memory of its member
  173 // AttributeValue objects.
  174 class AttributeValueList : public Resource {
  175 public:
  176     AttributeValueList(AttributeValueList* = nil);
  177     // construct with optional AttributeValueList to copy.
  178     virtual ~AttributeValueList();
  179     // do not call directly.  Frees memory of associated AttributeValue objects.
  180 
  181 public:
  182     void First(ALIterator&);
  183     // set iterator to point to first AttributeValue in list.
  184     void Last(ALIterator&);
  185     // set iterator to point to last AttributeValue in list.
  186     void Next(ALIterator&);
  187     // set iterator to point to next AttributeValue in list.
  188     void Prev(ALIterator&);
  189     // set iterator to point to previous AttributeValue in list.
  190     boolean Done(ALIterator);
  191     // return true if iterator is pointing off the end of the list.
  192     // works for forward and backward traversals.
  193     boolean IsEmpty();
  194     // true if no AttributeValue objects in list.
  195     const int Number();
  196     // number of AttributeValue objects in list.
  197 
  198     void Append(AttributeValue*);
  199     // append AttributeValue to end of list.
  200     void Prepend(AttributeValue*);
  201     // append AttributeValue to front of list.
  202     void InsertAfter(ALIterator, AttributeValue*);
  203     // insert AttributeValue after position pointed to by iterator.
  204     void InsertBefore(ALIterator, AttributeValue*);
  205     // insert AttributeValue before position pointed to by iterator.
  206     void Remove(AttributeValue*);
  207     // remove AttributeValue from list, returning responsibility for freeing the
  208     // associated memory.
  209     void Remove(ALIterator&);
  210     // remove AttributeValue pointed to by iterator from the list, 
  211     // returning responsibility for freeing the associated memory.
  212     // This requires saving a pointer to the AttributeValue before calling this method.
  213     AttributeValue* Replace(ALIterator&, AttributeValue*);
  214     // remove AttributeValue pointed to by iterator from the list, 
  215     // returning responsibility for freeing the associated memory.
  216     // Then insert new AttributeValue in the same place.
  217 
  218 
  219     AttributeValue* GetAttrVal(ALIterator);
  220     // get AttributeValue pointed to by iterator.
  221     void SetAttrVal(AttributeValue*, ALIterator&);
  222     // set AttributeValue pointed to by iterator.
  223     boolean Includes(AttributeValue*);
  224     // check if list includes AttributeValue by pointer-comparison.
  225 
  226     AttributeValue* Get(unsigned int index);
  227     // retrieve value by index, return nil if not there
  228     AttributeValue* Set(unsigned int index, AttributeValue* av);
  229     // set value by index, increase list length if necessary with nil padding,
  230     // take responsibility for the memory (and return responsibility for old memory)
  231     void Insert(int index, AttributeValue* av);
  232     // insert value after index, use -1 to insert at beginning
  233     // take responsibility for the memory (and return responsibility for old memory)
  234 
  235     AList* Elem(ALIterator); 
  236     // return AList (UList) pointed to by ALIterator (Iterator).
  237     AttributeValue* AttrVal(AList*);
  238     // return AttributeValue pointed to by AList (UList).
  239 
  240     friend ostream& operator << (ostream& s, const AttributeValueList&);
  241     // print list to ostream.
  242 
  243     void clear(); 
  244     // empty AttributeValueList, deleting all AttributeValue's.
  245 
  246     void nested_insert(boolean flag) { _nested_insert = flag; }
  247     // set flag to insert in a nested fashion
  248 
  249     boolean nested_insert() { return _nested_insert; }
  250     // get flag to insert in a nested fashion
  251 
  252     int max_out() { return _max_out; }
  253     // get maximum to print 
  254     void max_out(int num) { _max_out = num; }
  255     // set maximum to print 
  256 
  257     boolean Equal(AttributeValueList* avl);
  258     boolean GreaterThan(AttributeValueList* avl);
  259     boolean LesserThan(AttributeValueList* avl);
  260 
  261 protected:
  262     AList* _alist;
  263     unsigned int _count;
  264     boolean _nested_insert;
  265     int _max_out;
  266     int _prevget_i;
  267     ALIterator _prevget_it;
  268 
  269 #ifdef LEAKCHECK
  270  public:
  271     static LeakChecker* _leakchecker;
  272 #endif
  273 };
  274 
  275 #endif