#ifndef _NSRAUX_ // -*-c++-*-
#define _NSRAUX_

//----------------------------------------------------------------------
//  nsrAux.h
//   Miscellaneous classes for shared use between ms and ss.
//
//      Unpublished Confidential Information of Hewlett-Packard
//      Company. Do not disclose.  Copyright (c) Hewlett-Packard
//      Company 1995. All rights reserved
// 
// The contents of this software are proprietary and confidential to
// the Hewlett- Packard Company, and are limited in distribution to
// those with a direct need to know.  Individuals having access to
// this software are responsible for maintaining the confidentiality
// of the content and for keeping the software secure when not in use.
// Transfer to any party is strictly forbidden other than as expressly
// permitted in writing by Hewlett-Packard Company.  Unauthorized
// transfer to or possession by any unauthorized party may be a
// criminal offense.
//
//                  RESTRICTED RIGHTS LEGEND
//
//      Use,  duplication,  or disclosure by the U. S. Government is
//      subject to restrictions as set forth in subparagraph (c) (1)
//      (ii) in the Rights in Technical Data and Computer Software
//      clause in DFARS 252.227-7013 or any other successor clause.
//
//                      HEWLETT-PACKARD COMPANY
//                      3000 Hanover St.
//                      Palo Alto, CA  94304 U.S.A.
//
//      Rights for non-DOD U.S. Government Departments and Agencies
//      are as set forth in FAR 52.227-19 (c) (1,2) or any other
//      successor clause.
//
//  CLASSES:
//   String
//   SmallByteArray
//   ByteArray
//   ByteArrayRef
//   PathElement
//   PathElementList
//   Bitmap
//  
//----------------------------------------------------------------------
// $Source: /projects/HMS/nsr/udfCore/sys/nsrAux.h,v $
// $Revision: 1.50 $    $Author: hmgr $
// $State: Exp $        $Locker:  $
// $Date: 96/05/21 15:07:29 $

//----------------------------------------------------------------------
// ENUM: CharSetType
//
//  Specifies whether a string is in ASCII or OSTA Compressed Unicode.
//
// DEFINITIONS:
//  charset_Ascii   8- bit ascii
//  charset_OCU     OSTA Compressed Unicode
//
// USES:
//  This is used internally, to allow backward compatibility with
//  non-OCU (ASCII) strings.  Used mainly by String constructor, to
//  allow conversion from OCU into internal representation form.
//
// NOTES:
//
//----------------------------------------------------------------------
enum CharSetType {

    charset_Ascii = 0,
    charset_OCU   = 1
};

//----------------------------------------------------------------------
// CLASS: String     --JD/DVM
//
//  This string is inherited from the RogueWave RWCString class, and 
//  simply adds a few specialized methods.  
//
//  Since the underlying RWCString is not virtual, the String class must
//  not have any data members.
//
// PUBLIC DATA MEMBERS:
//  NONE.
//
// PUBLIC METHODS:
//  String()     - Constructor: empty string
//  String(s)    - Constructor: makes copy from CHAR_PTR
//  String(bp,l) - Constructor: from BYTE_PTR , len
//  operator==() - comparison (Inherited from RWCString)
//  operator=()  - assign from String or CHAR_PTR (Inherited from RWCString)
//  CHAR_PTR()   - casts to CHAR_PTR or CONST_CHAR_PTR (Inherited frm RWCString)
//  remove()     - truncates (Inherited from RWCString)
//  toMem()      - copies to region of memory
//  toMemArea()  - toMem with limited length.
//  toMemOCU()   - toMem with OSTA Compressed Unicode
//  length()     - strlen() equivalent (Inherited from RWCString)
//  * * *        - all other RWCString methods
//
// USAGE NOTES:
// String Constructors
//
//    (void)                 - empty string of length 0
//    (CONST_CHAR_PTR)          - from c strings (null terminated)
//    (BYTE_PTR rbp, len)       - takes len chars starting at rbp
//    (BYTE_PTR rbp, len, type) - as above, with ASCII or OCU
//    (String &s)            - copy constructor, to allow passing as arg,
//                             return value, etc.
// 
// String Method Overview
//
// Operator support for String:
//
//    == (comparison - between two strings)
//    =  (assignment - from String or CHAR_PTR)
//    () (casting    - to CHAR_PTR, CONST_CHAR_PTR)
//
// Special member functions:
//
//    remove(max)    - This truncates the string to the supplied length
//    toMem(CHAR_PTR s) - This copies its contents to the supplied memory
//                     location.
//    toMemArea()    - above to location with limits on length
//    toMemOCU()     - above but prepending 0x08 (OSTA Compressed Unicode)
//    length()       - Returns the length of the string.
//
// Special considerations:
//
//    If a String is assigned or promoted to a CHAR_PTR, it will use the
//    CHAR_PTR casting operator. This returns the address of the
//    characters, and is suitable for sending to a printf() call, for
//    example. However, if the String may go out of scope, a copy of
//    the string is needed, so the toMem() method should be used.
// 
//----------------------------------------------------------------------
// COLLABORATORS:  
//  NONE.
//
// PRIVATE METHODS:
// 
// None.
//
// IMPLEMENTATION NOTES:
//
//----------------------------------------------------------------------

#ifdef OLD_STRING
class String {

    CHAR_PTR str;
    UINT16 strLen;

    void copy( const String & );
    void free() { if (str) FreeMemory(str); str = 0; }

public:

    //cbay--8/3/95--g++ does not distinguish const char/char
    String( CONST_CHAR_PTR s );
    String( CONST_BYTE_PTR s, UINT16 l, CharSetType cst = charset_Ascii);
    String() : strLen(0) {      // default constructor
        str = (CHAR_PTR)AllocateMemory(1);
        if ( str != 0 )
            str[0] = '\0';
    }
    String( const String &obj) :
            str(NULL),
            strLen(0)
    {
        copy(obj);
    }
    ~String() { free(); }
    Error error() const {
        return (( str == 0 ) ?
                Error(error_No_free_store) :
                Error(error_None         ) ); 
    }

    Boolean operator== ( const String &obj ) const ;
    Boolean operator!= ( const String &obj ) const ;
    String &operator+= ( const String &obj ) ;
    String &operator=  ( const String &obj ) {

        if (this != &obj) {
            free();
            copy(obj);
        }
        return *this;
    }

    String & operator=( CONST_CHAR_PTR s) { 

        copy( String(s));
        return *this; 
    }

//    operator CONST_CHAR_PTR() { return str; } // OK (empty string has valid addr)
    operator CONST_CHAR_PTR() const { return str; } // OK (see above)
    String& remove( UINT16 maxLen ) ;
    void toMem( CHAR_PTR s ) const ;
    void toMemArea( BYTE_PTR s, UINT16 memLen ) const ;
    void toMemOCU( BYTE_PTR s, UINT16 memLen ) const ;
    UINT16 length() const { return strLen; }
};

#else

class String : public RWCString {

public:

    //cbay--8/3/95--g++ does not distinguish const char/char
    String() : RWCString() { }
    String( CONST_CHAR_PTR s ) : RWCString(s) { }
    String( CONST_BYTE_PTR s, UINT16 l, CharSetType cst =
            charset_Ascii);
    String( const String &obj) : RWCString(obj) { }
    Error error() const { 
        return Error(error_None);
    }
    void toMem( CHAR_PTR s ) const ;
    void toMemArea( BYTE_PTR s, UINT16 memLen ) const ;
    void toMemOCU( BYTE_PTR s, UINT16 memLen ) const ;
};

#endif // OLD_STRING



//----------------------------------------------------------------------
// CLASS: SmallByteArray     --DVM
//
//  Byte container - up to 65535 bytes long
//
// PUBLIC METHODS:
//  SmallByteArray(l)    - Constructor: l bytes long
//  SmallByteArray(bp,l) - Constructor: copy from bp, l bytes
//  length()             - returns length
//  error()              - returns error
//  operatorXX()         - cast to BYTE_PTR , CONST_BYTE_PTR , String
//  operator=()          - assign from string or sba
//  setLen()             - dynamically set length
//  clear()              - sets len to zero, deallocates
//  toMem()              - copies to mem
//  fromMem()            - copies from mem
//
// USAGE NOTES:
//  This is provided for use inside of descriptors. Most users will
//  use ByteArray instead.
// 
//----------------------------------------------------------------------
// COLLABORATORS:  
//  String
//
// PRIVATE METHODS:
//  copy()  - boilerplate
//  free()  - boilerplate
//
// IMPLEMENTATION NOTES:
//  Basic foundation class
//
//----------------------------------------------------------------------
class SmallByteArray {

