⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmulist.h

📁 用c++变得一个测量财富的+游戏
💻 H
📖 第 1 页 / 共 2 页
字号:
*   if (filStatus != FIP_END_OF_DIR)
*     {
*     filFlist.InsertAsciiSorted(fileCompare,
*                                sizeof(FIP_FILE_TY),
*                                &filInfo );
*     }
*   }
* while (filStatus != FIL_END_OF_DIR);
*
* // Now print entire, sorted file list -
*
* filEntry = filFlist.First();
*
* while (filEntry)
*   {
*   filPtr = (FIP_FILE_TY *)filFlist->body;
*   printf( "File: %s, Size: %7ld, Date: %s\n",
*            filPtr->fileName,
*            filPtr->fileSize,
*            filPtr->date );
*   filEntry = filFlist.Next();
*   }
* filFlist.DeleteList();
* }
*
* You must construct the list sorted.  If you start
* with a partially built list before using this
* function, your list won't be completely sorted.
*
*/

STAT_TYPE        InsertSorted( int (* pasFncCompare) (const void *pasStru1,
                                                      const void *pasStru2 ),
                                       INT32  pasSizeOfBuf,
                                       void  *pasBufPtr );


// Also provide this method, although the 'compare'
// function MUST be based on the pasEntry.body only,
// not &pasEntry!

STAT_TYPE        InsertSorted( int (* pasFncCompare) (const void *pasStru1,
                                                      const void *pasStru2 ),
                                MMP_DATA_TY &pasEntry );


/****************************************
* You provide a function to compare
* two entries in your list.  Then
* this function will find that entry
* based on your matching algorithm
* implemented at 'pasFncCompare'. This
* allows you to see if an 'equivalent
* item exists' in a list before adding
* another, for example.  It's up to
* you to ensure that all "oranges"
* are being added to the list so
* that 'pasFncCompare' is comparing
* "oranges" to "oranges".  Or, if
* comparing "oranges" and "apples"
* (e.g. two different structure
* types being stored in the same list),
* your compare function can handle
* it. You may wish to subclass this
* puppy so that another layer can
* ensure such consistency.
*
* If the entry isn't found, a NULL
* is returned.  The 'pasFncCompare'
* function must return a 0 for
* what you consider an "exact match"
* (such as the result of 'strcmpi'
* for example).
*
* If the item is found a pointer
* that list entry is returned,
* and that list entry becomes
* current.  If not found,
* NULL is returned and
* 'current' remains unchanged.
*
*/

/****************************************
* Search for first and next occurrences
* of an entry in a list.  You provide
* the comparison function. If not found
* or error, a NULL is returned. Else
* pointer to the stored data is returned.
*/

// Start search from head of list

MMP_DATA_TY  *FindFirstEntry( int (* pasFncCompare) (const void *pasStru1,
                                                     const void *pasStru2 ),
                              void *pasBufPtr );

// Start search from current list position

MMP_DATA_TY  *FindNextEntry ( int (* pasFncCompare) (const void *pasStru1,
                                                     const void *pasStru2 ),
                              void *pasBufPtr );

/****************************************
* Same as search functions above, but
* they also return an index to the entry
* found.  The "FindNextEntry" algorithm
* could be rather slow when fetching the
* index as well, so don't use it unless
* you really need the index value back too.
*/

// Start search from head of list

MMP_DATA_TY  *FindFirstEntry( int (* pasFncCompare) (const void *pasStru1,
                                                     const void *pasStru2 ),
                              void *pasBufPtr,
                              INT32 &refIndexFound );

// Start search from current list position

MMP_DATA_TY  *FindNextEntry ( int (* pasFncCompare) (const void *pasStru1,
                                                     const void *pasStru2 ),
                              void *pasBufPtr,
                              INT32 &refIndexFound );

/********************** private declarations **************************/
private:

MMG_LLIST_TY  *head;
MMG_LLIST_TY  *tail;
MMG_LLIST_TY  *current;
INT32          numEntries;

MMG_LLIST_TY *mmuCreateEntry( INT32     pasSizeofBuf,
                              void     *pasBufPtr );

STAT_TYPE     mmuSetFirstEntry( MMG_LLIST_TY *pasEntry );
STAT_TYPE     mmuDestroyEntry( MMG_LLIST_TY *refEntry );

/********************* protected declarations *************************/

protected:

}; /* MMUllist end class */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  MMUvlist_class

    PURPOSE:  to declare a linked list class that makes it easy
      to generate and maintain a linked list, returning VOID POINTERS
      instead of pointers to MMP_DATA_TY structures.  This one is
      easy to subclass for whatever specific data type you wish to
      implement a list for.

**                                                                    **
**                                                                    **
**                                                                    **
**\p*******************************************************************/

class  MMUvlist

{ /* MMUvlist class */

/********************** friend declarations ***************************/

/********************** public declarations ***************************/
public:

                        MMUvlist();
                        ~MMUvlist();

// Copy contents of this linked list to the
// referenced destination. Start at FIRST of
// this list and APPEND all to refList.
        STAT_TYPE        CopyTo( MMUvlist *refList );
virtual void            *First();
virtual void            *Last();
virtual void            *Next();
virtual void            *Prev();
virtual void            *Current();
        INT32            NumEntries();
virtual void            *Indexed( INT32 pasIndex );
        INT32            GetIndexOfCurrent();

virtual STAT_TYPE               InsertBeforeHead   ( INT32       pasSizeOfBuf,
                                                     void       *pasBufPtr );

virtual STAT_TYPE               AppendAfterTail    ( INT32       pasSizeOfBuf,
                                                     void       *pasBufPtr );

virtual STAT_TYPE               InsertBeforeCurrent( INT32       pasSizeOfBuf,
                                                     void       *pasBufPtr );

virtual STAT_TYPE               InsertAfterCurrent( INT32       pasSizeOfBuf,
                                                    void       *pasBufPtr );
STAT_TYPE               DeleteCurrentEntry();

STAT_TYPE               DeleteList();



virtual STAT_TYPE     InsertSorted( int (* pasFncCompare) (const void *pasStru1,
                                                           const void *pasStru2 ),
                                     INT32  pasSizeOfBuf,
                                     void  *pasBufPtr );

virtual void  *FindFirstEntry( int (* pasFncCompare) (const void *pasStru1,
                                                      const void *pasStru2 ),
                                                      void *pasBufPtr );

virtual void  *FindNextEntry ( int (* pasFncCompare) (const void *pasStru1,
                                                      const void *pasStru2 ),
                                                      void *pasBufPtr );


virtual void  *FindFirstEntry( int (* pasFncCompare) (const void *pasStru1,
                                                      const void *pasStru2 ),
                                                      void *pasBufPtr,
                                                      INT32 &refIndexFound );

virtual void  *FindNextEntry ( int (* pasFncCompare) (const void *pasStru1,
                                                      const void *pasStru2 ),
                                                      void *pasBufPtr,
                                                      INT32 &refIndexFound );

/********************** private declarations **************************/
private:

MMUllist        *mmhList;

/********************* protected declarations *************************/

protected:

}; /* MMUvlist end class */

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -