本文整理汇总了C++中Pattern类的典型用法代码示例。如果您正苦于以下问题:C++ Pattern类的具体用法?C++ Pattern怎么用?C++ Pattern使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pattern类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: computeFunction
double RateMeyerHaeseler::computeFunction(double value) {
if (!rate_mh) {
if (value != cur_scale) {
ptn_tree->scaleLength(value/cur_scale);
cur_scale = value;
ptn_tree->clearAllPartialLH();
}
return -ptn_tree->computeLikelihood();
}
int nseq = phylo_tree->leafNum;
int nstate = phylo_tree->getModel()->num_states;
int i, j, state1, state2;
double lh = 0.0;
ModelSubst *model = phylo_tree->getModel();
Pattern *pat = & phylo_tree->aln->at(optimizing_pattern);
for (i = 0; i < nseq-1; i++) if ((state1 = pat->at(i)) < nstate)
for (j = i+1; j < nseq; j++) if ((state2 = pat->at(j)) < nstate)
lh -= log(model->computeTrans(value * dist_mat[i*nseq + j], state1, state2));
return lh;
}
示例2: run
void CreateWithPatternCommand::run(World* world)
{
if(world != NULL){
Factories<Pattern>& pattern_factories = Factories<Pattern>::getInstance();
Factories<Command>& command_factories = Factories<Command>::getInstance();
Factory<Command>* command_factory;
Factory<Pattern>* pattern_factory = pattern_factories[concrete_type];
Pattern* pattern;
Command* command;
FactoryParams::iterator it = params.begin();
pattern_factory = pattern_factories[concrete_type];
//use first string for pattern params
FactoryParams pattern_params;
pattern_params.push_back(*it++);
pattern = pattern_factory->create(pattern_params);
//use second string for command params
command_factory = command_factories[*it++];
//remaining params go to the object to be created
FactoryParams template_params;
template_params.insert(template_params.begin(),it,params.end());
//create objects, tacking on pattern params
while(!pattern->isEmpty()){
FactoryParams command_params = template_params;
FactoryParams pattern_data = pattern->getNext();
for(size_t i=0; i<pattern_data.size(); ++i){
command_params.push_back(pattern_data[i]);
}
command = command_factory->create(command_params);
command->run(world);
delete command;
}
}
}
示例3: checkGradient
bool NeuralNet::checkGradient (NNTYPE& E, NNTYPE& E_delta, NNTYPE& E_delta_gradient, const Pattern& pattern, NNTYPE delta, NNTYPE limit)
{
// m_net.clear (e_dE);
calculateSample (pattern.beginInput (), pattern.endInput ());
// compute the error
E = m_net.errorFunction (pattern.beginOutput (), pattern.endOutput (), pattern.weight ());
int numWeights = std::distance (m_net.begin (), m_net.end ());
m_net.compute_dE ();
m_net.update_dE (false);
int changeWeightPosition = randomInt (numWeights);
auto it = m_net.begin ();
std::advance (it, changeWeightPosition);
Synapsis& syn = *it;
NNTYPE dE = syn.dE;
NNTYPE myDelta = -E/dE;
syn.weight += myDelta;
calculateSample (pattern.beginInput (), pattern.endInput ());
E_delta = m_net.errorFunction (pattern.beginOutput (), pattern.endOutput (), pattern.weight ());
E_delta_gradient = E + myDelta*dE;
NNTYPE relDiff = fabs (E_delta-E_delta_gradient)/E;
syn.weight -= myDelta;
return relDiff <= limit;
}
示例4: readPapers
void readPapers(int papers, Scanner scanIn) {
int paper;
for (paper = 1; paper <= papers; paper++) {
String paperAuthors;
paperAuthors = scanIn.nextLine();
#ifdef DEBUG
printf("paper #%d %s\n", paper, paperAuthors);
#endif
Author authors[] = new Author[Author.MAX_PAPER_AUTHORS];
int authorsIndex = 0;
Pattern p = Pattern.compile("\\s*(\\S*)[,]\\s*(\\S*)[,:]");
Matcher m = p.matcher(paperAuthors);
while (m.find()) {
String lname = m.group(1);
String fname = m.group(2);
if (debug) {
printf("\t'%s' => '%s', '%s'\n", paperAuthors, lname, fname);
}
authors[authorsIndex] = Author.find(fname, lname);
if (authors[authorsIndex] == null) {
if (lname.length() == 0 || fname.length() == 0) {
continue;
}
authors[authorsIndex] = new Author(fname, lname);
}
authorsIndex++;
}
for (int i = 0; i < authorsIndex; i++) {
for (int j = 0; j < authorsIndex; j++) {
authors[i].publicouCom(authors[j]);
}
}
}
}
示例5: QSettings
void Window::showDetails() {
Pattern* pattern = m_board->pattern();
if (!pattern) {
return;
}
QString patternid = QSettings().value("Current/Pattern", 0).toString();
static const QStringList sizes = QStringList() << NewGameDialog::tr("Low")
<< NewGameDialog::tr("Medium")
<< NewGameDialog::tr("High")
<< NewGameDialog::tr("Very High");
QString number = "4"
+ m_board->words()->language()
+ patternid
+ QString::number(pattern->wordCount())
+ QString("%1").arg(int(pattern->wordLength() - 4), 2, 16, QLatin1Char('0'))
+ QString::number(pattern->seed(), 16);
QMessageBox dialog(QMessageBox::Information,
tr("Details"),
QString("<p><b>%1</b> %2<br><b>%3</b> %4<br><b>%5</b> %6<br><b>%7</b> %8<br><b>%9</b> %10</p>")
.arg(tr("Pattern:")).arg(pattern->name())
.arg(NewGameDialog::tr("Language:")).arg(LocaleDialog::languageName(m_board->words()->language()))
.arg(NewGameDialog::tr("Amount of Words:")).arg(sizes.value(pattern->wordCount()))
.arg(NewGameDialog::tr("Word Length:")).arg(NewGameDialog::tr("%n letter(s)", "", pattern->wordLength() + 1))
.arg(tr("Game Number:")).arg(number),
QMessageBox::NoButton,
this);
dialog.setIconPixmap(QIcon(QString(":/patterns/%1.png").arg(patternid)).pixmap(96,96));
dialog.exec();
}
示例6: BadKeyException
bool
PatternCutoff::operator()(const Pattern &p) const {
if (p.attributes.find(key) == p.attributes.end())
throw BadKeyException(key, p.get_accession());
string val = p.attributes.find(key)->second;
if (reverse && numeric)
return atof(val.c_str()) > atof(value.c_str());
else if (reverse)
return val > value;
else if (numeric)
return atof(val.c_str()) < atof(value.c_str());
else return val < value;
}
示例7: childrenMatching
PathList Path::childrenMatching(const Pattern& pattern) const
{
PathList children;
#if WENDY_SYSTEM_WIN32
WIN32_FIND_DATA data;
HANDLE search;
search = FindFirstFile(m_string.c_str(), &data);
if (search == INVALID_HANDLE_VALUE)
return PathList();
do
{
if (pattern.matches(data.cFileName))
children.push_back(operator + (data.cFileName));
}
while (FindNextFile(search, &data));
FindClose(search);
#else
DIR* stream;
dirent* entry;
stream = opendir(m_string.c_str());
if (!stream)
return PathList();
while ((entry = readdir(stream)))
{
if (pattern.matches(entry->d_name))
children.push_back(operator + (entry->d_name));
}
closedir(stream);
#endif
return children;
}
示例8: new
std::pair<VarDecl *, PatternBindingDecl *>
DerivedConformance::declareDerivedProperty(TypeChecker &tc, Decl *parentDecl,
NominalTypeDecl *typeDecl,
Identifier name,
Type propertyInterfaceType,
Type propertyContextType,
bool isStatic,
bool isFinal) {
auto &C = tc.Context;
auto parentDC = cast<DeclContext>(parentDecl);
VarDecl *propDecl = new (C) VarDecl(/*IsStatic*/isStatic, VarDecl::Specifier::Var,
/*IsCaptureList*/false, SourceLoc(), name,
propertyContextType, parentDC);
propDecl->setImplicit();
propDecl->copyFormalAccessAndVersionedAttrFrom(typeDecl);
propDecl->setInterfaceType(propertyInterfaceType);
// If this is supposed to be a final property, mark it as such.
assert(isFinal || !parentDC->getAsClassOrClassExtensionContext());
if (isFinal && parentDC->getAsClassOrClassExtensionContext() &&
!propDecl->isFinal())
propDecl->getAttrs().add(new (C) FinalAttr(/*IsImplicit=*/true));
Pattern *propPat = new (C) NamedPattern(propDecl, /*implicit*/ true);
propPat->setType(propertyContextType);
propPat = new (C) TypedPattern(propPat,
TypeLoc::withoutLoc(propertyContextType),
/*implicit*/ true);
auto pbDecl = PatternBindingDecl::create(C, SourceLoc(),
StaticSpellingKind::None,
SourceLoc(), propPat, nullptr,
parentDC);
pbDecl->setImplicit();
return {propDecl, pbDecl};
}
示例9:
void
LTBDots::printStrip(char *title, bool dotsOnly)
{
Serial.print("\n<<STRIP - "); Serial.print(title); Serial.println(" - STRIP >> ");
if (dotsOnly)
Serial.println("*** DOTS ONLY ***");
else
{
Serial.print("this = 0x"); Serial.println((uint16_t)this, 16);
Serial.print("MaxPix = "); Serial.println(nPix);
Serial.print("dots = 0x"); Serial.println((uint16_t)dots);
Serial.print("lastMS = "); Serial.println(lastMsec);
}
Serial.println("Pix\tTag\tBlu\tGrn\tRed");
for (int i = 0; i < nPix; i++)
{
Serial.print(""); Serial.print(i);
Serial.print("\t0x"); Serial.print( dots[i * 4 +0], HEX);
Serial.print("\t0x"); Serial.print( dots[i * 4 +1], HEX);
Serial.print("\t0x"); Serial.print( dots[i * 4 +2], HEX);
Serial.print("\t0x"); Serial.println(dots[i * 4 +3], HEX);
}
if (pats == NULL)
Serial.println("No Patterns");
else
{
Pattern *ptr = pats;
while (true)
{
ptr->printPat(title);
if (ptr->isLast())
break;
ptr = ptr->Nxt();
}
}
}
示例10: assert
/// InstantiateNonterminal - This method takes the nonterminal specified by
/// NT, which should not be completely resolved, clones it, applies ResultTy
/// to its root, then runs the type inference stuff on it. This should
/// produce a newly resolved nonterminal, which we make a record for and
/// return. To be extra fancy and efficient, this only makes one clone for
/// each type it is instantiated with.
Record *InstrSelectorEmitter::InstantiateNonterminal(Pattern *NT,
MVT::ValueType ResultTy) {
assert(!NT->isResolved() && "Nonterminal is already resolved!");
// Check to see if we have already instantiated this pair...
Record* &Slot = InstantiatedNTs[std::make_pair(NT, ResultTy)];
if (Slot) return Slot;
Record *New = new Record(NT->getRecord()->getName()+"_"+getName(ResultTy));
// Copy over the superclasses...
const std::vector<Record*> &SCs = NT->getRecord()->getSuperClasses();
for (unsigned i = 0, e = SCs.size(); i != e; ++i)
New->addSuperClass(SCs[i]);
DEBUG(std::cerr << " Nonterminal '" << NT->getRecord()->getName()
<< "' for type '" << getName(ResultTy) << "', producing '"
<< New->getName() << "'\n");
// Copy the pattern...
Pattern *NewPat = NT->clone(New);
// Apply the type to the root...
NewPat->getTree()->updateNodeType(ResultTy, New->getName());
// Infer types...
NewPat->InferAllTypes();
// Make sure everything is good to go now...
if (!NewPat->isResolved())
NewPat->error("Instantiating nonterminal did not resolve all types!");
// Add the pattern to the patterns map, add the record to the RecordKeeper,
// return the new record.
Patterns[New] = NewPat;
Records.addDef(New);
return Slot = New;
}
示例11: track_proxy_data
void track_proxy_data(t_track_proxy *x, t_symbol *s, int argc, t_atom *argv)
{
if(argc == 1 && IS_A_SYMBOL(argv,0) && argv[0].a_w.w_symbol == gensym("end"))
{
pd_unbind(&x->x_obj.ob_pd, gensym(TRACK_SELECTOR));
return;
}
if(argc < 3 || !IS_A_SYMBOL(argv,0) || !IS_A_FLOAT(argv,1) || !IS_A_FLOAT(argv,2))
{
pd_error(x, "unrecognized format for in-patch data");
return;
}
t_symbol *pat = argv[0].a_w.w_symbol;
t_int rows = (t_int) argv[1].a_w.w_float;
t_int cols = (t_int) argv[2].a_w.w_float;
if(argc != (3 + rows * cols))
{
pd_error(x, "unrecognized format for in-patch data (malformed data?)");
return;
}
Track *t = x->track;
t->addPattern(rows, cols, pat->s_name);
Pattern *p = t->getPattern(pat->s_name);
if(!p)
{
pd_error(x, "fatal error: cannot create patern");
return;
}
int a = 3;
for(int r = 0; r < rows; r++)
{
for(int c = 0; c < cols; c++)
{
p->setCell(r, c, argv[a]);
a++;
}
}
}
示例12:
// worker methods
bool Pattern::operator==(const Pattern & obj) const {
bool match = true;
if (&obj == 0) {
std::cout << "Pattern::operator ==: obj is null" << std::endl;
return false;
}
match = match && (this->getPattern() == obj.getPattern());
if (match == false) {
std::cout << "Pattern::equals: vector mismatch" << std::endl;
return false;
}
return true;
}
示例13: testInlineAutomation
void testInlineAutomation()
{
auto song = Engine::getSong();
InstrumentTrack* instrumentTrack =
dynamic_cast<InstrumentTrack*>(Track::create(Track::InstrumentTrack, song));
Pattern* notePattern = dynamic_cast<Pattern*>(instrumentTrack->createTCO(0));
notePattern->changeLength(MidiTime(4, 0));
Note* note = notePattern->addNote(Note(MidiTime(4, 0)), false);
note->createDetuning();
DetuningHelper* dh = note->detuning();
auto pattern = dh->automationPattern();
pattern->setProgressionType( AutomationPattern::LinearProgression );
pattern->putValue(MidiTime(0, 0), 0.0);
pattern->putValue(MidiTime(4, 0), 1.0);
QCOMPARE(pattern->valueAt(MidiTime(0, 0)), 0.0f);
QCOMPARE(pattern->valueAt(MidiTime(1, 0)), 0.25f);
QCOMPARE(pattern->valueAt(MidiTime(2, 0)), 0.5f);
QCOMPARE(pattern->valueAt(MidiTime(4, 0)), 1.0f);
}
示例14: while
double Pattern::compare(const Pattern & obj) const {
const std::vector<bool> this_pat = this->getPattern();
const std::vector<bool> obj_pat = obj.getPattern();
int this_sz = this_pat.size();
int obj_sz = obj_pat.size();
#ifdef PATTERN_DEBUG // DEBUG
std::cout << "Pattern::compare: this: ";
common::Misc::print(std::cout, this_pat);
std::cout << std::endl;
std::cout << "Pattern::compare: obj: ";
common::Misc::print(std::cout, obj_pat);
std::cout << std::endl;
#endif // DEBUG
if (this_sz == 0) {
std::cout << "Pattern::compare: this zero pattern mismatch" << std::endl;
return 0;
} else {
if (obj_sz == 0) {
std::cout << "Pattern::compare: obj zero pattern mismatch" << std::endl;
return 0;
}
}
if (this_sz != obj_sz) {
std::cout << "Pattern::compare: size mismatch " << std::endl;
return 0;
}
double fraction = static_cast<double>(1) / static_cast<double>(this_sz);
double match = 0;
std::vector<bool>::const_iterator it_this_vec = this_pat.begin();
const std::vector<bool>::const_iterator it_this_vec_end = this_pat.end();
std::vector<bool>::const_iterator it_obj_vec = obj_pat.begin();
const std::vector<bool>::const_iterator it_obj_vec_end = obj_pat.end();
while (it_this_vec != it_this_vec_end && it_obj_vec != it_obj_vec_end) {
if (*it_this_vec == *it_obj_vec) {
match += fraction;
}
++it_this_vec;
++it_obj_vec;
}
#ifdef PATTERN_DEBUG // DEBUG
std::cout << "Pattern::compare: match: " << match << std::endl;
#endif // DEBUG
return match;
}
示例15: CheckNot
bool CheckString::CheckNot(const SourceMgr &SM, StringRef Buffer,
const std::vector<const Pattern *> &NotStrings,
StringMap<StringRef> &VariableTable) const {
for (unsigned ChunkNo = 0, e = NotStrings.size();
ChunkNo != e; ++ChunkNo) {
const Pattern *Pat = NotStrings[ChunkNo];
assert((Pat->getCheckTy() == Check::CheckNot) && "Expect CHECK-NOT!");
size_t MatchLen = 0;
size_t Pos = Pat->Match(Buffer, MatchLen, VariableTable);
if (Pos == StringRef::npos) continue;
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()+Pos),
SourceMgr::DK_Error,
Prefix + "-NOT: string occurred!");
SM.PrintMessage(Pat->getLoc(), SourceMgr::DK_Note,
Prefix + "-NOT: pattern specified here");
return true;
}
return false;
}