Ejemplo n.º 1
0
void MDGeometryBuilderXML<CheckDimensionPolicy>::addManyOrdinaryDimensions(
    VecIMDDimension_sptr manyDims) const {
  VecIMDDimension_sptr::iterator it = manyDims.begin();
  for (; it != manyDims.end(); ++it) {
    addOrdinaryDimension(*it);
  }
}
Ejemplo n.º 2
0
/**
Peforms the processing associated with these transformations.
*/
void MDGeometryXMLParser::execute() {
  Poco::XML::DOMParser pParser;
  Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(m_xmlToProcess);
  Poco::XML::Element *pRootElem = pDoc->documentElement();
  // Apply root node checking if supplied.
  Poco::XML::Element *geometryXMLElement = nullptr;
  if (!m_rootNodeName.empty()) {
    Poco::XML::Element *temp = pRootElem->getChildElement(m_rootNodeName);
    geometryXMLElement = temp;
    if (geometryXMLElement == nullptr) {
      std::string message =
          "Root node was not found to be the expected value of " +
          m_rootNodeName;
      throw std::runtime_error(message);
    }
  } else {
    // The default is to take the root node to be the geometry xml element.
    geometryXMLElement = pRootElem;
  }

  Poco::AutoPtr<Poco::XML::NodeList> dimensionsXML =
      geometryXMLElement->getElementsByTagName(
          MDGeometryXMLDefinitions::workspaceDimensionElementName());
  size_t nDimensions = dimensionsXML->length();
  VecIMDDimension_sptr vecAllDims(nDimensions);

  ////Extract dimensions
  for (size_t i = 0; i < nDimensions; i++) {
    Poco::XML::Element *dimensionXML = static_cast<Poco::XML::Element *>(
        dimensionsXML->item(static_cast<unsigned long>(i)));
    vecAllDims[i] = createDimension(*dimensionXML);
  }
  VecIMDDimension_sptr vecNonMappedDims = vecAllDims;
  Poco::XML::Element *xDimensionElement = geometryXMLElement->getChildElement(
      MDGeometryXMLDefinitions::workspaceXDimensionElementName());
  std::string xDimId =
      xDimensionElement
          ->getChildElement(
                MDGeometryXMLDefinitions::workspaceRefDimensionElementName())
          ->innerText();
  if (!xDimId.empty()) {
    auto xDimensionIt =
        find_if(vecAllDims.begin(), vecAllDims.end(), findID(xDimId));
    if (xDimensionIt == vecAllDims.end()) {
      throw std::invalid_argument("Cannot determine x-dimension mapping.");
    }
    m_xDimension = *xDimensionIt;
    vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(),
                                          vecNonMappedDims.end(),
                                          findID(xDimId)),
                           vecNonMappedDims.end());
  }

  Poco::XML::Element *yDimensionElement = geometryXMLElement->getChildElement(
      MDGeometryXMLDefinitions::workspaceYDimensionElementName());
  std::string yDimId =
      yDimensionElement
          ->getChildElement(
                MDGeometryXMLDefinitions::workspaceRefDimensionElementName())
          ->innerText();

  if (!yDimId.empty()) {
    auto yDimensionIt =
        find_if(vecAllDims.begin(), vecAllDims.end(), findID(yDimId));
    if (yDimensionIt == vecAllDims.end()) {
      throw std::invalid_argument("Cannot determine y-dimension mapping.");
    }
    m_yDimension = *yDimensionIt;
    vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(),
                                          vecNonMappedDims.end(),
                                          findID(yDimId)),
                           vecNonMappedDims.end());
  }

  Poco::XML::Element *zDimensionElement = geometryXMLElement->getChildElement(
      MDGeometryXMLDefinitions::workspaceZDimensionElementName());
  std::string zDimId =
      zDimensionElement
          ->getChildElement(
                MDGeometryXMLDefinitions::workspaceRefDimensionElementName())
          ->innerText();

  if (!zDimId.empty()) {
    auto zDimensionIt =
        find_if(vecAllDims.begin(), vecAllDims.end(), findID(zDimId));
    if (zDimensionIt == vecAllDims.end()) {
      throw std::invalid_argument("Cannot determine z-dimension mapping.");
    }
    m_zDimension = *zDimensionIt;
    vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(),
                                          vecNonMappedDims.end(),
                                          findID(zDimId)),
                           vecNonMappedDims.end());
  }

  Poco::XML::Element *tDimensionElement = geometryXMLElement->getChildElement(
      MDGeometryXMLDefinitions::workspaceTDimensionElementName());
  std::string tDimId =
      tDimensionElement
          ->getChildElement(
                MDGeometryXMLDefinitions::workspaceRefDimensionElementName())
          ->innerText();
  if (!tDimId.empty()) {
    auto tDimensionIt =
        find_if(vecAllDims.begin(), vecAllDims.end(), findID(tDimId));
    if (tDimensionIt == vecAllDims.end()) {
      throw std::invalid_argument("Cannot determine t-dimension mapping.");
    }
    m_tDimension = *tDimensionIt;
    if (!vecNonMappedDims.empty()) {
      vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(),
                                            vecNonMappedDims.end(),
                                            findID(tDimId)),
                             vecNonMappedDims.end());
    }
  }
  m_vecNonMappedDims = vecNonMappedDims; // Copy with strong guarantee.
  m_vecAllDims = vecAllDims;
  m_executed = true;
}