void XMLTreeGenerator::startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs) { string name = XMLUtil::trim(XMLUtil::WideCharToString(localname )); if (name.empty() ) return; XMLTree* pTree = NULL; if (m_pBuffer == NULL ) { m_pRoot->SetName(name); pTree = m_pRoot; } else { pTree = m_pBuffer->AddChild(name); } for (unsigned int i = 0; i < attrs.getLength(); i++ ) { pTree->AddAttribute( XMLUtil::trim(XMLUtil::WideCharToString(attrs.getLocalName(i ) ) ), XMLUtil::trim(XMLUtil::WideCharToString(attrs.getValue(i ) ) )); } m_pBuffer = pTree; }
void XMLWriter::declareAttributeNamespaces(const Attributes& attributes) { for (int i = 0; i < attributes.getLength(); i++) { XMLString namespaceURI = attributes.getURI(i); XMLString localName = attributes.getLocalName(i); XMLString qname = attributes.getQName(i); if (!localName.empty()) { XMLString prefix; XMLString splitLocalName; Name::split(qname, prefix, splitLocalName); if (prefix.empty()) prefix = _namespaces.getPrefix(namespaceURI); if (prefix.empty() && !namespaceURI.empty() && !_namespaces.isMapped(namespaceURI)) { prefix = newPrefix(); _namespaces.declarePrefix(prefix, namespaceURI); } const XMLString& uri = _namespaces.getURI(prefix); if ((uri.empty() || uri != namespaceURI) && !namespaceURI.empty()) { _namespaces.declarePrefix(prefix, namespaceURI); } } } }
void MySAX2Handler::startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs) { char* message = XMLString::transcode(localname); if (strcmp(message, "TIME_SLOT") == 0) { string label; int value; for (int i=0; i<attrs.getLength(); i++) { char *localname = XMLString::transcode(attrs.getLocalName(i)); char *atvalue = XMLString::transcode(attrs.getValue(i)); if (strcmp(localname, "TIME_SLOT_ID") == 0) { label = atvalue; } else if (strcmp(localname, "TIME_VALUE") == 0) { value = atoi(atvalue); } //cout << localname << " " << value << endl; time_slots[label] = value; XMLString::release(&localname); XMLString::release(&atvalue); } cout << label << " " << value << endl; } else { cout << "I saw element: "<< message << endl; } XMLString::release(&message); }
void GpXmlStateMachine::SetAttributes(GpType* target, const Attributes& attrs) { XMLSize_t numAtts = attrs.getLength(); string retValue; map<string, string> attributes; DEBOUT("GpXmlStateMachine::SetAttributes - Type"); if (numAtts > 0) { for (XMLSize_t i = 0; i < numAtts; i++) { string local(XMLString::transcode(attrs.getLocalName(i) ) ); string value(XMLString::transcode(attrs.getValue(i) ) ); attributes[local] = value; DEBOUT(i); DEBOUT(local); DEBOUT(value); } // Checking the member for constness if (FindAttribute(attributes, ConstStr, retValue) ) { if (retValue.compare(TrueStr) == 0) { target->Const(true); } } // Checking the member for staticness if (FindAttribute(attributes, StaticStr, retValue) ) { if (retValue.compare(TrueStr) == 0) { target->Static(true); } } // Checking if the member is a pointer or reference if (FindAttribute(attributes, DirecStr, retValue) ) { if (retValue.compare(PtrStr) == 0) { target->Direc(POINTER); DEBOUT("Pointer"); } else { if (retValue.compare(RefStr) == 0) { target->Direc(REFERENCE); DEBOUT("Reference"); } } } } }
void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes) { where("startElement"); std::cout << "uri: " << uri << std::endl << "localName: " << localName << std::endl << "qname: " << qname << std::endl; std::cout << "Attributes: " << std::endl; for (int i = 0; i < attributes.getLength(); ++i) { std::cout << attributes.getLocalName(i) << "=" << attributes.getValue(i) << std::endl; } }
void AttributesImpl::setAttributes(const Attributes& attributes) { if (&attributes != this) { int count = attributes.getLength(); _attributes.clear(); _attributes.reserve(count); for (int i = 0; i < count; i++) { addAttribute(attributes.getURI(i), attributes.getLocalName(i), attributes.getQName(i), attributes.getType(i), attributes.getValue(i)); } } }
bool qm::AutoPilotContentHandler::startElement(const WCHAR* pwszNamespaceURI, const WCHAR* pwszLocalName, const WCHAR* pwszQName, const Attributes& attributes) { if (wcscmp(pwszLocalName, L"entry") == 0) { if (state_ != STATE_AUTOPILOT) return false; bEnabled_ = true; for (int n = 0; n < attributes.getLength(); ++n) { const WCHAR* pwszAttrName = attributes.getLocalName(n); if (wcscmp(pwszAttrName, L"enabled") == 0) bEnabled_ = wcscmp(attributes.getValue(n), L"false") != 0; else return false; } state_ = STATE_ENTRY; } else { struct { const WCHAR* pwszName_; State stateBefore_; State stateAfter_; } states[] = { { L"autoPilot", STATE_ROOT, STATE_AUTOPILOT }, { L"course", STATE_ENTRY, STATE_COURSE }, { L"interval", STATE_ENTRY, STATE_INTERVAL } }; int n = 0; for (n = 0; n < countof(states); ++n) { if (wcscmp(pwszLocalName, states[n].pwszName_) == 0) { if (state_ != states[n].stateBefore_) return false; if (attributes.getLength() != 0) return false; state_ = states[n].stateAfter_; break; } } if (n == countof(states)) return false; } return true; }
void CVxmlSAXHandler::startElement( const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs ){ TTagAttributes iAttributes char* pTagName; TTagAttribute iAttr; //get Tag's name and Attributes pTagName = XMLString::transcode(localname); // cout<<"attrs:"<<endl; for(int i=0;i<attrs.getLength();i++) { //get the Attribute's infomation iAttr.pName = XMLString::transcode(attrs.getLocalName(i)); iAttr.pType = XMLString::transcode(attrs.getType(i)); iAttr.pValue = XMLString::transcode(attrs.getValue(i)); // add to attributes's vector in order to send to Vxml Builder iAttributes.push_back(iAttr); // cout<<"\tLocalName="<<XMLString::transcode(attrs.getLocalName(i)); // cout<<"\tType="<<XMLString::transcode(attrs.getType(i)); // cout<<"\tVaule="<<XMLString::transcode(attrs.getValue(i))<<endl; } // build the Module by pass the infomation to Vxml Builder m_iBuilder->StartModule(pTagName,iAttributes); // release the resource XMLString::release(&pTagName); for(int i=0;i<iAttributes.size();i++) { iAttr = iAttributes.at(i); XMLString::release(&iAttr.pName); XMLString::release(&iAttr.pAttrType); XMLString::release(&iAttr.pAttrValue); } return; }
// Read first 'units' attribute and return a scaling factor an input quantity // to convert to standard analysis units // The options are for time, length, and velocity units // If no 'units' found or invalid one found, return 1. double CommonReadHandler::ReadUnits(const Attributes& attrs,int type) { int i,numAttr=(int)attrs.getLength(); char *aName,*value; double attrScale=1.; for(i=0; i<numAttr; i++) { aName=XMLString::transcode(attrs.getLocalName(i)); if(strcmp(aName,"units")==0) { value=XMLString::transcode(attrs.getValue(i)); attrScale = UnitsController::UnitsAttribute(value,type); delete [] aName; delete [] value; break; } delete [] aName; } return attrScale; }
// Read tag with name *theTag and return its value as a double // If not found, return the supplied default value // Main use is for command with a single numeric tag double CommonReadHandler::ReadNumericAttribute(const char *theTag,const Attributes& attrs,double defaultValue) { int i,numAttr=(int)attrs.getLength(); char *aName,*value; double attrValue=defaultValue; for(i=0; i<numAttr; i++) { aName=XMLString::transcode(attrs.getLocalName(i)); if(strcmp(aName,theTag)==0) { value=XMLString::transcode(attrs.getValue(i)); sscanf(value,"%lf",&attrValue); delete [] aName; delete [] value; break; } delete [] aName; } return attrValue; }
void SAX2PrintHandlers::startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes) { // The name has to be representable without any escapes fFormatter << XMLFormatter::NoEscapes << chOpenAngle ; if ( fExpandNS ) { if (XMLString::compareIString(uri,XMLUni::fgZeroLenString) != 0) fFormatter << uri << chColon; fFormatter << localname ; } else fFormatter << qname ; unsigned int len = attributes.getLength(); for (unsigned int index = 0; index < len; index++) { // // Again the name has to be completely representable. But the // attribute can have refs and requires the attribute style // escaping. // fFormatter << XMLFormatter::NoEscapes << chSpace ; if ( fExpandNS ) { if (XMLString::compareIString(attributes.getURI(index),XMLUni::fgZeroLenString) != 0) fFormatter << attributes.getURI(index) << chColon; fFormatter << attributes.getLocalName(index) ; } else fFormatter << attributes.getQName(index) ; fFormatter << chEqual << chDoubleQuote << XMLFormatter::AttrEscapes << attributes.getValue(index) << XMLFormatter::NoEscapes << chDoubleQuote; } fFormatter << chCloseAngle; }
// read the 'number' attribute in current tag, ignore other attributes void CommonReadHandler::ReadTagNumber(int *myval,const Attributes& attrs) { int i,aval; char *aName,*value; int numAttr=(int)attrs.getLength(); *myval=0; for(i=0; i<numAttr; i++) { aName=XMLString::transcode(attrs.getLocalName(i)); if(strcmp(aName,"number")==0) { value=XMLString::transcode(attrs.getValue(i)); sscanf(value,"%i",&aval); *myval=aval; delete [] value; delete [] aName; break; } delete [] aName; } }
vector<string> DAGXMLParser::attributesToStrings(const int nattr, const char* attrNames[], const Attributes& attrs) { vector<string> ret(nattr); XMLSize_t i; int j; for(i=0;i<attrs.getLength();i++) { char* lname = XMLString::transcode(attrs.getLocalName(i)); char* val = XMLString::transcode(attrs.getValue(i)); for(j=0;j<nattr;j++) { if(strcmp(lname,attrNames[j])==0) { ret[j] = val; break; } } if(j==nattr) { stringstream errMsg("DAGXMLParser::attributesToStrings(): Attribute not recognised: "); errMsg << lname; error(errMsg.str().c_str()); } XMLString::release(&lname); XMLString::release(&val); } return ret; }
void XMLWriter::addAttributes(AttributeMap& attributeMap, const Attributes& attributes, const XMLString& elementNamespaceURI) { for (int i = 0; i < attributes.getLength(); i++) { XMLString namespaceURI = attributes.getURI(i); XMLString localName = attributes.getLocalName(i); XMLString qname = attributes.getQName(i); if (!localName.empty()) { XMLString prefix; if (namespaceURI != elementNamespaceURI) prefix = _namespaces.getPrefix(namespaceURI); if (!prefix.empty()) { qname = prefix; qname.append(toXMLString(MARKUP_COLON)); } else qname.clear(); qname.append(localName); } attributeMap[qname] = attributes.getValue(i); } }
void GpXmlStateMachine::SetAttributes(GpMember* target, const Attributes& attrs) { XMLSize_t numAtts = attrs.getLength(); string retValue; map<string, string> attributes; DEBOUT("GpXmlStateMachine::SetAttributes - Member"); if (numAtts > 0) { for (XMLSize_t i = 0; i < numAtts; i++) { string local(XMLString::transcode(attrs.getLocalName(i) ) ); string value(XMLString::transcode(attrs.getValue(i) ) ); attributes[local] = value; DEBOUT(i); DEBOUT(local); DEBOUT(value); } // Checking the member for access if (FindAttribute(attributes, AccessStr, retValue) ) { if (retValue.compare(PublicStr) == 0) { target->Access(PUBLIC); } if (retValue.compare(PrivateStr) == 0) { target->Access(PRIVATE); } if (retValue.compare(ProtectedStr) == 0) { target->Access(PROTECTED); } } } }
// --------------------------------------------------------------------------- // SAX2SortAttributesFilter: Overrides of the SAX2XMLFilter interface // --------------------------------------------------------------------------- void SAX2SortAttributesFilter::startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes) { AttrList sortedList(attributes.getLength()); for(XMLSize_t i=0;i<attributes.getLength();i++) { XMLSize_t j; for(j=0;j<sortedList.getLength();j++) { if(XMLString::compareString(sortedList.elementAt(j)->qName,attributes.getQName(i))>=0) break; } Attr* pClone=new Attr; pClone->qName = attributes.getQName(i); pClone->uri = attributes.getURI(i); pClone->localPart = attributes.getLocalName(i); pClone->value = attributes.getValue(i); pClone->attrType = attributes.getType(i); sortedList.insertElementAt(pClone, j); } SAX2XMLFilterImpl::startElement(uri, localname, qname, sortedList); }
//----------------------------------------------------------- // Check for bmp element, return false if not //----------------------------------------------------------- short CommonReadHandler::BMPFileCommonInput(char *xName,const Attributes& attrs,int expectedBlock) { char *aName,*value; int i,numAttr; double aScaling; //----------------------------------------------------------- // Read BMP file name and resolution //----------------------------------------------------------- if(strcmp(xName,"BMP")==0) { ValidateCommand(xName,expectedBlock,ANY_DIM); block=BMPBLOCK; bwidth=bheight=-1.e9; // < -1.e8 means dimension was not specified bmpFileName[0]=0; bmpAngleFileName[0]=0; xorig=yorig=0.; yflipped=FALSE; zslice=0.; aScaling=ReadUnits(attrs,LENGTH_UNITS); numAttr=attrs.getLength(); #ifdef MPM_CODE rotationAxes[0]=0; // no rotations yet #endif for(i=0;i<numAttr;i++) { aName=XMLString::transcode(attrs.getLocalName(i)); value=XMLString::transcode(attrs.getValue(i)); if(strcmp(aName,"width")==0) sscanf(value,"%lf",&bwidth); else if(strcmp(aName,"height")==0) sscanf(value,"%lf",&bheight); else if(strcmp(aName,"name")==0) strcpy(bmpFileName,value); else if(strcmp(aName,"angles")==0) strcpy(bmpAngleFileName,value); delete [] aName; delete [] value; } if(bwidth<-1.e8 && bheight<-1.e8) throw SAXException(BMPError("<BMP> must specify width and/or height as size or pixels per mm.",bmpFileName)); bwidth*=aScaling; bheight*=aScaling; if(bmpFileName[0]==0) throw SAXException("<BMP> must specify the file in a name attribute."); } //----------------------------------------------------------- // Set origin on input data //----------------------------------------------------------- else if(strcmp(xName,"Origin")==0) { ValidateCommand(xName,BMPBLOCK,ANY_DIM); aScaling=ReadUnits(attrs,LENGTH_UNITS); numAttr=attrs.getLength(); for(i=0;i<numAttr;i++) { aName=XMLString::transcode(attrs.getLocalName(i)); value=XMLString::transcode(attrs.getValue(i)); if(strcmp(aName,"x")==0) { sscanf(value,"%lf",&xorig); xorig*=aScaling; } else if(strcmp(aName,"y")==0) { sscanf(value,"%lf",&yorig); yorig*=aScaling; } else if(strcmp(aName,"z")==0) { sscanf(value,"%lf",&zslice); zslice*=aScaling; } else if(strcmp(aName,"flipped")==0) { if(strcmp(value,"yes")==0 || strcmp(value,"Yes")==0 || strcmp(value,"YES")==0 || strcmp(value,"1")==0 ) yflipped=TRUE; else yflipped=FALSE; } delete [] aName; delete [] value; } } //----------------------------------------------------------- // Assign intensity to some material properties //----------------------------------------------------------- else if(strcmp(xName,"Intensity")==0) { ValidateCommand(xName,BMPBLOCK,ANY_DIM); numAttr=attrs.getLength(); int mat=-1; int imin=-1; int imax=-1; minAngle=0.; double maxAngle=0.; char matname[200]; matname[0]=0; for(i=0;i<numAttr;i++) { aName=XMLString::transcode(attrs.getLocalName(i)); value=XMLString::transcode(attrs.getValue(i)); if(strcmp(aName,"mat")==0) sscanf(value,"%d",&mat); else if(strcmp(aName,"matname")==0) { if(strlen(value)>199) value[200]=0; strcpy(matname,value); } else if(strcmp(aName,"imin")==0) sscanf(value,"%d",&imin); else if(strcmp(aName,"imax")==0) sscanf(value,"%d",&imax); else if(strcmp(aName,"minAngle")==0) sscanf(value,"%lf",&minAngle); else if(strcmp(aName,"maxAngle")==0) sscanf(value,"%lf",&maxAngle); delete [] aName; delete [] value; } // if gave a matname, it takes precedence over mat number if(strlen(matname)>0) mat = matCtrl->GetIDFromNewName(matname); if(imin<0 || imax<0) throw SAXException(BMPError("<Intensity> has incomplete set of attributes.",bmpFileName)); if(imin>=imax) throw SAXException(BMPError("<Intensity> range is not valid.",bmpFileName)); if(mat>=0) { BMPLevel *newLevel=new BMPLevel(mat,imin,imax); if(newLevel==NULL) throw SAXException(BMPError("<Intensity> failed due to memory error.",bmpFileName)); if(currentLevel==NULL) firstLevel=newLevel; else currentLevel->SetNextObject(newLevel); currentLevel=newLevel; block=INTENSITYBLOCK; } else { angleScale=(maxAngle-minAngle)/((double)imax-(double)imin); minIntensity=(double)imin; } } //----------------------------------------------------------- // Intensity properties for both MPM and FEA //----------------------------------------------------------- // thickness else if(strcmp(xName,"Thickness")==0) { ValidateCommand(xName,INTENSITYBLOCK,MUST_BE_2D); input=DOUBLE_NUM; inputPtr=(char *)¤tLevel->thickness; gScaling=ReadUnits(attrs,LENGTH_UNITS); } // angle else if(strcmp(xName,"Angle")==0) { ValidateCommand(xName,INTENSITYBLOCK,ANY_DIM); input=DOUBLE_NUM; inputPtr=(char *)¤tLevel->angle; } // temperature else if(strcmp(xName,"Temperature")==0) { #ifdef FEA_CODE if(block==THERMAL) return FALSE; #endif ValidateCommand(xName,INTENSITYBLOCK,ANY_DIM); input=DOUBLE_NUM; inputPtr=(char *)¤tLevel->temperature; } else return FALSE; return TRUE; }
void GpXmlStateMachine::SetAttributes(GpMethod* target, const Attributes& attrs) { XMLSize_t numAtts = attrs.getLength(); string retValue; map<string, string> attributes; DEBOUT("GpXmlStateMachine::SetAttributes - Method"); if (numAtts > 0) { for (XMLSize_t i = 0; i < numAtts; i++) { string local(XMLString::transcode(attrs.getLocalName(i) ) ); string value(XMLString::transcode(attrs.getValue(i) ) ); attributes[local] = value; DEBOUT(i); DEBOUT(local); DEBOUT(value); } // Checking the method for constness if (FindAttribute(attributes, ConstStr, retValue) ) { if (retValue.compare(TrueStr) == 0) { target->Const(true); } } // Checking the method for runtime binding if (FindAttribute(attributes, VirtualStr, retValue) ) { if (retValue.compare(TrueStr) == 0) { target->Virtual(true); } } // Checking if the method defines an abstract class if (FindAttribute(attributes, PureStr, retValue) ) { if (retValue.compare(TrueStr) == 0) { // Can't have a pure non-virtual if (mCurrentMethod->Virtual() ) { target->Pure(true); } } } // Checking if the method returns a pointer or reference if (FindAttribute(attributes, DirecStr, retValue) ) { if (retValue.compare(PtrStr) == 0) { target->Type().Direc(POINTER); DEBOUT("Pointer"); } else { if (retValue.compare(RefStr) == 0) { target->Type().Direc(REFERENCE); DEBOUT("Reference"); } } } // Checking the method for access if (FindAttribute(attributes, AccessStr, retValue) ) { if (retValue.compare(PublicStr) == 0) { target->Access(PUBLIC); } if (retValue.compare(PrivateStr) == 0) { target->Access(PRIVATE); } if (retValue.compare(ProtectedStr) == 0) { target->Access(PROTECTED); } } } }
// Start a new element void CommonReadHandler::startElement(const XMLCh* const uri,const XMLCh* const localname, const XMLCh* const qname,const Attributes& attrs) { // decode tag name char *xName=XMLString::transcode(localname); input=NO_INPUT; // Handle all elements common between MPM and FEA analysis //------------------------------------------------------- // <Header> elements if(strcmp(xName,"Header")==0) block=HEADER; else if(strcmp(xName,"Description")==0) { if(block!=HEADER) throw SAXException("<Description> must be within the <Header> element."); input=TEXT_BLOCK; inputID=DESCRIPTION; } else if(strcmp(xName,"Analysis")==0) { if(block!=HEADER) throw SAXException("<Analysis> must be within the <Header> element."); input=ANALYSIS_NUM; } // begin a material else if(strcmp(xName,"DevelFlag")==0) { if(block!=HEADER) throw SAXException("<DevelFlag> must be within the <Header> element."); double flagNumDble=ReadNumericAttribute("Number",attrs,(double)0.0); int flagNum=(int)(flagNumDble+0.5); if(flagNum<0 || flagNum>=NUMBER_DEVELOPMENT_FLAGS) throw SAXException("The <DevelFlag> 'Number' must be from 0 to 9"); input=INT_NUM; inputPtr=(char *)&fmobj->dflag[flagNum]; } else if(strcmp(xName,"ConsistentUnits")==0) { if(block!=HEADER) throw SAXException("<ConsistentUnits> must be within the <Header> element."); char length[10],mass[10],timeu[10]; strcpy(length,""); strcpy(mass,""); strcpy(timeu,""); char *aName,*value; int i,numAttr=(int)attrs.getLength(); for(i=0; i<numAttr; i++) { aName=XMLString::transcode(attrs.getLocalName(i)); value=XMLString::transcode(attrs.getValue(i)); if(strlen(value)>9) throw SAXException("<ConsistentUnits> length, mass, or time attribute is invalid."); if(strcmp(aName,"length")==0) strcpy(length,value); else if(strcmp(aName,"mass")==0) strcpy(mass,value); else if(strcmp(aName,"time")==0) strcpy(timeu,value); delete [] aName; delete [] value; } if(strlen(length)==0 && strlen(mass)==0 && strlen(timeu)==0) { strcpy(length,"L"); strcpy(mass,"M"); strcpy(timeu,"T"); } if(!UnitsController::SetConsistentUnits(length, mass, timeu)) throw SAXException("Duplicated <ConsistentUnits> command or one of the units is invalid."); } //------------------------------------------------------- // <Mesh> block // Node list else if(strcmp(xName,"NodeList")==0) { ValidateCommand(xName,MESHBLOCK,ANY_DIM); if(meshType!=UNKNOWN_MESH) throw SAXException("<NodeList> can not be used with a generated mesh."); block=NODELIST; meshType=EXPLICIT_MESH; if(theNodes==NULL) theNodes=new NodesController(); } // Element list else if(strcmp(xName,"ElementList")==0) { ValidateCommand(xName,MESHBLOCK,ANY_DIM); if(meshType!=EXPLICIT_MESH) throw SAXException("<ElementList> cannot be used with a generated mesh."); block=ELEMENTLIST; // MPM only uses when in ElementList (which is uncommon because does not suppport GIMP) if(theElems==NULL) theElems=new ElementsController(); } //----------------------------------------------------------- // <GridBCs> section // DisplacementBC section else if(strcmp(xName,"DisplacementBCs")==0) { ValidateCommand(xName,GRIDBCHEADER,ANY_DIM); block=FIXEDNODES; } //------------------------------------------------------- // <Thermal> section // begin Thermal section else if(strcmp(xName,"Thermal")==0) { block=THERMAL; } //------------------------------------------------------- // <Material> Definitions // begin a material else if(strcmp(xName,"Material")==0) { block=MATERIAL; int matID=0; // invalid ID unless it is set char matName[200],*aName,*value; matName[0]=0; // to get the name of the material int i,numAttr=(int)attrs.getLength(); for(i=0; i<numAttr; i++) { aName=XMLString::transcode(attrs.getLocalName(i)); value=XMLString::transcode(attrs.getValue(i)); if(strcmp(aName,"Type")==0) sscanf(value,"%d",&matID); else if(strcmp(aName,"Name")==0) { if(strlen(value)>199) value[200]=0; strcpy(matName,value); } delete [] aName; delete [] value; } if(strlen(matName)==0) throw SAXException("<Material> must be named using 'Name' atttribute."); if(!matCtrl->AddMaterial(matID,matName)) ThrowCatErrorMessage("Invalid material: either undefined type or not allowed for current analysis type",matName); } // begin a material else if(strcmp(xName,"color")==0) { if(block!=MATERIAL) throw SAXException("<color> must be within a <Material> definition."); float redClr=-1.,greenClr=-1.,blueClr=-1.,alpha=1.; char *aName,*value; int i,numAttr=(int)attrs.getLength(); for(i=0; i<numAttr; i++) { aName=XMLString::transcode(attrs.getLocalName(i)); value=XMLString::transcode(attrs.getValue(i)); if(strcmp(aName,"red")==0) sscanf(value,"%f",&redClr); else if(strcmp(aName,"green")==0) sscanf(value,"%f",&greenClr); else if(strcmp(aName,"blue")==0) sscanf(value,"%f",&blueClr); else if(strcmp(aName,"alpha")==0) sscanf(value,"%f",&alpha); delete [] aName; delete [] value; } if(redClr>0.) { if(redClr>1.) redClr=1.; if(greenClr<0.) greenClr=redClr; if(blueClr<0.) blueClr=redClr; if(greenClr>1.) greenClr=1.; if(blueClr>1.) blueClr=1.; if(alpha<0.) alpha=0.; if(alpha>1.) alpha=1.; matCtrl->SetMatColor(redClr,greenClr,blueClr,alpha); } } //------------------------------------------------------- // Analysis-specific elements else if(!myStartElement(xName,attrs)) { // look for material property if(block==MATERIAL) { inputPtr=matCtrl->InputPointer(xName,input,gScaling); if(inputPtr==NULL) { char msg[255]; strcpy(msg,"Unrecognized "); strcat(msg,matCtrl->MaterialType()); strcat(msg," material property was found"); ThrowCatErrorMessage(msg,xName); } } // or an invalid tag else if(!(strcmp(xName,"JANFEAInput")==0)) ThrowCatErrorMessage("Unrecognized input element found",xName); } // delete tag string delete [] xName; }
void QgarAppDescr::startParam(const Attributes& atts) { // Set flag indicating that we're parsing a parameter now _parseData->state = PARAM; // Reset current parameter delete _parseData->currentParam; _parseData->currentParam = new QgarAppParamDescr(); //-- Read Parameter Attributes for (int i = 0; i < atts.getLength(); ++i) { string name = atts.getLocalName(i); string value = atts.getValue(i); if (name == "name") { (_parseData->currentParam)->setName(value); } else if (name == "flag") { (_parseData->currentParam)->setFlag(value); } else if (name == "required") { if (value == "false") { (_parseData->currentParam)->setRequired(false); } else { (_parseData->currentParam)->setRequired(true); } } else if (name == "passing-mode") { QgarAppParamDescr::ParamPassing mode; if (value == "in") { mode = QgarAppParamDescr::QGE_IN; } else if (value == "out") { mode = QgarAppParamDescr::QGE_OUT; } else if (value == "inout") { mode = QgarAppParamDescr::QGE_INOUT; } else { mode = QgarAppParamDescr::QGE_NONE; ostringstream os; os << "Unknown mode: " << value; throw QgarErrorDeveloper(__FILE__, __LINE__, "void QgarAppDescr::startParam(const Attributes&)", os.str()); } (_parseData->currentParam)->setPassingMode(mode); } else if (name == "type") { if ( (value == "grayscale") || (value == "binary") || (value == "vectorial") ) { (_parseData->currentParam)->setType(QgarAppParamDescr::QGE_IMAGE); } else { (_parseData->currentParam)->setType(QgarAppParamDescr::QGE_NUM); } } else if (name == "format") { QgarAppParamDescr::ParamFormat format; if (value == "PBM") { format = QgarAppParamDescr::QGE_PBM; } else if (value == "PPM") { format = QgarAppParamDescr::QGE_PPM; } else if (value == "PGM") { format = QgarAppParamDescr::QGE_PGM; } else if (value == "DXF") { format = QgarAppParamDescr::QGE_DXF; } else if (value == "SVG") { format = QgarAppParamDescr::QGE_SVG; } else if (value == "int") { format = QgarAppParamDescr::QGE_INT; } else if (value == "real") { format = QgarAppParamDescr::QGE_REAL; } else { format = QgarAppParamDescr::QGE_UNKNOWN_FORMAT; } (_parseData->currentParam)->setFormat(format); } else if (name == "default") { (_parseData->currentParam)->setDefaultValue(value); } else if (name == "min") { (_parseData->currentParam)->setMinValue(value); } else if (name == "max") { (_parseData->currentParam)->setMaxValue(value); } } }