home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / CMTPOps.c < prev    next >
C/C++ Source or Header  |  1997-03-21  |  25KB  |  638 lines

  1. /* @(#)Z 1.4 com/src/cm/CMTPOps.c, odstorage, od96os2, odos29712d 97/03/21 17:19:33 (96/10/29 09:17:10) */
  2. /*====START_GENERATED_PROLOG======================================
  3.  */
  4. /*
  5.  *   COMPONENT_NAME: odstorage
  6.  *
  7.  *   CLASSES: none
  8.  *
  9.  *   ORIGINS: 82,27
  10.  *
  11.  *
  12.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13.  *   All Rights Reserved
  14.  *   Licensed Materials - Property of IBM
  15.  *   US Government Users Restricted Rights - Use, duplication or
  16.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17.  *       
  18.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24.  *   OR PERFORMANCE OF THIS SOFTWARE.
  25.  */
  26. /*====END_GENERATED_PROLOG========================================
  27.  */
  28.  
  29. /*
  30.     File:             CMTPOps.c     
  31.  
  32.     Contains:    Container Manager Type and Property Operations
  33.  
  34.     Written by:    Ira L. Ruben
  35.  
  36.     Owned by:    Ed Lai
  37.  
  38.     Copyright:    ⌐ 1991-1994 by Apple Computer, Inc., all rights reserved.
  39.  
  40.     Change History (most recent first):
  41.  
  42.          <3>     12/9/94    EL        #1182275 Optionally do not maintain
  43.                                     continue flag.
  44.          <2>     8/26/94    EL        #1181622 Ownership update.
  45.          <1>      2/3/94    EL        first checked in
  46.          <3>     10/6/93    EL        Rename CMGetAdjacentXXXX to GetAdjacentXXXX
  47.                                                     and static near.
  48.          <2>     10/4/93    EL        Add CMGetPrevProperty and CMGetPrevType
  49.  
  50.     To Do:
  51. */
  52.  
  53. /*---------------------------------------------------------------------------*
  54.  |                                                                           |
  55.  |                        <<<      CMTPOps.c      >>>                        |
  56.  |                                                                           |
  57.  |              Container Manager Type and Property Operations               |
  58.  |                                                                           |
  59.  |                               Ira L. Ruben                                |
  60.  |                                 12/15/91                                  |
  61.  |                                                                           |
  62.  |                  Copyright Apple Computer, Inc. 1991-1994                 |
  63.  |                           All rights reserved.                            |
  64.  |                                                                           |
  65.  *---------------------------------------------------------------------------*
  66.  
  67.  All types and properties must be registered with CMRegisterType() and CMRegisterProperty()
  68.  to get their associated refNums.  The refNums, in turn, are used as "type" and "property"
  69.  parameters to other API calls.  When reading containers CMRegisterType() and
  70.  CMRegisterProperty() are also used to get refNums for existing types and properties in
  71.  the container.  Obviously CMRegisterType() and CMRegisterProperty() are two key routines 
  72.  and are defined in this file.
  73.  
  74.  The other routines here allow for testing refNums to see if they are types or properties
  75.  and for accessing all the types and properties in the container.
  76. */
  77.  
  78.  
  79. #include <stddef.h>
  80. #include <stdio.h>
  81.  
  82. #ifndef __CMTYPES__
  83. #include "CMTypes.h"
  84. #endif
  85. #ifndef __CM_API__
  86. #include "CMAPI.h"
  87. #endif
  88. #ifndef __LISTMGR__
  89. #include "ListMgr.h"
  90. #endif
  91. #ifndef __DYNAMICVALUES__
  92. #include "DynValus.h"     
  93. #endif
  94. #ifndef __TOCENTRIES__
  95. #include "TOCEnts.h"   
  96. #endif
  97. #ifndef __TOCOBJECTS__
  98. #include "TOCObjs.h"   
  99. #endif
  100. #ifndef __GLOBALNAMES__
  101. #include "GlbNames.h"   
  102. #endif
  103. #ifndef __CONTAINEROPS__
  104. #include "Containr.h"  
  105. #endif
  106. #ifndef __HANDLERS__
  107. #include "Handlers.h"
  108. #endif
  109. #ifndef __FREESPACE__
  110. #include "FreeSpce.h" 
  111. #endif
  112. #ifndef __UPDATING__
  113. #include "Update.h"  
  114. #endif
  115. #ifndef __SESSIONDATA__
  116. #include "Session.h"          
  117. #endif
  118. #ifndef __ERRORRPT__
  119. #include "ErrorRpt.h"      
  120. #endif
  121. #ifndef __UTILITYROUTINES__
  122. #include "Utility.h"        
  123. #endif
  124.                                                                     
  125.                                                                     CM_CFUNCTIONS
  126.  
  127. /* The following generates a segment directive for Mac only due to 32K Jump Table             */
  128. /* Limitations.  If you don't know what I'm talking about don't worry about it.  The        */
  129. /* default is not to generate the pragma.  Theoritically unknown pragmas in ANSI won't    */
  130. /* choke compilers that don't recognize them.  Besides why would they be looked at if        */
  131. /* it's being conditionally skipped over anyway?  I know, famous last words!                        */
  132.  
  133. #if CM_MPW
  134. #pragma segment CMTypePropertyOps
  135. #endif
  136.                                                                     
  137.  
  138. /*----------------------------------------------*
  139.  | CMRegisterType - register a global type name |
  140.  *----------------------------------------------*
  141.  
  142.  The specified type name is registered as a type in the specified container.  A refNum
  143.  for it is returned.  If the type name already exists, the refNum for it is returned.
  144.  
  145.  Note, types may be used to create dynamic values when passed to CMNewValue().  Such types
  146.  must have a metahandler registered for them and that metahandler must have handler 
  147.  routines for "use value", "new value", and "metadata" operation types.  See
  148.    DynValus.c    for a full explaination of dynamic values (more than you probably ever
  149.  want to know).
  150. */
  151.  
  152. CMType CM_FIXEDARGS CMRegisterType(CMContainer targetContainer, CMconst_CMGlobalName name)
  153. {
  154.     TOCObjectPtr     t;
  155.     GlobalNamePtr g;
  156.     ContainerPtr     container = (ContainerPtr)targetContainer;
  157.     
  158.     NOPifNotInitialized(NULL);                                                /* NOP if not initialized!                    */
  159.     
  160.     /* See if the type global name already exists...                                                                            */
  161.     
  162.     g = cmLookupGlobalName(container->globalNameTable, (CM_UCHAR *)name);
  163.     
  164.     if (!SessionSuccess) {
  165.         ERROR2(CM_err_GloblaNameError, name, CONTAINERNAME);
  166.         return (NULL);
  167.     }
  168.     
  169.     /* If the name previously existed, cmLookupGlobalName() will return a pointer to the    */
  170.     /* global name entry.  Even deleted global names have entries!  But we can tell that    */
  171.     /* because the value back pointer in the entry is NULLed out. If we do have a already */
  172.     /* existing entry, just return the owning object pointer after one last validation         */
  173.     /* that it is indeed a type object (so I'm paranoid).                                                                    */
  174.     
  175.     if (g && g->theValue) {                                                        /* previously existing name                    */
  176.         t = g->theValue->theValueHdr->theProperty->theObject;
  177.         if ((t->objectFlags & TypeObject) == 0) {
  178.             ERROR4(CM_err_MultTypeProp, "type", name, CONTAINERNAME,
  179.                          (t->objectFlags & PropertyObject) ? "property" : "object");
  180.             t = NULL;
  181.         } else
  182.             ++t->useCount;                                                                /* bump this object's use count            */
  183.     } else {                                                                                    /* a new name                                                */
  184.         t = cmDefineGlobalNameObject(container, container->nextUserObjectID, CM_StdObjID_GlobalTypeName,
  185.                                                                  CM_StdObjID_7BitASCII, (CM_UCHAR *)name,
  186.                                                                  container->generation, 0, TypeObject);
  187.         if (t) {
  188.             t->useCount = 1;                                                            /* initial use of this object                */
  189.             IncrementObjectID(container->nextUserObjectID);
  190.         }
  191.     }
  192.         
  193.     return ((CMType)t);
  194. }
  195.  
  196.  
  197. /*-----------------------------------------------*
  198.  | CMRegisterProperty - register a property name |
  199.  *-----------------------------------------------*
  200.  
  201.  The specified property name is registered as a property in the specified container.  A
  202.  refNum or it is returned.  If the property name already exists, the refNum for it is
  203.  returned.
  204.  
  205.  Note, the implementation here is basically the same as CMRegisterType() except for the
  206.  metaData.  Properties have none.
  207. */
  208.  
  209. CMProperty CM_FIXEDARGS CMRegisterProperty(CMContainer targetContainer,
  210.                                                                                      CMconst_CMGlobalName name)
  211. {
  212.     TOCObjectPtr    p;
  213.     GlobalNamePtr g;
  214.     ContainerPtr     container = (ContainerPtr)targetContainer;
  215.     
  216.     NOPifNotInitialized(NULL);                                                /* NOP if not initialized!                    */
  217.  
  218.     g = cmLookupGlobalName(container->globalNameTable, (CM_UCHAR *)name);
  219.     
  220.     if (!SessionSuccess) {
  221.         ERROR2(CM_err_GloblaNameError, name, CONTAINERNAME);
  222.         return (NULL);
  223.     }
  224.     
  225.     if (g && g->theValue) {
  226.         p = g->theValue->theValueHdr->theProperty->theObject;
  227.         if ((p->objectFlags & PropertyObject) == 0) {
  228.             ERROR4(CM_err_MultTypeProp, "type", name, CONTAINERNAME,
  229.                          (p->objectFlags & TypeObject) ? "type" : "object");
  230.             p = NULL;
  231.         } else
  232.             ++p->useCount;                                                                /* bump this object's use count            */
  233.     } else {
  234.         p = cmDefineGlobalNameObject(container, container->nextUserObjectID, CM_StdObjID_GlobalPropName,
  235.                                                                  CM_StdObjID_7BitASCII, (CM_UCHAR *)name,
  236.                                                                  container->generation, 0, PropertyObject);
  237.         if (p) {
  238.             p->useCount = 1;                                                            /* initial use of this object                */
  239.             IncrementObjectID(container->nextUserObjectID);
  240.         }
  241.     }
  242.     
  243.     return ((CMProperty)p);
  244. }
  245.  
  246.  
  247. /*-------------------------------------------*
  248.  | CMAddBaseType - add a base type to a type |
  249.  *-------------------------------------------*
  250.  
  251.  A base type (baseType) is added to the specified type.  For each call to CMAddBaseType()
  252.  for the type a new base type is recorded.  They are recorded in the order of the calls.
  253.  The total number of base types recorded for the type is retuned.   0 is returned if there
  254.  is an error and the error reporter returns.
  255.  
  256.  It is an error to attempt to add the SAME base type more than once to the type. Base types
  257.  may be removed from a type by using CMRemoveBaseType().
  258.  
  259.  The purpose of this routine is to define base types for a given type so that layered
  260.  dynamic values can be created.  Base types simulate the form of type inheritance.
  261.  
  262.  See   DynValus.c    for a full description of dynamic values and how base types are used.
  263. */
  264.  
  265. CMCount CM_FIXEDARGS CMAddBaseType(CMType type, CMType baseType)
  266. {
  267.     ContainerPtr     container;
  268.     TOCObjectPtr      theObject;
  269.     TOCPropertyPtr theProperty;
  270.     TOCValueHdrPtr theValueHdr;
  271.     TOCValuePtr      theValue;
  272.     TOCValueBytes     valueBytes;
  273.     CMObjectID         baseTypeID;
  274.     char                      *typeName, *baseTypeName;
  275.     
  276.     ExitIfBadType(type, 0);
  277.     ExitIfBadType(baseType, 0);
  278.     
  279.     container = ((TOCObjectPtr)type)->container;
  280.  
  281.     if (container->targetContainer != ((TOCObjectPtr)type)->container->targetContainer) {
  282.         ERROR2(CM_err_2Containers, CONTAINERNAMEx(container),
  283.                                                              CONTAINERNAMEx(((TOCObjectPtr)baseType)->container));
  284.         return (0);
  285.     }
  286.     
  287.     container = container->updatingContainer;
  288.  
  289.     if ((container->useFlags & kCMWriting) == 0) {            /* make sure opened for writing        */
  290.         ERROR1(CM_err_WriteIllegal1, CONTAINERNAME);
  291.         return (0);
  292.     }
  293.     
  294.     /* Scan the "base type" property value data to see if the base type ID is already         */
  295.     /* there.     It's an error if it's already there.                                                                                */
  296.     
  297.     baseTypeID  = ((TOCObjectPtr)baseType)->objectID;
  298.     theProperty = cmGetObjectProperty((TOCObjectPtr)type, CM_StdObjID_BaseTypes);
  299.     
  300.     if (theProperty != NULL) {                                                    /* if base type property exists        */
  301.         theValueHdr = (TOCValueHdrPtr)cmGetListHead(&theProperty->valueHdrList);
  302.         
  303.         if (theValueHdr != NULL) {                                                /* double check for value hdr            */
  304.             theValue  = (TOCValuePtr)cmGetListHead(&theValueHdr->valueList); /* 1st base ID        */
  305.             
  306.             while (theValue != NULL) {                                            /* look at the base type values        */
  307.                 if ((CMObjectID)theValue->value.imm.ulongValue == baseTypeID) {    /* look for ID    */
  308.                     typeName          = cmIsGlobalNameObject((TOCObjectPtr)type, CM_StdObjID_GlobalTypeName);
  309.                     baseTypeName = cmIsGlobalNameObject((TOCObjectPtr)baseType, CM_StdObjID_GlobalTypeName);
  310.                     ERROR3(CM_err_DupBaseType, baseTypeName, typeName, CONTAINERNAME);
  311.                     return (0);
  312.                 }
  313.                 
  314.                 theValue = (TOCValuePtr)cmGetNextListCell(theValue); /* look at next base type    */
  315.             } /* while */
  316.             
  317.         } /* theValueHdr */
  318.     } /* theProperty */
  319.     
  320.     /* We have a new base type for the type.  If this is the first base type, create the     */
  321.     /* special "base type" property with a single immediate base type ID value. Additional*/
  322.     /* base type ID's form a continued immediate value producing the list of base types.    */
  323.     /* Note, this is rare instance where we allow a continued immediate value!                        */
  324.  
  325.     cmSetValueBytes(container, &valueBytes, Value_Imm_Long, (CM_ULONG)baseTypeID, sizeof(CMObjectID));
  326.     
  327.     if (theProperty == NULL || theValueHdr == NULL) {        /* if 1st base type for type...        */
  328.         theObject = cmDefineObject(container,                         /* ...create base type property        */
  329.                                                              ((TOCObjectPtr)type)->objectID,
  330.                                                              CM_StdObjID_BaseTypes, CM_StdObjID_BaseTypeList,
  331.                                                              &valueBytes, container->generation, kCMImmediate, 
  332.                                                              TypeObject, &theValueHdr);
  333.         if (theObject == NULL) return (0);
  334.         theValueHdr->useCount = 1;                                                /* ...always count use of value        */
  335.     } else {                                                                                        /* if additional base types...        */
  336.         theValue  = (TOCValuePtr)cmGetListTail(&theValueHdr->valueList);
  337. #if CMKEEP_CONTINUE_FLAG
  338.         theValue->flags |= kCMContinued;                                    /* ...flag current value as cont'd*/
  339. #endif
  340.         cmAppendValue(theValueHdr, &valueBytes, kCMImmediate); /* ...add in new base type        */    
  341. #if CMKEEP_CONTINUE_FLAG
  342.         theValueHdr->valueFlags |= ValueContinued;                /* ...create cont'd imm ID list        */
  343. #endif
  344.         cmTouchBaseType(theValueHdr);                                            /* touch for updating if necessary*/
  345.     }
  346.  
  347.     return ((CMCount)cmCountListCells(&theValueHdr->valueList)); /* ret nbr of base types    */
  348. }
  349.  
  350.  
  351. /*---------------------------------------------------*
  352.  | CMRemoveBaseType - remove a base type from a type |
  353.  *---------------------------------------------------*
  354.  
  355.  A base type (baseType) previously added to the specifed type by CMAddBaseType() is
  356.  removed.  If NULL is specified as the baseType, ALL base types are removed.  The number of
  357.  base types remaining for the type is returned.
  358.  
  359.  Note, no error is reported if the specified base type is not present or the type has no
  360.  base types.
  361. */
  362.  
  363. CMCount CM_FIXEDARGS CMRemoveBaseType(CMType type, CMType baseType)
  364. {
  365.     ContainerPtr     container;
  366.     TOCPropertyPtr theProperty;
  367.     TOCValueHdrPtr theValueHdr;
  368.     TOCValuePtr      theValue;
  369. #if CMKEEP_CONTINUE_FLAG
  370.     TOCValuePtr      thePrevValue;
  371. #endif
  372.     CMObjectID         baseTypeID;
  373.     CMCount                 n;
  374.     
  375.     ExitIfBadType(type, 0);
  376.     ExitIfBadType(baseType, 0);
  377.     
  378.     container = ((TOCObjectPtr)type)->container;
  379.  
  380.     if (container->targetContainer != ((TOCObjectPtr)type)->container->targetContainer) {
  381.         ERROR2(CM_err_2Containers, CONTAINERNAMEx(container),
  382.                                                              CONTAINERNAMEx(((TOCObjectPtr)baseType)->container));
  383.         return (0);
  384.     }
  385.         
  386.     container = container->updatingContainer;
  387.  
  388.     if ((container->useFlags & kCMWriting) == 0) {            /* make sure opened for writing        */
  389.         ERROR1(CM_err_WriteIllegal1, CONTAINERNAME);
  390.         return (0);
  391.     }
  392.  
  393.     /* Scan the "base type" property value data to see if the base type ID is already         */
  394.     /* there so that we know we can delete it.  We count the number of base types so that    */
  395.     /* we may return the new count as the function result. Note if the base type does not    */
  396.     /* exist, we return the current count and do nothing else.  The user didn't want the    */
  397.     /* the type and it's not there, so it's not an error to not find it.  In a similar         */
  398.     /* vain, we remove the property if the caller asked that all base types be removed.        */
  399.     
  400.     theProperty = cmGetObjectProperty((TOCObjectPtr)type, CM_StdObjID_BaseTypes);
  401.     if (theProperty == NULL) return (0);
  402.         
  403.     theValueHdr = (TOCValueHdrPtr)cmGetListHead(&theProperty->valueHdrList);
  404.     if (theValueHdr == NULL) return (0);
  405.     
  406.     if (baseType == NULL) {                                                            /* delete entire property ?                */
  407.         CMDeleteObjectProperty((CMObject)type, container->baseTypesProperty);
  408.         return (0); 
  409.     }
  410.     
  411.     baseTypeID = ((TOCObjectPtr)baseType)->objectID;
  412.     
  413.     theValue = (TOCValuePtr)cmGetListHead(&theValueHdr->valueList); /* 1st base ID                */
  414.             
  415.     while (theValue != NULL) {                                                           /* look at base type values..*/
  416.         if ((CMObjectID)theValue->value.imm.ulongValue != baseTypeID) { /*if ID is not found*/
  417.             theValue = (TOCValuePtr)cmGetNextListCell(theValue); /* ...look at next base type    */
  418.             continue;                                                                                         /* ...keep looking                        */
  419.         }
  420.             
  421. #if CMKEEP_CONTINUE_FLAG
  422.         if (cmCountListCells(&theValueHdr->valueList) > 1) {      /* if more than 1 basetype...*/
  423.             if (cmGetNextListCell(theValue) == NULL) {                     /* make sure of seg contd bit*/
  424.                 thePrevValue = (TOCValuePtr)cmGetPrevListCell(theValue);
  425.                 if (thePrevValue != NULL)                                                     /* ...no longer cont'd if        */
  426.                     thePrevValue->flags &= ~kCMContinued;                         /*    last sef is deleted        */
  427.             }
  428.         }
  429. #endif
  430.             
  431.         cmAddToFreeList(container, theValue, 0, 0);                /* add freed space to free list        */
  432.         cmDeleteListCell(&theValueHdr->valueList, theValue);
  433.         CMfree(theValue);                                                                    /* poof!                                                    */
  434.         
  435.         theValueHdr->size -= sizeof(CMObjectID);                    /* update total size in value hdr    */
  436. #if CMKEEP_CONTINUE_FLAG
  437.         if (cmCountListCells(&theValueHdr->valueList) < 2)/* make sure of cont'd bit in hdr    */
  438.             theValueHdr->valueFlags &= ~ValueContinued;
  439. #endif
  440.  
  441.         break;                                                                                        /* we're done -- it's gone                */
  442.     } /* while */
  443.     
  444.     /* If there are no base types left, remove the property.  Also touch for updating if    */
  445.     /* needed.                                                                                                                                                        */
  446.     
  447.     n = (CMCount)cmCountListCells(&theValueHdr->valueList);
  448.     
  449.     if (n > 0)
  450.         cmTouchBaseType(theValueHdr);                                            /* touch for updating if necessary*/
  451.     else
  452.         CMDeleteObjectProperty((CMObject)type, container->baseTypesProperty);
  453.         
  454.     return (n);                                                                                 /* nbr of base types left                    */
  455. }
  456.  
  457.  
  458. /*----------------------------------------*
  459.  | CMIsType - test if an object is a type |
  460.  *----------------------------------------*
  461.  
  462.  Returns non-zero if the object is a type and 0 otherwise.
  463. */
  464.  
  465. CMBoolean CM_FIXEDARGS CMIsType(CMObject theObject)
  466. {
  467.     ExitIfBadObject(theObject, 0);                                        /* validate theObject                                */
  468.     
  469.     return ((CMBoolean)((((TOCObjectPtr)theObject)->objectFlags & TypeObject) != 0));
  470. }
  471.  
  472.  
  473. /*------------------------------------------------*
  474.  | CMIsProperty - test if an object is a property |
  475.  *------------------------------------------------*
  476.  
  477.  Returns non-zero if the object is a property and 0 otherwise.
  478. */
  479.  
  480. CMBoolean CM_FIXEDARGS CMIsProperty(CMObject theObject)
  481. {
  482.     ExitIfBadObject(theObject, 0);                                        /* validate theObject                                */
  483.  
  484.     return ((CMBoolean)((((TOCObjectPtr)theObject)->objectFlags & PropertyObject) != 0));
  485. }
  486.  
  487.  
  488. /*------------------------------------------------------------------------------*
  489.  | getAdjacentType - get adjacent type in the container by increasing object ID |
  490.  *------------------------------------------------------------------------------*
  491.  
  492.  This routine returns the refNum for the adjacent type in the container following/preceding
  493.  currType.  If currType is NULL, the refNum for the first/last type object is returned.  If
  494.  currType is not NULL, the type object with the next highest/lowest ID is returned.  NULL is
  495.  returned if there are no more type objects following/[receding currType.
  496.  
  497.  currType is generally a refNum previously returned from this routine.  Successive calls
  498.  to this routine will thus yield all the type objects in the container.
  499. */
  500.  
  501. static CMType CM_NEAR getAdjacentType(CMContainer targetContainer, CMType currType, Boolean forward)
  502. {
  503.     TOCObjectPtr theObject;
  504.     ContainerPtr container = (ContainerPtr)targetContainer;
  505.     
  506.     NOPifNotInitialized(NULL);                                                /* NOP if not initialized!                    */
  507.     
  508.     if (currType == NULL)                                                         /* NULL ==> use head of list                */
  509.         if (forward)
  510.             return ((CMType)cmGetMasterListHead(container->toc, TypeObject));
  511.         else
  512.             return ((CMType)cmGetMasterListTail(container->toc, TypeObject));
  513.  
  514.     ExitIfBadType(currType, NULL);                                        /* validate currType                                */
  515.     
  516.     #if 0
  517.     if (((TOCObjectPtr)currType)->container != container ||     /* safety check container        */
  518.             (((TOCObjectPtr)currType)->objectFlags & TypeObject) == 0) {
  519.         ERROR3(CM_err_BadType, "CMType", "CMGetNextType", CONTAINERNAME);
  520.         return (NULL);
  521.     }
  522.     #endif
  523.     
  524.     /* In our implementation the type objects are already chained in sorted order. So all */
  525.     /* we have to do is follow the type chain.                                                                                        */
  526.     
  527.     if (forward)
  528.         theObject = ((TOCObjectPtr)currType)->nextTypeProperty;
  529.     else
  530.         theObject = ((TOCObjectPtr)currType)->prevTypeProperty;
  531.     if (theObject) ++theObject->useCount;                            /* bump use count for next object        */
  532.     
  533.     return ((CMType)theObject);
  534. }
  535.  
  536. /*------------------------------------------------------------------------*
  537.  | CMGetNextType - get next type in the container by increasing object ID |
  538.  *------------------------------------------------------------------------*
  539.  
  540.  Just call getAdjacentType with forward = true.
  541. */
  542.  
  543. CMType CM_FIXEDARGS CMGetNextType(CMContainer targetContainer, CMType currType)
  544. {
  545.     return getAdjacentType(targetContainer, currType, true);
  546. }
  547.                                                          
  548. /*----------------------------------------------------------------------------*
  549.  | CMGetPrevType - get previous type in the container by decreasing object ID |
  550.  *----------------------------------------------------------------------------*
  551.  
  552.  Just call getAdjacentType with forward = false.
  553. */
  554.  
  555. CMType CM_FIXEDARGS CMGetPrevType(CMContainer targetContainer, CMType currType)
  556. {
  557.     return getAdjacentType(targetContainer, currType, false);
  558. }
  559.                                                          
  560. /*-------------------------------------------------------------------------------------*
  561.  | getAdjacentProperty - get adjacent property in the container by next/prev object ID |
  562.  *-------------------------------------------------------------------------------------*
  563.  
  564.  This routine returns the refNum for the next/prev property object in the container following
  565.  currProperty.  If currProperty is NULL, the refNum for the first/last property object is
  566.  returned.  If currProperty is not NULL, the property object with the next highest/lowest ID is
  567.  returned.  NULL is returned if there are no more property objects following/preceding currProperty.
  568.  
  569.  currProperty is generally a refNum previously returned from this routine.  Successive
  570.  calls to this routine will thus yield all the property objects in the container.
  571. */
  572.  
  573. static CMProperty CM_NEAR getAdjacentProperty(CMContainer targetContainer,
  574.                                                                                             CMProperty currProperty,
  575.                                                                                             Boolean forward)
  576. {
  577.     TOCObjectPtr theObject;
  578.     ContainerPtr container = (ContainerPtr)targetContainer;
  579.  
  580.     NOPifNotInitialized(NULL);                                                /* NOP if not initialized!                    */
  581.  
  582.     if (currProperty == NULL)                                                 /* NULL ==> use head of list                */
  583.         if (forward)
  584.             return ((CMProperty)cmGetMasterListHead(container->toc, PropertyObject));
  585.         else
  586.             return ((CMProperty)cmGetMasterListTail(container->toc, PropertyObject));
  587.     
  588.     ExitIfBadProperty(currProperty, NULL);                        /* validate currProperty                        */
  589.  
  590.     #if 0
  591.     if (((TOCObjectPtr)currProperty)->container != container || /* safety check container    */
  592.             (((TOCObjectPtr)currProperty)->objectFlags & PropertyObject) == 0) {
  593.         ERROR3(CM_err_BadType, "CMProperty", "CMGetNextProperty", CONTAINERNAME);
  594.         return (NULL);
  595.     }
  596.     #endif
  597.  
  598.     /* In our implementation the property objects are already chained in sorted order.         */
  599.     /* So all we have to do is follow the property chain.                                                                    */
  600.     
  601.     if (forward)
  602.         theObject = ((TOCObjectPtr)currProperty)->nextTypeProperty;
  603.     else
  604.         theObject = ((TOCObjectPtr)currProperty)->prevTypeProperty;
  605.  
  606.     if (theObject) ++theObject->useCount;                            /* bump use count for next object        */
  607.     
  608.     return ((CMProperty)theObject);
  609. }
  610.  
  611. /*----------------------------------------------------------------------------------*
  612.  | CMGetNextProperty - get next property in the container by next highest object ID |
  613.  *----------------------------------------------------------------------------------*
  614.  
  615.  Just call getAdjacentProperty with forward = true.
  616. */
  617.  
  618. CMProperty CM_FIXEDARGS CMGetNextProperty(CMContainer targetContainer,
  619.                                                                                     CMProperty currProperty)
  620. {
  621.     return getAdjacentProperty(targetContainer, currProperty, true);
  622. }
  623.                                                          
  624. /*-------------------------------------------------------------------------------------*
  625.  | CMGetPrevProperty - get previous property in the container by next lowest object ID |
  626.  *-------------------------------------------------------------------------------------*
  627.  
  628.  Just call getAdjacentProperty with forward = false.
  629. */
  630.  
  631. CMProperty CM_FIXEDARGS CMGetPrevProperty(CMContainer targetContainer,
  632.                                                                                     CMProperty currProperty)
  633. {
  634.     return getAdjacentProperty(targetContainer, currProperty, false);
  635. }
  636.                                                          
  637.                                                           CM_END_CFUNCTIONS
  638.