    BYTE_PTR bytes;
    UINT16 baLen;

    void copy( const SmallByteArray &obj );
    void free() { delete [] bytes; bytes = 0; }

public:

    SmallByteArray( UINT16 l = 0 );
    SmallByteArray( CONST_BYTE_PTR b, UINT16 l);
    SmallByteArray( const SmallByteArray &obj) { copy(obj); }
    ~SmallByteArray() { free(); }

    UINT16 length() const { return baLen; }

    Error error() const
    { 
        return (( bytes == 0 ) ?
                Error(error_No_free_store) :
                Error(error_None         ) ); 
    }

    operator BYTE_PTR ()             { return bytes; }
    operator CONST_BYTE_PTR () const { return bytes; }
    operator String () const { return String(bytes,baLen); }
    SmallByteArray & operator=( const String &str)
    { 
        str.toMemArea(bytes,baLen);
        return *this; 
    }

    Boolean operator == ( const SmallByteArray &obj ) const ;
    Boolean operator != ( const SmallByteArray &obj ) const ;
    SmallByteArray &operator=( const SmallByteArray &obj )
    {
        if (this != &obj) {
            free();
            copy(obj);
        }
        return *this;
    }

    void setLen(UINT16 l);
    
    void clear() ;
    void toMem( BYTE_PTR b ) const ;
    void fromMem( CONST_BYTE_PTR b ) ;
};

//----------------------------------------------------------------------
// CLASS: ByteArray     --DVM
//
//  Byte container - up to 4GB-1
//
// PUBLIC METHODS:
//  ByteArray(l)    - Constructor: l bytes long
//  ByteArray(bp,l) - Constructor: copy from bp, l bytes
//  length()        - returns length
//  error()         - returns error
//  operatorXX()    - cast to BYTE_PTR , CONST_BYTE_PTR , String
//  operator=()     - assign from string or sba
//  setLen()        - dynamically set length
//  clear()         - sets len to zero, deallocates
//  toMem()         - copies to mem
//  fromMem()       - copies from mem
//  32-bit length array of bytes
//
// USAGE NOTES:
//  General-purpose container for bytes. Unlike strings, can hold nulls.
// 
//----------------------------------------------------------------------
// COLLABORATORS:  
//  String
//
// PRIVATE METHODS:
//  copy()  - boilerplate
//  free()  - boilerplate
//
// IMPLEMENTATION NOTES:
//  Basic foundation class
//
//----------------------------------------------------------------------
class ByteArray {

    BYTE_PTR bytes_;
    UINT32   baLen_;

    void copy( const ByteArray &obj );
    void free() { if (bytes_) FreeMemory(bytes_); bytes_ = 0; }

public:

    ByteArray( UINT32 l = 0 );
    ByteArray( CONST_BYTE_PTR b, UINT32 l);
    ByteArray( const ByteArray &obj) { copy(obj); }
    ~ByteArray() { free(); }

    UINT32 length() const { return baLen_; }

    Error error() const { 
        return (( bytes_ == 0 ) ?
                Error(error_No_free_store) :
                Error(error_None         ) ); 
    }

    operator BYTE_PTR () { return bytes_; }
    operator CONST_BYTE_PTR () const { return bytes_; }
    operator String() const { return String(bytes_,baLen_); }
    ByteArray & operator=( const String &str) { 

        str.toMemArea(bytes_,baLen_);
        return *this; 
    }

    Boolean operator == ( const ByteArray &obj ) const ;
    Boolean operator != ( const ByteArray &obj ) const ;
    ByteArray &operator=( const ByteArray &obj ) {

        if (this != &obj) {
            free();
            copy(obj);
        }
        return *this;
    }

    void setLen(UINT32 l);
    
    void clear() ;
    void toMem( BYTE_PTR b ) const ;
    void fromMem( CONST_BYTE_PTR b ) ;
    void insertBytes( UINT32 offset, UINT32 len, CONST_BYTE_PTR bp );
    void removeBytes( UINT32 offset, UINT32 len );

};

