void EventFunctionMFactory::parseXml(TiXmlNode* node) { boost::shared_ptr<EventFunction> ptr; //bool equality = getElementBool(node,"equality"); bool equality = node->FirstChild("checkValue").Attribute("equality"); double checkValue = d_xpath_double(node,"//checkValue/text()"); std::string functionType = getElementValue(node,"functionType"); if(to_upper_copy(functionType)=="UPEVENTCHECK"){ptr = boost::shared_ptr<EventFunction>(new UpEventCheck(checkValue,equality));} else if(to_upper_copy(functionType)=="DOWNEVENTCHECK"){ptr = boost::shared_ptr<EventFunction>(new DownEventCheck(checkValue,equality));} else if(to_upper_copy(functionType)=="UPDOWNEVENTCHECK"){ptr = boost::shared_ptr<EventFunction>( new UpDownEventCheck(checkValue,equality,checkValue,equality));} //else if(functionType=="RangeCheck"){ptr = boost::shared_ptr<EventFunction>(new IdentityEventCheck(checkValue,equality));} else{ptr = boost::shared_ptr<EventFunction>(new IdentityEventCheck(equality));} //std::string value = node->FirstChildElement()->GetText(); std::string functionSymbol = getElementValue(node,"functionSymbol"); std::string indexSymbol = getElementValue(node,"indexSymbol"); eventFunctionM_ = boost::shared_ptr<EventFunctionManager>( new EventFunctionManager(functionSymbol, indexSymbol, ptr)); }
bool ReadJoystick(F32 axes[MaxJoystickAxes], U32 &buttonMask, U32 &hatMask) { if(!gJoystickInit) return false; S32 i; for(i = 0; i < MaxJoystickAxes; i++) { ControllerElement *e = &gController.axes[i]; S32 elementValue = getElementValue(e); S32 diff = e->maxValue - e->minValue; if(diff != 0) { axes[i] = (elementValue - e->minValue) * 2 / F32(diff); axes[i] -= 1; } else axes[i] = 0; } buttonMask = 0; for(i = 0; i < gController.buttons.size(); i++) { ControllerElement *e = &gController.buttons[i]; S32 value = getElementValue(e); if(value) buttonMask |= (1 << i); } return true; }
// start<limit && all strings longer than unitIndex && // length different units at unitIndex StringTrieBuilder::Node * StringTrieBuilder::makeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, int32_t length, UErrorCode &errorCode) { if(U_FAILURE(errorCode)) { return NULL; } UChar middleUnits[kMaxSplitBranchLevels]; Node *lessThan[kMaxSplitBranchLevels]; int32_t ltLength=0; while(length>getMaxBranchLinearSubNodeLength()) { // Branch on the middle unit. // First, find the middle unit. int32_t i=skipElementsBySomeUnits(start, unitIndex, length/2); // Create the less-than branch. middleUnits[ltLength]=getElementUnit(i, unitIndex); // middle unit lessThan[ltLength]=makeBranchSubNode(start, i, unitIndex, length/2, errorCode); ++ltLength; // Continue for the greater-or-equal branch. start=i; length=length-length/2; } if(U_FAILURE(errorCode)) { return NULL; } ListBranchNode *listNode=new ListBranchNode(); if(listNode==NULL) { errorCode=U_MEMORY_ALLOCATION_ERROR; return NULL; } // For each unit, find its elements array start and whether it has a final value. int32_t unitNumber=0; do { int32_t i=start; UChar unit=getElementUnit(i++, unitIndex); i=indexOfElementWithNextUnit(i, unitIndex, unit); if(start==i-1 && unitIndex+1==getElementStringLength(start)) { listNode->add(unit, getElementValue(start)); } else { listNode->add(unit, makeNode(start, i, unitIndex+1, errorCode)); } start=i; } while(++unitNumber<length-1); // unitNumber==length-1, and the maxUnit elements range is [start..limit[ UChar unit=getElementUnit(start, unitIndex); if(start==limit-1 && unitIndex+1==getElementStringLength(start)) { listNode->add(unit, getElementValue(start)); } else { listNode->add(unit, makeNode(start, limit, unitIndex+1, errorCode)); } Node *node=registerNode(listNode, errorCode); // Create the split-branch nodes. while(ltLength>0) { --ltLength; node=registerNode( new SplitBranchNode(middleUnits[ltLength], lessThan[ltLength], node), errorCode); } return node; }
/************************************************************************ * Function : getServiceTable * * Parameters : * IXML_Node *node ; XML node information * service_table *out ; output parameter which will contain the * service list and URL * const char *DefaultURLBase ; Default base URL on which the URL * will be returned. * * Description : Retrieve service from the table * * Return : int ; * * Note : ************************************************************************/ int getServiceTable( IXML_Node * node, service_table * out, const char *DefaultURLBase ) { IXML_Node *root = NULL; IXML_Node *URLBase = NULL; if( getSubElement( "root", node, &root ) ) { if( getSubElement( "URLBase", root, &URLBase ) ) { out->URLBase = getElementValue( URLBase ); } else { if( DefaultURLBase ) { out->URLBase = ixmlCloneDOMString( DefaultURLBase ); } else { out->URLBase = ixmlCloneDOMString( "" ); } } if( ( out->serviceList = getAllServiceList( root, out->URLBase, &out->endServiceList ) ) ) { return 1; } } return 0; }
Vector BridgedMultiColvarFunction::retrieveCentralAtomPos(){ if( atomsWithCatomDer.getNumberActive()==0 ){ Vector cvec = mycolv->retrieveCentralAtomPos(); // Copy the value and derivatives from the MultiColvar atomsWithCatomDer.emptyActiveMembers(); for(unsigned i=0;i<3;++i){ setElementValue( getCentralAtomElementIndex() + i, mycolv->getElementValue( mycolv->getCentralAtomElementIndex() + i ) ); unsigned nbase = ( getCentralAtomElementIndex() + i)*getNumberOfDerivatives(); unsigned nbas2 = ( mycolv->getCentralAtomElementIndex() + i )*mycolv->getNumberOfDerivatives(); for(unsigned j=0;j<mycolv->atomsWithCatomDer.getNumberActive();++j){ unsigned n=mycolv->atomsWithCatomDer[j], nx=3*n; atomsWithCatomDer.activate(n); addElementDerivative(nbase + nx + 0, mycolv->getElementDerivative(nbas2 + nx + 0) ); addElementDerivative(nbase + nx + 1, mycolv->getElementDerivative(nbas2 + nx + 1) ); addElementDerivative(nbase + nx + 2, mycolv->getElementDerivative(nbas2 + nx + 2) ); } } for(unsigned j=0;j<mycolv->atomsWithCatomDer.getNumberActive();++j) atomsWithCatomDer.updateIndex( mycolv->atomsWithCatomDer[j] ); atomsWithCatomDer.sortActiveList(); return cvec; } Vector cvec; for(unsigned i=0;i<3;++i) cvec[i]=getElementValue(1+i); return cvec; }
/************************************************************************ * Function : removeServiceTable * * Parameters : * IXML_Node *node ; XML node information * service_table *in ; service table from which services will be * removed * * Description : This function assumes that services for a particular * root device are placed linearly in the service table, and in the * order in which they are found in the description document * all services for this root device are removed from the list * * Return : int ; * * Note : ************************************************************************/ int removeServiceTable( IXML_Node * node, service_table * in ) { IXML_Node *root = NULL; IXML_Node *currentUDN = NULL; DOMString UDN = NULL; IXML_NodeList *deviceList = NULL; service_info *current_service = NULL; service_info *start_search = NULL; service_info *prev_service = NULL; long unsigned int NumOfDevices = 0lu; long unsigned int i = 0lu; if( getSubElement( "root", node, &root ) ) { current_service = in->serviceList; start_search = in->serviceList; deviceList = ixmlElement_getElementsByTagName( ( IXML_Element * ) root, "device" ); if( deviceList != NULL ) { NumOfDevices = ixmlNodeList_length( deviceList ); for( i = 0lu; i < NumOfDevices; i++ ) { if( ( start_search ) && ( ( getSubElement( "UDN", node, ¤tUDN ) ) && ( UDN = getElementValue( currentUDN ) ) ) ) { current_service = start_search; /*Services are put in the service table in the order in which they appear in the */ /*description document, therefore we go through the list only once to remove a particular */ /*root device */ while( ( current_service ) && ( strcmp( current_service->UDN, UDN ) ) ) { current_service = current_service->next; if( current_service != NULL) prev_service = current_service->next; } while( ( current_service ) && ( !strcmp( current_service->UDN, UDN ) ) ) { if( prev_service ) { prev_service->next = current_service->next; } else { in->serviceList = current_service->next; } if( current_service == in->endServiceList ) in->endServiceList = prev_service; start_search = current_service->next; freeService( current_service ); current_service = start_search; } ixmlFreeDOMString( UDN ); UDN = NULL; } } ixmlNodeList_free( deviceList ); } } return 1; }
void MultiColvarBase::quotientRule( const unsigned& uder, const unsigned& vder, const unsigned& iout ){ unsigned ustart=uder*getNumberOfDerivatives(); unsigned vstart=vder*getNumberOfDerivatives(); unsigned istart=iout*getNumberOfDerivatives(); double weight = getElementValue( vder ), pref = getElementValue( uder ) / (weight*weight); if( !doNotCalculateDerivatives() ){ for(unsigned i=0;i<atoms_with_derivatives.getNumberActive();++i){ unsigned n=3*atoms_with_derivatives[i], nx=n, ny=n+1, nz=n+2; setElementDerivative( istart + nx, getElementDerivative(ustart+nx) / weight - pref*getElementDerivative(vstart+nx) ); setElementDerivative( istart + ny, getElementDerivative(ustart+ny) / weight - pref*getElementDerivative(vstart+ny) ); setElementDerivative( istart + nz, getElementDerivative(ustart+nz) / weight - pref*getElementDerivative(vstart+nz) ); } unsigned vbase=3*getNumberOfAtoms(); for(unsigned i=0;i<9;++i){ setElementDerivative( istart + vbase + i, getElementDerivative(ustart+vbase+i) / weight - pref*getElementDerivative(vstart+vbase+i) ); } } thisval_wasset[iout]=false; setElementValue( iout, getElementValue(uder) / weight ); }
Vector MultiColvarBase::retrieveCentralAtomPos(){ if( atomsWithCatomDer.getNumberActive()==0 ){ Vector cvec = calculateCentralAtomPosition(); for(unsigned i=0;i<3;++i) setElementValue( getCentralAtomElementIndex()+i, cvec[i] ); return cvec; } Vector cvec; for(unsigned i=0;i<3;++i) cvec[i]=getElementValue( 2+i ); return cvec; }
/************************************************************************************************************ * The JsonList for the findElement Function to test are as shown below, * * * * { * * "NAME1":"JS", * * "AGE" :{ "NAME2":"STEVEN", * * "NAME3":"YEN"} * * } * * * * -Test to find the 'Key'="AGE" in recur=0. * * -Test to find the 'Key'="NAME3" in recur=1. * * -Test to get the 'Value' for the 'Key' found in recur=1. * * * * ************************************************************************************************************/ void test_Finding_Element_in_Recursion_JSON_List() { printf("JSON list Finding Element test No.4\n"); JsonObject *jsonObj; Token *jsonTok; ListElement *findKey; Token *findVal; ErrorObject *err; TOKEN_DECLARE; getToken_ExpectAndReturn(openBrace0); //"{" getToken_ExpectAndReturn(NAME1); //"NAME1" getToken_ExpectAndReturn(colon0); //":" getToken_ExpectAndReturn(JS); //"JS" getToken_ExpectAndReturn(coma0); //"," getToken_ExpectAndReturn(AGE); //"AGE" getToken_ExpectAndReturn(colon1); //":" getToken_ExpectAndReturn(openBrace1); //"{" getToken_ExpectAndReturn(NAME2); //"NAME2" getToken_ExpectAndReturn(colon2); //":" getToken_ExpectAndReturn(STEVEN); //"STEVEN" getToken_ExpectAndReturn(coma1); //"," getToken_ExpectAndReturn(NAME3); //"NAME3" getToken_ExpectAndReturn(colon3); //":" getToken_ExpectAndReturn(YEN); //"YEN" getToken_ExpectAndReturn(closeBrace0); //"}" getToken_ExpectAndReturn(closeBrace1); //"}" getToken_ExpectAndReturn(dollarSign); jsonObj=createJsonObject(); Try{ jsonTok=jsonParse(jsonObj); TEST_ASSERT_EQUAL(END,jsonObj->state); findKey=(ListElement *)(keyFind(((JsonToken *)jsonTok)->list, "AGE", strCompare)); findKey=(ListElement *)(keyFind(((JsonToken *)(((OperatorToken *)(findKey->value))->token[1]))->list, "NAME3", strCompare)); findVal=(Token *)(getElementValue(findKey)); TEST_ASSERT_NOT_NULL(findVal); }Catch(err){ TEST_FAIL_JSON("unexpected error occurred =>'%s'",err->errorMsg); free(err); } TEST_ASSERT_EQUAL_STRING(((StringToken *)(YEN))->name,((StringToken *)(findVal))->name); free(jsonObj); free(jsonTok); free(err); free(findKey); free(findVal); TOKEN_FREE; printf("\n\n"); }
void ExposedModel::notifyListeners(QString key) { std::map<std::string, std::vector<QScriptValue> >::iterator listenersFound = m_listeners.find(key.toStdString()); if(listenersFound != m_listeners.end()) { std::vector<QScriptValue>& listeners = listenersFound->second; for(size_t i = 0; i < listeners.size(); ++i) { listeners[i].call(QScriptValue(), QScriptValueList() << key << getElementValue(key)); } } }
void MultiColvarBase::copyElementsToBridgedColvar( BridgedMultiColvarFunction* func ){ func->setElementValue( 0, getElementValue(0) ); for(unsigned i=0;i<atoms_with_derivatives.getNumberActive();++i){ unsigned n=atoms_with_derivatives[i], nx=3*n; func->atoms_with_derivatives.activate(n); func->addElementDerivative( nx+0, getElementDerivative(nx+0) ); func->addElementDerivative( nx+1, getElementDerivative(nx+1) ); func->addElementDerivative( nx+2, getElementDerivative(nx+2) ); } unsigned nvir=3*getNumberOfAtoms(); for(unsigned i=0;i<9;++i){ func->addElementDerivative( nvir, getElementDerivative(nvir) ); nvir++; } }
// Requires start<limit, // and all strings of the [start..limit[ elements must be sorted and // have a common prefix of length unitIndex. StringTrieBuilder::Node * StringTrieBuilder::makeNode(int32_t start, int32_t limit, int32_t unitIndex, UErrorCode &errorCode) { if(U_FAILURE(errorCode)) { return NULL; } UBool hasValue=FALSE; int32_t value=0; if(unitIndex==getElementStringLength(start)) { // An intermediate or final value. value=getElementValue(start++); if(start==limit) { return registerFinalValue(value, errorCode); } hasValue=TRUE; } Node *node; // Now all [start..limit[ strings are longer than unitIndex. int32_t minUnit=getElementUnit(start, unitIndex); int32_t maxUnit=getElementUnit(limit-1, unitIndex); if(minUnit==maxUnit) { // Linear-match node: All strings have the same character at unitIndex. int32_t lastUnitIndex=getLimitOfLinearMatch(start, limit-1, unitIndex); Node *nextNode=makeNode(start, limit, lastUnitIndex, errorCode); // Break the linear-match sequence into chunks of at most kMaxLinearMatchLength. int32_t length=lastUnitIndex-unitIndex; int32_t maxLinearMatchLength=getMaxLinearMatchLength(); while(length>maxLinearMatchLength) { lastUnitIndex-=maxLinearMatchLength; length-=maxLinearMatchLength; node=createLinearMatchNode(start, lastUnitIndex, maxLinearMatchLength, nextNode); nextNode=registerNode(node, errorCode); } node=createLinearMatchNode(start, unitIndex, length, nextNode); } else { // Branch node. int32_t length=countElementUnits(start, limit, unitIndex); // length>=2 because minUnit!=maxUnit. Node *subNode=makeBranchSubNode(start, limit, unitIndex, length, errorCode); node=new BranchHeadNode(length, subNode); } if(hasValue && node!=NULL) { if(matchNodesCanHaveValues()) { ((ValueNode *)node)->setValue(value); } else { node=new IntermediateValueNode(value, registerNode(node, errorCode)); } } return registerNode(node, errorCode); }
/** * * The neuronsWithActivationChange parameter can be used to collect all DoubelValues that correspond * to activation values of neurons. These neurons have to be collected in each DymnamcisPlotter in * variable DynamcisPlotter::mNeuronsWithActivationsToTransfer to be handled correctly, if the * activation of a neuron should be varied during an analyzer run. Otherwise the varied activations * are immediately overwritten by the newly calculated activations at the first network update. * * If this method is used to collect elements that will NOT be changed during analyzer runs, * then the last parameter MUST be empty. Othewise activations of neurons collected in this way * will be treated differently compared to the other neurons in the network. This may lead to * unexpected and erroneous behavior. * * @param specifier the specification of the desired DoubleValue object. * @param networkElements the list of objects that are considered to find the specified DoubleValue object. * @param neuronsWithActivationChange (optional) list to collect all activation values that are going to be changed during a run. */ DoubleValue* DynamicsPlotterUtil::getElementValue(QString const &specifier, QList<NeuralNetworkElement*> const &networkElements, QList<Neuron*> *neuronsWithActivationChange) { if(specifier.isEmpty()) { reportProblem("DynamicsPlotterUtil::getElementValue(2) : " "Empty specifier!"); return 0; } QStringList specifierParts = specifier.split(":"); if(specifierParts.size() < 2 || specifierParts.size() > 3) { reportProblem("DynamicsPlotterUtil::getElementValue(2) : " "Invalid specifier ["+specifier+"]!"); return 0; } bool idValid; QString idString = specifierParts.first(); QString parameter = specifier; parameter = parameter.remove(0, idString.size()+1); qulonglong id = idString.toULongLong(&idValid); if(!idValid) { reportProblem("DynamicsPlotterUtil::getElementValue(2) : " "Invalid ID ["+idString+"]!"); return 0; } NeuralNetworkElement* networkElement; networkElement = NeuralNetwork::selectNetworkElementById(id, networkElements); if(networkElement == 0) { reportProblem("DynamicsPlotterUtil::getElementValue(2) : " "No element with ID ["+idString+"] " "found in given list!"); return 0; } DoubleValue* elementValue; elementValue = getElementValue(parameter, networkElement, neuronsWithActivationChange); if(elementValue == 0) { reportProblem("DynamicsPlotterUtil::getElementValue(2) : " "Could not find specified parameter value at element!"); return 0; } return elementValue; }
// Requires start<limit, // and all strings of the [start..limit[ elements must be sorted and // have a common prefix of length unitIndex. int32_t StringTrieBuilder::writeNode(int32_t start, int32_t limit, int32_t unitIndex) { UBool hasValue=FALSE; int32_t value=0; int32_t type; if(unitIndex==getElementStringLength(start)) { // An intermediate or final value. value=getElementValue(start++); if(start==limit) { return writeValueAndFinal(value, TRUE); // final-value node } hasValue=TRUE; } // Now all [start..limit[ strings are longer than unitIndex. int32_t minUnit=getElementUnit(start, unitIndex); int32_t maxUnit=getElementUnit(limit-1, unitIndex); if(minUnit==maxUnit) { // Linear-match node: All strings have the same character at unitIndex. int32_t lastUnitIndex=getLimitOfLinearMatch(start, limit-1, unitIndex); writeNode(start, limit, lastUnitIndex); // Break the linear-match sequence into chunks of at most kMaxLinearMatchLength. int32_t length=lastUnitIndex-unitIndex; int32_t maxLinearMatchLength=getMaxLinearMatchLength(); while(length>maxLinearMatchLength) { lastUnitIndex-=maxLinearMatchLength; length-=maxLinearMatchLength; writeElementUnits(start, lastUnitIndex, maxLinearMatchLength); write(getMinLinearMatch()+maxLinearMatchLength-1); } writeElementUnits(start, unitIndex, length); type=getMinLinearMatch()+length-1; } else { // Branch node. int32_t length=countElementUnits(start, limit, unitIndex); // length>=2 because minUnit!=maxUnit. writeBranchSubNode(start, limit, unitIndex, length); if(--length<getMinLinearMatch()) { type=length; } else { write(length); type=0; } } return writeValueAndType(hasValue, value, type); }
void MultiColvarBase::performTask(){ // Currently no atoms have derivatives so deactivate those that are active atoms_with_derivatives.deactivateAll(); // Currently no central atoms have derivatives so deactive them all atomsWithCatomDer.deactivateAll(); // Retrieve the atom list if( !setupCurrentAtomList( getCurrentTask() ) ) return; // Do a quick check on the size of this contribution calculateWeight(); // printf("HELLO WEIGHT %f \n",getElementValue(1) ); if( getElementValue(1)<getTolerance() ){ updateActiveAtoms(); return; } // Compute everything double vv=doCalculation(); // Set the value of this element in ActionWithVessel setElementValue( 0, vv ); return; }
/************************************************************************ * Function : addServiceTable * * Parameters : * IXML_Node *node ; XML node information * service_table *in ; service table that will be initialized with * services * const char *DefaultURLBase ; Default base URL on which the URL * will be returned to the service list. * * Description : Add Service to the table. * * Return : int ; * * Note : ************************************************************************/ int addServiceTable( IXML_Node * node, service_table * in, const char *DefaultURLBase ) { IXML_Node *root = NULL; IXML_Node *URLBase = NULL; service_info *tempEnd = NULL; if( in->URLBase ) { free( in->URLBase ); in->URLBase = NULL; } if( getSubElement( "root", node, &root ) ) { if( getSubElement( "URLBase", root, &URLBase ) ) { in->URLBase = getElementValue( URLBase ); } else { if( DefaultURLBase ) { in->URLBase = ixmlCloneDOMString( DefaultURLBase ); } else { in->URLBase = ixmlCloneDOMString( "" ); } } if( ( in->endServiceList->next = getAllServiceList( root, in->URLBase, &tempEnd ) ) ) { in->endServiceList = tempEnd; return 1; } } return 0; }
/** * * The neuronsWithActivationChange parameter can be used to collect all DoubelValues that correspond * to activation values of neurons. These neurons have to be collected in each DymnamcisPlotter in * variable DynamcisPlotter::mNeuronsWithActivationsToTransfer to be handled correctly, if the * activation of a neuron should be varied during an analyzer run. Otherwise the varied activations * are immediately overwritten by the newly calculated activations at the first network update. * * If this method is used to collect elements that will NOT be changed during analyzer runs, * then the last parameter MUST be empty. Othewise activations of neurons collected in this way * will be treated differently compared to the other neurons in the network. This may lead to * unexpected and erroneous behavior. * * @param specifierLists a list of stringlists, containing the single specifications of DoubleValues. * @param networkElements the list of objects that are considered to find the specified DoubleValue object. * @param neuronsWithActivationChange (optional) list to collect all activation values that are going to be changed during a run. */ QList< QList<DoubleValue*> > DynamicsPlotterUtil::getElementValues(QList<QStringList> const &specifierLists, QList<NeuralNetworkElement*> const &networkElements, QList<Neuron*> *neuronsWithActivationChange) { QList< QList<DoubleValue*> > plotElements, emptyList; emptyList = QList< QList<DoubleValue*> >(); for(int listNr = 0; listNr < specifierLists.size(); ++listNr) { QList<DoubleValue*> elementValues; QStringList specifierList = specifierLists.at(listNr); for(int specifierNr = 0; specifierNr < specifierList.size(); ++specifierNr) { QString specifier = specifierList.at(specifierNr); if(specifier.isEmpty()) { reportProblem("DynamicsPlotterUtil::getElementValues : Empty specifier!"); return emptyList; } QStringList parameters = specifier.split(":"); if(parameters.size() < 2 || parameters.size() > 3) { reportProblem("DynamicsPlotterUtil::getElementValues : Invalid specifier ["+specifier+"]!"); return emptyList; } if(parameters.first() == "all") { QList<DoubleValue*> netValues; DoubleValue* elementValue; QString parameter = specifier.remove("all:"); for(int elemNr = 0; elemNr < networkElements.size(); ++elemNr) { NeuralNetworkElement* networkElement = networkElements.at(elemNr); elementValue = getElementValue(parameter, networkElement, neuronsWithActivationChange); if(elementValue != 0) { netValues.append(elementValue); } } elementValues.append(netValues); } else { DoubleValue* elementValue; elementValue = getElementValue(specifier, networkElements, neuronsWithActivationChange); if(elementValue == 0) { reportProblem("DynamicsPlotterUtil::getElementValues : Could not find a value " "for element specifier ["+specifier+"]!"); return emptyList; } elementValues.append(elementValue); } } plotElements.append(elementValues); } return plotElements; }
// start<limit && all strings longer than unitIndex && // length different units at unitIndex int32_t StringTrieBuilder::writeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, int32_t length) { UChar middleUnits[kMaxSplitBranchLevels]; int32_t lessThan[kMaxSplitBranchLevels]; int32_t ltLength=0; while(length>getMaxBranchLinearSubNodeLength()) { // Branch on the middle unit. // First, find the middle unit. int32_t i=skipElementsBySomeUnits(start, unitIndex, length/2); // Encode the less-than branch first. middleUnits[ltLength]=getElementUnit(i, unitIndex); // middle unit lessThan[ltLength]=writeBranchSubNode(start, i, unitIndex, length/2); ++ltLength; // Continue for the greater-or-equal branch. start=i; length=length-length/2; } // For each unit, find its elements array start and whether it has a final value. int32_t starts[kMaxBranchLinearSubNodeLength]; UBool isFinal[kMaxBranchLinearSubNodeLength-1]; int32_t unitNumber=0; do { int32_t i=starts[unitNumber]=start; UChar unit=getElementUnit(i++, unitIndex); i=indexOfElementWithNextUnit(i, unitIndex, unit); isFinal[unitNumber]= start==i-1 && unitIndex+1==getElementStringLength(start); start=i; } while(++unitNumber<length-1); // unitNumber==length-1, and the maxUnit elements range is [start..limit[ starts[unitNumber]=start; // Write the sub-nodes in reverse order: The jump lengths are deltas from // after their own positions, so if we wrote the minUnit sub-node first, // then its jump delta would be larger. // Instead we write the minUnit sub-node last, for a shorter delta. int32_t jumpTargets[kMaxBranchLinearSubNodeLength-1]; do { --unitNumber; if(!isFinal[unitNumber]) { jumpTargets[unitNumber]=writeNode(starts[unitNumber], starts[unitNumber+1], unitIndex+1); } } while(unitNumber>0); // The maxUnit sub-node is written as the very last one because we do // not jump for it at all. unitNumber=length-1; writeNode(start, limit, unitIndex+1); int32_t offset=write(getElementUnit(start, unitIndex)); // Write the rest of this node's unit-value pairs. while(--unitNumber>=0) { start=starts[unitNumber]; int32_t value; if(isFinal[unitNumber]) { // Write the final value for the one string ending with this unit. value=getElementValue(start); } else { // Write the delta to the start position of the sub-node. value=offset-jumpTargets[unitNumber]; } writeValueAndFinal(value, isFinal[unitNumber]); offset=write(getElementUnit(start, unitIndex)); } // Write the split-branch nodes. while(ltLength>0) { --ltLength; writeDeltaTo(lessThan[ltLength]); offset=write(middleUnits[ltLength]); } return offset; }
/************************************************************************ * Function : getServiceList * * Parameters : * IXML_Node *node ; XML node information * service_info **end ; service added is returned to the output * parameter * char * URLBase ; provides Base URL to resolve relative URL * * Description : Returns pointer to service info after getting the * sub-elements of the service info. * * Return : service_info * - pointer to the service info node ; * * Note : ************************************************************************/ service_info * getServiceList( IXML_Node * node, service_info ** end, char *URLBase ) { IXML_Node *serviceList = NULL; IXML_Node *current_service = NULL; IXML_Node *UDN = NULL; IXML_Node *serviceType = NULL; IXML_Node *serviceId = NULL; IXML_Node *SCPDURL = NULL; IXML_Node *controlURL = NULL; IXML_Node *eventURL = NULL; DOMString tempDOMString = NULL; service_info *head = NULL; service_info *current = NULL; service_info *previous = NULL; IXML_NodeList *serviceNodeList = NULL; int NumOfServices = 0; int i = 0; int fail = 0; if( getSubElement( "UDN", node, &UDN ) && getSubElement( "serviceList", node, &serviceList ) ) { serviceNodeList = ixmlElement_getElementsByTagName( ( IXML_Element * ) serviceList, "service" ); if( serviceNodeList != NULL ) { NumOfServices = ixmlNodeList_length( serviceNodeList ); for( i = 0; i < NumOfServices; i++ ) { current_service = ixmlNodeList_item( serviceNodeList, i ); fail = 0; if( current ) { current->next = ( service_info * ) malloc( sizeof( service_info ) ); previous = current; current = current->next; } else { head = ( service_info * ) malloc( sizeof( service_info ) ); current = head; } if( !current ) { freeServiceList( head ); return NULL; } current->next = NULL; current->controlURL = NULL; current->eventURL = NULL; current->serviceType = NULL; current->serviceId = NULL; current->SCPDURL = NULL; current->active = 1; current->subscriptionList = NULL; current->TotalSubscriptions = 0; if( !( current->UDN = getElementValue( UDN ) ) ) fail = 1; if( ( !getSubElement( "serviceType", current_service, &serviceType ) ) || ( !( current->serviceType = getElementValue( serviceType ) ) ) ) fail = 1; if( ( !getSubElement( "serviceId", current_service, &serviceId ) ) || ( ! ( current->serviceId = getElementValue( serviceId ) ) ) ) fail = 1; if( ( ! ( getSubElement ( "SCPDURL", current_service, &SCPDURL ) ) ) || ( !( tempDOMString = getElementValue( SCPDURL ) ) ) || ( ! ( current->SCPDURL = resolve_rel_url( URLBase, tempDOMString ) ) ) ) fail = 1; ixmlFreeDOMString( tempDOMString ); tempDOMString = NULL; if( ( ! ( getSubElement ( "controlURL", current_service, &controlURL ) ) ) || ( !( tempDOMString = getElementValue( controlURL ) ) ) || ( ! ( current->controlURL = resolve_rel_url( URLBase, tempDOMString ) ) ) ) { UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, "BAD OR MISSING CONTROL URL" ); UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, "CONTROL URL SET TO NULL IN SERVICE INFO" ); current->controlURL = NULL; fail = 0; } ixmlFreeDOMString( tempDOMString ); tempDOMString = NULL; if( ( ! ( getSubElement ( "eventSubURL", current_service, &eventURL ) ) ) || ( !( tempDOMString = getElementValue( eventURL ) ) ) || ( ! ( current->eventURL = resolve_rel_url( URLBase, tempDOMString ) ) ) ) { UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, "BAD OR MISSING EVENT URL" ); UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, "EVENT URL SET TO NULL IN SERVICE INFO" ); current->eventURL = NULL; fail = 0; } ixmlFreeDOMString( tempDOMString ); tempDOMString = NULL; if( fail ) { freeServiceList( current ); if( previous ) previous->next = NULL; else head = NULL; current = previous; } } ixmlNodeList_free( serviceNodeList ); } ( *end ) = current; return head; } else return NULL; }
inline void CameraSet<T>::load( const std::string& filename ) { // load the document tinyxml2::XMLDocument doc; int loadStatus = doc.LoadFile( filename.c_str() ); if( tinyxml2::XML_SUCCESS != loadStatus ) throw std::runtime_error( "CameraSet::load: " + std::string( doc.GetErrorStr1() ) ); // get the root tinyxml2::XMLNode* root = doc.FirstChildElement( "CameraCalibration" ); if( root == 0 ) throw std::runtime_error( "CameraSet::load: root node not found." ); // get the cameras tinyxml2::XMLNode* cameras = root->FirstChildElement( "Cameras" ); if( cameras == 0 ) throw std::runtime_error( "CameraSet::load: no cameras." ); // run over all the cameras m_cameras.clear(); for( tinyxml2::XMLNode* camPtr=cameras->FirstChildElement( "Camera" ); camPtr != 0; camPtr = camPtr->NextSiblingElement( "Camera" ) ) { Camera<T> camera; // get camera parameters str2scalar( getElementValue( camPtr, "Id" ), camera.id ); str2eigen( getElementValue( camPtr, "ImageSize" ), camera.imageSize ); str2eigen( getElementValue( camPtr, "Intrinsic" ), camera.intrinsic ); str2vector( getElementValue( camPtr, "Distortion" ), camera.distortion ); // read the poses tinyxml2::XMLNode* poses = camPtr->FirstChildElement( "Poses" ); if( poses != 0 ) { for( tinyxml2::XMLNode* posePtr=poses->FirstChildElement( "Pose" ); posePtr != 0; posePtr = posePtr->NextSiblingElement( "Pose" ) ) { Pose<T> pose; // get the pose attributes str2scalar( getElementValue( posePtr, "Id" ), pose.id ); pose.name = getElementValue( posePtr, "Name" ); str2eigenVector( getElementValue( posePtr, "Points2D" ), pose.points2D ); str2eigenVector( getElementValue( posePtr, "Points3D" ), pose.points3D ); str2vector( getElementValue( posePtr, "PointIndices" ), pose.pointIndices ); str2eigen( getElementValue( posePtr, "Transformation" ), pose.transformation ); str2eigenVector( getElementValue( posePtr, "ProjectedPoints" ), pose.projected2D ); pose.rejected = pose.pointIndices.size() == 0; if( !pose.rejected && ( pose.points2D.size() != pose.pointIndices.size() || pose.points2D.size() != pose.points3D.size() ) ) { pose.rejected = false; std::cerr << "CameraSet::load: point arrays' sizes do not match:"; std::cerr << " Points3D=" << pose.points2D.size(); std::cerr << ", Points3D=" << pose.points3D.size(); std::cerr << ", PointIndices=" << pose.pointIndices.size() << "." << std::endl; } camera.poses.push_back( pose ); } } m_cameras[ camera.id ] = camera; } }