Protected Attributes

KStringListTemplate< Type > Class Template Reference

Search for all occurrences

Detailed Description

template<class Type>
class KStringListTemplate< Type >

Definition at line 81 of file kstringlist.h.

#include <kstringlist.h>

List of all members.

Public Member Functions

Operation With The Array
int  AddItem (Type *pItem)
  Append a item at the end of the array.
int  InsertItemAt (int pIndex, Type *pItem)
  Insert a item in the array.
Type *  GetItemAt (int pIndex) const
  Access item at given index.
int  FindItem (Type *pItem) const
  Find first matching item.
Constructor and Destructor
  KStringListTemplate ()
  Default constructor.
virtual  ~KStringListTemplate ()
  Destructor.
void  RemoveLast ()
  Remove the item at the end of the array and delete the associated object.
int  GetCount () const
  Get number of items in the array.
KString operator[] (int pIndex)
  Access the string in the item at given index.
kReference  GetReferenceAt (int pIndex) const
  Access the value of reference in the item at given index.
void  SetReferenceAt (int pIndex, kReference pRef)
  Set the value of reference at given index.
char *  GetStringAt (int pIndex) const
  Access the pointer of string at given index.
virtual bool  SetStringAt (int pIndex, const char *pString)
  Set string at given index.
int  Find (Type &pItem) const
  Find first matching item.
int  FindIndex (kReference pReference) const
  Find first matching item which has the same reference as given parameter.
int  FindIndex (const char *pString) const
  Find first matching item in array whose string address is the same as given pointer.
kReference  FindReference (const char *pString) const
  Access the value of reference of the first matching item in array whose string address is the same as given pointer.
bool  Remove (Type &pItem)
  Remove first matching item.
bool  Remove (const char *pString)
  Remove first matching item in array whose string address is the same as given pointer.
bool  RemoveIt (Type &pItem)
  Remove first matching item.
void  Sort ()
  Sort the array by the string of every item,not case sensitive.
void *  FindEqual (const char *pString) const
  Find first matching item which has the same string as given parameter,not case sensitive.
void *  FindCaseSensitive (const char *pString) const
  Find first matching item which has the same string as given parameter, case sensitive.
int  Add (const char *pString, kReference pItem=0)
  Add a new item at the end of array.
virtual int  InsertAt (int pIndex, const char *pString, kReference pItem=0)
virtual void  RemoveAt (int pIndex)
  Remove the item at the given position in the array and delete the associated object.
virtual void  Clear ()
  Delete the array.
virtual void  GetText (KString &pText) const
  Get the string of all the item.
virtual int  SetText (const char *pList)
  Clear the array and set the array's new items with the substring separated by '~' from the given string.

Protected Attributes

KArrayTemplate< Type * >  mList

Constructor & Destructor Documentation

KStringListTemplate ( ) [inline]

Default constructor.

Definition at line 120 of file kstringlist.h.

        {
        }
virtual ~KStringListTemplate ( ) [inline, virtual]

Destructor.

Definition at line 125 of file kstringlist.h.

{ Clear(); }

Member Function Documentation

int AddItem ( Type *  pItem ) [inline]

Append a item at the end of the array.

Returns:
Index of appended pointer.

Definition at line 94 of file kstringlist.h.

{ return mList.Add( pItem ); }
int InsertItemAt ( int  pIndex,
Type *  pItem 
) [inline]

Insert a item in the array.

Parameters:
pIndex Position where to insert the item.
pItem Item to insert.
Returns:
Position of the inserted item in the array.
Remarks:
If the given index is out of range, the pointer is appended at the end of the array.

Definition at line 102 of file kstringlist.h.

{ return mList.InsertAt( pIndex, pItem ); }
Type* GetItemAt ( int  pIndex ) const [inline]

Access item at given index.

Definition at line 105 of file kstringlist.h.

{ return mList[pIndex]; }
int FindItem ( Type *  pItem ) const [inline]

Find first matching item.

Returns:
Index of first matching item found or -1 if there is no matching element.

Definition at line 110 of file kstringlist.h.