//----------------------------------------------------------------------
// CLASS: ByteArrayRef     --JKH
//
//  Special class to reference sub-portions of a ByteArray
//
//  A ByteArrayRef object points to a certain subset of the address
//  space of the ByteArray passed as reference during construction
//  (where a subset may include the entire ByteArray).  It allocates
//  no memory.
// 
//  When the (BYTE_PTR ) casting operator is used on a ByteArrayRef
//  object, the ByteArrayRef will return a pointer to the beginning of
//  memory occupied by the subarray represented by ByteArrayRef.
//  NOTE: if the ByteArrayRef object is invalid, this casting operator
//  will return NULL.
//
// PUBLIC METHODS:
//  Offset()   - set/get  the ByteArrayRef's offset
//  Length()   - set/get the ByteArrayRef's length
//  theArray() - returns the ByteArray reference
//  toMem()    - copy from ByteArrayRef's subarray to specified memory
//  fromMem()  - copy to ByteArrayRef's subarray from specified memory
//  isValid()  - returns True if object is valid, False otherwise.
//  (BYTE_PTR )   - casting operator:  returns a BYTE_PTR  pointing to 
//               ByteArrayRef's subarray.
//  ByteArrayRef(BA)     - use BA, at offset=0, len=BA.length()
//  ByteArrayRef(BA,o,l) - use BA, at offset=o, len=l
//
// USAGE NOTES:
//  Enjoy.
// 
//----------------------------------------------------------------------
// COLLABORATORS:  
//  ByteArray
//
// PRIVATE METHODS:
//  NONE.
//
// IMPLEMENTATION NOTES:
//  This class uses the compiler-generated defaults for the copy
//  constructor, destructor, and the = (assignment) operator.
//  !!!: ByteArrayRef::operator= is not explicitly defined; uses default.
//  Proposed solution:  define the method explicitly.
//
//----------------------------------------------------------------------

#ifdef OLD_BYTE_ARRAY_REF

class ByteArrayRef {
    ByteArray * barrp_;
    UINT32      offset_;
    UINT32      length_;

public:

    ByteArrayRef(ByteArray& theArray);  
    ByteArrayRef(ByteArray& theArray,UINT32 off,UINT32 len);
    UINT32      offset(void) const { return offset_; }
    UINT32      offset(UINT32 newoffset);
    UINT32      length(void) const { return length_; }
    UINT32      length(UINT32 newlen);
    ByteArray&  theArray(void) const { return *barrp_; }
    Boolean     toMem(BYTE_PTR buf) const;
    Boolean     fromMem(CONST_BYTE_PTR buf);
    Boolean     isValid(void) const {
        return (((length_ == 0) || (offset_ + length_ > barrp_->length()) ||
                 ((CONST_BYTE_PTR) *barrp_ == NULL)) ? False : True);
    }

    operator BYTE_PTR () const {
        return (isValid() ? (( (BYTE_PTR) *barrp_) + offset_) : NULL);
    }
    operator CONST_BYTE_PTR () const {
        return (isValid() ? (( (CONST_BYTE_PTR) *barrp_) + offset_) : NULL);
    }
};

#else   // This is the new ByteArrayRef

class ByteArrayRef {

private:

    BYTE_PTR    theArray_;      // Actual array
    UINT32      arrayLen_;      // Length (capacity) of actual array
    UINT32      offset_;        // Offset into the array
    UINT32      length_;        // Length of the "window" into the array

public:

    ByteArrayRef(BYTE_PTR array,UINT32 arraylen);
    ByteArrayRef(BYTE_PTR array,UINT32 arraylen,UINT32 off,UINT32 len);
    ByteArrayRef(ByteArray& theArray);  
    ByteArrayRef(ByteArray& theArray,UINT32 off,UINT32 len);
    UINT32      offset(void) const { return offset_; }
    UINT32      offset(UINT32 newoffset);
    UINT32      length(void) const { return length_; }
    UINT32      length(UINT32 newlen);
    BYTE_PTR    theArray(void) const { return theArray_; }
    UINT32      arrayLen(void) const { return arrayLen_; }
    Boolean     toMem(BYTE_PTR buf) const;
    Boolean     fromMem(CONST_BYTE_PTR buf);
    Boolean     isValid(void) const {
        return (((length_ == 0) || (offset_ + length_ > arrayLen_) ||
                 ((CONST_BYTE_PTR) theArray_ == NULL)) ? False : True);
    }

