Skip to content
Snippets Groups Projects
Commit 9f053e53 authored by Andrea Zoli's avatar Andrea Zoli
Browse files

Fix xml parsing of SDFBlocks.

parent 130beaa6
No related branches found
No related tags found
No related merge requests found
......@@ -87,7 +87,6 @@ char* ConfigurationFile::getLine() throw(PacketExceptionIO*)
char* ConfigurationFile::getLine(const char* s) throw(PacketExceptionIO*)
{
char* line;
try
{
line = this->getLine();
......
......@@ -19,6 +19,8 @@
#include "Field.h"
#include "Utility.h"
//#define DEBUG 1
using namespace PacketLib;
static FieldType** filedTypeList = 0;
......@@ -92,7 +94,7 @@ Field::Field(std::string name, std::string typeStr, std::string dim, std::string
type->dimension = atoi(dim.c_str());
type->type = Field::typeStringToEnum[typeStr];
#ifdef DEBUG
std::cout << "Adding field '" << name << "' at index " << i << ", " << type->dimension << " bits type " << typeStr << " (" << type->type << ")" << std::endl;
std::cout << "Adding field '" << name << "', " << type->dimension << " bits type " << typeStr << " (" << type->type << ")" << std::endl;
#endif
if(prVal.compare("none") != 0)
......
......@@ -20,6 +20,7 @@
using namespace PacketLib;
#undef DEBUG
InputPacketStream::InputPacketStream() : PacketStream()
{
......
......@@ -64,52 +64,6 @@ Packet::~Packet()
delete[] identifiers;
}
const std::string fixed32[] = { "uint32", "int32", "float" };
const std::string fixed64[] = { "uint64", "int64", "double" };
void cachePhysicalIndexes(pugi::xml_node node, std::map<pugi::xml_node, int>& physicalIndex)
{
int index = 0;
for(pugi::xml_node_iterator it=node.begin(); it != node.end(); ++it)
{
if(string(it->name()).compare("field") != 0)
continue;
physicalIndex[*it] = index;
// if 32bits fields
string typeStr = it->attribute("type").value();
bool found = false;
for(unsigned int i=0; i<3; i++)
{
if(typeStr.compare(fixed32[i]) == 0)
{
index+=2;
found = true;
break;
}
}
if(found)
continue;
// if 64bits fields
for(unsigned int i=0; i<3; i++)
{
if(typeStr.compare(fixed64[i]) == 0)
{
index+=4;
found = true;
break;
}
}
if(found)
continue;
// else (<= 16bits fields)
index++;
}
}
void Packet::createPacketType(pugi::xml_document& doc, pugi::xml_node hNode, int plPhysicalIndex, int plSize, pugi::xml_node pNode, bool isprefix, word dimprefix, std::map<pugi::xml_node, int>& physicalIndex)
{
name = pNode.attribute("name").value();
......
......@@ -25,10 +25,6 @@
using namespace PacketLib;
PacketStream::PacketStream(string fileNameConfig)
{
filenameConfig = realpath(fileNameConfig.c_str(), NULL);
......@@ -158,7 +154,9 @@ void PacketStream::cachePhysicalIndexes(pugi::xml_node node, std::map<pugi::xml_
{
if(string(it->name()).compare("field") != 0)
continue;
#ifdef DEBUG
std::cout << "Physical index of " << it->attribute("name").value() << " is " << index << std::endl;
#endif
physicalIndex[*it] = index;
// if 32bits fields
......
......@@ -36,11 +36,17 @@ void SDFBlockType::loadType(pugi::xml_node node, const pugi::xml_document& doc,
{
nblockmax = 0;
const char* popName = node.attribute("name").value();
std::string tmp;
if(strcmp(node.name(),"sourcedatafield") == 0)
{
tmp = std::string(node.parent().attribute("name").value()) + "_sdf";
}
else
tmp = node.attribute("name").value();
int dimline = strlen(popName);
name = (char*) new char[dimline+1];
strncpy(name, popName, dimline+1);
name = (char*) new char[tmp.size()+1];
strncpy(name, tmp.c_str(), tmp.size());
name[tmp.size()] = 0;
pugi::xml_node fNode = node.child("field");
if(fNode)
......@@ -52,7 +58,23 @@ void SDFBlockType::loadType(pugi::xml_node node, const pugi::xml_document& doc,
pugi::xpath_node_set rbNodeSet = node.select_nodes("rblock");
if(rbNodeSet.size() == 0)
{
numberOfRBlocks = 0;
rblockFilename = 0;
rBlockVariable = 0;
maxNumberOfBlock = 0;
indexOfNBlock = 0;
subFromNBlock = 0;
numberOfBlockFixed = 0;
headerLevelOfNBlockIndex = 0;
operatorType = 0;
return;
}
variablePresent = true;
#ifdef DEBUG
std::cout << "fixed part: " << variablePresent;
std::cout << " variable part: " << variablePresent << std::endl;
#endif
numberOfRBlocks = rbNodeSet.size();
if(numberOfRBlocks > 65535)
throw new PacketExceptionFileFormat("Too many number of Rblocks in the packet type.");
......@@ -80,9 +102,12 @@ void SDFBlockType::loadType(pugi::xml_node node, const pugi::xml_document& doc,
throw new PacketExceptionFileFormat("Too many number of blocks in the packet type.");
if(!idref)
headerLevelOfNBlockIndex[i] = 0;
else
{
stringstream ss;
ss << "idref attribute not defined for rblock" << rbNode.attribute("name").value();
throw new PacketExceptionFileFormat(ss.str().c_str());
}
string query = string("//field[@id=\"")+idref.value()+"\"]";
pugi::xml_node numberofblocksid = doc.select_nodes(query.c_str())[0].node();
pugi::xml_node nodetmp = rbNode;
......@@ -119,7 +144,7 @@ void SDFBlockType::loadType(pugi::xml_node node, const pugi::xml_document& doc,
nodetmp = nodetmp.parent();
}
headerLevelOfNBlockIndex[i] = level;
indexOfNBlock[i] = physicalIndex[numberofblocksid]; // TODO fix this..
indexOfNBlock[i] = physicalIndex[numberofblocksid];
pugi::xml_attribute offsetAttr = numberofblocksid.attribute("numberofblocksoffset");
const char* offset;
if(offsetAttr)
......@@ -141,26 +166,15 @@ void SDFBlockType::loadType(pugi::xml_node node, const pugi::xml_document& doc,
operatorType[i] = 0;
subFromNBlock[i] = atoi(offset);
}
#ifdef DEBUG
std::cout << "Add rblock index for " << rbNode.attribute("name").value();
std::cout << " level " << level << " phyindex " << indexOfNBlock[i] << " offset " << offset << std::endl;
#endif
rblockFilename[i] = (char*) rbNode.attribute("name").value();
}
nblockmax += maxNumberOfBlock[i];
}
}
else
{
numberOfRBlocks = 0;
rblockFilename = 0;
rBlockVariable = 0;
maxNumberOfBlock = 0;
indexOfNBlock = 0;
subFromNBlock = 0;
numberOfBlockFixed = 0;
headerLevelOfNBlockIndex = 0;
operatorType = 0;
}
}
bool SDFBlockType::loadType(InputText& fp) throw(PacketException*)
{
......@@ -367,7 +381,18 @@ SDFBlock::~SDFBlock()
void SDFBlock::loadFieldsSDFB(pugi::xml_node rbNode, const pugi::xml_document& doc,
std::map<pugi::xml_node, int>& physicalIndex)
{
popName = (char*) rbNode.attribute("name").value();
std::string tmp;
if(strcmp(rbNode.name(),"sourcedatafield") == 0)
{
tmp = std::string(rbNode.parent().attribute("name").value()) + "_sdf";
}
else
tmp = rbNode.attribute("name").value();
popName = (char*) new char[tmp.size()+1];
strncpy(popName, tmp.c_str(), tmp.size());
popName[tmp.size()] = 0;
dword indexlist = 0;
type = 0;
while(blockTypeList[indexlist] != 0)
......@@ -384,7 +409,6 @@ void SDFBlock::loadFieldsSDFB(pugi::xml_node rbNode, const pugi::xml_document& d
this->previous = previous;
if(type == 0)
{
// cout << "create the type " << popName << endl;
type = new SDFBlockType;
blockTypeList[indexlist] = type;
type->loadType(rbNode, doc, physicalIndex);
......@@ -423,7 +447,7 @@ void SDFBlock::loadFieldsSDFB(pugi::xml_node rbNode, const pugi::xml_document& d
block[nblock].setPreviousPop(&fixed);
block[nblock].setRBlockType(indexRBlock);
block[nblock].setID(id);
pugi::xml_node childNode = rbNode.child(type->rblockFilename[indexRBlock]);
pugi::xml_node childNode = rbNode.find_child_by_attribute("name", type->rblockFilename[indexRBlock]);
block[nblock].loadFieldsSDFB(childNode, doc, physicalIndex);
id++;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment