void rectangle_set_border_color_html(rectangle_t * const obj, const char* html_color_code) { PTR_CHECK(obj, "rectangle"); obj->border_color = color_html(html_color_code); obj->has_border = true; }
void rectangle_set_border_tickness(rectangle_t * const obj, dim_t tickness) { PTR_CHECK(obj, "rectangle"); obj->border_tickness = tickness; obj->has_border = true; }
void rectangle_set_fill_color_html(rectangle_t * const obj, const char *html_color_code) { PTR_CHECK(obj, "rectangle"); obj->fill_color = color_html(html_color_code); obj->is_filled = true; }
void signal2_delete(signal2_t * obj) { PTR_CHECK(obj, "signal2"); stack_delete(obj->slot2s_stack); free(obj); }
void rectangle_delete(rectangle_t * const obj) { PTR_CHECK(obj, "rectangle"); my_log_delete(obj->log); widget_delete_instance_only(obj->glyph); free(obj); }
static void signal2_connect(signal2_t *obj, slot2_t *slot2) { PTR_CHECK(obj, "signal2"); if (signal2_is_connected(obj, slot2)) return; stack_add(obj->slot2s_stack, (BUFFER_PTR)&slot2); }
void ring_fifo_zerocopy_push_finish(ring_fifo_t * cobj) { struct s_ring_fifo_private * obj = (struct s_ring_fifo_private *)cobj; PTR_CHECK(obj, "ring_fifo"); if (!obj->nocp_push_started) return; obj->wr++; obj->nocp_push_started = false; }
void my_string_delete(my_string_t *obj) { PTR_CHECK(obj, "my_string"); if (obj->str_data) free(obj->str_data); signal_delete(obj->update_signal); free(obj); }
void slot2_set(slot2_t *obj, slot2_func function, slot_arg arg) { PTR_CHECK(obj, "slot2"); if (!function) { LOG_ERROR("slot2", "bad slot2 function"); return; } obj->func = function; obj->arg0 = arg; obj->set = true; }
void ring_fifo_deinit(ring_fifo_t *cobj) { struct s_ring_fifo_private * obj = (struct s_ring_fifo_private *)cobj; PTR_CHECK(obj, "ring_fifo"); obj->buffer = NULL; obj->client_buffer = NULL; #ifdef CHELPER_ALLOW_MALLOC if (obj->own_buffer) { free (obj->own_buffer); obj->own_buffer = NULL; } #endif }
void signal2_emit(signal2_t *obj, size_t x, size_t y) { uint32_t n_of_slot2s; slot2_t *slot2_to_be_called = NULL; PTR_CHECK(obj, "signal2"); n_of_slot2s = stack_size(obj->slot2s_stack); while(n_of_slot2s--) { stack_get(obj->slot2s_stack, (BUFFER_PTR)&slot2_to_be_called, n_of_slot2s); slot2_call(slot2_to_be_called, x, y); } }
static void slot2_call(slot2_t *obj, size_t x, size_t y) { PTR_CHECK(obj, "slot2"); if (!obj->set) { LOG_ERROR("slot2", "no slot2 function set"); return; } if (!obj->func) { LOG_ERROR("slot2", "bad slot2 function"); return; } obj->func(obj->arg0, x, y); }
void ring_fifo_init(ring_fifo_t * cobj, size_t element_size, int32_t num_of_elements) { struct s_ring_fifo_private * obj = (struct s_ring_fifo_private *)cobj; PTR_CHECK(obj, "ring_fifo"); obj->own_buffer = (BUFFER_PTR)malloc(element_size * num_of_elements); obj->num_fifo_slots = num_of_elements; obj->client_buffer = NULL; obj->buffer = obj->own_buffer; obj->element_size = element_size; obj->rd = 0; obj->wr = 0; obj->nocp_pop_started = false; obj->nocp_push_started = false; }
void ring_fifo_init_buffer(ring_fifo_t * cobj, BUFFER_PTR buffer, size_t buffer_size, size_t element_size) { size_t num_of_elements; struct s_ring_fifo_private * obj = (struct s_ring_fifo_private *)cobj; PTR_CHECK(obj, "ring_fifo"); num_of_elements = buffer_size / element_size; obj->num_fifo_slots = num_of_elements; obj->own_buffer = NULL; obj->client_buffer = buffer; obj->buffer = obj->client_buffer; obj->element_size = element_size; obj->rd = 0; obj->wr = 0; obj->nocp_pop_started = false; obj->nocp_push_started = false; }
static void draw(rectangle_t * obj, const area_t * limiting_canvas_area) { dim_t least_dim;; PTR_CHECK(obj, "rectangle"); if (!ready_to_draw(obj)) { my_log(ERROR, __FILE__, __LINE__, "Object not initialized properly, can't draw.", obj->log); return; } if (bad_corner_radius(obj)) { my_log(WARNING, __FILE__, __LINE__, "Bad corner radius. Radius has been reduced.", obj->log); least_dim = get_smaller( widget_area(obj->glyph)->width, widget_area(obj->glyph)->height); obj->corner_radius = least_dim / 2; } decode_and_draw(obj, limiting_canvas_area); }
void slot2_delete(slot2_t * obj) { PTR_CHECK(obj, "slot2"); free(obj); }
void slot2_connect(slot2_t *obj, signal2_t* signal2) { PTR_CHECK(obj, "slot2"); signal2_connect(signal2, obj); }
void my_string_clear(my_string_t * obj) { PTR_CHECK(obj, "my_string"); _clear(obj); }
void rectangle_set_size(rectangle_t * const obj, dim_t width, dim_t height) { PTR_CHECK(obj, "rectangle"); widget_set_dim(obj->glyph, width, height); }
#include "core/var.h" #include "core/signal.h" std::string points_move_ops_test_str_1 = R"({ "content" : [ )" R"({ "type" : "start_of_line", "name" : "A" }, )" R"({ "type" : "points", "name" : "P1" }, )" R"({ "type" : "end_of_line", "name" : "B" }, )" R"({ "type" : "end_of_line", "name" : "C", "connect" : { "to" : "P1" } } )" "] }"; TEST_CASE( "track/ops/points/movement", "Test basic points movement future" ) { test_fixture_world_init_checked env(points_move_ops_test_str_1); points *p1; auto setup = [&]() { p1 = PTR_CHECK(env.w->FindTrackByNameCast<points>("P1")); }; auto test = [&](std::function<void()> RoundTrip) { env.w->SubmitAction(action_points_action(*(env.w), *p1, 0, generic_points::PTF::REV, generic_points::PTF::REV)); RoundTrip(); REQUIRE(p1->GetPointsFlags(0) == generic_points::PTF::ZERO); env.w->GameStep(500); RoundTrip(); REQUIRE(p1->GetPointsFlags(0) == (generic_points::PTF::REV | generic_points::PTF::OOC)); env.w->GameStep(4500); RoundTrip(); REQUIRE(p1->GetPointsFlags(0) == generic_points::PTF::REV); env.w->SubmitAction(action_points_action(*(env.w), *p1, 0, generic_points::PTF::LOCKED, generic_points::PTF::LOCKED));
// Vyber retezce : zpracovani [ num/id/() : num/id/() ] EOL // String / id je j*z nacteny int expr_string(T_Var **num1 , T_Var **num2) { // [ -------cekam cislo nebo : lex_rc = GetToken(&token); TOKEN_CHECK; if ((lex_rc == NID_NUMBER) || (lex_rc == TOKEN_IDENTIFICATOR)) { //1. NUMBER if (lex_rc == NID_NUMBER) { *num1 = malloc(sizeof(T_Var)); PTR_CHECK(*num1); CDoubleToT_Var(atof(token.data), *num1); if (debug)printf("%f" , (*num1)->vals.d_val); } //2. IDENTIFIKATOR if (lex_rc == TOKEN_IDENTIFICATOR) { if (T_HTableExport(id_table, token.data, num1) == HASH_NOT_FOUND) { if (errno == 0) errno = SYNTACTIC_ERROR; if (debug)printf("non exist id"); return EXIT_FAILURE; } } //------------------------------------------------------------------ //COMA PO CISLE NEBO ID lex_rc = GetToken(&token); TOKEN_CHECK; if (debug) printf("-----%s----", token.data); if (lex_rc != TOKEN_COLUMN) { if (errno == 0) errno = SYNTACTIC_ERROR; if (debug)printf("cekam colum1"); return EXIT_FAILURE; } } //colum PO HRANATE ZAVORCE else if (lex_rc == TOKEN_COLUMN) { *num1 = NULL; if (debug) printf("prazdno"); } else { if (errno == 0) errno = SYNTACTIC_ERROR; if (debug) printf("cekam colum2"); return EXIT_FAILURE; } //------------------------------------------------------------------ lex_rc = GetToken(&token); TOKEN_CHECK; if ((lex_rc == NID_NUMBER) || (lex_rc == TOKEN_IDENTIFICATOR)) { //1. NUMBER 2 if (lex_rc == NID_NUMBER) { *num2 = malloc(sizeof(T_Var)); PTR_CHECK(*num2); CDoubleToT_Var(atof(token.data), *num2); if (debug) printf("%f" , (*num2)->vals.d_val); } //2. IDENTIFIKATOR 2 if (lex_rc == TOKEN_IDENTIFICATOR) { if (T_HTableExport(id_table, token.data, &(*num2)) == HASH_NOT_FOUND) { if (errno == 0) errno = SYNTACTIC_ERROR; if (debug) printf("non exist id"); return EXIT_FAILURE;} } // hranata po cisle nebo id lex_rc = GetToken(&token); TOKEN_CHECK; if (lex_rc != TOKEN_RSBRACKET) { if (errno == 0) errno = SYNTACTIC_ERROR; if (debug) printf("cekam hranata"); return EXIT_FAILURE; } } else if (lex_rc == TOKEN_RSBRACKET) {*num2 = NULL; if (debug) printf("prazdno2");} else { if (errno == 0) errno = SYNTACTIC_ERROR; if (debug) printf("cekam hranata"); return EXIT_FAILURE; } lex_rc=GetToken(&token); if ((lex_rc == TOKEN_EOL) || (lex_rc == TOKEN_EOF)) if (debug) printf(" %d ", lex_rc); else { if (errno == 0) errno = SYNTACTIC_ERROR; if (debug) printf("neni EOL"); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int stat(int mode) { DEBUG_STAT; if (lex_rc == TOKEN_EOL) return EXIT_SUCCESS; if (lex_rc == TOKEN_IDENTIFICATOR) { if (T_HTableSearch(kw_table, token.data) != NULL) { // Keyword DEBUG_STAT_KEYWORD; return keyword(mode); } if (T_HTableSearch(builtin_table, token.data) != NULL) return CallBuiltin(); int htable_rc = T_HTableExport(id_table, token.data, &write_var); if (htable_rc == HASH_FOUND && write_var->NID == NID_FUNCTION) { // Known function DEBUG_STAT_FUNCTION; CALL_CHECK(CallFunction()); DEBUG_STAT_END; return EXIT_SUCCESS; } else { // Variable DEBUG_STAT_VAR; if (htable_rc == HASH_NOT_FOUND) { // Variable doesn't exist, create it as undefined and save into table T_Var *tmp_var = malloc(sizeof(T_Var)); PTR_CHECK(tmp_var); T_VarInit(tmp_var); if (T_HTableInsert(id_table, token.data, tmp_var) == EXIT_FAILURE) { free(tmp_var); return EXIT_FAILURE; } free(tmp_var); } // Assign write_var pointer to newly created variable if (T_HTableExport(id_table, token.data, &write_var) == HASH_NOT_FOUND) { errno = INTERNAL_ERROR; return EXIT_FAILURE; } // Next expected token is assignment character lex_rc = GetToken(&token); TOKEN_CHECK; if (lex_rc == TOKEN_ASSIGN) { CALL_CHECK(expr()); // write_var points to variable from the table, read_var points to the expression result GenerateInstruction(IID_COPY, write_var, read_var, NULL); DEBUG_STAT_END; return EXIT_SUCCESS; } } } errno = SYNTACTIC_ERROR; return EXIT_FAILURE; }
int CallFunction() { // Saves a name of called function, currently located in token T_String f_name; T_StringInit(&f_name); T_StringCopy(&f_name, &token); // Opening bracket must follow lex_rc = GetToken(&token); TOKEN_CHECK; if (lex_rc == TOKEN_LBRACKET) { T_HashTable *tmp_table = malloc(sizeof(T_HashTable)); T_Var *f_var = malloc(sizeof(T_Var)); if (tmp_table == NULL || f_var == NULL) { free(tmp_table); free(f_var); errno = INTERNAL_ERROR; return EXIT_FAILURE; } T_HTableInit(tmp_table); T_VarInit(f_var); // Adds current id_table to table list and change its pointer T_IdListAppend(table_list, id_table); id_table = tmp_table; T_Var *var = malloc(sizeof(T_Var)); PTR_CHECK(var); T_VarInit(var); var->NID = NID_CONST; char *reserved[] = {"as", "def", "directive", "export", "from", "import", "launch", "load", "macro", "input", "print", "numeric", "typeOf", "len", ""}; T_HTableInit(id_table); for (int i = 0; strcmp(reserved[i], "") != 0; i++) T_HTableInsert(id_table, reserved[i], var); free(var); // Gets all function parameters into hash table if (write_var->vals.args.size > 0) { lex_rc = GetToken(&token); TOKEN_CHECK; CALL_CHECK(item()); CALL_CHECK(T_HTableInsert(id_table, write_var->vals.args.first->data.data, read_var)); CALL_CHECK(it_list(write_var->vals.args.first->next)); } else { lex_rc = GetToken(&token); TOKEN_CHECK; if (lex_rc != TOKEN_RBRACKET) { errno = SYNTACTIC_ERROR; return EXIT_FAILURE; } } // Calls the function with the saved name T_StringToT_Var(&f_name, f_var); GenerateInstruction(IID_JUMP, f_var, NULL, NULL); // Generates a lable as a return point GenerateVariable(TRUE, &write_var); GenerateInstruction(IID_LABEL, write_var, NULL, NULL); T_LabelListAppend(cal_list, inst_list->last); free(f_var); return EXIT_SUCCESS; } errno = SYNTACTIC_ERROR; return EXIT_FAILURE; }
void rectangle_set_rounded_corner_radius(rectangle_t * const obj, dim_t radius) { PTR_CHECK(obj, "rectangle"); obj->corner_radius = radius; }
void rectangle_set_position(rectangle_t * const obj, dim_t x, dim_t y) { PTR_CHECK(obj, "rectangle"); widget_set_pos(obj->glyph, x, y); }