forceinline ModEvent ConstSetView::exclude(Space&,int i,int j) { Iter::Ranges::Singleton single(i,j); ArrayRanges ar(ranges, size); return (single() && Iter::Ranges::subset(single, ar)) ? ME_SET_FAILED : ME_SET_NONE; }
/* play - the main loop */ void play(void) { /* establish the restart point */ setjmp(restart); /* execute the initialization code */ execute(h_init); /* turn handling loop */ for (;;) { /* execute the update code */ execute(h_update); /* parse the next input command */ if (parse()) { if (single()) while (next() && single()) ; } /* parse error, call the error handling code */ else execute(h_error); } }
void visit(ast::range_matcher& m) { std::string indent(++tabs, '\t'); //chain matcher ranges out << "( "; if ( m.rs.empty() ) { out << "true"; } else { auto it = m.rs.begin(); if ( it->single() ) { out << "parse::matches<\'" << strings::escape(it->to) << "\'>(ps)"; } else { out << "parse::in_range<\'" << strings::escape(it->from) << "\',\'" << strings::escape(it->to) << "\'>(ps)"; } while ( ++it != m.rs.end() ) { out << std::endl << indent << "|| " ; if ( it->single() ) { out << "parse::matches<\'" << strings::escape(it->to) << "\'>(ps)"; } else { out << "parse::in_range<\'" << strings::escape(it->from) << "\',\'" << strings::escape(it->to) << "\'>(ps)"; } } } out << " )"; --tabs; }
void check_antisymmetric(R r) { auto rvar = single(r); auto tvar = quantify_over<Domain<R>>(); quick_check(antisymmetric {}, rvar, tvar, tvar); }
void check_irreflexive(R r) { auto rvar = single(r); auto tvar = quantify_over<Domain<R>>(); quick_check(irreflexive {}, rvar, tvar); }
void check_equivalence(R r) { auto rvar = single(r); auto tvar = quantify_over<Domain<R>>(); quick_check(equivalence {}, rvar, tvar); }
void check_strict_total_ordering(R r) { auto rvar = single(r); auto tvar = quantify_over<Domain<R>>(); quick_check(strict_total_ordering {}, rvar, tvar); }
inline void setbit( int x, int y, int w) { int i,j; for( i = 0; i < w; i++ ) for( j = 0; j < w; j++ ) single(field[x+i],y+j); }
void check_trichotomous(R r) { auto rvar = single(r); auto tvar = quantify_over<Domain<R>>(); quick_check(trichotomous {}, rvar, tvar); }
void check_transitive(R r) { auto rvar = single(r); auto tvar = quantify_over<Domain<R>>(); quick_check(transitive {}, rvar, tvar, tvar, tvar); }
void AST_t::replace(AST_t ast) { if (ast._ast == NULL) { internal_error("Trying to replace a tree with an empty tree", 0); } if (this->_ast == NULL) { internal_error("Trying to replace an empty tree with another tree", 0); } if (ASTType(ast._ast) == AST_NODE_LIST) { // If the replacement is a list but the original is not, let's check two cases // maybe this list is a one-element list or not. if (ASTType(this->_ast) != AST_NODE_LIST) { // If it is a one element list if (ASTSon0(ast._ast) == NULL) { // then replace the whole thing with the list information AST_t repl_tree(ASTSon1(ast._ast)); replace_with(repl_tree); } // If this is not a one-element list then try to replace using // a typical replace_in_list but this may fail sometimes // because we'll look for the first enclosing list else { // Maybe we should yield a message here // std::cerr << "Warning: Replacing a non-list tree at '" // << this->get_locus() // << "' with a list tree of more than one element" << std::endl; replace_in_list(ast); } } // If both are lists is easy else { replace_in_list(ast); } } // If the thing being replaced is a list, but the replacement // is not, then convert the latter into a list else if (ASTType(_ast) == AST_NODE_LIST && ASTType(_ast) != AST_NODE_LIST) { // Create a single element list AST single(ASTListLeaf(ast._ast)); replace_in_list(single); } // Otherwise replace directly. Neither the replaced nor the replacement // are lists in this case. else { replace_with(ast); } }
node_t * add_file(list_t *list, char *path, int rev){ if (list->head == NULL){ list->head = list->tail = single(node_t); gstrcpy(&list->head->path, path); return list->head; } node_t *node = get_open_file(path); if (node) return node; node = single(node_t); list->tail->next = node; node->prev = list->tail; list->tail = node; gstrcpy(&node->path, path); node->rev = rev; return node; };
void check_reflexive(R r) { using D = Domain<R>; auto rvar = single(r); auto tvar = quantify_over<D>(); quick_check(reflexive {}, rvar, tvar); }
void LocalPotential::relax(ISO& iso, const Symmetry& symmetry, double* totalEnergy, OList<Vector3D >* totalForces, \ bool restart, bool reduce) const { initialize(iso, totalEnergy, totalForces); Relax relax; relax.structure(iso, *this, symmetry); if ((totalEnergy) || (totalForces)) single(iso, symmetry, totalEnergy, totalForces); }
void operator()(R&& rvar, T&& tvar) const { // Derive the symmetric complement of r and quantify over it. I // wouldn't need to do this if I had a symmetric_complement function. using U = Result_of<T()>; auto r = rvar(); auto sc = [r](const U& a, const U& b) { return !r(a, b) && !r(b, a); }; auto svar = single(sc); quick_check(ord, rvar, tvar); quick_check(eq, svar, tvar); }
void call(dynd::nd::array *dst, const dynd::nd::array *src) { const dynd::ndt::callable_type *fpt = m_proto.extended<dynd::ndt::callable_type>(); intptr_t nsrc = fpt->get_narg(); std::vector<char *> src_data(nsrc); for (int i = 0; i < nsrc; ++i) { src_data[i] = const_cast<char *>(src[i].cdata()); } single(const_cast<char *>(dst->cdata()), src_data.data()); }
// averages the results of benchmark over several runs // returns the avg, stdev is modified by reference void benchmark(int n, bool sorted, std::string type, int runs, double &avg, double &stdev) { double sum = 0.0, squares = 0.0; for (int i = 0; i < runs; ++i) { double result = single(n, sorted, type); sum += result; squares += result * result; } avg = sum / runs; double avgsquares = squares / (double)runs; stdev = sqrt(abs(avgsquares - (avg * avg))); }
int retriever_init_common(struct file_system_info *fsinfo){ int i = 0, j = 0; debug(2, "Received %d repos;\n", fsinfo->repo_count); file_mutex = calloc(fsinfo->repo_count, sizeof(pthread_mutex_t *)); for (i = 0; i < fsinfo->repo_count; i++){ file_mutex[i] = calloc(fsinfo->rev_count[i], sizeof(pthread_mutex_t)); for (j = 0; j < fsinfo->rev_count[i]; j++) pthread_mutex_init(&file_mutex[i][j], 0); }; return (open_files = single(list_t)) != NULL; };
void insert(uthread_impl *_prev) { if(_prev->next == this) return; if(!single()) remove(); uthread_impl *n = _prev->next; prev = _prev; next = n; prev->next = next->prev = this; }
int single(unsigned A[], int n) { if (n == 1) return A[0]; unsigned remind = 0; for (int i = 0; i < n; ++i) { remind = (remind + A[i] % 3) % 3; } int m = 0; for (int i = 0; i < n; ++i) { if (A[i] % 3 == remind) { A[m++] = A[i] / 3; } } return single(A, m) * 3 + remind; }
void Game::runGame() { while(state != END) { switch (state) { case GameState::MENU: menu(); break; case GameState::GAME: single(); break; } } }
/** * Activate is basically a switch/redirect to the appropriate function */ bool PowerManager::activate(int power_index, StatBlock *src_stats, Point target) { // logic for different types of powers are very different. We allow these // separate functions to handle the details. if (powers[power_index].type == POWTYPE_SINGLE) return single(power_index, src_stats, target); else if (powers[power_index].type == POWTYPE_MISSILE) return missile(power_index, src_stats, target); else if (powers[power_index].type == POWTYPE_REPEATER) return repeater(power_index, src_stats, target); else if (powers[power_index].type == POWTYPE_EFFECT) return effect(power_index, src_stats, target); return false; }
int main(int argc, char **argv) { struct test test; int t; test_init(&test, argc, argv); XSetErrorHandler(_check_error_handler); for (t = TARGET_FIRST; t <= TARGET_LAST; t++) { single(&test, t); //overlapping(&test, t); //gap(&test, t); //mixed(&test, t); } return 0; }
void copy_stats(stats_t *source, stats_t **dest){ debug(3, "copying stats for: path %s, internal: %s, name: %s, rev: %d\n", source->path, source->internal, source->name, source->rev); *dest = single(stats_t); memcpy((*dest), source, sizeof(stats_t)); if (source->path){ (*dest)->path = 0; gstrcpy(&(*dest)->path, source->path); } if (source->internal) (*dest)->internal = (*dest)->path + (source->internal - source->path); if (source->name) (*dest)->name = (*dest)->path + (source->name - source->path); if (source->link) { (*dest)->link = 0; gstrcpy(&(*dest)->link, source->link); } debug(4, "done copying stats: path %s, internal %s, name %s, rev: %d\n", (*dest)->path, (*dest)->internal, (*dest)->name, (*dest)->rev); };
int main(int argc, char *argv[]) { if (!TanoApplication::preInit(argc, argv)) return -10; TanoApplication instance(argc, argv); // Is another instance of the program is already running if (!instance.shouldContinue()) return 0; if (!instance.postInit()) return -10; MainWindow main(instance.arguments()); main.show(); QObject::connect(&instance, SIGNAL(activate()), &main, SLOT(single())); QObject::connect(&instance, SIGNAL(dockClicked()), &main, SLOT(dockClicked())); return instance.exec(); }
TEST(TestSequence, Construction) { Sequence empty; EXPECT_EQ(empty.size(), 0); Sequence voidSequence((Object())); // most vexing parse EXPECT_EQ(voidSequence.size(), 0); Sequence single(id(L"ginny")); EXPECT_EQ(single.size(), 1); Sequence cats(boolean(L"ginny"), boolean(L"max")); EXPECT_EQ(cats.size(), 2); Sequence array(array(id(L"ginny"), id(L"max"))); EXPECT_EQ(array.size(), 2); Knowledge k; k.Know(sequence(id(L"table"), id(L"moon"), id(L"hope"))); EXPECT_EQ(k.Clauses(), 1); }
int main(int argc, char * argv[]) { setlocale(LC_ALL, ""); struct wordlist wl; if (init_wl(&wl)) return 1; if (argc < 2) return usage(argv[0]); switch(argv[1][0]) { case 's': return single(&wl, argc, argv); case 'm': return multi(&wl, argc, argv); case 'r': return random(&wl, argc, argv); case 'c': return contained(&wl, argc, argv); default: return usage(argv[0]); } }
static struct token fetch_token(struct parser *parser, struct lexer *lex) { /* {{{ fetch_token body */ /* a nifty shorthand for the current position */ #define p (lex->curr_pos) char tmp_arr[MAX_NAME_LENGTH + 1] = { '\0' }; char *tmp_str = NULL; int i = 0; bool keyword_found = false, typename_found = false; int slen = 0; struct token ret; /* {{{ skip over whitespace and comments */ do { if (isspace(*p)){ for (; isspace(*p); p++){ if (*p == '\n'){ lex->line++; lex->col = 0; } else { lex->col++; } } } else if (*p == '/' && *(p + 1) == '*'){ int nest_level = 1; p += 2; lex->col += 2; for (; *p != '\0' && nest_level > 0; p++){ if (*p == '\n'){ lex->line++; lex->col = 0; } else if (*p == '/' && *(p + 1) == '*'){ nest_level++; p++; lex->col += 2; } else if (*p == '*' && *(p + 1) == '/'){ nest_level--; p++; lex->col += 2; } else lex->col++; } } } while (isspace(*p) || (*p == '/' && *(p + 1) == '*')); /* }}} */ if (p == NULL || *p == '\0' || (lex->fptr != NULL && feof(lex->fptr))){ ret.type = TOK_EOS; return ret; } if (name_beg(*p)){ /* {{{ NAME / KEYWORD / TYPE NAME */ const char **kptr = NULL; strncpy(tmp_arr, p, MAX_NAME_LENGTH - 1); tmp_arr[MAX_NAME_LENGTH] = '\0'; while (name_mid(*p)){ p++; i++; } tmp_arr[i] = '\0'; /* see if it's a keyword */ for (kptr = keywords; *kptr != NULL; kptr++){ if (!strcmp(*kptr, tmp_arr)){ keyword_found = true; break; } } /* see if it's a type name (only if it's not a keyword already) */ if (!keyword_found){ struct types_list *q; for (q = NM_types; q != NULL; q = q->next){ /* don't check anonymous types */ if (q->type->name != NULL){ if (!strcmp(q->type->name, tmp_arr)){ typename_found = true; break; } } } } if (keyword_found){ ret.type = TOK_KEYWORD; strcpy(ret.value.s, *kptr); lex->col += strlen(*kptr); } else if (typename_found){ ret.type = TOK_TYPE; strcpy(ret.value.s, tmp_arr); lex->col += strlen(tmp_arr); } else { ret.type = TOK_NAME; strcpy(ret.value.s, tmp_arr); lex->col += strlen(tmp_arr); } /* }}} */ } else if (isdigit(*p)){ /* {{{ NUMBER */ int i2 = 0; while (isdigit(*p) || (*p == '_' && isdigit(*(p + 1)))){ if (isdigit(*p)){ tmp_arr[i2++] = *p; } p++; i++; } if (*p == '.'){ /* {{{ FLOAT */ tmp_arr[i2++] = '.'; p++; i++; /* skip over the '.' */ if (isdigit(*p)){ while (isdigit(*p) || (*p == '_' && isdigit(*(p + 1)))){ if (isdigit(*p)){ tmp_arr[i2++] = *p; } p++; i++; } tmp_arr[i2] = '\0'; ret.type = TOK_REAL; ret.value.f = strtod(tmp_arr, NULL); } else { /* it's something like 2. */ tmp_arr[i] = '\0'; ret.type = TOK_REAL; ret.value.f = strtod(tmp_arr, NULL); } /* }}} */ } else { /* {{{ DECIMAL */ ret.type = TOK_INTEGER; ret.value.i = strtol(tmp_arr, NULL, 10); /* }}} */ } lex->col += i; /* }}} */ } else if (*p == '`'){ /* {{{ CHAR */ nchar_t value; /* skip over the opening "'" */ p++; /* fetch the (possibly multibyte) character */ value = u8_fetch_char(&p); if (*p != '`') err(parser, lex, "unterminated character"); /* skip over the closing "'" */ p++; ret.type = TOK_CHAR; ret.value.c = value; /* }}} */ } else if (*p == '"'){ /* {{{ STRING */ char *savep; int i2 = 0; p++; i++; lex->col++; savep = p; /* skip over the opening '"' */ while (*p != '"' && *p != '\n'){ p++; i++; lex->col++; slen++; } if (*p == '\n'){ err(parser, lex, "unterminated string"); } tmp_str = nmalloc(/* sizeof(char) times */slen + 1); while (*savep != '"') *(tmp_str + i2++) = *savep++; i--; p++; /* jump to the next character so the next `fetch_token' doesn't start lexing at the closing '"' */ push_str(lex, tmp_str); ret.type = TOK_STRING; ret.value.sp = tmp_str; /* }}} */ } else if (*p == '\''){ /* {{{ TYPE VARIABLE */ /* skip over the ' */ p++; ret.type = TOK_TYPE_VARIABLE; ret.value.c = u8_fetch_char(&p); /* }}} */ } else if (*p == '%'){ if (isdigit(*(p + 1))){ /* {{{ ACCUMULATOR */ unsigned i = 0; tmp_arr[i++] = '%'; p++; while (isdigit(*p) && i < MAX_NAME_LENGTH) tmp_arr[i++] = *p++; lex->col += i; strcpy(ret.value.s, tmp_arr); ret.type = TOK_ACCUMULATOR; /* }}} */ } else { /* {{{ PERCENT SIGN */ if (*(p + 1) == '='){ /* %= */ lex->col += 2; p += 2; ret.type = TOK_PERCENT_EQ; } else { /* % */ lex->col++; p++; ret.type = TOK_PERCENT; } /* }}} */ } } else switch (*p){ /* {{{ OPERATOR */ #define single(TYPE) { \ lex->col++; \ p++; \ ret.type = TOK_##TYPE; \ } \ break /* no semicolon */ #define possibly_double(TYPE) \ if (*(p + 1) == *p){ \ lex->col += 2; \ p += 2; \ ret.type = TOK_##TYPE##_2; \ } else \ single(TYPE); /* `single` already handles the `break` */ #define possibly_eq(TYPE) \ if (*(p + 1) == '='){ \ lex->col += 2; \ p += 2; \ ret.type = TOK_##TYPE##_EQ; \ } else \ single(TYPE); /* `single` already handles the `break` */ #define possibly_double_or_eq(TYPE) \ if (*(p + 1) == *p){ \ lex->col += 2; \ p += 2; \ ret.type = TOK_##TYPE##_2; \ } else if (*(p + 1) == '='){ \ lex->col += 2; \ p += 2; \ ret.type = TOK_##TYPE##_EQ; \ } else \ single(TYPE); /* `single` already handles the `break` */ #define possibly_double_or_eq_or_both(TYPE) \ if (*(p + 1) == *p){ \ if (*(p + 2) == '='){ \ /* double and eq */ \ lex->col += 3; \ p += 3; \ ret.type = TOK_##TYPE##_2_EQ; \ } else { \ /* double */ \ lex->col += 2; \ p += 2; \ ret.type = TOK_##TYPE##_2; \ } \ } else if (*(p + 1) == '='){ \ /* single and eq */ \ lex->col += 2; \ p += 2; \ ret.type = TOK_##TYPE##_EQ; \ } else \ single(TYPE); /* `single` already handles the `break` */ case '=': possibly_double(EQ); case ':': single(COLON); case ';': single(SEMICOLON); case ',': single(COMMA); case '-': possibly_double_or_eq(MINUS); case '+': possibly_double_or_eq(PLUS); case '*': possibly_eq(TIMES); case '/': possibly_eq(SLASH); case '(': single(LPAREN); case ')': single(RPAREN); case '{': single(LMUSTASHE); case '}': single(RMUSTASHE); case '[': single(LBRACKET); case ']': single(RBRACKET); case '!': possibly_eq(BANG); case '?': single(QUESTION); case '&': possibly_double_or_eq(AMPERSAND); case '^': possibly_eq(CARET); case '|': possibly_double_or_eq(PIPE); case '<': possibly_double_or_eq_or_both(LCHEVRON); case '>': possibly_double_or_eq_or_both(RCHEVRON); /* no case for the percent sign - it was already covered by the * 'accumulator' thingy */ default: fprintf(stderr, "nemo: unknown character '%c' (0x%x) in %s" " at line %u column %u\n", *p, *p, lex->name, lex->line, lex->col); /* FIXME don't exit here */ exit(1); /* }}} */ } #undef p #undef single #undef possibly_double #undef possibly_eq #undef possibly_double_or_eq #undef possibly_double_or_eq_or_both return ret; /* }}} */ }
double nslit(double *x, double *par){ return single(x,par) * nslit0(x,par); }
int main() { //std::string stringtest = "3:hogAB"; //std::string numbertest = "i30eA"; //std::string numbertest2 = "i00e"; //std::string listtest= "l3:hogi30el2:bi3:bioi1eee"; //std::string ltest = "l3:hog2:go5:abcdee"; //std::string ltest2 = "l3:hog2:go5:abcdei10ee"; //std::string dic1= "d3:cow3:moo4:spam4:eggse"; // represents the dictionary { "cow" => "moo", "spam" => "eggs" } //std::string dic2="d4:spaml1:a1:bee"; // represents the dictionary { "spam" => [ "a", "b" ] } //std::string dic3="d9:publisher3:bob17:publisher-webpage15:www.example.com18:publisher.location4:homee"; // represents { "publisher" => "bob", "publisher-webpage" => "www.example.com", "publisher.location" => "home" } //std::string dic4="de"; // represents an empty dictionary {} // String test //BDecoder t1(stringtest, 0); //t1.decode(); //std::cout << boost::any_cast<std::string>(t1.get()) << std::endl; // Integer test //BDecoder t2(numbertest,0); //std::cout << t2.decode() << std::endl; //std::cout << boost::any_cast<int>(t2.get()) << std::endl; //BDecoder t3(numbertest2,0); //std::cout << t3.decode() << std::endl; // List test //BDecoder t4(listtest,0); //t4.decode(); //std::vector<boost::any> list = boost::any_cast<std::vector<boost::any>>(t4.get()); //std::cout << list.size() << std::endl; //std::cout << (list[0].type() == typeid(std::string)) << std::endl; // Dictionary test //BDecoder t5(dic1,0); //std::cout << t5.decode() << std::endl; //std::unordered_map<std::string,boost::any> dict = boost::any_cast<std::unordered_map<std::string,boost::any>>(t5.get()); ////std::cout << dict.size() << std::endl; //std::unordered_map<std::string,boost::any>::const_iterator got = dict.find ("cow"); //std::cout << boost::any_cast<std::string>(got->second) << std::endl; //BDecoder t6(dic2,0); //std::cout << t6.decode() << std::endl; //std::unordered_map<std::string,boost::any> dict = boost::any_cast<std::unordered_map<std::string,boost::any>>(t6.get()); ////std::cout << dict.size() << std::endl; //std::unordered_map<std::string,boost::any>::const_iterator got = dict.find ("spam"); //std::vector<boost::any> dictlist = boost::any_cast<std::vector<boost::any>>(got->second); //std::cout << boost::any_cast<std::string>(dictlist[1]) << std::endl; //BDecoder t7(dic4,0); //std::cout << t7.decode() << std::endl; //std::unordered_map<std::string,boost::any> dict = boost::any_cast<std::unordered_map<std::string,boost::any>>(t7.get()); //std::cout << dict.size() << std::endl; std::string singleFile("test.torrent"); TorrentFileParser single(singleFile); //std::cout << "getPieces: " << single.info.getPieces() << std::endl; //std::cout << "getPieceLength: " << single.info.getPieceLength() << std::endl; //std::cout << "getName: " << single.info.getName() << std::endl; //std::cout << "getPrivate: " << single.info.getPrivate() << std::endl; //std::cout << "getLength: " << single.info.getLength() << std::endl; //std::cout << "getMD5: " << single.info.getMD5() << std::endl; //std::cout << "getNumberOfFiles: " << single.info.getNumberOfFiles() << std::endl; //std::cout << "getRawInfoDict: " << single.info.string << std::endl; //std::cout << "Info: getHash: " << single.info.getHash() << " of length " << single.info.getHash().length() << std::endl; std::string testURL("test"); std::string infoHash = single.info.getHash(); //Tracker trackHandler(testURL, infoHash); //std::cout << "URL encoded hash: " << trackHandler.urlEncode(single.info.getHash()) << std::endl; std::string multipleFile("multi.torrent"); TorrentFileParser multi(multipleFile); std::cout << "getPieces: " << multi.info.getPieces() << std::endl; std::cout << "getPieceLength: " << multi.info.getPieceLength() << std::endl; std::cout << "getName: " << multi.info.getName() << std::endl; std::cout << "getPrivate: " << multi.info.getPrivate() << std::endl; std::cout << "getLength: " << multi.info.getLength() << std::endl; std::cout << "getMD5: " << multi.info.getMD5() << std::endl; std::cout << "getNumberOfFiles: " << multi.info.getNumberOfFiles() << std::endl; //int i=1; //for(boost::any file : multi.info.files) { //std::cout << "File " << i++ << std::endl; //std::unordered_map<std::string, boost::any> dict = boost::any_cast<std::unordered_map<std::string, boost::any>>(file); //std::cout << "length=" << InfoParser::fileLength(dict) << std::endl; //std::cout << "path=" << InfoParser::filePath(dict) << std::endl; //std::cout << "md5=" << InfoParser::fileMD5(dict) << std::endl; //} }