static int ft_arrows(int buffer) { if (buffer == UP_ARROW) singleton()->current = singleton()->current->previous; if (buffer == DOWN_ARROW) singleton()->current = singleton()->current->next; ft_rightarr(buffer); ft_leftarr(buffer); return (1); }
bool key::released(int key) { if (singleton().oldkey(key) && singleton().nowkey(key) == false) { return true; } return false; }
char * postgresGetViewDefinition(char *viewName) { PGresult *res = NULL; ASSERT(postgresCatalogViewExists(viewName)); if (MAP_HAS_STRING_KEY(plugin->plugin.cache->viewDefs, viewName)) return STRING_VALUE(MAP_GET_STRING(plugin->plugin.cache->viewDefs,viewName)); // do query ACQUIRE_MEM_CONTEXT(memContext); res = execPrepared(NAME_GET_VIEW_DEF, singleton(createConstString(viewName))); if (PQntuples(res) == 1) { Constant *def = createConstString(PQgetvalue(res,0,0)); MAP_ADD_STRING_KEY(plugin->plugin.cache->viewDefs, viewName, def); PQclear(res); return STRING_VALUE(def); } PQclear(res); RELEASE_MEM_CONTEXT(); return NULL; }
boolean postgresIsAgg(char *functionName) { PGresult *res = NULL; char *f = strdup(functionName); // int i = 0; for(char *p = f; *p != '\0'; *(p) = tolower(*p), p++) ; if (hasSetElem(plugin->plugin.cache->aggFuncNames, f)) return TRUE; // do query ACQUIRE_MEM_CONTEXT(memContext); res = execPrepared(NAME_IS_AGG_FUNC, singleton(createConstString(f))); if (strcmp(PQgetvalue(res,0,0),"t") == 0) { addToSet(plugin->plugin.cache->aggFuncNames, f); PQclear(res); return TRUE; } PQclear(res); RELEASE_MEM_CONTEXT(); return FALSE; }
List * postgresGetAttributeNames (char *tableName) { List *attrs = NIL; PGresult *res = NULL; ASSERT(postgresCatalogTableExists(tableName)); if (MAP_HAS_STRING_KEY(plugin->plugin.cache->tableAttrs, tableName)) return (List *) MAP_GET_STRING(plugin->plugin.cache->tableAttrs,tableName); // do query ACQUIRE_MEM_CONTEXT(memContext); res = execPrepared(NAME_TABLE_GET_ATTRS, singleton(createConstString(tableName))); // loop through results for(int i = 0; i < PQntuples(res); i++) attrs = appendToTailOfList(attrs, strdup(PQgetvalue(res,i,0))); // clear result PQclear(res); MAP_ADD_STRING_KEY(plugin->plugin.cache->tableAttrs, tableName, attrs); DEBUG_LOG("table %s attributes are <%s>", tableName, stringListToString(attrs)); RELEASE_MEM_CONTEXT(); return attrs; }
/** * Compile a signal * @param sig the signal expression to compile. * @return the C code translation of sig as a string */ string VectorCompiler::generateLoopCode (Tree sig) { int i; Tree x; Loop* l; l = fClass->topLoop(); assert(l); //cerr << "VectorCompiler::OLDgenerateCode " << ppsig(sig) << endl; if (needSeparateLoop(sig)) { // we need a separate loop unless it's an old recursion if (isProj(sig, &i, x)) { // projection of a recursive group x if (l->hasRecDependencyIn(singleton(x))) { // x is already in the loop stack return ScalarCompiler::generateCode(sig); } else { // x must be defined fClass->openLoop(x, "count"); string c = ScalarCompiler::generateCode(sig); fClass->closeLoop(sig); return c; } } else { fClass->openLoop("count"); string c = ScalarCompiler::generateCode(sig); fClass->closeLoop(sig); return c; } } else { return ScalarCompiler::generateCode(sig); } }
QueryPtr DisjunctionMaxQuery::rewrite(IndexReaderPtr reader) { int32_t numDisjunctions = disjuncts.size(); if (numDisjunctions == 1) { QueryPtr singleton(disjuncts[0]); QueryPtr result(singleton->rewrite(reader)); if (getBoost() != 1.0) { if (result == singleton) result = boost::dynamic_pointer_cast<Query>(result->clone()); result->setBoost(getBoost() * result->getBoost()); } return result; } DisjunctionMaxQueryPtr clone; for (int32_t i = 0; i < numDisjunctions; ++i) { QueryPtr clause(disjuncts[i]); QueryPtr rewrite(clause->rewrite(reader)); if (rewrite != clause) { if (!clone) clone = boost::dynamic_pointer_cast<DisjunctionMaxQuery>(this->clone()); clone->disjuncts[i] = rewrite; } } return clone ? clone : shared_from_this(); }
void tst1() { std::cerr << singleton(10) << "\n"; std::cerr << all() << "\n"; std::cerr << l(-10) << "\n"; std::cerr << r(10) << "\n"; std::cerr << l(-10, true) << "\n"; std::cerr << r(10, true) << "\n"; std::cerr << b(2, 10) << "\n"; std::cerr << wd(b(-5, 5, true, false, 1, 2) * b(-5, 5, false, true, 3, 4)) << "\n"; std::cerr << wd(l(2, false, 1) / b(2, 6, false, false, 2, 3)) << "\n"; std::cerr << wd(expt(b(-2, 3, true, false, 1, 2), 2)) << "\n"; std::cerr << wd(expt(b(-4, 3, true, false, 1, 2), 2)) << "\n"; std::cerr << wd(expt(b(2, 4, true, false, 1, 2), 2)) << "\n"; std::cerr << wd(expt(b(0, 3, true, false, 1, 2), 2)) << "\n"; std::cerr << wd(expt(b(-4, -2, true, false, 1, 2), 2)) << "\n"; std::cerr << b(2, 10, false, false, 1, 2) << " * " << l(10, false, 3).inv() << " = " << wd(b(2, 10, false, false, 1, 2) / l(10, false, 3)) << "\n"; std::cerr << b(-2, -1, false, true) << " * " << b(-3,0) << " = "; std::cerr.flush(); std::cerr << (b(-2, -1, false, true) * b(-3,0)) << "\n"; std::cerr << b(1, 2, true, false) << " * " << b(0,3) << " = "; std::cerr.flush(); std::cerr << (b(1, 2, true, false) * b(0,3)) << "\n"; std::cerr << b(1, 2, true, true) << " * " << b(-3,0) << " = "; std::cerr.flush(); std::cerr << (b(1, 2, true, true) * b(-3,0)) << "\n"; std::cerr << b(10,20) << " / " << b(0,1,true,false) << " = "; std::cerr.flush(); std::cerr << (b(10,20)/b(0,1,true,false)) << "\n"; std::cerr << (b(10,20)/b(0,2,true,false)) << "\n"; }
/* * Character */ Character::Character( ItemFactory &_factory, uint32 _characterID, // InventoryItem stuff: const CharacterType &_charType, const ItemData &_data, // Character stuff: const CharacterData &_charData, const CorpMemberInfo &_corpData) : Owner(_factory, _characterID, _charType, _data), m_accountID(_charData.accountID), m_title(_charData.title), m_description(_charData.description), m_gender(_charData.gender), m_bounty(_charData.bounty), m_balance(_charData.balance), m_aurBalance(_charData.aurBalance), m_securityRating(_charData.securityRating), m_logonMinutes(_charData.logonMinutes), m_totalSPtrained(((double)(_charData.skillPoints))), m_corporationID(_charData.corporationID), m_corpHQ(_corpData.corpHQ), m_allianceID(_charData.allianceID), m_warFactionID(_charData.warFactionID), m_corpRole(_corpData.corpRole), m_rolesAtAll(_corpData.rolesAtAll), m_rolesAtBase(_corpData.rolesAtBase), m_rolesAtHQ(_corpData.rolesAtHQ), m_rolesAtOther(_corpData.rolesAtOther), m_stationID(_charData.stationID), m_solarSystemID(_charData.solarSystemID), m_constellationID(_charData.constellationID), m_regionID(_charData.regionID), m_ancestryID(_charData.ancestryID), m_careerID(_charData.careerID), m_schoolID(_charData.schoolID), m_careerSpecialityID(_charData.careerSpecialityID), m_startDateTime(_charData.startDateTime), m_createDateTime(_charData.createDateTime), m_corporationDateTime(_charData.corporationDateTime) { // allow characters to be only singletons //assert(singleton() && quantity() == -1); assert(singleton()); // Activate Save Info Timer with somewhat randomized timer value: //SetSaveTimerExpiry( MakeRandomInt( (10 * 60), (15 * 60) ) ); // Randomize save timer expiry to between 10 and 15 minutes //EnableSaveTimer(); }
void *malloc(size_t size) { void *ret; if (!ptr_list) ptr_list = (t_chunk *)malloc_base(sizeof(t_chunk)); ret = mmap(singleton(), size, PROT_WRITE | PROT_READ , MAP_ANON | MAP_PRIVATE, -1, 0); if (ret == MAP_FAILED) { write(2, "mmap fail.\n", 12); ret = NULL; } return (ret); }
void InventoryItem::GetItemRow( PyPackedRow* into ) const { into->SetField( "itemID", new PyLong( itemID() ) ); into->SetField( "typeID", new PyInt( typeID() ) ); into->SetField( "ownerID", new PyInt( ownerID() ) ); into->SetField( "locationID", new PyLong( locationID() ) ); into->SetField( "flagID", new PyInt( flag() ) ); into->SetField( "quantity", new PyInt( singleton() ? -1 : quantity()) ); into->SetField( "groupID", new PyInt( groupID() ) ); into->SetField( "categoryID", new PyInt( categoryID() ) ); into->SetField( "customInfo", new PyString( customInfo() ) ); //into->SetField( "singleton", new PyBool( singleton() ) ); //into->SetField( "stacksize", new PyInt (quantity()) ); }
static int ft_rightarr(int buffer) { int i; if (buffer == RIGHT_ARROW) { if (ft_currentidx(singleton()->clst, singleton()->current) < ft_clstsize(singleton()->clst) - singleton()->winsz->ws_row) { i = 0; while (i < singleton()->winsz->ws_row) { singleton()->current = singleton()->current->next; i++; } } else singleton()->current = singleton()->current->next; } return (1); }
void Statistics::initialize(const String& databasePath) { ASSERT(RunLoop::isMain()); auto startTime = std::chrono::system_clock::now(); StringCapture databasePathCapture(databasePath); StringCapture networkCachePathCapture(singleton().recordsPath()); serialBackgroundIOQueue().dispatch([this, databasePathCapture, networkCachePathCapture, startTime] { WebCore::SQLiteTransactionInProgressAutoCounter transactionCounter; String databasePath = databasePathCapture.string(); if (!WebCore::makeAllDirectories(WebCore::directoryName(databasePath))) return; LOG(NetworkCache, "(NetworkProcess) Opening network cache statistics database at %s...", databasePath.utf8().data()); m_database.open(databasePath); m_database.disableThreadingChecks(); if (!m_database.isOpen()) { LOG_ERROR("Network cache statistics: Failed to open / create the network cache statistics database"); return; } executeSQLCommand(m_database, ASCIILiteral("CREATE TABLE IF NOT EXISTS AlreadyRequested (hash TEXT PRIMARY KEY)")); executeSQLCommand(m_database, ASCIILiteral("CREATE TABLE IF NOT EXISTS UncachedReason (hash TEXT PRIMARY KEY, reason INTEGER)")); WebCore::SQLiteStatement statement(m_database, ASCIILiteral("SELECT count(*) FROM AlreadyRequested")); if (statement.prepareAndStep() != SQLITE_ROW) { LOG_ERROR("Network cache statistics: Failed to count the number of rows in AlreadyRequested table"); return; } m_approximateEntryCount = statement.getColumnInt(0); #if !LOG_DISABLED auto elapsedMS = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - startTime).count(); #endif LOG(NetworkCache, "(NetworkProcess) Network cache statistics database load complete, entries=%lu time=%lldms", static_cast<size_t>(m_approximateEntryCount), elapsedMS); if (!m_approximateEntryCount) { bootstrapFromNetworkCache(networkCachePathCapture.string()); #if !LOG_DISABLED elapsedMS = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - startTime).count(); #endif LOG(NetworkCache, "(NetworkProcess) Network cache statistics database bootstrapping complete, entries=%lu time=%lldms", static_cast<size_t>(m_approximateEntryCount), elapsedMS); } }); }
List * listMake(void *elem, ...) { List *result = singleton(elem); va_list args; void *p; va_start(args, elem); while((p = va_arg(args, void *))) result = appendToTailOfList(result, p); va_end(args); return result; }
/* compute the interval i to be the smallest interval including all <v | dir> for points in the pathlist. If the pathlist is empty, return the singleton interval [0,0]. */ void path_limits(potrace_path_t *path, dpoint_t dir, interval_t *i) { potrace_path_t *p; /* empty image? */ if (path == NULL) { interval(i, 0, 0); return; } /* initialize interval to a point on the first curve */ singleton(i, iprod(path->curve.c[0][2], dir)); /* iterate */ list_forall(p, path) { curve_limits(&p->curve, dir, i); }
void FileLine::deleteAllRemaining() { #ifdef VL_LEAK_CHECKS // FileLines are allocated, but never nicely freed, as it's much faster // that way. Unfortunately this makes our leak checking a big mess, so // only when leak checking we'll track them all and cleanup. while (1) { FileLineCheckSet::iterator it=fileLineLeakChecks.begin(); if (it==fileLineLeakChecks.end()) break; delete *it; // Operator delete will remove the iterated object from the list. // Eventually the list will be empty and terminate the loop. } fileLineLeakChecks.clear(); singleton().clear(); #endif }
void get_link(t_stat *p_stat, t_dir *file, t_lst *lst, t_data *data) { char *link; int ret; t_opt *flag; flag = singleton(); if (!(link = (char *)ft_memalloc(sizeof(char) * p_stat->st_size + 2))) return (print_error("")); if ((ret = readlink(lst->path, link, p_stat->st_size + 1)) == -1) return (print_error("")); if (flag->l) data->name = ft_strjoin(ft_strjoin(file->d_name, "\033[00m -> "), link); else data->name = ft_strdup(file->d_name); }
int solve_sudoku(sudoku_board board, int side){ int i=0; while (1){ //printf("\tALONE\n"); if (alone(board, side)) continue; if (check_solution(board, side)==0) break; //printf("\t\tSINGLETON\n"); if (singleton(board, side, 0, 0, side, side)) continue; if (check_solution(board, side)==0) break; //printf("\t\t\tPAIRS\n"); if (pairs(board, side, 0, 0, side, side)) continue; if (check_solution(board, side)==0) break; //print_board(board, side); //printf("\t\t\t\tBAD POSSIBLE\n"); i=bad_possible_elimination(board, side); //printf(" %d\n", i); if(i) continue; if (check_solution(board, side)==0) break; //printf("\t\t\t\t\tRECURSIVE\n"); recursive_solution(board, side, 0, 0); break; } /*switch (check_solution(board, side)) { case 0: printf("\n--OK--\n"); break; case 1: printf("\n--ERRORS--\n"); break; case 2: printf("\n--MISSES--\n"); break; default: break; }*/ return 0; }
int main (int argc, char **argv) { if (argc == 2 && 0 == g_strcmp0(argv[1], "-d")) g_setenv("G_MESSAGES_DEBUG", "all", FALSE); if (is_livecd()){ dde_session_register(); return 0; } if (is_application_running("com.deepin.dde.guide")) { g_warning("another instance of application dde-guide is running...\n"); return 0; } else { singleton("com.deepin.dde.guide"); } init_i18n (); gtk_init (&argc, &argv); g_log_set_default_handler((GLogFunc)log_to_file, "dde-guide"); if (!guide_is_debug()){ struct DisplayInfo rect_screen; update_screen_info(&rect_screen); widget_move_by_rect(get_container(),rect_screen); listen_monitors_changed_signal(G_CALLBACK(monitors_changed_cb),NULL); } GtkWidget *webview = d_webview_new_with_uri (GET_HTML_PATH("guide")); gtk_container_add (GTK_CONTAINER(get_container()), GTK_WIDGET (webview)); g_signal_connect(webview, "draw", G_CALLBACK(erase_background), NULL); gtk_widget_realize (get_container()); gtk_widget_realize (webview); GdkWindow* gdkwindow = gtk_widget_get_window (get_container()); if (!guide_is_debug()) gdk_window_set_override_redirect (gdkwindow, TRUE); gtk_widget_show_all (get_container()); gtk_main (); return 0; }
int ft_keycmp(int buffer) { ft_arrows(buffer); if (buffer == SPACE) { singleton()->current->selected ^= 1; singleton()->current = singleton()->current->next; } if (buffer == DELETE || buffer == BACKSPACE) { if (singleton()->current->first == 1) singleton()->clst = singleton()->clst->next; ft_clstdelone(&singleton()->current); if (!singleton()->current) ft_reset(); ft_getmax(singleton()->clst); } if (buffer == ESCAPE) ft_reset(); if (buffer == RETURN) ft_returnslct(); return (1); }
List level_order(BinaryTree t) { List trav, next, level = singleton(t); Node n; while(!level.is_empty()) { freeList(next); emptyList(next); /* this could be optimized */ append(l, trav); while(n) { if(n->l) cons(n->l, next); if(n->r) cons(n->r, next); n = n->next; } level = next; } return trav; }
/// Factory used by PluginHooks to dynamically link the plugin instance extern "C" AuthPlugin* getAuthPlugin(const UtlString& pluginName) { OsLock singleton(CallerAlias::sSingletonLock); if (!CallerAlias::spInstance) { CallerAlias::spInstance = new CallerAlias(pluginName); } else { Os::Logger::instance().log(FAC_SIP, PRI_CRIT, "CallerAlias[%s]: " "it is invalid to configure more than one instance of the CallerAlias plugin.", pluginName.data()); assert(false); } return CallerAlias::spInstance; }
void Statistics::shrinkIfNeeded() { ASSERT(RunLoop::isMain()); const size_t maxEntries = 100000; if (m_approximateEntryCount < maxEntries) return; LOG(NetworkCache, "(NetworkProcess) shrinking statistics cache m_approximateEntryCount=%lu, maxEntries=%lu", static_cast<size_t>(m_approximateEntryCount), maxEntries); clear(); StringCapture networkCachePathCapture(singleton().recordsPath()); serialBackgroundIOQueue().dispatch([this, networkCachePathCapture] { bootstrapFromNetworkCache(networkCachePathCapture.string()); LOG(NetworkCache, "(NetworkProcess) statistics cache shrink completed m_approximateEntryCount=%lu", static_cast<size_t>(m_approximateEntryCount)); }); }
int main(int argc, char **argv) { t_game game; singleton(&game); signal(SIGINT, exit); srand(time(NULL)); if (argc == 1) ft_usage(argv[0]); ft_init_game(&game); ft_check_args(argv, &game); ft_init_map(&game); atexit(ft_quit); ft_resource(&game); game.sock = create_server(game); ft_init_cls(&game); ft_serveur(&game); return (0); }
static int ft_leftarr(int buffer) { int i; if (buffer == LEFT_ARROW) { if (ft_currentidx(singleton()->clst, singleton()->current) - singleton()->winsz->ws_row >= 0) { i = 0; while (i < singleton()->winsz->ws_row) { singleton()->current = singleton()->current->previous; i++; } } else singleton()->current = singleton()->current->previous; } return (1); }
void cleanup(void) { t_game *game; int i; game = singleton(NULL); ft_strdel2(&game->team); i = -1; while (++i < game->height) free(game->map[i]); free(game->map); SDL_Quit(); SDL_DestroyRenderer(game->renderer); i = -1; while (game->textures[++i]) SDL_DestroyTexture(game->textures[i]); free(game->textures); SDL_DestroyWindow(game->window); }
t_block *find_by_ptr(void *ptr) { t_heap *heap; t_block *block; heap = singleton(); while (heap) { block = heap->block; while (block) { if (block->ptr == ptr) return (block); block = block->next; } heap = heap->next; } return (NULL); }
/* * Character */ Character::Character( ItemFactory &_factory, uint32 _characterID, // InventoryItem stuff: const CharacterType &_charType, const ItemData &_data, // Character stuff: const CharacterData &_charData, const CorpMemberInfo &_corpData) : Owner(_factory, _characterID, _charType, _data), m_accountID(_charData.accountID), m_title(_charData.title), m_description(_charData.description), m_gender(_charData.gender), m_bounty(_charData.bounty), m_balance(_charData.balance), m_securityRating(_charData.securityRating), m_logonMinutes(_charData.logonMinutes), m_corporationID(_charData.corporationID), m_corpHQ(_corpData.corpHQ), m_allianceID(_charData.allianceID), m_warFactionID(_charData.warFactionID), m_corpRole(_corpData.corpRole), m_rolesAtAll(_corpData.rolesAtAll), m_rolesAtBase(_corpData.rolesAtBase), m_rolesAtHQ(_corpData.rolesAtHQ), m_rolesAtOther(_corpData.rolesAtOther), m_stationID(_charData.stationID), m_solarSystemID(_charData.solarSystemID), m_constellationID(_charData.constellationID), m_regionID(_charData.regionID), m_ancestryID(_charData.ancestryID), m_careerID(_charData.careerID), m_schoolID(_charData.schoolID), m_careerSpecialityID(_charData.careerSpecialityID), m_startDateTime(_charData.startDateTime), m_createDateTime(_charData.createDateTime), m_corporationDateTime(_charData.corporationDateTime) { // allow characters to be only singletons assert(singleton() && quantity() == 1); }
List * postgresGetKeyInformation(char *tableName) { List *result = NIL; PGresult *res = NULL; // do query ACQUIRE_MEM_CONTEXT(memContext); res = execPrepared(NAME_GET_PK, singleton(createConstString(tableName))); // loop through results for(int i = 0; i < PQntuples(res); i++) result = appendToTailOfList(result, strdup(PQgetvalue(res,i,0))); // cleanup PQclear(res); RELEASE_MEM_CONTEXT(); return result; }
/// Return the "global" configuration instance, for the current /// thread. This may be the same as instance(), but on some occasions, /// it may be a different one. For example, ACE_Service_Config_Guard /// provides a way of temporarily replacing the "current" /// configuration instance in the context of a thread. ACE_Service_Gestalt* ACE_Service_Config::current (void) { void* temp = ACE_Service_Config::singleton()->threadkey_.get (); if(temp == 0) { // The most likely reason is that the current thread was spawned // by some native primitive, like pthreads or Windows API - not // from ACE. This is perfectly legal for callers who are not, or // do not need to be ACE-aware. Such callers must have no // expectation that the pluggable, multi-context configuration // support will work - they would always get the global context, // because at this point there is no information what the "parent" // thread's configuration context was. temp = global(); singleton()->threadkey_.set (temp); } return static_cast<ACE_Service_Gestalt*> (temp); }