DataStructureDescription.cpp
Go to the documentation of this file.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
00026
00027
00028
00029
00030 #include "config.h"
00031
00032 #include "DataStructureDescription.hpp"
00033
00034 #include <Exception.hpp>
00035 #include <XmlAttribute.hpp>
00036 #include <XmlAttributeVector.hpp>
00037 #include <XmlElementVector.hpp>
00038 #include <iostream>
00039
00040 using namespace mermaid::support::data;
00041
00042 using mermaid::support::errorhandling::Exception;
00043 using mermaid::support::xml::XmlAttribute;
00044 using mermaid::support::xml::XmlAttributeVector;
00045 using mermaid::support::xml::XmlElementVector;
00046
00047 #include <sstream>
00048
00049 DataStructureDescription::DataStructureDescription (shared_ptr<XmlElement> structureDescriptionElement)
00050 {
00051 if (structureDescriptionElement->getName().compare ("data-structure") != 0) {
00052 throw Exception ("DataStructureDescription::DataStructureDescription : expected \"data-structure\" element");
00053 }
00054
00055 XmlElementVector children = structureDescriptionElement->getChildrenElements();
00056
00057 shared_ptr<XmlElement> dataNameElement = children.getFirstElementWithName ("data-name");
00058 shared_ptr<XmlElement> dataCompositionElement = children.getFirstElementWithName ("data-composition");
00059
00060 name_ = * (dataNameElement->getFirstNonBlankCharData());
00061 composition_ = XmlElement (*dataCompositionElement);
00062
00063
00064 XmlElementVector dataItemVector = dataCompositionElement->getChildrenElements();
00065
00066 XmlElementVector::iterator it;
00067
00068 for (it = dataItemVector.begin(); it != dataItemVector.end(); it++) {
00069 shared_ptr<XmlElement> dataItem = *it;
00070 XmlElementVector dataItemChildren = dataItem->getChildrenElements();
00071
00072 shared_ptr<XmlElement> itemNameElement = dataItemChildren.getFirstElementWithName ("name");
00073 shared_ptr<XmlElement> itemTypeElement = dataItemChildren.getFirstElementWithName ("type");
00074
00075 std::string itemName = * (itemNameElement->getFirstNonBlankCharData());
00076 std::string itemType = * (itemTypeElement->getFirstNonBlankCharData());
00077
00078 XmlAttributeVector itemTypeAttributes = itemTypeElement->getAttributes();
00079 shared_ptr<XmlAttribute> isArrayAttribute = itemTypeAttributes.getFirstAttributeWithName ("isArray");
00080 shared_ptr<XmlAttribute> arraySizeAttribute = itemTypeAttributes.getFirstAttributeWithName ("arraySize");
00081
00082 bool isArray = false;
00083 bool isDynamic = false;
00084
00085 if (isArrayAttribute == false) {
00086 isArray = false;
00087 }
00088 else {
00089 isArray = isArrayAttribute->getValue().compare ("true") == 0 ? true : false;
00090 }
00091
00092 if (isArray == true) {
00093 if (arraySizeAttribute == false) {
00094 isDynamic = true;
00095 }
00096 else {
00097 isDynamic = arraySizeAttribute->getValue().compare ("dynamic") == 0 ? true : false;
00098 }
00099 }
00100
00101
00102
00103
00104 if ( (itemName.compare ("integer") == 0) | (itemName.compare ("double") == 0) | (itemName.compare ("string") == 0)) {
00105 throw Exception ("DataBox::DataBox(DataStructureDescription) : itemName cannot be any of: integer, double or string");
00106 }
00107
00108
00109
00110 if (isArray == false) {
00111 shared_ptr<DataItemDescription> did (new DataItemDescription (itemName, itemType));
00112 itemDescriptionVector_.push_back (did);
00113
00114 }
00115 else {
00116 if (isDynamic == true) {
00117 shared_ptr<DataItemDescription> did (new DataItemDescription (itemName, itemType, true));
00118 itemDescriptionVector_.push_back (did);
00119 }
00120 else {
00121 std::stringstream ss;
00122 ss << arraySizeAttribute->getValue();
00123 int size;
00124 ss >> size;
00125
00126 shared_ptr<DataItemDescription> did (new DataItemDescription (itemName, itemType, true, true, size));
00127 itemDescriptionVector_.push_back (did);
00128 }
00129 }
00130 }
00131
00132
00133
00134 };
00135
00136 std::string DataStructureDescription::getName()
00137 {
00138 return name_;
00139 };
00140
00141 std::vector<shared_ptr<DataItemDescription> > DataStructureDescription::getItemDescriptionVector()
00142 {
00143 return itemDescriptionVector_;
00144 };