    operator BYTE_PTR () const {
        return (isValid() ? (( theArray_ ) + offset_) : NULL);
    }
    operator CONST_BYTE_PTR () const {
        return (isValid() ? (( (CONST_BYTE_PTR) theArray_ ) + offset_) : NULL);
    }
};

#endif


//----------------------------------------------------------------------
// CLASS: ImplementationInfo     --DVM
//
//  Struct holding information about who wrote a file set.
//
//  This structure holds all of the information held in the
//  Implementation Entity Identifier in the FileSetDescriptor. It is
//  provided for inspection only.
//
// PUBLIC DATA MEMBERS:
//  String Id             - Must match HP's hard-coded string
//  UINT8  osClassId      - See UDF 
//  UINT8  osId           - See UDF
//  UINT8  librVersionNo  - Version of HP's implementation
//  UINT16 implRegistrNo  - Unique number assigned to HP user
//  UINT8  implVersionNo  - HP user-defined and set
//  UINT8  implRevisionNo - HP user-defined and set
//
// PUBLIC METHODS:
//  NONE.
//
// USAGE NOTES:
// 
//----------------------------------------------------------------------
// COLLABORATORS:  
//  String
//
// PRIVATE METHODS:
//  NONE
//
// IMPLEMENTATION NOTES:
//  It's just a struct!
//
//----------------------------------------------------------------------
struct ImplementationInfo {

    String Id;
    UINT8  osClassId;
    UINT8  osId;
    UINT8  librVersionNo;
    UINT16 implRegistrNo;
    UINT8  implVersionNo;
    UINT8  implRevisionNo;

};

//----------------------------------------------------------------------
// ENUM: PathElementType
//
//  Possible types associated with path elements
//
// DEFINITIONS:
//  path_Unknown
//    DO NOT USE. This indicates an invalid PathElement type.
//  path_Custom_Root
//    Name field may not be null here. Could possibly mean: 'Name:/'
//  path_Standard_Root
//    Root, as in '/' or '\'
//  path_Parent
//    As in '..'
//  path_Same
//    As in '.'
//  path_Name
//    As in name.
//
// USES:
//  Used in constructing or inspecting symbolic links. See PathElement
//  and PathElementList classes.
//
// ABUSES:
//  NEVER use path_Unknown.
//
// NOTES:
//  See PathElementList documentation for an example of how this is
//  used.
//
//----------------------------------------------------------------------
enum PathElementType {

    path_Unknown        = 0,
    path_Custom_Root    = 1,
    path_Standard_Root  = 2,
    path_Parent         = 3,
    path_Same           = 4,
    path_Name           = 5
};

//----------------------------------------------------------------------
// CLASS: PathElement     --JD
//
//  Holds a part of a file name for symbolic links.
//
//  This is an abstraction of the ISO/IEC 13346 PathComponent.
//
// PUBLIC DATA MEMBERS:
//  PathElementType   type   Enum defining type of path element:
//  String            name   name associated with that part of the path
//
// PUBLIC METHODS:
//  PathElement()     - Default constructor: path_Unknown,""
//  operator==()      - Returns True if same type and name (inline)
//  
// USAGE NOTES:
//  Used in construction of PathElementLists
//
//----------------------------------------------------------------------
// COLLABORATORS:  
//  String
//  PathElementType
//
// PRIVATE METHODS:
//  NONE
//
// IMPLEMENTATION NOTES:
//  Could eventually be folded into PathComponent?
//
//----------------------------------------------------------------------
class PathElement {

public:

    PathElementType     type;
    String              name;

    PathElement() :
        name(""),
        type(path_Unknown) {
    }

    PathElement( CONST_CHAR_PTR d ) :
        name(d),
        type(path_Name) {
    }

    PathElement( PathElementType t ) :
        name(""),
        type(t) {
    }

    Boolean operator == ( const PathElement &obj ) const {

        if ( type == obj.type )
            if ( type == path_Name )
                return (name == obj.name) ? True : False;
            else
                return (type == obj.type) ? True : False;
        else
            return False;

    }
};

//----------------------------------------------------------------------
// CLASS: PathElementList     --DVM
//
//  Holds a file name for symbolic links
//
//  This is an abstraction of a PathComponentList in ISO/IEC 13346.
//
// PUBLIC METHODS:
//  PathElementList() - Constructor: optional size slots reserved.
//  error()           - Returns error state (inline)
//  clear()           - empties and deallocates the list contents
//  operator[]()      - accesses ith PathElement
//  append()          - Appends an element to list
//  remove()          - removes ith PathElement
//  getCount()        - returns number of entries
//  totalBytes()      - returns number of bytes to write list (inline)
//
// USAGE NOTES:
//  This has value-based semantics, where the allocation and
//  deallocation of space for list entries are done by this class.
//
//  An example of how a name is represented as a PathElementList is
//  provided below:
//
//  Path(using UNIX conventions):
// 
//      '../mydir/myFile.h'
//
//  PathElementList contents:
//
//      Name        Type
//      ----------- -----------
//      ""          path_Parent
//      "mydir"     path_Name
//      "myFile.h"  path_Name
// 
//----------------------------------------------------------------------
// COLLABORATORS:  
//  PathElement
//
// PRIVATE METHODS:
//  copy()   - Paul Anderson boilerplate
//  extend() - Paul Anderson boilerplate
//  free()   - Paul Anderson boilerplate
//  full()   - Paul Anderson boilerplate
//  empty()  - Paul Anderson boilerplate
//
// IMPLEMENTATION NOTES:
//  Follows Paul Anderson's standard array stuff.
//
//----------------------------------------------------------------------
class PathElementList {

    PathElement nullPathElement;

    PathElement *element;
    UINT32 size, count;

    Error err;

    void copy(const PathElementList &);
    void extend();
    void free() { delete [] element; element = 0; }
    Boolean full() const { return Boolean(count == size); }
    Boolean empty() const { return Boolean(count == 0); }

public:

    // Constructors
    // INLINE: PathElementList::PathElementList()
    PathElementList( UINT32 sz = 10 ) {
        element = new PathElement[size = (sz) ? sz : 1 ];
        if (!element) { err = error_No_free_store; }
        count = 0;
    }

    PathElementList(const PathElementList &obj) { copy(obj); }

    // Destructor
    ~PathElementList() { free(); }

    Error error() const { return err; }

    // Modifiers

    // INLINE: PathElementList::clear()
    void clear() { 
        err = error_None;
        free(); 
        element = 0; 
        count = 0; 
        size = 0; 

        PathElementList plist;
        copy( plist );
    }

    PathElementList &operator=( const PathElementList &obj ) {
        if (this != &obj) {
            free();
            copy(obj);
        }
        return *this;
    }

    // INLINE: PathElementList::operator[]()
    PathElement &operator[]( UINT32 i) {
        if (i < count)
            return element[i];
        else {
            err = error_Index_out_of_bounds;
            return nullPathElement;
        }
    }

    // INLINE: PathElementList::operator[]()
    const PathElement &operator[]( UINT32 i) const {
        if (i < count)
            return element[i];
        else {
            // err = error_Index_out_of_bounds;
            return nullPathElement;
        }
    }

    // INLINE: PathElementList::append()
    void append( const PathElement p ) { 
        if ( full() ) extend();
        element[count++] = p;
    }

    void remove( UINT32 );

    // Selectors
    // INLINE: PathElementList::getCount()
    unsigned getCount() const { return count; }

    UINT32 totalBytes() const;
};

//----------------------------------------------------------------------
// METHOD: PathElementList::PathElementList()   --JD
//      
//  Constructor for PathElementList
//
// ARGS:
//  UINT16   size  IN  how many entries before growth required.
//                     (defaults to 10)
// POST-CONDITIONS:
//  size entries are allocated, but number of entries is 0.
// 
// ERRORS:
//  error_No_free_store - new failed.
// 
// NOTES:
//  (none.)
//
//----------------------------------------------------------------------

//----------------------------------------------------------------------
// METHOD: PathElementList::clear()  --JD
//      
//  Empties and reallocates the list (at default size).
//
// ARGS: none.
//
// PRE-CONDITIONS: none.
// 
// POST-CONDITIONS: Current list is destroyed, and replaced by a new
//                  list.
//
// ERRORS:  error_No_free_store  - new failed.
// 
//----------------------------------------------------------------------

