int main() { test::TabBar t; auto x = t.alpha = 7; auto y = t.beta = "kaesekuchen"; auto z = t.gamma = true; { using T = decltype(remove_from(t)); static_assert(sqlpp::is_regular<T>::value, "type requirement"); } { using T = decltype(remove_from(t).where(t.beta != "transparent")); static_assert(sqlpp::is_regular<T>::value, "type requirement"); } { using T = decltype(dynamic_remove_from(db, t).dynamic_using_().dynamic_where()); static_assert(sqlpp::is_regular<T>::value, "type requirement"); } interpret(remove_from(t), printer).flush(); interpret(remove_from(t).where(t.beta != "transparent"), printer).flush(); interpret(remove_from(t).using_(t), printer).flush(); auto r = dynamic_remove_from(db, t).dynamic_using_().dynamic_where(); r = r.add_using_(t); r = r.add_where(t.beta != "transparent"); interpret(r, printer).flush(); return 0; }
IDataStorage::ReturnCode DataStorage::removeSensor(const std::string& systemSensorName, OnSuccessCallbackType onSuccessCallback, OnErrorCallbackType onErrorCallback) { if (isConnected == false) { return ReturnCode::WRONG_CONFIG; } if (onSuccessCallback == nullptr || onErrorCallback == nullptr) { return ReturnCode::NULLPTR_CALLBACKS; } std::string sensorType; try { int inc = 0; const auto tabMainTable = DataDB::MainTable(); for (const auto &row : db->operator()(sqlpp::select( tabMainTable.sensorType).from(tabMainTable) .where(tabMainTable.systemSensorName == systemSensorName))) { inc++; sensorType = row.sensorType; } if (inc == 0) { dsThreadPool->enqueue(onErrorCallback, "NO_SUCH_SS_NAME"); return ReturnCode::NO_SUCH_SS_NAME; } else if (inc > 1) { dsThreadPool->enqueue(onErrorCallback, "TOO MANY SS NAMES"); return ReturnCode::TOO_MANY_SS_NAMES; } } catch (std::exception& e) { dsThreadPool->enqueue(onErrorCallback, "EXCEPTION"); return ReturnCode::EXCEPTION_ERROR; } try { auto tabMainTable = DataDB::MainTable(); db->operator()(remove_from(tabMainTable).where(tabMainTable.systemSensorName == systemSensorName)); if (sensorType == sensorTypeConstants.binaryType) { auto tabBinaryType = DataDB::BinaryType(); db->operator()(remove_from(tabBinaryType).where(tabBinaryType.systemSensorName == systemSensorName)); } else if (sensorType == sensorTypeConstants.manyStatesType) { auto tabManyStatesType = DataDB::ManyStatesType(); db->operator()(remove_from(tabManyStatesType).where(tabManyStatesType.systemSensorName == systemSensorName)); } else if (sensorType == sensorTypeConstants.monitorType) { auto tabMonitorType = DataDB::MonitorType(); db->operator()(remove_from(tabMonitorType).where(tabMonitorType.systemSensorName == systemSensorName)); } else { dsThreadPool->enqueue(onErrorCallback, "No such sensor type"); return ReturnCode::WRONG_SENSOR_TYPE; } } catch (std::exception& e) { dsThreadPool->enqueue(onErrorCallback, e.what()); return ReturnCode::EXCEPTION_ERROR; } dsThreadPool->enqueue(onSuccessCallback, "remove - success"); return ReturnCode::SUCCESS; }
std::shared_ptr<job::Job> make_storage_job(const Point& dest, item::Item* item) { auto e = item->parent; auto pos = e->assert_get<Position>(); clearance c = { (Security::Mask)(Security::INFRARED | Security::RED), Department::FACILITIES }; auto ais = std::make_shared<ai::SequenceAI>(); ais->add_task(ai::make_do_at(pos->as_point().as_point(), 10, "Collecting Item")); ais->add_task(ai::make_callbackai([=](ai::AI* ai){ delete e->remove<Position>(); auto it = ai->parent->assert_get<item::Item>(); auto it2 = e->assert_get<item::Item>(); it2->insert_into(it); })); ais->add_task(ai::make_do_at(dest.as_point(), 10, "Storing Item")); ais->add_task(ai::make_callbackai([=](ai::AI*){ auto it2 = e->assert_get<item::Item>(); it2->remove_from(); e->emplace<Position>(dest); })); auto script = ai::make_lockai(e->assert_get<item::Item>(), ais); return std::make_shared<job::Job>("Store Food", c, script); }
void edit_depot_dialog() { Depot *the_depot; print_all_depots(); prt(TYPE_DEPOT_NAME_TO_EDIT); scan_to_buf(); if (is_zero()) { prt(CLS); return; } prt(CLS); the_depot = find_object_with_item_in(&depots, buffer, get_depot_name, names_cmp); if (!the_depot) return; prt(CURRENT); printf("%s\n", the_depot->name); prt(NEW); scan_to_buf(); prt(CLS); /* if edited successfully - find new place for new name (sort) */ if (edit_depot_name(the_depot, buffer)) { remove_from(&depots, the_depot, del_node_only); append_to(&depots, the_depot, depots_names_cmp); reappend_depot_assignments(the_depot); } modified = 1; }
void* tram_ep(void *arg){ task_context_t * ctx = arg; int start = rand() % 4; int stop = rand() % 3; ctx->posX = from_to[start][0][0]; ctx->posY = from_to[start][0][1]; while (!place_at(ctx->posX, ctx->posY)) { sleep(1); } int destX = from_to[start][stop+1][0]; int destY = from_to[start][stop+1][1]; //printf("going from %d %d to %d %d\n", ctx->posX, ctx->posY, destX, destY); while (destX != ctx->posX || destY != ctx->posY) { if (destX > ctx->posX && ctx->posY == TRAM_LANE_BOTTOM) { try_move(ctx, +1, 0); } else if (destX < ctx->posX && ctx->posY == TRAM_LANE_TOP) { try_move(ctx, -1, 0); } else if (destY > ctx->posY && ctx->posX == TRAM_LANE_LEFT) { try_move(ctx, 0, 1); } else if (destY < ctx->posY && ctx->posX == TRAM_LANE_RIGHT) { try_move(ctx, 0, -1); } sleep(1); } remove_from(ctx->posX, ctx->posY); ctx->alive = 0; return NULL; }
int remove_depot(Depot* the_depot) { /* removes list of buses' pointers */ delete_depot_references(the_depot); if (!remove_from(&depots, the_depot, del_depot)) { msg(DEPOT_REMOVE_FAILED); return 0; } return 1; }
int remove_bus(Bus* the_bus) { /* removes list of depots' pointers */ delete_bus_references(the_bus); if(!remove_from(&buses, the_bus, del_bus)) { msg(BUS_REMOVE_FAILED); return 0; } return 1; }
// Removes a user from the given UserList U, if any // Returns a UserList UserList remove_from(UserList U, User user) { if (U is_not None) { if (U->info == user) { return U->next; // Will not free the user on purpose } U->next = remove_from(U->next, user); return U; } return None; }
void slot_manager::move_device(input_source* dev, output_slot* target) { //private, should only be called with lock acquired if (!dev) return; if (dev->out_dev == target) return; if (dev->out_dev) { remove_from(dev->out_dev); } if (target) { target->pad_count += 1; } dev->set_slot(target); if (target) { log.take_message(dev->name + " assigned to slot " + target->name); } else { log.take_message(dev->name + " not assigned to any slot"); } }
int Where(int, char* []) { const auto foo = test::TabFoo{}; const auto bar = test::TabBar{}; // Unconditionally compare(__LINE__, select(foo.omega).from(foo).unconditionally(), "SELECT tab_foo.omega FROM tab_foo"); compare(__LINE__, remove_from(foo).unconditionally(), "DELETE FROM tab_foo"); compare(__LINE__, update(foo).set(foo.omega = 42).unconditionally(), "UPDATE tab_foo SET omega=42"); compare(__LINE__, where(sqlpp::value(true)), " WHERE " + getTrue()); // Never compare(__LINE__, where(sqlpp::value(false)), " WHERE " + getFalse()); // Sometimes compare(__LINE__, where(bar.gamma), " WHERE tab_bar.gamma"); compare(__LINE__, where(bar.gamma == false), " WHERE (tab_bar.gamma=" + getFalse() + ")"); compare(__LINE__, where(bar.beta == "SQL"), " WHERE (tab_bar.beta='SQL')"); return 0; }
void remap_user(User user, int x, int y) { assert(user is_not None); if (x < 0) { x = 0; } if (y < 0) { y = 0; } if (x >= 256) { x = 255; } if (y >= 256) { y = 255; } pthread_mutex_lock(&map_mutex); map[user->x][user->y]->users = remove_from(map[user->x][user->y]->users, user); map[x][y]->users = add_to(map[x][y]->users, user); user->x = x; user->y = y; pthread_mutex_unlock(&map_mutex); _infoUser("User moved.", user->username); }
int Remove(int, char* []) { MockDb db = {}; MockDb::_serializer_context_t printer = {}; const auto t = test::TabBar{}; const auto f = test::TabFoo{}; { using T = decltype(remove_from(t)); static_assert(sqlpp::is_regular<T>::value, "type requirement"); } { using T = decltype(remove_from(t).where(t.beta != "transparent")); static_assert(sqlpp::is_regular<T>::value, "type requirement"); } { using T = decltype(dynamic_remove_from(db, t).dynamic_using().dynamic_where()); static_assert(sqlpp::is_regular<T>::value, "type requirement"); } serialize(remove_from(t), printer).str(); serialize(remove_from(t).where(t.beta != "transparent"), printer).str(); serialize(remove_from(t).using_(t), printer).str(); serialize(remove_from(t).using_(f), printer).str(); auto r = dynamic_remove_from(db, t).dynamic_using().dynamic_where(); r.using_.add(t); r.where.add(t.beta != "transparent"); printer.reset(); std::cerr << serialize(r, printer).str() << std::endl; printer.reset(); std::cerr << serialize(remove_from(t).unconditionally(), printer).str() << std::endl; db(r); return 0; }
void World::save() { sql::connection db(getDbConfig()); box_db::Box tbl; // clear the table db(remove_from(tbl).unconditionally()); // insert all boxes for (const auto& box : _boxes) { btTransform trans; box.pose->getWorldTransform(trans); auto& p = trans.getOrigin(); float yaw, pitch, roll; trans.getBasis().getEulerYPR(yaw, pitch, roll); auto& c = box.color; db(insert_into(tbl).set( // position tbl.x = p.x(), tbl.y = p.y(), tbl.z = p.z(), // orientation tbl.yaw = yaw, tbl.pitch = pitch, tbl.roll = roll, // color tbl.red = c.r, tbl.green = c.g, tbl.blue = c.b)); } }
void edit_bus_dialog() { int side_no, edit_type; Bus *the_bus; print_all_buses(); prt(TYPE_BUS_SIDE_NO_TO_EDIT); scan_to_buf(); if (is_zero()) { prt(CLS); return; } if (!is_number(buffer)) { prt(CLS); prt(NOT_A_NUMBER); return; } side_no = atoi(buffer); prt(CLS); the_bus = find_object_with_item_in(&buses, &side_no, get_side_no, side_no_cmp); if (!the_bus) return; while (1) { print_bus_labels(); print_bus_info(the_bus); prt(LINE); prt(WHAT_U_WANT_TO_EDIT); prt(CHOOSE_OPT); scan_to_buf(); if (is_zero()) { prt(CLS); return; } if (!is_number(buffer)){ prt(CLS); prt(NOT_A_NUMBER); continue; } edit_type = atoi(buffer); switch (edit_type) { case 1: prt(CURRENT); printf("%04d\n", the_bus->side_no); prt(NEW); scan_to_buf(); prt(CLS); /* if edited successfully - find new place for side_no name (sort) */ if (edit_bus_side_no(the_bus, buffer)) { remove_from(&buses, the_bus, del_node_only); append_to(&buses, the_bus, buses_side_no_cmp); reappend_bus_memberships(the_bus); } break; case 2: prt(CURRENT); printf("%d\n", the_bus->line_no); prt(NEW); scan_to_buf(); prt(CLS); edit_bus_line_no(the_bus, buffer); break; case 3: prt(CURRENT); printf("%s\n", the_bus->driver_pesel); prt(NEW); scan_to_buf(); prt(CLS); edit_bus_driver_pesel(the_bus, buffer); break; case 4: prt(CURRENT); printf("%s\n", the_bus->driver_name); prt(NEW); scan_to_buf(); prt(CLS); edit_bus_driver_name(the_bus, buffer); break; default: prt(CLS); prt(INVALID_OPTION); break; } /* switch */ modified = 1; } /* while */ }
int main(int argc, char *argv[]) { int port_no = 6666; // Server listening socket int sockd_wait; // Client sockets int client_sockets[MAX_CLIENTS]; // Number of connected clients int connected = 0; int i; char request; ssize_t actually_read; // Set of file descriptors (sockets) we want to read from fd_set waiting_set; // Set used when calling pselect fd_set selected_set; int selected; struct sockaddr_in server_address; clients = client_init(); FD_ZERO(&waiting_set); // Create listening socket sockd_wait = socket(AF_INET, SOCK_STREAM, 0); if (sockd_wait < 0) { perror("ERROR opening socket"); return EXIT_FAILURE; } // Receive from anyone bzero((char *) &server_address, sizeof(server_address)); server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = INADDR_ANY; server_address.sin_port = htons(port_no); // Bind the socket if (bind(sockd_wait, (struct sockaddr *) &server_address, sizeof(server_address)) < 0) { perror("ERROR on binding"); close(sockd_wait); return EXIT_FAILURE; } if (listen(sockd_wait, 5) < 0) { perror("ERROR on listen"); close(sockd_wait); return EXIT_FAILURE; } // Wait for new clients (accept) FD_SET(sockd_wait, &waiting_set); if (signal (SIGINT, termination_handler) == SIG_IGN) { // Ctrl+c handler to terminate early signal (SIGINT, SIG_IGN); } while (alive) { selected_set = waiting_set; selected = pselect(INT_MAX, &selected_set, NULL, NULL, NULL, NULL); if (selected < 0) { // pselect returned an error if (errno == EINTR) { // pselect was interrupted, try again continue; } perror("Error when waiting to receive from sockets"); alive = 0; break; } if (selected == 0) { continue; } if (FD_ISSET(sockd_wait, &selected_set)) { client_sockets[connected] = accept(sockd_wait, NULL, NULL); if (client_sockets[connected] < 0) { // Client could not connect perror("ERROR on accept"); continue; } // We have a new client FD_SET(client_sockets[connected], &waiting_set); connected++; } for (i = 0; i < connected; i++) { if (FD_ISSET(client_sockets[i], &selected_set)) { // Got a message from a client, process it actually_read = recv(client_sockets[i], &request, 1, MSG_WAITALL); if (actually_read < 0) { perror("Error reading from client socket, closing socket"); close(client_sockets[i]); remove_from(i, client_sockets, connected); connected--; break; } if (process_request(request, client_sockets[i]) < 1) { close(client_sockets[i]); FD_CLR(client_sockets[i], &waiting_set); } } } } for (i = 0; i < connected; i++) { close(client_sockets[i]); } close(sockd_wait); return EXIT_SUCCESS; }
void slot_manager::remove(input_source* dev) { if (!dev || !dev->out_dev) return; lock.lock(); remove_from(dev->out_dev); lock.unlock(); }
int Interpret(int, char* []) { MockDb db = {}; MockDb::_serializer_context_t printer = {}; const auto f = test::TabFoo{}; const auto t = test::TabBar{}; select(t.alpha.as(t.beta)); serialize(insert_into(t).columns(t.beta, t.gamma), printer).str(); { auto i = insert_into(t).columns(t.gamma, t.beta); i.values.add(t.gamma = true, t.beta = "cheesecake"); serialize(i, printer).str(); i.values.add(t.gamma = false, t.beta = sqlpp::tvin("coffee")); i.values.add(t.gamma = false, t.beta = sqlpp::tvin(std::string())); serialize(i, printer).str(); i.values.add(t.gamma = sqlpp::default_value, t.beta = sqlpp::null); serialize(i, printer).str(); } serialize(t.alpha = sqlpp::null, printer).str(); serialize(t.alpha = sqlpp::default_value, printer).str(); serialize(t.alpha, printer).str(); serialize(-t.alpha, printer).str(); serialize(+t.alpha, printer).str(); serialize(-(t.alpha + 7), printer).str(); serialize(t.alpha = 0, printer).str(); serialize(t.alpha = sqlpp::tvin(0), printer).str(); serialize(t.alpha == 0, printer).str(); serialize(t.alpha == sqlpp::tvin(0), printer).str(); serialize(t.alpha != 0, printer).str(); serialize(t.gamma != sqlpp::tvin(false), printer).str(); serialize(t.alpha == 7, printer).str(); serialize(t.delta = sqlpp::tvin(0), printer).str(); serialize(t.beta + "kaesekuchen", printer).str(); serialize(sqlpp::select(), printer).str(); serialize(sqlpp::select().flags(sqlpp::distinct), printer).str(); serialize(select(t.alpha, t.beta).flags(sqlpp::distinct), printer).str(); serialize(select(t.alpha, t.beta), printer).str(); serialize(select(t.alpha, t.beta).from(t), printer).str(); serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3), printer).str(); serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma), printer).str(); serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")), printer).str(); serialize(select(t.alpha, t.beta) .from(t) .where(t.alpha == 3) .group_by(t.gamma) .having(t.beta.like("%kuchen")) .order_by(t.beta.asc()), printer).str(); serialize(select(t.alpha, t.beta) .from(t) .where(t.alpha == 3) .group_by(t.gamma) .having(t.beta.like("%kuchen")) .order_by(t.beta.asc()) .limit(17) .offset(3), printer).str(); serialize(parameter(sqlpp::bigint(), t.alpha), printer).str(); serialize(parameter(t.alpha), printer).str(); serialize(t.alpha == parameter(t.alpha), printer).str(); serialize(t.alpha == parameter(t.alpha) and (t.beta + "gimmick").like(parameter(t.beta)), printer).str(); serialize(insert_into(t), printer).str(); serialize(insert_into(f).default_values(), printer).str(); serialize(insert_into(t).set(t.gamma = true), printer).str(); // serialize(insert_into(t).set(t.gamma = sqlpp::tvin(false)), printer).str(); cannot test this since gamma cannot be // null and a static assert is thrown serialize(update(t), printer).str(); serialize(update(t).set(t.gamma = true), printer).str(); serialize(update(t).set(t.gamma = true).where(t.beta.in("kaesekuchen", "cheesecake")), printer).str(); serialize(update(t).set(t.gamma = true).where(t.beta.in()), printer).str(); serialize(remove_from(t), printer).str(); serialize(remove_from(t).using_(t), printer).str(); serialize(remove_from(t).where(t.alpha == sqlpp::tvin(0)), printer).str(); serialize(remove_from(t).using_(t).where(t.alpha == sqlpp::tvin(0)), printer).str(); // functions serialize(sqlpp::value(7), printer).str(); serialize(sqlpp::verbatim<sqlpp::integral>("irgendwas integrales"), printer).str(); serialize(sqlpp::value_list(std::vector<int>({1, 2, 3, 4, 5, 6, 8})), printer).str(); serialize(exists(select(t.alpha).from(t)), printer).str(); serialize(any(select(t.alpha).from(t)), printer).str(); serialize(some(select(t.alpha).from(t)), printer).str(); serialize(count(t.alpha), printer).str(); serialize(min(t.alpha), printer).str(); serialize(max(t.alpha), printer).str(); serialize(avg(t.alpha), printer).str(); serialize(sum(t.alpha), printer).str(); serialize(sqlpp::verbatim_table("whatever"), printer).str(); // alias serialize(t.as(t.alpha), printer).str(); serialize(t.as(t.alpha).beta, printer).str(); // select alias serialize(select(t.alpha).from(t).where(t.beta > "kaesekuchen").as(t.gamma), printer).str(); serialize(t.alpha.is_null(), printer).str(); // join serialize(t.inner_join(t.as(t.alpha)).on(t.beta == t.as(t.alpha).beta), printer).str(); { auto inner = t.inner_join(t.as(t.alpha)).on(t.beta == t.as(t.alpha).beta); serialize(select(t.alpha).from(inner), printer).str(); } // multi_column serialize(multi_column(t.alpha, (t.beta + "cake").as(t.gamma)).as(t.alpha), printer).str(); serialize(multi_column(all_of(t)).as(t), printer).str(); serialize(all_of(t).as(t), printer).str(); // dynamic select { auto s = dynamic_select(db).dynamic_flags().dynamic_columns().from(t); s.selected_columns.add(t.beta); s.selected_columns.add(t.gamma); serialize(s, printer).str(); } { auto s = dynamic_select(db).dynamic_flags().dynamic_columns().from(t); s.select_flags.add(sqlpp::distinct); s.selected_columns.add(t.beta); s.selected_columns.add(t.gamma); serialize(s, printer).str(); } { // Behold, dynamically constructed queries might compile but be illegal SQL auto s = dynamic_select(db).dynamic_flags(sqlpp::distinct).dynamic_columns(t.alpha); s.select_flags.add(sqlpp::all); s.selected_columns.add(without_table_check(t.beta)); s.selected_columns.add(without_table_check(t.gamma)); serialize(s, printer).str(); } // distinct aggregate serialize(count(sqlpp::distinct, t.alpha % 7), printer).str(); serialize(avg(sqlpp::distinct, t.alpha - 7), printer).str(); serialize(sum(sqlpp::distinct, t.alpha + 7), printer).str(); serialize(select(all_of(t)).from(t).unconditionally(), printer).str(); for (const auto& row : db(select(all_of(t)).from(t).unconditionally())) { serialize(row.alpha, printer); serialize(row.beta, printer); serialize(row.gamma, printer); } get_sql_name(t); get_sql_name(t.alpha); flatten(t.alpha == 7, db); auto x = boolean_expression(db, t.alpha == 7); x = sqlpp::boolean_expression<MockDb>(t.beta.like("%cheesecake")); x = x and boolean_expression(db, t.gamma); std::cerr << "----------------------------" << std::endl; printer.reset(); std::cerr << serialize(x, printer).str() << std::endl; printer.reset(); std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in(select(f.epsilon).from(f).unconditionally())), printer).str() << std::endl; printer.reset(); std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in()), printer).str() << std::endl; printer.reset(); std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.not_in()), printer).str() << std::endl; auto schema = db.attach("lorem"); auto s = schema_qualified_table(schema, t).as(sqlpp::alias::x); printer.reset(); std::cerr << serialize(select(all_of(s)).from(s).unconditionally(), printer).str() << std::endl; printer.reset(); std::cerr << serialize(sqlpp::case_when(true).then(t.alpha).else_(t.alpha + 1).as(t.beta), printer).str() << std::endl; return 0; }