DirectionType::DirectionType() :myChoice( Choice::rehearsal ) ,myRehearsalSet() ,mySegnoSet() ,myWordsSet() ,myCodaSet() ,myWedge( makeWedge() ) ,myDynamicsSet() ,myDashes( makeDashes() ) ,myBracket( makeBracket() ) ,myPedal( makePedal() ) ,myMetronome( makeMetronome() ) ,myOctaveShift( makeOctaveShift() ) ,myHarpPedals( makeHarpPedals() ) ,myDamp( makeDamp() ) ,myDampAll( makeDampAll() ) ,myEyeglasses( makeEyeglasses() ) ,myStringMute( makeStringMute() ) ,myScordatura( makeScordatura() ) ,myImage( makeImage() ) ,myPrincipalVoice( makePrincipalVoice() ) ,myAccordionRegistration( makeAccordionRegistration() ) ,myPercussionSet() ,myOtherDirection( makeOtherDirection() ) { myRehearsalSet.push_back( makeRehearsal() ); mySegnoSet.push_back( makeSegno() ); myWordsSet.push_back( makeWords() ); myCodaSet.push_back( makeCoda() ); myDynamicsSet.push_back( makeDynamics() ); myPercussionSet.push_back( makePercussion() ); }
void DirectionType::clearWordsSet() { myWordsSet.clear(); while( myWordsSet.size() < 1 ) { myWordsSet.push_back( makeWords() ); } }
void HelloWorld::addRight(Ref * p,Widget::TouchEventType type) { auto layoutParameter = LinearLayoutParameter::create(); layoutParameter->setGravity(LinearLayoutParameter::LinearGravity::RIGHT); ScrollView * scrollView = (ScrollView *)rootNode->getChildByName("ScrollView_1"); Widget * widget = makeWords(); widget->setLayoutParameter(layoutParameter); scrollView->addChild(widget); log("...%zd",scrollView->getChildren().size()); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } rootNode = CSLoader::createNode("MainScene.csb"); addChild(rootNode); Button * bt1 = dynamic_cast<Button *>(rootNode->getChildByName("Button_1")); bt1->addTouchEventListener([&](Ref * pSender,Widget::TouchEventType type){ auto layoutParameter = LinearLayoutParameter::create(); layoutParameter->setGravity(LinearLayoutParameter::LinearGravity::LEFT); ScrollView * scrollView = (ScrollView *)rootNode->getChildByName("ScrollView_1"); Widget * widget = makeWords(); widget->setLayoutParameter(layoutParameter); scrollView->addChild(widget); // scrollView->cocos2d::ui::LayoutProtocol::doLayout(); log("...%zd",scrollView->getChildren().size()); }); Button * bt2 = dynamic_cast<Button *>(rootNode->getChildByName("Button_2")); bt2->addTouchEventListener(CC_CALLBACK_2(HelloWorld::addRight, this)); return true; }
void Diff::DiffStrings( const wchar_t* destStr, const wchar_t* sourceStr, DiffResults& destDiffs, DiffResults& sourceDiffs) { int i,j; std::set<str_elem> elements; std::vector<str_elem> destArray, sourceArray; makeWords(destStr, destArray, elements); makeWords(sourceStr, sourceArray, elements); // Array 'V' described in the diff algorithm struct diff_hash* hashArray = (struct diff_hash*) alloca(sizeof (struct diff_hash) * (destArray.size()+1)); // Hash all the destination elements for (j=1; j<=(int)destArray.size(); j++) { hashArray[j].serial = j; hashArray[j].hash = hash(destArray[j-1]); } // Sort the array qsort(hashArray+1, destArray.size(), sizeof(struct diff_hash), hashCompare); // Array 'E' described in the diff algorithm struct diff_equivalence* equiv = (struct diff_equivalence*) alloca(sizeof (struct diff_equivalence) * (destArray.size()+1)); equiv[0].serial = 0; equiv[0].last = true; // Work out the equivalence classes for (j=1; j<(int)destArray.size(); j++) { equiv[j].serial = hashArray[j].serial; equiv[j].last = hashArray[j].hash != hashArray[j+1].hash; } equiv[j].serial = hashArray[j].serial; equiv[j].last = true; // Array 'P' described in the diff algorithm. This points to the beginning // of the class of lines in the destination equivalent to lines in the source int* srcEquiv = (int*)alloca(sizeof (int) * (sourceArray.size()+1)); for (i=1; i<=(int)sourceArray.size(); i++) { struct diff_hash searchHash; searchHash.serial = i; searchHash.hash = hash(sourceArray[i-1]); // Search for an item with the same hash struct diff_hash* diffItem = (struct diff_hash*)bsearch(&searchHash, hashArray+1, destArray.size(), sizeof(struct diff_hash), hashCompare2); if (diffItem == NULL) { srcEquiv[i] = 0; } else { j = (int)(diffItem - hashArray); while (!equiv[j-1].last) j--; srcEquiv[i] = j; } } // Array 'K' described in the diff algorithm int candidateSize = (int) (sourceArray.size()<destArray.size()?sourceArray.size():destArray.size()); struct diff_candidate* candidates = (struct diff_candidate*) alloca(sizeof (struct diff_candidate) * (candidateSize+2)); candidates[0].srcItem = 0; candidates[0].destItem = 0; candidates[0].previous = NULL; candidates[1].srcItem = (int)sourceArray.size() + 2; candidates[1].destItem = (int)destArray.size() + 2; candidates[1].previous = NULL; int lastCandidate = 0; // Find the longest common subsequences for (i=1; i<=(int)sourceArray.size(); i++) { if (srcEquiv[i] != 0) { int p = srcEquiv[i]; // 'Merge step': algorithm A.3 from the diff paper int candidateNum = 0; struct diff_candidate candidate = candidates[0]; while (1) { int serial = equiv[p].serial; int s; for (s=candidateNum; s<=lastCandidate; s++) { if (candidates[s].destItem < serial && candidates[s+1].destItem > serial) break; } if (s <= lastCandidate) { // (Step 4) if (candidates[s+1].destItem > serial) { candidates[candidateNum] = candidate; candidateNum = s+1; candidate.srcItem = i; candidate.destItem = serial; candidate.previous = candidates + s; } // (Step 5) if (s == lastCandidate) { candidates[lastCandidate+2] = candidates[lastCandidate+1]; lastCandidate++; break; } } if (equiv[p].last) break; p++; } candidates[candidateNum] = candidate; } } // Array of Longest Common Subsequences int* subsequence = (int*)alloca(sizeof (int) * (sourceArray.size()+1)); for (i=0; i<=(int)sourceArray.size(); i++) subsequence[i] = 0; struct diff_candidate* candidate = candidates + lastCandidate; while (candidate) { subsequence[candidate->srcItem] = candidate->destItem; candidate = candidate->previous; } int* subsequence2 = (int*)alloca(sizeof (int) * (destArray.size()+1)); for (i=1; i<=(int)destArray.size(); i++) subsequence2[i] = 0; // Finally: produce a result for (i=1; i<=(int)sourceArray.size(); i++) { if (subsequence[i] == 0) { DiffResult result; result.start = (int)(sourceArray[i-1].str - sourceStr); result.length = sourceArray[i-1].len; sourceDiffs.push_back(result); } else { subsequence2[subsequence[i]] = i; } } for (i=1; i<=(int)destArray.size(); i++) { if (subsequence2[i] == 0) { DiffResult result; result.start = (int)(destArray[i-1].str - destStr); result.length = destArray[i-1].len; destDiffs.push_back(result); } } }
DirectionTypePtr Direction::createDirectionType( std::ostream& message, xml::XElementIterator& subIter, xml::XElementIterator& subIterEnd, bool& isSuccess ) { auto directionType = makeDirectionType(); if( subIter == subIterEnd ) { message << "Direction: well thats weird - should not get here" << std::endl; isSuccess = false; return directionType; } if( subIter->getName() == "wedge" ) { directionType->setChoice( DirectionType::Choice::wedge ); isSuccess &= directionType->getWedge()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "dashes" ) { directionType->setChoice( DirectionType::Choice::dashes ); isSuccess &= directionType->getDashes()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "bracket" ) { directionType->setChoice( DirectionType::Choice::bracket ); isSuccess &= directionType->getBracket()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "pedal" ) { directionType->setChoice( DirectionType::Choice::pedal ); isSuccess &= directionType->getPedal()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "metronome" ) { directionType->setChoice( DirectionType::Choice::metronome ); isSuccess &= directionType->getMetronome()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "octave-shift" ) { directionType->setChoice( DirectionType::Choice::octaveShift ); isSuccess &= directionType->getOctaveShift()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "harp-pedals" ) { directionType->setChoice( DirectionType::Choice::harpPedals ); isSuccess &= directionType->getHarpPedals()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "damp" ) { directionType->setChoice( DirectionType::Choice::damp ); isSuccess &= directionType->getDamp()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "damp-all" ) { directionType->setChoice( DirectionType::Choice::dampAll ); isSuccess &= directionType->getDampAll()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "eyeglasses" ) { directionType->setChoice( DirectionType::Choice::eyeglasses ); isSuccess &= directionType->getEyeglasses()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "string-mute" ) { directionType->setChoice( DirectionType::Choice::stringMute ); isSuccess &= directionType->getStringMute()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "scordatura" ) { directionType->setChoice( DirectionType::Choice::scordatura ); isSuccess &= directionType->getScordatura()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "image" ) { directionType->setChoice( DirectionType::Choice::image ); isSuccess &= directionType->getImage()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "principal-voice" ) { directionType->setChoice( DirectionType::Choice::principalVoice ); isSuccess &= directionType->getPrincipalVoice()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "accordion-registration" ) { directionType->setChoice( DirectionType::Choice::accordionRegistration ); isSuccess &= directionType->getAccordionRegistration()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "other-direction" ) { directionType->setChoice( DirectionType::Choice::otherDirection ); isSuccess &= directionType->getOtherDirection()->fromXElement( message, *subIter ); return directionType; } std::string name = "rehearsal"; if( subIter->getName() == name ) { directionType->setChoice( DirectionType::Choice::rehearsal ); bool isFirstSubItemAdded = false; while( subIter != subIterEnd ) { if( subIter->getName() != name ) { message << "Direction: createDirectionType encountered an unexpected element '" << subIter->getName() << "' while parsing a collection of '" << name << "' elements" << std::endl; isSuccess = false; return directionType; } auto itemToAdd = makeRehearsal(); isSuccess &= itemToAdd->fromXElement( message, *subIter ); if( !isFirstSubItemAdded && directionType->getRehearsalSet().size() == 1 ) { directionType->addRehearsal( itemToAdd ); directionType->removeRehearsal( directionType->getRehearsalSet().cbegin() ); } else { directionType->addRehearsal( itemToAdd ); } isFirstSubItemAdded = true; ++subIter; } // end loop return directionType; } // end rehearsal name = "segno"; if( subIter->getName() == name ) { directionType->setChoice( DirectionType::Choice::segno ); bool isFirstSubItemAdded = false; while( subIter != subIterEnd ) { if( subIter->getName() != name ) { message << "Direction: createDirectionType encountered an unexpected element '" << subIter->getName() << "' while parsing a collection of '" << name << "' elements" << std::endl; isSuccess = false; return directionType; } auto itemToAdd = makeSegno(); isSuccess &= itemToAdd->fromXElement( message, *subIter ); if( !isFirstSubItemAdded && directionType->getSegnoSet().size() == 1 ) { directionType->addSegno( itemToAdd ); directionType->removeSegno( directionType->getSegnoSet().cbegin() ); } else { directionType->addSegno( itemToAdd ); } isFirstSubItemAdded = true; ++subIter; } // end loop return directionType; } // end segno name = "words"; if( subIter->getName() == name ) { directionType->setChoice( DirectionType::Choice::words ); bool isFirstSubItemAdded = false; while( subIter != subIterEnd ) { if( subIter->getName() != name ) { message << "Direction: createDirectionType encountered an unexpected element '" << subIter->getName() << "' while parsing a collection of '" << name << "' elements" << std::endl; isSuccess = false; return directionType; } auto itemToAdd = makeWords(); isSuccess &= itemToAdd->fromXElement( message, *subIter ); if( !isFirstSubItemAdded && directionType->getWordsSet().size() == 1 ) { directionType->addWords( itemToAdd ); directionType->removeWords( directionType->getWordsSet().cbegin() ); } else { directionType->addWords( itemToAdd ); } isFirstSubItemAdded = true; ++subIter; } // end loop return directionType; } // end words name = "coda"; if( subIter->getName() == name ) { directionType->setChoice( DirectionType::Choice::coda ); bool isFirstSubItemAdded = false; while( subIter != subIterEnd ) { if( subIter->getName() != name ) { message << "Direction: createDirectionType encountered an unexpected element '" << subIter->getName() << "' while parsing a collection of '" << name << "' elements" << std::endl; isSuccess = false; return directionType; } auto itemToAdd = makeCoda(); isSuccess &= itemToAdd->fromXElement( message, *subIter ); if( !isFirstSubItemAdded && directionType->getCodaSet().size() == 1 ) { directionType->addCoda( itemToAdd ); directionType->removeCoda( directionType->getCodaSet().cbegin() ); } else { directionType->addCoda( itemToAdd ); } isFirstSubItemAdded = true; ++subIter; } // end loop return directionType; } // end coda name = "dynamics"; if( subIter->getName() == name ) { directionType->setChoice( DirectionType::Choice::dynamics ); bool isFirstSubItemAdded = false; while( subIter != subIterEnd ) { if( subIter->getName() != name ) { message << "Direction: createDirectionType encountered an unexpected element '" << subIter->getName() << "' while parsing a collection of '" << name << "' elements" << std::endl; isSuccess = false; return directionType; } auto itemToAdd = makeDynamics(); isSuccess &= itemToAdd->fromXElement( message, *subIter ); if( !isFirstSubItemAdded && directionType->getDynamicsSet().size() == 1 ) { directionType->addDynamics( itemToAdd ); directionType->removeDynamics( directionType->getDynamicsSet().cbegin() ); } else { directionType->addDynamics( itemToAdd ); } isFirstSubItemAdded = true; ++subIter; } // end loop return directionType; } // end dynamics name = "percussion"; if( subIter->getName() == name ) { directionType->setChoice( DirectionType::Choice::percussion ); bool isFirstSubItemAdded = false; while( subIter != subIterEnd ) { if( subIter->getName() != name ) { message << "Direction: createDirectionType encountered an unexpected element '" << subIter->getName() << "' while parsing a collection of '" << name << "' elements" << std::endl; isSuccess = false; return directionType; } auto itemToAdd = makePercussion(); isSuccess &= itemToAdd->fromXElement( message, *subIter ); if( !isFirstSubItemAdded && directionType->getPercussionSet().size() == 1 ) { directionType->addPercussion( itemToAdd ); directionType->removePercussion( directionType->getPercussionSet().cbegin() ); } else { directionType->addPercussion( itemToAdd ); } isFirstSubItemAdded = true; ++subIter; } // end loop return directionType; } // end percussion return directionType; }