{ return mList.Find( pItem ); }
void RemoveLast ( ) [inline]

Remove the item at the end of the array and delete the associated object.

Definition at line 129 of file kstringlist.h.

{ RemoveAt( mList.GetCount()-1 ); }
int GetCount ( ) const [inline]

Get number of items in the array.

Returns:
The number of items in the array.

Definition at line 134 of file kstringlist.h.

{ return mList.GetCount(); }
KString& operator[] ( int  pIndex ) [inline]

Access the string in the item at given index.

Definition at line 137 of file kstringlist.h.

{ return mList[pIndex]->mString; }
kReference GetReferenceAt ( int  pIndex ) const [inline]

Access the value of reference in the item at given index.

Definition at line 140 of file kstringlist.h.

{ return mList[pIndex]->mReference; }
void SetReferenceAt ( int  pIndex,
kReference  pRef 
) [inline]

Set the value of reference at given index.

Definition at line 143 of file kstringlist.h.

{ mList[pIndex]->mReference = pRef; }
char* GetStringAt ( int  pIndex ) const [inline]

Access the pointer of string at given index.

Definition at line 146 of file kstringlist.h.

{ if (pIndex<mList.GetCount()) return mList[pIndex]->mString.Buffer(); else return NULL; }
virtual bool SetStringAt ( int  pIndex,
const char *  pString 
) [inline, virtual]

Set string at given index.

Definition at line 149 of file kstringlist.h.

        { 
            if (pIndex<mList.GetCount()) 
            {
                mList[pIndex]->mString = pString; 
                return true;
            } else return false; 
        }
int Find ( Type &  pItem ) const [inline]

Find first matching item.

Returns:
Index of first matching item found or -1 if there is no matching element.

Definition at line 162 of file kstringlist.h.

        { 
            for (int Count=0; Count<mList.GetCount(); Count++) {
                if (mList[Count]==&pItem) {
                    return Count;
                }
            }
            return -1;
        }
int FindIndex ( kReference  pReference ) const [inline]

Find first matching item which has the same reference as given parameter.

Returns:
Index of first matching item found or -1 if there is no matching element.

Definition at line 176 of file kstringlist.h.

        { 
            for (int Count=0; Count<mList.GetCount(); Count++) {
                if (mList[Count]->mReference==pReference) {
                    return Count;
                }
            }
            return -1;
        }
int FindIndex ( const char *  pString ) const [inline]

Find first matching item in array whose string address is the same as given pointer.

Returns:
Index of first matching item found or -1 if there is no matching element.

Definition at line 190 of file kstringlist.h.

        { 
            for (int Count=0; Count<mList.GetCount(); Count++) {
                if (mList[Count]->mString==pString) {
                    return Count;
                }
            }
            return -1;
        }
kReference FindReference ( const char *  pString ) const [inline]

Access the value of reference of the first matching item in array whose string address is the same as given pointer.

Returns:
The value of reference of the first matching item found or NULL if there is no matching element.

Definition at line 205 of file kstringlist.h.

        {
        int Index = FindIndex( pString );
            if (Index!=-1) {
                return mList[Index]->mReference;
            }
            return 0; // NULL
        }
bool Remove ( Type &  pItem ) [inline]

Remove first matching item.

Definition at line 215 of file kstringlist.h.

        {
        int Index = Find( pItem );
            if (Index>=0) {
                RemoveAt( Index );
                return true;
            }
            return false;
        }
bool Remove ( const char *  pString ) [inline]

Remove first matching item in array whose string address is the same as given pointer.

Definition at line 226 of file kstringlist.h.

        {
        int Index = FindIndex( pString );
            if (Index>=0) {
                RemoveAt( Index );
                return true;
            }
            return false;
        }
bool RemoveIt ( Type &  pItem ) [inline]

Remove first matching item.

Definition at line 237 of file kstringlist.h.

        {
        int Index = Find( pItem );
            if (Index>=0) {
                RemoveAt( Index );
                return true;
            }
            return false;
        }
void Sort ( ) [inline]

Sort the array by the string of every item,not case sensitive.

