#include //注,解析未完善,仅解析上海深圳所需!!!,喜欢大而全的可以去用xerces来解析。
namespace QuickFAST
{
namespace Codecs
{
//具体的解析函数
bool parse(SegmentBodyPtr body,pugi::xml_node &node_item);
bool parseOp(FieldInstructionPtr field,pugi::xml_node &node_item)
{
pugi::xml_node nodeop=node_item.first_child();
if(nodeop.empty())
return true;
FieldOpPtr op;
std::string opname=nodeop.name();
if(opname=="increment")
op.reset(new FieldOpIncrement());
else if(opname=="default")
op.reset(new FieldOpDefault());
else if(opname=="copy")
op.reset(new FieldOpCopy());
else if(opname=="delta")
op.reset(new FieldOpDelta());
else if(opname=="constant")
{
op.reset(new FieldOpConstant());
}
else
{
return true;
}
std::string dictionary=nodeop.attribute("dictionary").value();
if(!dictionary.empty())
{
op->setDictionaryName(dictionary);
}
std::string key=nodeop.attribute("key").value();;
if(!key.empty())
{
op->setKey(key);
std::string nsKey=nodeop.attribute("nskey").value();
if(!nsKey.empty())
{
op->setKeyNamespace(nsKey);
}
}
std::string value=nodeop.attribute("value").value();
if(!value.empty())
{
op->setValue(value);
}
std::string pmapBitStr=nodeop.attribute("pmap").value();
if(!pmapBitStr.empty())
{
size_t pmapBit = atoi(pmapBitStr.c_str());
op->setPMapBit(pmapBit);
}
field->setFieldOp(op);
return true;
}
bool parseLength(std::string &tag,SegmentBodyPtr body,pugi::xml_node &node_item)
{
std::string name=node_item.attribute("name").value();
std::string ns=node_item.attribute("ns").value();
FieldInstructionPtr field(new FieldInstructionUInt32(name, ns));
std::string id=node_item.attribute("id").value();
if (!id.empty())
{
field->setId(atoi(id.c_str()));
}
std::string presence=node_item.attribute("presence").value();
if(!presence.empty())
{
field->setPresence(presence == "mandatory");
}
parseOp(field,node_item);
body->allowLengthField();
body->addLengthInstruction(field);
return true;
}
bool parseInt8(std::string &tag,SegmentBodyPtr body,pugi::xml_node &node_item)
{
std::string name=node_item.attribute("name").value();
std::string ns=node_item.attribute("ns").value();
FieldInstructionPtr field(new FieldInstructionInt8(name, ns));
std::string id=node_item.attribute("id").value();
if (!id.empty())
{
field->setId(atoi(id.c_str()));
}
std::string presence=node_item.attribute("presence").value();
if(!presence.empty())
{
field->setPresence(presence == "mandatory");
}
parseOp(field,node_item);
body->addInstruction(field);
return true;</