00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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 }