Back to index

im-sdk  12.3.91
Classes | Public Member Functions | Protected Types | Protected Attributes | Private Member Functions
IMList< T > Class Template Reference

#include <IMList.hh>

Inheritance diagram for IMList< T >:
Inheritance graph
[legend]
Collaboration diagram for IMList< T >:
Collaboration graph
[legend]

List of all members.

Classes

struct  _Tnode

Public Member Functions

 IMList ()
 ~IMList ()
void addItem (T *)
void addItemByKey (T *, int)
T & getItem (unsigned int) const
T & getItemByKey (int) const
T & getItemMakeTop (unsigned int)
T & getFirstItem (void)
T & getNextItem (void)
unsigned int getIndex (T *) const
int getSize () const
void remove (T *)
void destroy ()
void disable_reordering ()

Protected Types

typedef struct IMList::_Tnode Tnode

Protected Attributes

Tnodelist
Tnodenext_node
Tnode null_obj
int nSize
unsigned int nIndex
int reorder

Private Member Functions

void * getNodeByKey (int) const

Detailed Description

template<class T>
class IMList< T >

Definition at line 48 of file IMList.hh.


Class Documentation

struct IMList::_Tnode

template<class T>
struct IMList< T >::_Tnode

Definition at line 69 of file IMList.hh.

Collaboration diagram for IMList< T >::_Tnode:
Class Members
unsigned int index
int key
struct _Tnode * next
T * obj

Member Typedef Documentation

template<class T>
typedef struct IMList::_Tnode IMList< T >::Tnode [protected]

Constructor & Destructor Documentation

template<class T >
IMList< T >::IMList ( )

Definition at line 86 of file IMList.hh.

                  {
  nSize = nIndex = 0;
  list = (Tnode *)0;
  next_node = (Tnode *)0;
  null_obj.obj = (T*)0;
  null_obj.key = 0;
  null_obj.index = 0;
  null_obj.next = 0;
  reorder = 1;
}
template<class T>
IMList< T >::~IMList ( ) [inline]

Definition at line 51 of file IMList.hh.

            {
    delete list;
  }

Member Function Documentation

template<class T>
void IMList< T >::addItem ( T *  item)

Definition at line 103 of file IMList.hh.

                               {
  Tnode *node = new Tnode;
  node->obj  = item;
  nIndex++;
  node->index = nIndex;
  node->next = list;
  list = node;
  nSize++;
}

Here is the caller graph for this function:

template<class T>
void IMList< T >::addItemByKey ( T *  item,
int  key 
)

Definition at line 114 of file IMList.hh.

                                             {
  Tnode *node = (Tnode*)getNodeByKey(key);
  if (!node) {
    node = new Tnode;
    node->obj  = item;
    node->key  = key;
    nIndex++;
    node->index = nIndex;
    node->next = list;
    list = node;
    nSize++;
  } else {
    node->obj = item;
  }
}

Here is the caller graph for this function:

template<class T >
void IMList< T >::destroy ( )

Definition at line 250 of file IMList.hh.

                        {
  Tnode *tnode = (Tnode *)list;
  Tnode *del_node = (Tnode *)0;

  while (tnode) {
    del_node = tnode;
    tnode = tnode->next;
    //delete del_node->obj;
    delete del_node;
  }
  list = (Tnode *)0;
  nSize = 0;
  nIndex = 0;
}

Here is the caller graph for this function:

template<class T >
void IMList< T >::disable_reordering ( )

Definition at line 98 of file IMList.hh.

                                   {
  reorder = 0;
}

Here is the caller graph for this function:

template<class T >
T & IMList< T >::getFirstItem ( void  )

Definition at line 180 of file IMList.hh.

                               {
  Tnode * tnode = (Tnode *)list;
  if(tnode==0){
     return *(null_obj.obj);
  }
  next_node=tnode->next;
  return *(tnode->obj);
}

Here is the caller graph for this function:

template<class T>
unsigned int IMList< T >::getIndex ( T *  item) const

Definition at line 200 of file IMList.hh.

                                              {
  Tnode *tnode = (Tnode *)list;

  if (item == 0) return 0;
  while (tnode) {
    if (tnode->obj == item) return tnode->index;
    tnode = tnode->next;
  }
  return 0;
}

Here is the caller graph for this function:

template<class T >
T & IMList< T >::getItem ( unsigned int  index) const

Definition at line 212 of file IMList.hh.

                                              {
  Tnode * tnode = (Tnode *)list;

  if (index == 0 || index > nIndex)
    return *(null_obj.obj);

  if (tnode == 0 && nSize == 0 && reorder == 0)  // not error
    return *(null_obj.obj);

  while (tnode) {
    if (tnode->index == index) return *(tnode->obj);
    tnode = tnode->next;
  }
  if (tnode == 0)    // should not be an error
    return *(null_obj.obj);

  return *(tnode->obj);
}
template<class T >
T & IMList< T >::getItemByKey ( int  key) const

Definition at line 232 of file IMList.hh.

                                        {
  Tnode *node = (Tnode*)getNodeByKey(key);
  if (!node) return *(null_obj.obj);
  return *(node->obj);
}

Here is the caller graph for this function:

template<class T >
T & IMList< T >::getItemMakeTop ( unsigned int  index)

Definition at line 151 of file IMList.hh.

                                               {
  Tnode * tnode = (Tnode *)list;
  Tnode * tnode_prev = NULL;

  if (index == 0 || index > nIndex)
    return *(null_obj.obj);

  if (tnode == 0 && nSize == 0 && reorder == 0)  // not error
    return *(null_obj.obj);

  while (tnode) {
    if (tnode->index == index) {
      if (NULL != tnode_prev) {
       tnode_prev->next = tnode->next;
       tnode->next = list;
       list = tnode;
      }
      return *(tnode->obj);
    }
    tnode_prev = tnode;
    tnode = tnode->next;
  }
  if (tnode == 0)    // should not be an error
    return *(null_obj.obj);

  return *(tnode->obj);
}

Here is the caller graph for this function:

template<class T >
T & IMList< T >::getNextItem ( void  )

Definition at line 190 of file IMList.hh.

                              {
  Tnode * tnode = (Tnode *)next_node;
  if(tnode==0){
     return *(null_obj.obj);
  }
  next_node=tnode->next;
  return *(tnode->obj);
}

Here is the caller graph for this function:

template<class T >
void * IMList< T >::getNodeByKey ( int  key) const [private]

Definition at line 239 of file IMList.hh.

                                           {
  Tnode *tnode = (Tnode *)list;

  while (tnode) {
    if (tnode->key == key) return (void*)tnode;
    tnode = tnode->next;
  }
  return (void*)0;
}
template<class T>
int IMList< T >::getSize ( ) const [inline]

Definition at line 62 of file IMList.hh.

{return nSize;}

Here is the caller graph for this function:

template<class T>
void IMList< T >::remove ( T *  item)

Definition at line 131 of file IMList.hh.

                              {
  Tnode **prev, *tnode;
  int index=1;
  for (prev = &list; tnode = *prev;) {
    if (tnode->obj == item) {
      *prev = tnode->next;
      if (next_node == tnode) next_node = tnode->next;      
      delete tnode;
      nSize--;
      if (reorder == 0) break;
    } else {
      prev = &tnode->next;
      if (reorder == 1) tnode->index=index++;
    }
  }
  if (reorder == 1) nIndex=nSize;
  return;
}

Here is the caller graph for this function:


Member Data Documentation

template<class T>
Tnode* IMList< T >::list [protected]

Definition at line 75 of file IMList.hh.

template<class T>
Tnode* IMList< T >::next_node [protected]

Definition at line 76 of file IMList.hh.

template<class T>
unsigned int IMList< T >::nIndex [protected]

Definition at line 79 of file IMList.hh.

template<class T>
int IMList< T >::nSize [protected]

Definition at line 78 of file IMList.hh.

template<class T>
Tnode IMList< T >::null_obj [protected]

Definition at line 77 of file IMList.hh.

template<class T>
int IMList< T >::reorder [protected]

Definition at line 80 of file IMList.hh.


The documentation for this class was generated from the following file: