src/skill-entry.cpp

00001 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
00002 /*
00003  * frpuniverse
00004  * Copyright (C) Peter L. Berghold 2008 <Peter@Berghold.net>
00005  * 
00006  * frpuniverse is free software.
00007  * 
00008  * You may redistribute it and/or modify it under the terms of the
00009  * GNU General Public License, as published by the Free Software
00010  * Foundation; either version 2 of the License, or (at your option)
00011  * any later version.
00012  * 
00013  * frpuniverse is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with frpuniverse.  If not, write to:
00020  *      The Free Software Foundation, Inc.,
00021  *      51 Franklin Street, Fifth Floor
00022  *      Boston, MA  02110-1301, USA.
00023  */
00024 
00025 #include "skill-entry.hpp"
00026 #include <string.h>
00027 #include <malloc.h>
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include "xmlutils.hpp"
00031 
00032 static void checkString(char* s){
00033         int ix;
00034         for(ix=0;ix<strlen(s);ix++)
00035                 if ( ! 
00036                          ( 
00037                            ( 'a' <= s[ix] ) && ( s[ix] <= 'z' ) || 
00038                            ( 'A' <= s[ix] ) && ( s[ix] <= 'Z' ) ||
00039                            ( s[ix] == '\''  ) ||
00040                            ( s[ix] == ' '  )
00041                           ) 
00042                         ) {
00043                                 fprintf(stderr,"Bad string: \"%s\"\n",s);
00044                                 exit(1);
00045                         }
00046 
00047 }
00048 
00049 skillEntry::skillEntry(){
00050         level=0;
00051         skill = (char*)0;
00052         
00053 }
00054 
00055 skillEntry::skillEntry(char *s){
00056         
00057         skill=(char*)malloc(strlen(s)+1);
00058         sprintf(skill,"%s",s);
00059         level=1;
00060 }
00061 
00062 skillEntry::skillEntry(char* s,int l){
00063         level = l;
00064         
00065         skill = (char*) malloc(strlen(s)+1);
00066         sprintf(skill,"%s",s);
00067 }
00068 
00069 skillEntry* skillEntry::getNext(){
00070         return next;
00071 }
00072 
00073 void skillEntry::setNext(skillEntry* p){
00074         next =p;
00075 }
00076 
00077 int skillEntry::getLevel(){
00078         return level;
00079 }
00080 void skillEntry::setLevel(int l){
00081         level=l;
00082 }
00083 
00084 char* skillEntry::getSkill(){
00085         checkString(skill);
00086         return skill;
00087 }
00088 
00089 void skillEntry::setSkill(char *p){
00090         skill=(char*) malloc(strlen(p)+1);
00091         sprintf(skill,"%s",p);
00092 }
00093 
00094 #define FILLER " - "
00095 
00096 char* skillEntry::toString(){
00097         char rvalue[10]; // I doubt it should ever be more than that. 
00098         char *buffer;    // This will evenually be our return value 
00099         
00100         sprintf(rvalue,"%d",this->getLevel());
00101         buffer=(char*)malloc(strlen(this->getSkill()) + strlen(FILLER) + 
00102                                                  strlen(rvalue) + 1 );
00103         sprintf(buffer,"%s%s%s",this->getSkill(),FILLER,rvalue);
00104         return buffer;
00105 }
00106 
00107 void skillEntry::XMLout(FILE* fout){
00108         
00109         fprintf(fout,"\t\t%s\n",createStartElement("skill"));
00110         fprintf(fout,"\t\t\t%s%s%s\n",
00111                         createStartElement("skill-name"),
00112                         this->getSkill(),
00113                         createEndElement("skill-name")
00114                         );
00115         fprintf(fout,"\t\t\t%s%d%s\n",
00116                         createStartElement("skill-level"),
00117                         this->getLevel(),
00118                         createEndElement("skill-level"));
00119         fprintf(fout,"\t\t%s\n",createEndElement("skill"));
00120         
00121 }

Generated on Fri Mar 7 16:40:53 2008 for frpuniverse by  doxygen 1.4.7