Definition at line 248 of file kstringlist.h.

void* FindEqual ( const char *  pString ) const [inline]

Find first matching item which has the same string as given parameter,not case sensitive.

Returns:
the pointer of matching item found or NULL if there is no matching element.

Definition at line 257 of file kstringlist.h.

        {
        KStringListItem Key(pString);  
        
            if (mList.GetCount() != 0)
            {
                return bsearch ( &Key, &(mList.GetArray()[0]),mList.GetCount(),sizeof(KStringListItem *),CompareKStringListFindEqual );
            }
            else
            {
                return NULL ;
            }
        }
void* FindCaseSensitive ( const char *  pString ) const [inline]

Find first matching item which has the same string as given parameter, case sensitive.

Returns:
the pointer of matching item found or NULL if there is no matching element.

Definition at line 275 of file kstringlist.h.

        {
        KStringListItem Key(pString);  
        
            if (mList.GetCount() != 0)
            {
                return bsearch ( &Key, &(mList.GetArray()[0]),mList.GetCount(),sizeof(KStringListItem *), CompareCaseSensitiveKStringList);
            }
            else
            {
                return NULL ;
            }
        
        }
int Add ( const char *  pString,
kReference  pItem = 0 
) [inline]

Add a new item at the end of array.

Definition at line 292 of file kstringlist.h.

        { 
            return InsertAt( mList.GetCount(),pString,pItem ); 
        }
virtual int InsertAt ( int  pIndex,
const char *  pString,
kReference  pItem = 0 
) [inline, virtual]

Definition at line 297 of file kstringlist.h.

        { 
            return mList.InsertAt( pIndex,FbxSdkNew< Type >( pString,(kReference)pItem )); 
        }
virtual void RemoveAt ( int  pIndex ) [inline, virtual]

Remove the item at the given position in the array and delete the associated object.

Parameters:
pIndex Position of the item to remove.
Remarks:
If the index is not valid, nothing is performed. Otherwise, the item is removed from the array and the items are shifted to fill the empty slot.

Definition at line 308 of file kstringlist.h.

        { 
            FbxSdkDelete(mList[pIndex]); mList.RemoveAt( pIndex ); 
        }
virtual void Clear ( ) [inline, virtual]

Delete the array.

Definition at line 314 of file kstringlist.h.

        {
            for (int Count=0; Count<mList.GetCount(); Count++ ) {
                FbxSdkDelete(mList[Count]);
            }
            mList.Clear();
        }
virtual void GetText ( KString pText ) const [inline, virtual]

Get the string of all the item.

Returns:
The text of string, each item's string separated by '~'.

Definition at line 325 of file kstringlist.h.

        {
            int     Count;
            for (Count=0; Count<mList.GetCount(); Count++) 
            {
                pText += mList[Count]->mString;
                if (Count<mList.GetCount()-1) 
                {
                   // HACK: Fix this
                    pText += "~";
                   //------- END HACK
                }
            }
        }
virtual int SetText ( const char *  pList ) [inline, virtual]

Clear the array and set the array's new items with the substring separated by '~' from the given string.

Parameters:
pList The string which used to generate the new items.
Returns:
The last index of the item in the new array.
Remarks:
The number of items in the new array is the same as the number of substrings, and the string of each item is decided by the content of each substring.

Definition at line 346 of file kstringlist.h.

        {
        int     Pos=0, OldPos = 0;
        int     LastIndex=0;
        KString Name=pList;

            Clear();
            for (Pos=0; Name.Buffer()[Pos]!=0; Pos++) {
                if (Name.Buffer()[Pos]==_T('~')) {
                    Name.Buffer()[Pos]=0;
                    LastIndex = Add(Name.Buffer()+OldPos);
                    OldPos=Pos+1;
                }
            }

            if(OldPos != Pos)
            {
                LastIndex = Add(Name.Buffer()+OldPos);
            }
            return LastIndex;
        } 

Member Data Documentation

KArrayTemplate<Type *> mList [protected]

Definition at line 83 of file kstringlist.h.


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