⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmdsutils.cc

📁 XMDS is a code generator that integrates equations. You write them down in human readable form in a
💻 CC
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 2000-2004 Code contributed by Greg Collecutt, Joseph Hope and Paul Cochrane This file is part of xmds.  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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*//*  $Id: xmdsutils.cc,v 1.14 2004/07/13 05:29:38 paultcochrane Exp $*//*! @file xmdsutils.cc  @brief Utility classes and methods  More detailed explanation...*/#include<xmlbasics.h>#include<dom3.h>#include<xmdsutils.h>#include<string>extern bool debugFlag;//#define DEBUG 0// ******************************************************************************// ******************************************************************************//                              xmdsException// ******************************************************************************// ******************************************************************************// ******************************************************************************xmdsException::xmdsException() :  myNode(0),  myErrorMessage("") {};// ******************************************************************************xmdsException::xmdsException(			     const char *const yourErrorMessage) :  myNode(0),  myErrorMessage(yourErrorMessage) {};// ******************************************************************************xmdsException::xmdsException(			     const Node *const yourNode,			     const char *const yourErrorMessage) :  myNode(yourNode),  myErrorMessage(yourErrorMessage) {};// ******************************************************************************const char* xmdsException::getError() {  char s2[256];  s[0]=0;  const Node* nextNode=myNode;  if(nextNode != 0) {    sprintf(s2,"In element '%s',\n",nextNode->nodeName()->c_str());    strcat(s,s2);    nextNode=nextNode->parentNode();  }  while(nextNode != 0) {    sprintf(s2," which is within element '%s',\n",nextNode->nodeName()->c_str());    strcat(s,s2);    nextNode=nextNode->parentNode();  }  sprintf(s2,"\nthe following error occurred:\n  %s\n",myErrorMessage);  strcat(s,s2);  return s;};// ******************************************************************************// ******************************************************************************//                              xmdsUtility public// ******************************************************************************// ******************************************************************************long nxmdsUtilitys=0;  //!< Number of xmds utility objects// ******************************************************************************xmdsUtility::xmdsUtility() {  if(debugFlag) {    nxmdsUtilitys++;    printf("xmdsUtility::xmdsUtility\n");    printf("nxmdsUtilitys=%li\n",nxmdsUtilitys);  }};// ******************************************************************************xmdsUtility::~xmdsUtility() {  if(debugFlag) {    nxmdsUtilitys--;    printf("xmdsUtility::~xmdsUtility\n");    printf("nxmdsUtilitys=%li\n",nxmdsUtilitys);  }};// ******************************************************************************// ******************************************************************************//                              xmdsUtility protected// ******************************************************************************// ******************************************************************************// ******************************************************************************char* xmdsUtility::errorMessage() const {  return myErrorMessage;};// ******************************************************************************void xmdsUtility::getAssignmentStrings(				       const Element *const inElement,				       const XMLString& ofName,				       const bool& required,				       const unsigned long& n2get,				       list<XMLString>&  outList) {  if(debugFlag) {    printf("xmdsUtility::getAssignmentStrings\n");  }  outList.clear();  // note that if an element is found, then the routine will throw an exception  // if n2get items aren't found within, except that passing n2get=0 will escape  // this behaviour  const NodeList* candidateElements = inElement->getElementsByTagName(ofName,0);    if(candidateElements->length()==0) {    if(required) {      sprintf(myErrorMessage,"Element '%s' not found",ofName.c_str());      throw xmdsException(inElement,myErrorMessage);    }    else {      return;    }  }  if(candidateElements->length()==1) {    const Node* nextNode = candidateElements->item(0);    parseXMLString(nextNode,candidateElements->item(0)->textContent(0),outList);    if(n2get!=0) {      // check that numbers of requested items match      if(outList.size()!=n2get) {	sprintf(myErrorMessage,	"%li strings wanted but %li found",n2get,(long)outList.size());	throw xmdsException(nextNode,myErrorMessage);      }    }  }  else {    sprintf(myErrorMessage,"Multiple Elements '%s' found",ofName.c_str());    throw xmdsException(inElement,myErrorMessage);  }};// ******************************************************************************void xmdsUtility::getAssignmentBools(				     const Element *const inElement,				     const XMLString& ofName,				     const bool& required,				     const unsigned long& n2get,				     list<bool>& outList) {  if(debugFlag) {    printf("xmdsUtility::getAssignmentBools\n");  }  // note that if an element is found, then the routine will throw an exception  // if n2get items aren't found withn, except that passing n2get=0 will escape  // this behaviour  outList.clear();  const NodeList* candidateElements = inElement->getElementsByTagName(ofName,0);  if(candidateElements->length()==0) {    if(required) {      sprintf(myErrorMessage,"Element '%s' not found",ofName.c_str());      throw xmdsException(inElement,myErrorMessage);    }    else {      return;    }  }  if(candidateElements->length()==1) {    list<XMLString> myOutList;    const Node* nextNode = candidateElements->item(0);    parseXMLString(nextNode,candidateElements->item(0)->textContent(0),myOutList);    for(list<XMLString>::const_iterator pXMLString = myOutList.begin(); pXMLString != myOutList.end(); pXMLString++) {      if(*pXMLString=="yes") {	outList.push_back(1);      }      else if(*pXMLString=="no") {	outList.push_back(0);      }      else {	throw xmdsException(nextNode,"'yes' or 'no' expected");      }    }    if(n2get!=0) {      // check that numbers of requested items match      if(outList.size()!=n2get) {	sprintf(myErrorMessage,"%li 'yes'/'no' wanted but %li found",n2get,(long)outList.size());	throw xmdsException(nextNode,myErrorMessage);      }    }  }  else {    sprintf(myErrorMessage,"Multiple Elements '%s' found",ofName.c_str());    throw xmdsException(inElement,myErrorMessage);  }};// ******************************************************************************void xmdsUtility::getAssignmentULongs(				      const Element *const inElement,				      const XMLString& ofName,				      const bool& required,				      const unsigned long& n2get,				      list<unsigned long>& outList) {  if(debugFlag) {    printf("xmdsUtility::getAssignmentLongs\n");  }  // note that if an element is found, then the routine will throw an exception  // if n2get items aren't found withn, except that passing n2get=0 will escape  // this behaviour  outList.clear();  const NodeList* candidateElements = inElement->getElementsByTagName(ofName,0);  if(candidateElements->length()==0) {    if(required) {      sprintf(myErrorMessage,"Element '%s' not found",ofName.c_str());      throw xmdsException(inElement,myErrorMessage);    }    else {      return;    }  }  if(candidateElements->length()==1) {    list<XMLString> myOutList;    const Node* nextNode = candidateElements->item(0);    parseXMLString(nextNode,candidateElements->item(0)->textContent(0),myOutList);    for(list<XMLString>::const_iterator pXMLString = myOutList.begin(); pXMLString != myOutList.end(); pXMLString++) {      unsigned long nextULong;      if(pXMLString->asULong(nextULong)) {	outList.push_back(nextULong);      }      else {	throw xmdsException(nextNode,"invalid positive integer");      }    }    if(n2get!=0) {      // check that numbers of requested items match      if(outList.size()!=n2get) {	sprintf(myErrorMessage,"%li integers wanted but %li found",n2get,(long)outList.size());	throw xmdsException(nextNode,myErrorMessage);      }    }  }  else {    sprintf(myErrorMessage,"Multiple Elements '%s' found",ofName.c_str());    throw xmdsException(inElement,myErrorMessage);  }};// ******************************************************************************void xmdsUtility::getAssignmentDoubles(				       const Element *const inElement,				       const XMLString& ofName,				       const bool& required,				       const unsigned long& n2get,				       list<double>& outList) {  if(debugFlag) {    printf("xmdsUtility::getAssignmentDoubles\n");  }  // note that if an element is found, then the routine will throw an exception  // if n2get items aren't found withn, except that passing n2get=0 will escape  // this behaviour  outList.clear();  const NodeList* candidateElements = inElement->getElementsByTagName(ofName,0);  if(candidateElements->length()==0) {    if(required) {      sprintf(myErrorMessage,"Element '%s' not found",ofName.c_str());      throw xmdsException(inElement,myErrorMessage);    }    else {      return;    }  }  if(candidateElements->length()==1) {    list<XMLString> myOutList;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -