home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / eaclib.zip / EAList.hpp < prev    next >
C/C++ Source or Header  |  1996-05-22  |  6KB  |  151 lines

  1. /* --------------------------------------------------------------------------
  2.  * $RCSfile: EAList.hpp,v $
  3.  * $Revision: 1.1 $
  4.  * $Date: 1996/05/22 20:59:55 $
  5.  * $Author: Bablok $
  6.  * --------------------------------------------------------------------------
  7.  * Synopsis:
  8.  *
  9.  * Interface for class EAList. This class wraps the extended attributes API of
  10.  * OS/2 and handles complete sets of file-EAs.
  11.  *
  12.  * An EAList is implemented as a key sorted set. This allows the conversion
  13.  * of an EAList to a multivalued EA and back again.
  14.  *
  15.  * This file is part of the EA classlib package.
  16.  * Copyright Bernhard Bablok, 1996
  17.  *
  18.  * The EA classlib package is distributed in the hope that it will be
  19.  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  20.  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  21.  *
  22.  * You may use the classes in the package to any extend you wish. You are
  23.  * allowed to change and copy the source of the classes, as long as you keep
  24.  * the copyright notice intact and as long as you document the changes you made.
  25.  *
  26.  * You are not allowed to sell the EA classlib package or a modified version
  27.  * thereof, but you may charge for costs of distribution media.
  28.  *
  29.  * --------------------------------------------------------------------------
  30.  * Change-Log:
  31.  *
  32.  * $Log: EAList.hpp,v $
  33.  * Revision 1.1  1996/05/22 20:59:55  Bablok
  34.  * Initial revision
  35.  *
  36.  * -------------------------------------------------------------------------- */
  37.  
  38. #ifndef EALIST_H
  39.   #define EALIST_H
  40.  
  41.   #ifndef INCL_BASE
  42.      #define INCL_BASE
  43.      #include <os2.h>
  44.   #endif
  45.   #ifndef _IKSSET_H
  46.      #include <iksset.h>
  47.   #endif
  48.   #ifndef _ISTRING_
  49.      #include <istring.hpp>
  50.   #endif
  51.   #ifndef EA_H
  52.      #include "EA.hpp"
  53.   #endif
  54.  
  55.   #define EALIST_DEFAULT_SIZE   20
  56.  
  57.   class ostream;
  58.   class istream;
  59.  
  60.   class EAOps : public IStdMemOps, public IStdAsOps<EA> {
  61.      public:
  62.         IString const& key(EA const& ea) const {return ea.name();}
  63.         class KeyOps {
  64.            public:
  65.               long compare(const IString& string1, const IString& string2) const {
  66.                  return strcmpi(string1,string2);
  67.               }
  68.         } keyOps;
  69.   };
  70.  
  71.   typedef IGKeySortedSet<EA,IString,EAOps> EASet;
  72.  
  73.   class EAList : public EASet{
  74.  
  75.     public:
  76.  
  77.        // constructors, destructor   -------------------------------------------
  78.  
  79.        EAList() : EASet(EALIST_DEFAULT_SIZE), mFEA2List(NULL) {}
  80.        EAList(const EAList& eaList);
  81.        EAList(const IString& basename, const EA& ea);
  82.        EAList(const char* pathName) : EASet(EALIST_DEFAULT_SIZE),
  83.                                                               mFEA2List(NULL)  {
  84.           read((PVOID)pathName,true,false);
  85.        }
  86.        EAList(HFILE fileHandle) : EASet(EALIST_DEFAULT_SIZE), mFEA2List(NULL)  {
  87.           read((PVOID) &fileHandle,false,false);
  88.        }
  89.        ~EAList() {
  90.            if (mFEA2List)
  91.               delete mFEA2List;
  92.        }
  93.  
  94.        // get/set functions   --------------------------------------------------
  95.  
  96.        EAList& setValues(const EA& mvEA);
  97.  
  98.        // interaction with physical files   ------------------------------------
  99.  
  100.        EAList& read(const char* pathName, Boolean onlyEAsFromList=true) {
  101.           return read((PVOID)pathName,true,onlyEAsFromList);
  102.        }
  103.        EAList& read(HFILE fileHandle, Boolean onlyEAsFromList=true) {
  104.           return read((PVOID) &fileHandle,false,onlyEAsFromList);
  105.        }
  106.  
  107.        EAList& write(const char* pathName, Boolean useFEA2List=false) {
  108.           return write((PVOID)pathName,true,useFEA2List);
  109.        }
  110.        EAList& write(HFILE fileHandle, Boolean useFEA2List=false) {
  111.           return write((PVOID) &fileHandle,false,useFEA2List);
  112.        }
  113.  
  114.        EAList& remove(const char* pathName, Boolean onlyEAsFromList=true) {
  115.           return remove((PVOID)pathName,true,onlyEAsFromList);
  116.        }
  117.        EAList& remove(HFILE fileHandle, Boolean onlyEAsFromList=true) {
  118.           return remove((PVOID) &fileHandle,false,onlyEAsFromList);
  119.        }
  120.  
  121.        // operators   ----------------------------------------------------------
  122.  
  123.        EAList& operator=(const EAList& eaList);
  124.        friend ostream& operator<<(ostream& out, EAList& eaList);
  125.        friend istream& operator>>(istream& in, EAList& eaList);
  126.  
  127.     private:
  128.  
  129.        // data members   -------------------------------------------------------
  130.  
  131.        FEA2LIST *mFEA2List;
  132.  
  133.        // auxiliary functions   ------------------------------------------------
  134.  
  135.        EAList& read(PVOID fileRef,Boolean isPathName,Boolean onlyEAsFromList);
  136.        EAList& write(PVOID fileRef,Boolean isPathName,Boolean useFEA2List);
  137.        EAList& remove(PVOID fileRef,Boolean isPathName,Boolean onlyEAsFromList);
  138.  
  139.        EAList&   convert();                              // FEA2LIST -> EAList
  140.        GEA2LIST* createGEA2LIST() const;                 // read list
  141.        GEA2LIST* createGEA2LIST(DENA2* pDENA2) const;    // read all
  142.        FEA2LIST* createFEA2LIST();                       // write
  143.        FEA2LIST* createFEA2LISTBuffer();                 // write
  144.        FEA2LIST* createFEA2LISTBuffer(PVOID fileRef,     // read list
  145.                                  Boolean isPathName);
  146.        FEA2LIST* createFEA2LISTBuffer(DENA2* pDENA2);    // read all
  147.        DENA2*    queryDENA2(PVOID fileRef,               // read all
  148.                             Boolean isPathName) const;
  149.     };
  150. #endif
  151.