1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/**************************************************************************
* *
* Regina - A Normal Surface Theory Calculator *
* Computational Engine *
* *
* Copyright (c) 1999-2008, Ben Burton *
* For further details contact Ben Burton (bab@debian.org). *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* You should have received a copy of the GNU General Public *
* License along with this program; if not, write to the Free *
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
**************************************************************************/
/* end stub */
#include "packet/npacket.h"
#include "packet/nxmlpacketreader.h"
#include "packet/packetregistry.h"
#include "utilities/stringutils.h"
namespace regina {
#define __PACKET_REGISTRY_BODY
#define REGISTER_PACKET(class, type, name) \
if (typeID == class::packetType) \
return class::getXMLReader(me);
NXMLElementReader* NXMLPacketReader::startSubElement(
const std::string& subTagName,
const regina::xml::XMLPropertyDict& subTagProps) {
if (subTagName == "packet") {
NPacket* me = getPacket();
if (! me)
return new NXMLPacketReader();
regina::xml::XMLPropertyDict::const_iterator it =
subTagProps.find("label");
if (it == subTagProps.end())
childLabel = "";
else
childLabel = (*it).second;
it = subTagProps.find("typeid");
if (it == subTagProps.end())
return new NXMLPacketReader();
long typeID;
if (! valueOf((*it).second, typeID))
return new NXMLPacketReader();
if (typeID <= 0)
return new NXMLPacketReader();
// Pull in cases from the packet registry.
#include "packet/packetregistry.h"
return new NXMLPacketReader();
} else if (subTagName == "tag") {
if (NPacket* me = getPacket()) {
std::string packetTag = subTagProps.lookup("name");
if (! packetTag.empty())
me->addTag(packetTag);
}
return new NXMLElementReader();
} else
return startContentSubElement(subTagName, subTagProps);
}
void NXMLPacketReader::endSubElement(const std::string& subTagName,
NXMLElementReader* subReader) {
if (subTagName == "packet") {
NPacket* child =
dynamic_cast<NXMLPacketReader*>(subReader)->getPacket();
if (child) {
NPacket* me = getPacket();
if (me) {
child->setPacketLabel(childLabel);
if (! child->getTreeParent())
me->insertChildLast(child);
} else
delete child;
}
} else if (subTagName == "tag")
return;
else
endContentSubElement(subTagName, subReader);
}
void NXMLPacketReader::abort(NXMLElementReader* /* subReader */) {
NPacket* me = getPacket();
if (me)
if (! me->getTreeParent())
delete me;
}
// Tidy up.
#undef REGISTER_PACKET
#undef __PACKET_REGISTRY_BODY
} // namespace regina
|