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

📄 kissdom.cc

📁 XMDS is a code generator that integrates equations. You write them down in human readable form in a
💻 CC
📖 第 1 页 / 共 5 页
字号:
/* 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: kissdom.cc,v 1.12 2004/07/13 05:29:37 paultcochrane Exp $*//*! @file kissdom.cc  @brief Greg Collecutt's implementation of DOM3  More detailed explanation...*/// My implementation of DOM3#include<xmlbasics.h>#include<dom3.h>#include<kissdom.h>#define DEBUGKISSDOM 0  //!< Whether or not to debug the KISS DOM// ******************************************************************************// ******************************************************************************//	DOMException// ******************************************************************************// ******************************************************************************long nDOMExceptions=0;  //!< The number of DOM exception objectsDOMException::DOMException() {  if(DEBUGKISSDOM) {    nDOMExceptions++;    printf("DOMException::DOMException();\n");    printf("nDOMExceptions=%li\n",nDOMExceptions);  }  code = 0;};DOMException::DOMException(			   unsigned long err) {  if(DEBUGKISSDOM) {    nDOMExceptions++;    printf("DOMException::DOMException(unsigned long err);\n");    printf("nDOMExceptions=%li\n",nDOMExceptions);  }  code = err;};DOMException::~DOMException() {  if(DEBUGKISSDOM) {    nDOMExceptions--;    printf("DOMException::~DOMException();\n");    printf("nDOMExceptions=%li\n",nDOMExceptions);  }  code = 0;};const char* DOMException::getError() const {  switch (code) {  case INDEX_SIZE_ERR :    return "INDEX_SIZE_ERR\n";    break;  case DOMSTRING_SIZE_ERR :    return "DOMSTRING_SIZE_ERR\n";    break;  case HIERARCHY_REQUEST_ERR :    return "HIERARCHY_REQUEST_ERR\n";    break;  case WRONG_DOCUMENT_ERR :    return "WRONG_DOCUMENT_ERR\n";    break;  case INVALID_CHARACTER_ERR :    return "INVALID_CHARACTER_ERR\n";    break;  case NO_DATA_ALLOWED_ERR :    return "NO_DATA_ALLOWED_ERR\n";    break;  case NO_MODIFICATION_ALLOWED_ERR :    return "NO_MODIFICATION_ALLOWED_ERR\n";    break;  case NOT_FOUND_ERR :    return "NOT_FOUND_ERR\n";    break;  case NOT_SUPPORTED_ERR :    return "NOT_SUPPORTED_ERR\n";    break;  case INUSE_ATTRIBUTE_ERR :    return "INUSE_ATTRIBUTE_ERR\n";    break;  case INVALID_STATE_ERR :    return "INVALID_STATE_ERR\n";    break;  case SYNTAX_ERR :    return "SYNTAX_ERR\n";    break;  case INVALID_MODIFICATION_ERR :    return "INVALID_MODIFICATION_ERR\n";    break;  case NAMESPACE_ERR :    return "NAMESPACE_ERR\n";    break;  case INVALID_ACCESS_ERR :    return "INVALID_ACCESS_ERR\n";    break;  default :    return "UNKOWN_ERR\n";    break;  }};// ******************************************************************************// ******************************************************************************//	KissDOMImplementation// ******************************************************************************// ******************************************************************************long nKissDOMImplementations=0;  //!< Number of KISS DOM implementation objects// ******************************************************************************KissDOMImplementation::KissDOMImplementation() {  if(DEBUGKISSDOM) {    nKissDOMImplementations++;    printf("KissDOMImplementation::KissDOMImplementation();\n");    printf("nKissDOMImplementations=%li\n",nKissDOMImplementations);  }};// ******************************************************************************KissDOMImplementation::~KissDOMImplementation() {  if(DEBUGKISSDOM) {    printf("KissDOMImplementation::~KissDOMImplementation();\n");  }  for(list<Node*>::const_iterator ppNode = myNodeList.begin(); ppNode != myNodeList.end(); ppNode++) {    if(DEBUGKISSDOM) {      printf("deleting *ppNode=%li\n",(long)*ppNode);    }    delete (*ppNode);  }  if(DEBUGKISSDOM) {    nKissDOMImplementations--;    printf("	... KissDOMImplementation deleted\n");    printf("nKissDOMImplementations=%li\n",nKissDOMImplementations);  }};// ******************************************************************************bool KissDOMImplementation::hasFeature(				       DOMString& feature,				       DOMString& version) const {  return 0;};// ******************************************************************************DocumentType* KissDOMImplementation::createDocumentType(							const DOMString& qualifiedName,							const DOMString& publicId,							const DOMString& systemId) {  if(qualifiedName.hasIllegalCharacters()) {    throw DOMException(DOMException::INVALID_CHARACTER_ERR);  }  if(!qualifiedName.isNSWellFormed()) {    throw DOMException(DOMException::NAMESPACE_ERR);  }  DOMString namePrefix;  DOMString nameLocalPart;  if(qualifiedName.splitNSName(namePrefix,nameLocalPart)) {    // was a namespace name    if(namePrefix.beginsWithxml()|nameLocalPart.beginsWithxml()) {      throw DOMException(DOMException::INVALID_CHARACTER_ERR);    }  }  else {    // was not a namespace name, in which case the name may be    // anything not begining with xml,    if(qualifiedName.beginsWithxml()) {      throw DOMException(DOMException::INVALID_CHARACTER_ERR);    }  }	  DocumentType* newDocumentType = new KissDocumentType(qualifiedName,publicId,systemId);  myNodeList.push_back(newDocumentType);  return newDocumentType;};// ******************************************************************************Document* KissDOMImplementation::createDocument(						const DOMString& namespaceURI,						const DOMString& qualifiedName,						DocumentType* doctype) {  if(qualifiedName.hasIllegalCharacters()) {    throw DOMException(DOMException::INVALID_CHARACTER_ERR);  }  if(!qualifiedName.isNSWellFormed()) {    throw DOMException(DOMException::NAMESPACE_ERR);  }  DOMString namePrefix;  DOMString nameLocalPart;  if(namespaceURI.length()>0) {    // We are making a document with a namespace root element.    if(qualifiedName.splitNSName(namePrefix,nameLocalPart)) {      // was a namespace name      if(namePrefix.eqxml()) {			// if the prefix is xml	// the namespaceURI must be exactly XML_NAMESPACEURI	if(namespaceURI != XML_NAMESPACEURI) {	  throw DOMException(DOMException::NAMESPACE_ERR);	}      }      else if(namePrefix.beginsWithxml() |nameLocalPart.beginsWithxml()) {	throw DOMException(DOMException::INVALID_CHARACTER_ERR);      }    }    else {      // was not a namespace name, in which case the name may be      // anything not begining with xml,      if(qualifiedName.beginsWithxml()) {	throw DOMException(DOMException::INVALID_CHARACTER_ERR);      }    }  }	  if(doctype != 0) {    if((doctype->ownerDocument() != 0)|doctype->readOnly()) {      throw DOMException(DOMException::WRONG_DOCUMENT_ERR);    }  }  // No further exceptions will occur beyond this point,  // therefore we may begin creating the document and element nodes.  Document* newDocument = new KissDocument((DOMImplementation*)this);  myNodeList.push_back(newDocument);  if(doctype != 0) {    doctype->setOwnerDocument(newDocument);    newDocument->appendChild(doctype);    // must look for doctype amongst nodes and remove it if there    // since it now belongs to the document    list<Node*>::iterator ppNode;    ppNode = myNodeList.begin();    while(((*ppNode) != doctype) && (ppNode != myNodeList.end())) {      ppNode++;    }    if((*ppNode) == doctype) {      myNodeList.erase(ppNode);    }  }  Element* documentElement = new KissElement(newDocument,0,namespaceURI,qualifiedName);  newDocument->appendChild(documentElement);  return newDocument;};// ******************************************************************************DOMImplementation* KissDOMImplementation::getAs(						DOMString& feature) {  return this;};// ******************************************************************************void KissDOMImplementation::printAll() {  if(DEBUGKISSDOM) {    printf("KissDOMImplementation::printAll()\n");  }  for(list<Node*>::const_iterator ppNode = myNodeList.begin(); ppNode != myNodeList.end(); ppNode++) {    printNode(0,*ppNode);  }};// ******************************************************************************void KissDOMImplementation::printNode(				      const unsigned long& indent,				      const Node* node2Print) {  if(DEBUGKISSDOM) {    printf("KissDOMImplementation::printNode()\n");  }  unsigned long i;  for(i = 0; i < indent; i++) {    printf("	");  }  printf("[%li] %s",node2Print->key(),node2Print->nodeName()->c_str());  const DOMString* s = node2Print->nodeValue();  if(s != 0) {    printf("='%s'",s->c_str());  }  printf("\n");  if(node2Print->namespaceURI() != 0) {    for(i = 0; i < indent; i++) {      printf("	");    }    printf("	(URI='%s')\n",node2Print->namespaceURI()->c_str());  }	  if(node2Print->attributes() != 0) {    if(node2Print->attributes()->length() != 0) {      for(i = 0; i < indent; i++) {	printf("	");      }      printf("Has Attributes (%li):\n",node2Print->attributes()->length());      for(i = 0; i < node2Print->attributes()->length(); i++) {	printNode(indent+1,node2Print->attributes()->item(i));      }    }  }  if(node2Print->childNodes()->length() != 0) {    for(i = 0; i < indent; i++) {      printf("	");    }    printf("Has Children (%li):\n",node2Print->childNodes()->length());    for(i = 0; i < node2Print->childNodes()->length(); i++) {      printNode(indent+1,node2Print->childNodes()->item(i));    }  }};// ******************************************************************************// ******************************************************************************//	KissNodeList// ******************************************************************************// ******************************************************************************long nKissNodeLists=0;  //!< Number of KISS node list objects// ******************************************************************************KissNodeList::KissNodeList(			   const list<Node*>* yourPNodeList) :  myPNodeList(yourPNodeList) {  if(DEBUGKISSDOM) {    nKissNodeLists++;    printf("KissNodeList::KissNodeList();\n");    printf("nKissNodeLists=%li\n",nKissNodeLists);  }};// ******************************************************************************KissNodeList::~KissNodeList() {  if(DEBUGKISSDOM) {    nKissNodeLists--;    printf("KissNodeList::~KissNodeList();\n");    printf("nKissNodeLists=%li\n",nKissNodeLists);  }};// ******************************************************************************Node* KissNodeList::item(			 unsigned long	index) const {  if(index >= myPNodeList->size()) {    return 0;  }  list<Node*>::const_iterator ppNode = myPNodeList->begin();  for(unsigned long i = 0; i<index; i++) {    ppNode++;  }  return (*ppNode);};// ******************************************************************************unsigned long KissNodeList::length() const {  return myPNodeList->size();};// ******************************************************************************// ******************************************************************************//	KissNamedNodeMap// ******************************************************************************// ******************************************************************************long nKissNamedNodeMaps=0;  //!< Number of KISS named node map objects// ******************************************************************************KissNamedNodeMap::KissNamedNodeMap(				   const unsigned long& yourNodeType) :  myNodeType(yourNodeType) {  if(DEBUGKISSDOM) {    nKissNamedNodeMaps++;    printf("KissNamedNodeMap::KissNamedNodeMap();\n");    printf("nKissNamedNodeMaps=%li\n",nKissNamedNodeMaps);  }  readOnly=0;};// ******************************************************************************KissNamedNodeMap::~KissNamedNodeMap() {  if(DEBUGKISSDOM) {    nKissNamedNodeMaps--;    printf("KissNamedNodeMap::~KissNamedNodeMap();\n");    printf("nKissNamedNodeMaps=%li\n",nKissNamedNodeMaps);  }  for(list<Node*>::const_iterator ppNode = myNodeList.begin(); ppNode != myNodeList.end(); ppNode++) {    delete (*ppNode);  }};// ******************************************************************************Node* KissNamedNodeMap::getNamedItem(				     const DOMString& name) const {  if(DEBUGKISSDOM) {    printf("KissNamedNodeMap::getNamedItem()\n");  }  if (DEBUGKISSDOM) {    printf("KissNamedNodeMap::getNamedItem() myNodeList.size() = %d\n",myNodeList.size());  }  if(myNodeList.size() == 0) {    return 0;  }  list<Node*>::const_iterator ppNode = myNodeList.begin();  list<const DOMString*>::const_iterator ppName = myNameList.begin();  bool found=0;  while((ppNode != myNodeList.end())&!found) {    found = (**ppName==name);    if(!found) {      ppNode++;      ppName++;    }  }  if(ppNode != myNodeList.end()) {    return *ppNode;  }	

⌨️ 快捷键说明

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