nsresult txXSLTNumber::createNumber(Expr* aValueExpr, txPattern* aCountPattern, txPattern* aFromPattern, LevelType aLevel, Expr* aGroupSize, Expr* aGroupSeparator, Expr* aFormat, txIEvalContext* aContext, nsAString& aResult) { aResult.Truncate(); nsresult rv = NS_OK; // Parse format txList counters; nsAutoString head, tail; rv = getCounters(aGroupSize, aGroupSeparator, aFormat, aContext, counters, head, tail); NS_ENSURE_SUCCESS(rv, rv); // Create list of values to format txList values; nsAutoString valueString; rv = getValueList(aValueExpr, aCountPattern, aFromPattern, aLevel, aContext, values, valueString); NS_ENSURE_SUCCESS(rv, rv); if (!valueString.IsEmpty()) { aResult = valueString; return NS_OK; } // Create resulting string aResult = head; bool first = true; txListIterator valueIter(&values); txListIterator counterIter(&counters); valueIter.resetToEnd(); int32_t value; txFormattedCounter* counter = 0; while ((value = NS_PTR_TO_INT32(valueIter.previous()))) { if (counterIter.hasNext()) { counter = (txFormattedCounter*)counterIter.next(); } if (!first) { aResult.Append(counter->mSeparator); } counter->appendNumber(value, aResult); first = false; } aResult.Append(tail); txListIterator iter(&counters); while (iter.hasNext()) { delete (txFormattedCounter*)iter.next(); } return NS_OK; }
/* * Attempts to read parameters from a XML file. * * @param element TiXmlElement to examine. * @return true if successful, false otherwise. */ bool FixedLayout::readParameters(const TiXmlElement& element) { cerr << "Attempting to parse a layout param" << endl; if (Layout::readParameters(element)) { // this parameter was already handled return true; } if (element.ValueStr().compare("LayoutFiles") == 0) { nParams++; return true; } /* * Following statements exist because although the logic for reading the parameters * contained in these elements is later in this function, the traversal of nodes * causes this function to be called to handle the each of the elements individually. */ /*needed? if (element.ValueStr().compare("A") == 0){ if(element.Parent()->ValueStr().compare("FixedLayoutParams") == 0){ return true; } } if (element.ValueStr().compare("I") == 0){ if(element.Parent()->ValueStr().compare("FixedLayoutParams") == 0){ return true; } } */ /* // Parse fixed layout (overrides random layouts) if (element.ValueStr().compare("FixedLayoutParams") == 0) { const TiXmlNode* pNode = NULL; while ((pNode = element.IterateChildren(pNode)) != NULL) { string activeNListFileName; string inhNListFileName; string probedNListFileName; if (strcmp(pNode->Value(), "A") == 0) { getValueList(pNode->ToElement()->GetText(), &m_endogenously_active_neuron_list); num_endogenously_active_neurons = m_endogenously_active_neuron_list.size(); } else if (strcmp(pNode->Value(), "I") == 0) { getValueList(pNode->ToElement()->GetText(), &m_inhibitory_neuron_layout); } else if (strcmp(pNode->Value(), "LayoutFiles") == 0) { if (pNode->ToElement()->QueryValueAttribute( "inhNListFileName", &inhNListFileName ) == TIXML_SUCCESS) { TiXmlDocument simDoc( inhNListFileName.c_str( ) ); if (!simDoc.LoadFile( )) { cerr << "Failed loading positions of inhibitory neurons list file " << inhNListFileName << ":" << "\n\t" << simDoc.ErrorDesc( ) << endl; cerr << " error: " << simDoc.ErrorRow( ) << ", " << simDoc.ErrorCol( ) << endl; return false; } TiXmlNode* temp2 = NULL; if (( temp2 = simDoc.FirstChildElement( "I" ) ) == NULL) { cerr << "Could not find <I> in positons of inhibitory neurons list file " << inhNListFileName << endl; return false; } getValueList(temp2->ToElement()->GetText(), &m_inhibitory_neuron_layout); } if (pNode->ToElement()->QueryValueAttribute( "activeNListFileName", &activeNListFileName ) == TIXML_SUCCESS) { TiXmlDocument simDoc( activeNListFileName.c_str( ) ); if (!simDoc.LoadFile( )) { cerr << "Failed loading positions of endogenously active neurons list file " << activeNListFileName << ":" << "\n\t" << simDoc.ErrorDesc( ) << endl; cerr << " error: " << simDoc.ErrorRow( ) << ", " << simDoc.ErrorCol( ) << endl; return false; } TiXmlNode* temp2 = NULL; if (( temp2 = simDoc.FirstChildElement( "A" ) ) == NULL) { cerr << "Could not find <A> in positons of endogenously active neurons list file " << activeNListFileName << endl; return false; } getValueList(temp2->ToElement()->GetText(), &m_endogenously_active_neuron_list); num_endogenously_active_neurons = m_endogenously_active_neuron_list.size(); } if (pNode->ToElement()->QueryValueAttribute( "probedNListFileName", &probedNListFileName ) == TIXML_SUCCESS) { TiXmlDocument simDoc( probedNListFileName.c_str( ) ); if (!simDoc.LoadFile( )) { cerr << "Failed loading positions of probed neurons list file " << probedNListFileName << ":" << "\n\t" << simDoc.ErrorDesc( ) << endl; cerr << " error: " << simDoc.ErrorRow( ) << ", " << simDoc.ErrorCol( ) << endl; return false; } TiXmlNode* temp2 = NULL; if (( temp2 = simDoc.FirstChildElement( "P" ) ) == NULL) { cerr << "Could not find <P> in positions of probed neurons list file " << probedNListFileName << endl; return false; } getValueList(temp2->ToElement()->GetText(), &m_probed_neuron_list); } } } nParams++; */ // Parse fixed layout (changed to utilize the Visiter Pattern provided by Tinyxml if (element.Parent()->ValueStr().compare("LayoutFiles") == 0) { if(element.ValueStr().compare("activeNListFileName") == 0){ const char* activeNListFileName = element.GetText(); if(activeNListFileName == NULL){ return true; } TiXmlDocument simDoc(activeNListFileName); if (!simDoc.LoadFile( )) { cerr << "Failed loading positions of endogenously active neurons list file " << activeNListFileName << ":" << "\n\t" << simDoc.ErrorDesc( ) << endl; cerr << " error: " << simDoc.ErrorRow( ) << ", " << simDoc.ErrorCol( ) << endl; return false; } TiXmlNode* temp2 = NULL; if (( temp2 = simDoc.FirstChildElement( "A" ) ) == NULL) { cerr << "Could not find <A> in positons of endogenously active neurons list file " << activeNListFileName << endl; return false; } getValueList(temp2->ToElement()->GetText(), &m_endogenously_active_neuron_list); num_endogenously_active_neurons = m_endogenously_active_neuron_list.size(); return true; } if(element.ValueStr().compare("inhNListFileName") == 0){ const char* inhNListFileName = element.GetText(); if(inhNListFileName == NULL){ return true; } TiXmlDocument simDoc(inhNListFileName); if (!simDoc.LoadFile( )) { cerr << "Failed loading positions of inhibitory neurons list file " << inhNListFileName << ":" << "\n\t" << simDoc.ErrorDesc( ) << endl; cerr << " error: " << simDoc.ErrorRow( ) << ", " << simDoc.ErrorCol( ) << endl; return false; } TiXmlNode* temp2 = NULL; if (( temp2 = simDoc.FirstChildElement( "I" ) ) == NULL) { cerr << "Could not find <I> in positions of inhibitory neurons list file " << inhNListFileName << endl; return false; } getValueList(temp2->ToElement()->GetText(), &m_inhibitory_neuron_layout); return true; } if(element.ValueStr().compare("probedNListFileName") == 0){ const char* probedNListFileName = element.GetText(); if(probedNListFileName == NULL){ return true; } TiXmlDocument simDoc(probedNListFileName); if (!simDoc.LoadFile( )) { cerr << "Failed loading positions of probed neurons list file " << probedNListFileName << ":" << "\n\t" << simDoc.ErrorDesc( ) << endl; cerr << " error: " << simDoc.ErrorRow( ) << ", " << simDoc.ErrorCol( ) << endl; return false; } TiXmlNode* temp2 = NULL; if (( temp2 = simDoc.FirstChildElement( "P" ) ) == NULL) { cerr << "Could not find <P> in positions of probed neurons list file " << probedNListFileName << endl; return false; } getValueList(temp2->ToElement()->GetText(), &m_probed_neuron_list); return true; } } return false; }