home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / shr93.zip / SOMLIST.C < prev    next >
Text File  |  1993-04-12  |  6KB  |  276 lines

  1. /*
  2.  * OS/2 Work Place Shell Sample Program - SOM simple ordered list
  3.  *
  4.  * Copyright (C) 1993 IBM Corporation
  5.  *
  6.  *   DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  7.  *   sample code created by IBM Corporation.  This sample code is
  8.  *   not part of any standard or IBM product and is provided to you
  9.  *   solely for the purpose of assisting you in the development of
  10.  *   your applications.  The code is provided "AS IS".  ALL
  11.  *   WARRANTIES ARE EXPRESSLY DISCLAIMED, INCLUDING THE IMPLIED
  12.  *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  13.  *   PURPOSE.  IBM shall not be liable for any damages arising out
  14.  *   of your use of the sample code, even if IBM has been advised of
  15.  *   the possibility of such damages.
  16.  *
  17.  * Simple ordered list based on the list functions provided by LIST.C.
  18.  */
  19.  
  20. #define SOM_NoTest
  21. #define ShrList_Class_Source
  22.  
  23. #include <os2.h>
  24.  
  25. #pragma checkout(suspend)
  26. #include "somlist.ih"
  27. #pragma checkout(resume)
  28.  
  29. /*
  30.  * Query and Set instance variable(s).
  31.  */
  32.  
  33. SOM_Scope PVOID SOMLINK ls_shrQueryList(ShrList *somSelf)
  34. {
  35.   ShrListData *somThis = ShrListGetData(somSelf);
  36.  
  37.   return _pList;
  38. }
  39.  
  40. SOM_Scope BOOL SOMLINK ls_shrSetList(ShrList *somSelf,
  41.                 PVOID pNewList)
  42. {
  43.   ShrListData *somThis = ShrListGetData(somSelf);
  44.  
  45.   _pList = pNewList;
  46.  
  47.   return TRUE;
  48. }
  49.  
  50. /*
  51.  *
  52.  * Add an item to a list.
  53.  */
  54.  
  55. SOM_Scope BOOL SOMLINK ls_shrAddLast(ShrList *somSelf,
  56.                 PVOID pValue)
  57. {
  58.   return ShrListAddLast(_shrQueryList(somSelf), pValue);
  59. }
  60.  
  61. SOM_Scope BOOL SOMLINK ls_shrAddFirst(ShrList *somSelf,
  62.                 PVOID pValue)
  63. {
  64.   return ShrListAddFirst(_shrQueryList(somSelf), pValue);
  65. }
  66.  
  67. SOM_Scope BOOL SOMLINK ls_shrAddBefore(ShrList *somSelf,
  68.                 PVOID pValue,
  69.                 PVOID pBeforeValue)
  70. {
  71.   return ShrListAddBefore(_shrQueryList(somSelf), pValue, pBeforeValue);
  72. }
  73.  
  74. SOM_Scope BOOL SOMLINK ls_shrAddAfter(ShrList *somSelf,
  75.                 PVOID pValue,
  76.                 PVOID pAfterValue)
  77. {
  78.   return ShrListAddAfter(_shrQueryList(somSelf), pValue, pAfterValue);
  79. }
  80.  
  81. /*
  82.  *
  83.  * Remove an item from list.
  84.  */
  85.  
  86. SOM_Scope BOOL SOMLINK ls_shrRemove(ShrList *somSelf,
  87.                 PVOID pValue)
  88. {
  89.   return ShrListRemove(_shrQueryList(somSelf), pValue);
  90. }
  91.  
  92. SOM_Scope BOOL SOMLINK ls_shrRemoveAll(ShrList *somSelf)
  93. {
  94.   return ShrListRemoveAll(_shrQueryList(somSelf));
  95. }
  96.  
  97. /*
  98.  *
  99.  * Enumerate items in a list.
  100.  */
  101.  
  102. SOM_Scope PVOID SOMLINK ls_shrBeginEnum(ShrList *somSelf)
  103. {
  104.   return ShrListBeginEnum(_shrQueryList(somSelf));
  105. }
  106.  
  107. SOM_Scope BOOL SOMLINK ls_shrEndEnum(ShrList *somSelf,
  108.                 PVOID pListEnum)
  109. {
  110.   return ShrListEndEnum(_shrQueryList(somSelf), pListEnum);
  111. }
  112.  
  113. SOM_Scope BOOL SOMLINK ls_shrNext(ShrList *somSelf,
  114.                 PVOID pListEnum,
  115.                 PVOID *ppValue)
  116. {
  117.   return ShrListNext(_shrQueryList(somSelf), pListEnum, ppValue);
  118. }
  119.  
  120. /*
  121.  *
  122.  * List statistics.
  123.  */
  124.  
  125. SOM_Scope ULONG SOMLINK ls_shrCount(ShrList *somSelf)
  126. {
  127.   return ShrListCount(_shrQueryList(somSelf));
  128. }
  129.  
  130. /*
  131.  *
  132.  * Membership.
  133.  */
  134.  
  135. SOM_Scope BOOL SOMLINK ls_shrIncludes(ShrList *somSelf,
  136.                 PVOID pValue)
  137. {
  138.   return ShrListIncludes(_shrQueryList(somSelf), pValue);
  139. }
  140.  
  141. /*
  142.  *
  143.  * When destroying a list.
  144.  */
  145.  
  146. SOM_Scope VOID SOMLINK ls_somUninit(ShrList *somSelf)
  147. {
  148.   PVOID pList = _shrQueryList(somSelf);
  149.  
  150.   if (pList)
  151.     ShrListFree(pList);
  152.  
  153.   parent_somUninit(somSelf);
  154. }
  155.  
  156. /*
  157.  * Class Methods.
  158.  *
  159.  * IMPORTANT! IMPORTANT! IMPORTANT! IMPORTANT! IMPORTANT!
  160.  * IMPORTANT! IMPORTANT! IMPORTANT! IMPORTANT! IMPORTANT!
  161.  * IMPORTANT! IMPORTANT! IMPORTANT! IMPORTANT! IMPORTANT!
  162.  *
  163.  * The "undef/define" below marks the begining of the
  164.  * class methods.  SOM's macros will generate the
  165.  * wrong code if instance methods are defined after
  166.  * this point (causing strange runtime traps).
  167.  *
  168.  * Be careful when adding new INSTANCE methods to the CSC file because
  169.  * they are automatically appended to the end of the C file, but
  170.  * must appear above the "#undef SOM_CurrentClass".
  171.  */
  172.  
  173. #undef SOM_CurrentClass
  174. #define SOM_CurrentClass SOMMeta
  175.  
  176. SOM_Scope SOMObject * SOMLINK lsM_shrclsExactStringListNew(M_ShrList *somSelf)
  177. {
  178.   SOMObject *newList;
  179.   PVOID pList = NULL;
  180.  
  181.   newList = _somNew(somSelf);
  182.  
  183.   if (newList)
  184.   {
  185.     pList = ShrExactStringListNew();
  186.  
  187.     if (pList)
  188.     {
  189.       _shrSetList(newList, pList);
  190.     }
  191.     else
  192.     {
  193.       _somFree(newList);
  194.       newList = NULL;
  195.     }
  196.   }
  197.  
  198.   return newList;
  199. }
  200.  
  201. SOM_Scope SOMObject * SOMLINK lsM_shrclsStringListNew(M_ShrList *somSelf)
  202. {
  203.   SOMObject *newList;
  204.   PVOID pList = NULL;
  205.  
  206.   newList = _somNew(somSelf);
  207.  
  208.   if (newList)
  209.   {
  210.     pList = ShrStringListNew();
  211.  
  212.     if (pList)
  213.     {
  214.       _shrSetList(newList, pList);
  215.     }
  216.     else
  217.     {
  218.       _somFree(newList);
  219.       newList = NULL;
  220.     }
  221.   }
  222.  
  223.   return newList;
  224. }
  225.  
  226. SOM_Scope SOMObject * SOMLINK lsM_shrclsValueListNew(M_ShrList *somSelf)
  227. {
  228.   SOMObject *newList;
  229.   PVOID pList = NULL;
  230.  
  231.   newList = _somNew(somSelf);
  232.  
  233.   if (newList)
  234.   {
  235.     pList = ShrValueListNew();
  236.  
  237.     if (pList)
  238.     {
  239.       _shrSetList(newList, pList);
  240.     }
  241.     else
  242.     {
  243.       _somFree(newList);
  244.       newList = NULL;
  245.     }
  246.   }
  247.  
  248.   return newList;
  249. }
  250.  
  251. SOM_Scope SOMObject * SOMLINK lsM_shrclsNew(M_ShrList *somSelf,
  252.                 PFNLISTCOMPARE pfnCompare)
  253. {
  254.   SOMObject *newList;
  255.   PVOID pList = NULL;
  256.  
  257.   newList = _somNew(somSelf);
  258.  
  259.   if (newList)
  260.   {
  261.     pList = ShrGenericListNew(pfnCompare);
  262.  
  263.     if (pList)
  264.     {
  265.       _shrSetList(newList, pList);
  266.     }
  267.     else
  268.     {
  269.       _somFree(newList);
  270.       newList = NULL;
  271.     }
  272.   }
  273.  
  274.   return newList;
  275. }
  276.