src/book1-person.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 "book1-person.hpp"
00026 
00027 #include <string.h>
00028 #include <malloc.h>
00029 #include <iostream>
00030 
00031 #include "xmlutils.hpp"
00032 
00033 static void checkString(char* mod,char* s){
00034         int ix;
00035         for(ix=0;ix<strlen(s);ix++)
00036                 if ( ! 
00037                          ( 
00038                            (( 'a' <= s[ix] ) && ( s[ix] <= 'z' ) )|| 
00039                            (( 'A' <= s[ix] ) && ( s[ix] <= 'Z' )) ||
00040                            (( '0' <= s[ix] ) && ( s[ix] <= '9' )) ||
00041                            ( s[ix] == '\''  ) ||
00042                            ( s[ix] == ' '  ) ||
00043                            ( s[ix] == '-' ) 
00044                           ) 
00045                         ) {
00046                                 fprintf(stderr,"%s: Bad string: \"%s\"\n",mod,s);
00047                                 exit(1);
00048                         }
00049 
00050 }
00051 
00052 
00053 book1Person::book1Person():personObj(){
00054                 
00055                 
00056                 
00057 };
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 void book1Person::toStdOut(){
00070         char *buffer;
00071         int  skillCount = this->skillCount();
00072         char **listOfSkills = this->listOfSkills();
00073         char cashBuffer[80];
00074         
00075         int  ix;
00076         int iy;
00077         
00078         std::cout << this->UPPasString() << " Age: " << this->getAge() << " " << this->getService();
00079         std::cout << "  " << this->getTerms() << " terms" ; 
00080         if ( this-> getCommissioned() == 1 ) {
00081                 std::cout << "  Rank: " << this->getRank();
00082         }
00083         std::cout << std::endl;
00084         sprintf(cashBuffer,"%7g",this->getCash());
00085         std::cout << "Cash: " << cashBuffer << std::endl;
00086         
00087         std::cout << "Skills:" << "\n\n";
00088         
00089         iy=1;
00090         
00091         std::cout << this->listOfSkillString() << "\n\n";
00092         
00093         
00094                 
00095         for(ix=0;ix<72;ix++) std::cout<< "*";
00096         
00097         std::cout<<std::endl;
00098         
00099         
00100         
00101 }
00102 static char* physicalElementNames[] = {
00103         "strength","dexterity","endurance","intelligence","education","social-standing"
00104 };
00105 
00106 void book1Person::PhysicalStats2XML(FILE* fout){
00107         int ix;
00108         fprintf(fout,"\t%s\n",createStartElement("physical-stats"));
00109         for(ix=0;ix<6;ix++)
00110                 fprintf(fout,"\t\t%s%d%s\n",
00111                                 createStartElement(physicalElementNames[ix]),
00112                                 this->getIndexedAttribute(ix),
00113                                 createEndElement(physicalElementNames[ix])
00114                                 );
00115         fprintf(fout,"\t\t%s%d%s\n",
00116                         createStartElement("age"),
00117                         this->getAge(),
00118                         createEndElement("age")
00119                         );
00120         
00121         fprintf(fout,"\t%s\n",createEndElement("physical-stats"));
00122         
00123 }
00124 
00125 void book1Person::XMLout(FILE* fout){
00126         fprintf(fout,"%s\n",createStartElement("person"));
00127         
00128         fprintf(fout,"\t%sbook-1%s\n",createStartElement("type"),createEndElement("type"));
00129         
00130         this->PhysicalStats2XML(fout);
00131         
00132         fprintf(fout,"\t%s%s%s\n",createStartElement("service"),
00133                         this->getService(),
00134                         createEndElement("service"));
00135         if ( this->getCommissioned() == 1 ) {
00136                 fprintf(fout,"\t%s%d%s\n",
00137                                 createStartElement("rank"),
00138                                 this->getRank(),
00139                                 createEndElement("rank")
00140                                 );
00141         }
00142         fprintf(fout,"\t%s%d%s\n",
00143                         createStartElement("terms"),
00144                         this->getTerms(),
00145                         createEndElement("terms")
00146                         );
00147         fprintf(fout,"\t%s%6g%s\n",
00148                         createStartElement("cash"),
00149                         this->getCash(),
00150                         createEndElement("cash")
00151                         );
00152         
00153         this->getSkillList()->XMLout(fout);
00154         this->getBenefitList()->XMLout(fout);
00155         
00156         fprintf(fout,"%s\n",createEndElement("person"));
00157                         
00158         
00159         
00160 }

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