00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "clothe.h"
00022 #include <map>
00023 #include <iostream>
00024 #include "member.h"
00025 #include "../tool/xml_document.h"
00026 #include "../tool/string_tools.h"
00027
00028 Clothe::Clothe(xmlpp::Element *xml, std::map<std::string, Member*>& members_lst)
00029 {
00030 XmlReader::ReadStringAttr( xml, "name", name);
00031
00032 xmlpp::Node::NodeList nodes = xml -> get_children("member");
00033 xmlpp::Node::NodeList::iterator
00034 it=nodes.begin(),
00035 end=nodes.end();
00036
00037 for (; it != end; ++it)
00038 {
00039 xmlpp::Element *elem = dynamic_cast<xmlpp::Element*> (*it);
00040 assert (elem != NULL);
00041 std::string att;
00042 if (!XmlReader::ReadStringAttr(elem, "name", att))
00043 {
00044 std::cerr << "Malformed attached member definition" << std::endl;
00045 continue;
00046 }
00047
00048 Member* member = NULL;
00049 if(members_lst.find(att) != members_lst.end())
00050 {
00051 member = members_lst.find(att)->second;
00052 }
00053 else
00054 {
00055 std::cerr << "Undefined member \"" << att << "\"" << std::endl;
00056 }
00057
00058 int lay=0;
00059 if(XmlReader::ReadIntAttr(elem, "layer", lay))
00060 {
00061 if((uint)lay >= layers.size())
00062 layers.resize( lay+1, (Member*)NULL);
00063 layers[lay] = member;
00064 }
00065 }
00066
00067 std::vector<Member*>::iterator i = layers.begin();
00068 while( i != layers.end())
00069 if(*i!=NULL)
00070 i++;
00071 else
00072 i=layers.erase(i);
00073 }
00074
00075 Clothe::Clothe(Clothe* c, std::map<std::string, Member*>& members_lst)
00076 {
00077 name = c->name;
00078
00079 for (std::vector<Member*>::iterator it = c->layers.begin();
00080 it != c->layers.end();
00081 ++it)
00082 {
00083 layers.push_back(members_lst.find((*it)->name)->second);
00084 }
00085 }
00086
00087 Clothe::~Clothe()
00088 {
00089 layers.clear();
00090 }