//----------------------------------------------------------------------
// METHOD: PathElementList::operator[]()   --JD
//      
//  Accesses the ith element. Supports rvalue and lvalue.
//
// ARGS:
//  UINT16  i  IN  index into array. 0 to count-1.
//
// RETURNS: Reference to ith PathElement.
// 
// PRE-CONDITIONS:
//  List must have at least i+1 elements. If not, a reference to a
//  NullPathElement is returned. If used as an lvalue, the error state
//  is set to error_Index_out_of_bounds.
// 
// POST-CONDITIONS:
//  List_postconditions (E.g., changes to class data members)
// 
// ERRORS:  error_Index_out_of_bounds  - Assigned to location outside
//                                       of list. 
//
//----------------------------------------------------------------------

//----------------------------------------------------------------------
// METHOD: PathElementList::append()    --JD
//      
//  Adds a PathElement to the end of the list.
//
// ARGS:
//  PathElement   pe  IN   path element to be added
//
// PRE-CONDITIONS: none.
// 
// POST-CONDITIONS:
//  List count is incremented, and new memory is allocated as needed.
// 
// ERRORS:
//  error_No_free_store  - new failed.
// 
//----------------------------------------------------------------------

//----------------------------------------------------------------------
// METHOD: PathElementList::getCount()   --JD
//      
//  Returns the number of entries in the list.
//
// ARGS: none
//
// RETURNS:
//  UINT16 number of entries
// 
// PRE-CONDITIONS: none.
// 
// POST-CONDITIONS: none.
// 
// ERRORS: none.
// 
//----------------------------------------------------------------------

//----------------------------------------------------------------------
// CLASS: Bitmap     --JKH
//
//  Bitmap class for internal use only.
//
//  The Bitmap class provides a simple bitmap abstraction, primarily
//  for use with the SpaceResource class.  The class provides methods
//  for clearing and setting individual bits, resizing, and finding
//  regions of set or clear bits.
//
//  This is likely to be revamped.
//
// PUBLIC METHODS:
//  Bitmap():        constructor; default length = 0
//  Bitmap(UINT32):  constructor; use length = specified # of bits      
//  numBytes():      return # of bytes allocated to bitmap
//  numBits():       return # of bits in bitmap
//  setBit(UINT32):  set the specified bit
//  clearBit(UINT32):clear the specified bit
//  readBit(UINT32): returns the value of the specified bit
//  resize(UINT32):  resizes the bitmap to the specified number of bits
//
// USAGE NOTES:
//  For internal use only.
// 
//----------------------------------------------------------------------
// COLLABORATORS:  
//  NONE.
//
// PRIVATE METHODS:
//  copy() - boilerplate
//  free() - boilerplate
//
// IMPLEMENTATION NOTES:
//  Jon is likely to rewrite this in the future.
//
//----------------------------------------------------------------------

class Bitmap {
  
private:

    UINT32      nbytes;         // Number of bytes allocated to bitmap
    UINT32      nbits;          // Number of bits in bitmap
    BYTE_PTR    bitmap;

    void copy(const Bitmap&);
    void free(void);

public:

    Bitmap(void) : nbytes(0), nbits(0), bitmap(NULL) { }
    Bitmap(UINT32 size);
    Bitmap(const Bitmap& bmap) { copy(bmap); }          // copy constructor
    ~Bitmap(void);
    UINT32      numBytes(void) const { return nbytes; }
    UINT32      numBits(void) const { return nbits; }
    INT32       setBit(UINT32 which);
    INT32       clearBit(UINT32 which);
    INT32       setRange(UINT32 offset,UINT32 numbits);
    INT32       clearRange(UINT32 offset,UINT32 numbits);
    INT32       readBit(UINT32 which) const;
    INT32       resize(UINT32 newsize);
    UINT32      countBits(UINT32 set) const;
    UINT32      rangeSize(UINT32 set) const;
    INT32       findSetRange(UINT32 numbits) const;
    INT32       findClearRange(UINT32 numbits) const;
#ifdef DEBUG
    void        print(UINT32 indent,const String& hdr,UINT32 numbits) const;
#endif
};

#endif

