skillList Class Reference

#include <skill-list.hpp>

Collaboration diagram for skillList:

Collaboration graph
[legend]
List of all members.

Detailed Description

A skill list is actually yet another implementation of a linked list. In this case each node in the list has a "name" and a "value."

Definition at line 41 of file skill-list.hpp.

Public Member Functions

 skillList ()
void addSkill (char *s, int l)
void addSkill (skillObj *s)
int skillCount ()
char ** listOfSkills ()
char * listOfSkillString ()
void XMLout (FILE *fout)


Constructor & Destructor Documentation

skillList::skillList (  ) 

Constructor without parameters.

Definition at line 51 of file skill-list.cpp.

References skillEntry::setLevel(), and skillEntry::setSkill().

00051                     {
00052         root = new skillEntry();
00053         root->setSkill("ROOT NODE");
00054         root->setLevel(-100);
00055         
00056 }

Here is the call graph for this function:


Member Function Documentation

void skillList::addSkill ( skillObj s  ) 

Add a skill using the skillObj interface rather than the now obsolete one above. The algorithm remains essentially the same, but now we don't pass a name and level, we pass a skillObj instead.

Parameters:
s pointer to a skillObj

Definition at line 77 of file skill-list.cpp.

References skillEntry::getLevel(), skillEntry::getNext(), skillEntry::getSkill(), skillEntry::setLevel(), and skillEntry::setNext().

00077                                    {
00078         skillEntry* p=root;
00079                 while(p->getNext() != (skillEntry*)0){
00080                 p = p->getNext();
00081                 if ( strcmp(p->getSkill(),s->getSkill()) == 0 ) {
00082                         p->setLevel(p->getLevel()+ s->getLevel());
00083                         if ( p->getLevel() < 0 ) 
00084                                 p->setLevel(0);
00085                         return;
00086                 }
00087         }
00088         
00089         p->setNext(s);
00090         s->setNext((skillEntry*)0);
00091         
00092 }

Here is the call graph for this function:

void skillList::addSkill ( char *  s,
int  l 
)

Add a skill with a name and a level. If the skill already exists in the list then the passed in level value is added to the currently existing skill.

Parameters:
s pointer to the string representing the skill
l integer value for the level of the skill.

Definition at line 58 of file skill-list.cpp.

References skillEntry::getLevel(), skillEntry::getNext(), skillEntry::getSkill(), skillEntry::setLevel(), and skillEntry::setNext().

Referenced by personObj::addSkill().

00058                                       {
00059         skillEntry* p = root;
00060         while(p->getNext() != (skillEntry*)0){
00061                 p = p->getNext();
00062                 if ( strcmp(p->getSkill(),s) == 0 ) {
00063                         p->setLevel(p->getLevel()+l);
00064                         if ( p->getLevel() < 0 ) 
00065                                 p->setLevel(0);
00066                         return;
00067                 }
00068         }
00069         skillEntry *n = new skillEntry(s,l);
00070         p->setNext(n);
00071         n->setNext((skillEntry*)0);
00072         fprintf(stderr,"WARN:  obsolete method skillList::addSkill(char*,int) being called.\n");
00073         
00074         
00075 }

Here is the call graph for this function:

Here is the caller graph for this function:

char ** skillList::listOfSkills (  ) 

Get a formatted text list of the skill in this list.

Returns:
an array of pointers of the skills and their levels

Definition at line 104 of file skill-list.cpp.

References skillEntry::getNext(), skillCount(), and skillEntry::toString().

Referenced by personObj::listOfSkills().

00104                               {
00105         int dimx = this->skillCount();
00106         char** buffer=(char**)malloc(dimx);
00107         int ix=0;
00108         skillEntry *p=root;
00109         
00110         if (root->getNext() == (skillEntry*)0)
00111                 return (char**)0;  // This should never happen. 
00112         while( p->getNext() != (skillEntry*)0){
00113                 p=p->getNext();
00114                 buffer[ix]=p->toString();
00115                 checkString("skillList::listOfSkills",buffer[ix]);
00116                 ix++;
00117         }
00118         return (char **) buffer;
00119 }

Here is the call graph for this function:

Here is the caller graph for this function:

char * skillList::listOfSkillString (  ) 

Yet another way to get the skill list

Definition at line 123 of file skill-list.cpp.

References skillEntry::getLevel(), skillEntry::getNext(), and skillEntry::getSkill().

Referenced by personObj::listOfSkillString().

00123                                   {
00124         int size = 0;
00125         int linesize=0;
00126         int ix;
00127         skillEntry *p=root;
00128         char* buffer;
00129         
00130         if ( this->skillCount() == 0 ) 
00131                 return "NONE";
00132         
00133         while(p->getNext()!=(skillEntry*)0){
00134                 p=p->getNext();
00135                 char *skill=p->getSkill();
00136                 int  level = p->getLevel();
00137                 char rval[10];
00138                 
00139                 sprintf(rval," - %d",level);
00140                 
00141                 linesize = linesize + strlen(skill) + strlen(rval) + 1 ;
00142                 size = size + strlen(skill) + strlen(rval) + 1 ;
00143                 
00144                 if ( linesize >= 71 ) {
00145                         linesize=0;
00146                         size = size + 2;
00147                 }
00148         }
00149         
00150         buffer=(char *)malloc(size+1);
00151         sprintf(buffer,"\n");
00152         p=root;
00153         linesize=0;
00154         while(p->getNext()!=(skillEntry*)0){
00155                 p=p->getNext();
00156                 char *skill=p->getSkill();
00157                 int  level = p->getLevel();
00158                 char rval[10];
00159                 
00160                 sprintf(rval,"-%d",level);
00161                 
00162                 
00163                 if ( (linesize + strlen(skill) + strlen(rval) )  >=72 ) {
00164                         linesize=0;
00165                         sprintf(buffer,"%s\n",buffer);
00166                 } else {
00167                         linesize = linesize + strlen(skill) + strlen(rval) + 1;
00168                 }
00169                 sprintf(buffer,"%s%s%s ",buffer,skill,rval);
00170         }
00171         return buffer;
00172 }

Here is the call graph for this function:

Here is the caller graph for this function:

int skillList::skillCount (  ) 

How many skills are there in the list?

Returns:
integer count of how many skills (nodes) are in the list.

Definition at line 94 of file skill-list.cpp.

References skillEntry::getNext().

Referenced by listOfSkills(), and personObj::skillCount().

00094                          {
00095         int count=0;
00096         skillEntry* p = root;
00097         while ( p->getNext() != (skillEntry*)0){
00098                 p = p->getNext();
00099                 count++;
00100         }
00101         return count;
00102 }

Here is the call graph for this function:

Here is the caller graph for this function:

void skillList::XMLout ( FILE *  fout  ) 

Output the skill list to an XML formatted file.

Parameters:
fout pointer to a file buffer to be written to.

Definition at line 174 of file skill-list.cpp.

References skillEntry::getNext(), and skillEntry::XMLout().

Referenced by book1Person::XMLout().

00174                                 {
00175         skillEntry *p = root;
00176         
00177         fprintf(fout,"\t%s\n",createStartElement("skill-list"));
00178         while(p->getNext() != (skillEntry*)0){
00179                 p=p->getNext();
00180                 p->XMLout(fout);
00181         }
00182         
00183         fprintf(fout,"\t%s\n",createEndElement("skill-list"));
00184         
00185 }

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
Generated on Fri Mar 7 16:43:00 2008 for frpuniverse by  doxygen 1.4.7