/** set current row **/
    void set_current_row( dom::element& table, dom::element& row, UINT keyboardStates, bool dblClick = false )
    {
      if(is_multiple(table))
      {
		     if (keyboardStates & SHIFT_KEY_PRESSED)
         {
			      checkall(table, false);
				    check_range(table,row.index(),TRUE); // from current to new
         } 
         else 
         {			
				   if (keyboardStates & CONTROL_KEY_PRESSED)
				     set_checked_row (table,row, true); // toggle
           else
             checkall(table, false);
           set_anchor(table,row.index ());
         }
      }

      // get previously selected row:
      dom::element prev = get_current_row( table );
      if( prev.is_valid() )
      {
        if( prev != row ) 
          prev.set_state(0,STATE_CURRENT, false); // drop state flags
      }
      row.set_state(STATE_CURRENT); // set state flags
      row.scroll_to_view();
      ::UpdateWindow(row.get_element_hwnd(false));
      table.post_event( dblClick? TABLE_ROW_DBL_CLICK:TABLE_ROW_CLICK, row.index(), row); 
    }
Exemplo n.º 2
0
	Light::Light(Renderer* renderer, const String& TextureFile, const Color& color)
		: Sprite(renderer, TextureFile)
	{
		set_color(color);
		set_anchor(Point::HALF);
		set_blend_mode(BLEND_MODE_ADD);
		m_need_redraw = true;
	}
Exemplo n.º 3
0
static gpointer
alloc_from_active_or_partial (MonoLockFreeAllocator *heap)
{
	Descriptor *desc;
	Anchor old_anchor, new_anchor;
	gpointer addr;

 retry:
	desc = heap->active;
	if (desc) {
		if (InterlockedCompareExchangePointer ((gpointer * volatile)&heap->active, NULL, desc) != desc)
			goto retry;
	} else {
		desc = heap_get_partial (heap);
		if (!desc)
			return NULL;
	}

	/* Now we own the desc. */

	do {
		unsigned int next;

		new_anchor = old_anchor = (Anchor)*(volatile gint32*)&desc->anchor.value;
		if (old_anchor.data.state == STATE_EMPTY) {
			/* We must free it because we own it. */
			desc_retire (desc);
			goto retry;
		}
		g_assert (old_anchor.data.state == STATE_PARTIAL);
		g_assert (old_anchor.data.count > 0);

		addr = (char*)desc->sb + old_anchor.data.avail * desc->slot_size;

		mono_memory_read_barrier ();

		next = *(unsigned int*)addr;
		g_assert (next < SB_USABLE_SIZE / desc->slot_size);

		new_anchor.data.avail = next;
		--new_anchor.data.count;

		if (new_anchor.data.count == 0)
			new_anchor.data.state = STATE_FULL;
	} while (!set_anchor (desc, old_anchor, new_anchor));

	/* If the desc is partial we have to give it back. */
	if (new_anchor.data.state == STATE_PARTIAL) {
		if (InterlockedCompareExchangePointer ((gpointer * volatile)&heap->active, desc, NULL) != NULL)
			heap_put_partial (desc);
	}

	return addr;
}
Exemplo n.º 4
0
void
mono_lock_free_free (gpointer ptr, size_t block_size)
{
	Anchor old_anchor, new_anchor;
	Descriptor *desc;
	gpointer sb;
	MonoLockFreeAllocator *heap = NULL;

	desc = *(Descriptor**) sb_header_for_addr (ptr, block_size);
	g_assert (block_size == desc->block_size);

	sb = desc->sb;

	do {
		new_anchor = old_anchor = *(volatile Anchor*)&desc->anchor.value;
		*(unsigned int*)ptr = old_anchor.data.avail;
		new_anchor.data.avail = ((char*)ptr - (char*)sb) / desc->slot_size;
		g_assert (new_anchor.data.avail < LOCK_FREE_ALLOC_SB_USABLE_SIZE (block_size) / desc->slot_size);

		if (old_anchor.data.state == STATE_FULL)
			new_anchor.data.state = STATE_PARTIAL;

		if (++new_anchor.data.count == desc->max_count) {
			heap = desc->heap;
			new_anchor.data.state = STATE_EMPTY;
		}
	} while (!set_anchor (desc, old_anchor, new_anchor));

	if (new_anchor.data.state == STATE_EMPTY) {
		g_assert (old_anchor.data.state != STATE_EMPTY);

		if (InterlockedCompareExchangePointer ((gpointer * volatile)&heap->active, NULL, desc) == desc) {
			/* We own it, so we free it. */
			desc_retire (desc);
		} else {
			/*
			 * Somebody else must free it, so we do some
			 * freeing for others.
			 */
			list_remove_empty_desc (heap->sc);
		}
	} else if (old_anchor.data.state == STATE_FULL) {
		/*
		 * Nobody owned it, now we do, so we need to give it
		 * back.
		 */

		g_assert (new_anchor.data.state == STATE_PARTIAL);

		if (InterlockedCompareExchangePointer ((gpointer * volatile)&desc->heap->active, desc, NULL) != NULL)
			heap_put_partial (desc);
	}
}
    /** set current row **/
    void set_current_row( dom::element& table, dom::element& row, UINT keyboardStates, bool dblClick = false, bool smooth = false )
    {
      // get previously selected row:
      dom::element prev = get_current_row( table );

      uint new_row_checked = STATE_CHECKED;
      uint old_row_checked = STATE_CHECKED;

      if(is_multiple(table))
      {
         if (keyboardStates & SHIFT_KEY_PRESSED)
         {
            checkall(table, false);
            check_range(table,row.index(),TRUE); // from current to new
         } 
         else 
         {      
           if (keyboardStates & CONTROL_KEY_PRESSED)
           {
             set_checked_row (table,row, true); // toggle
             new_row_checked = 0;
           }
           else
             checkall(table, false);
           set_anchor(table,row.index ());
         }
         old_row_checked = 0;
      }
      
      if( prev.is_valid() )
      {
        if( prev != row ) 
          prev.set_state(0,STATE_CURRENT | old_row_checked); // drop state flags
      }
      row.set_state(STATE_CURRENT | new_row_checked); // set state flags
      row.scroll_to_view(false,smooth);
      //::UpdateWindow(row.get_element_hwnd(false));
      table.post_event( dblClick? TABLE_ROW_DBL_CLICK:TABLE_ROW_CLICK, row.index(), row); 
      table.post_event(WY_GRID_VERTICAL_SCROLL, 0);
    }
Exemplo n.º 6
0
void Tagger::Init(int argc, char * argv[])
{

	setlocale(LC_CTYPE, "iso_8858_1");
#ifdef SpecialMalloc
	/* Force fast allocation */
	set_small_allocation(100);
#endif

	/* Clear data structures */
	InitDict(dict);
	InitDict(skip_dict);
	InitTrans(trans);
	InitTrans(c_newtrans);
	odictfile = otranfile = NULL;

	/* Verify command line */
	if (argc <= 2)
	  error_exit("Usage: label corpus options\n");

	/* Form options */
	InitOptions;

	set_up_options(argc, argv, &iterations, &initialise, &dict_size,
				dictname, tranname, odictname, otranname, outname, mapname,
				skipname, reducename, fsmname, grammarname, infername, ukwname,
				ofeaturesname, obadwordname, bdbmname, runkstatname, wunkstatname);

	any_output = !no_output || Option(report_stats) || OutOpt(prob_dist);


	/* Open BDBM dictionary */
	if (Option(bdbm)){
		/* Berkeley DB: first of all need to create the dbp data structure*/
		if((ret = db_create(&dbp, NULL, 0)) != 0) {
			fprintf(stderr, "db_create: %s\n", db_strerror(ret));
			exit (1);
		}
		/* Berkeley DB: Then you open it, readonly  */
		if((ret = dbp->open(dbp,bdbmname, NULL, DB_BTREE, DB_RDONLY, 0777)) != 0) {
			dbp->err(dbp, ret, "%s", bdbmname);
			exit(1);
		} 
	}

	/* Read mappings */
	if (Option(verbose)) printf("Read mappings\n");
	read_mapping(mapname);

	/* Read tag reduction mappings */
	if (Option(reduced_tags))
	{
		if (Option(verbose)) printf("Read reduced tag set\n");
		read_reduce_mapping(reducename);
	}

#ifdef Use_Parser
	/* Read parse rules */
	if (Option(use_parser))
	{
		if (Option(verbose)) printf("Read parse rules\n");
		parser_read_named(grammarname);
	}
#endif
#ifdef Use_FSM
	/* Read FSM definitions */
	if (Option(use_fsm))
	{
		if (Option(verbose)) printf("Read FSMs\n");
		fsm_read_named(fsmname);
	}
#endif

	/* Read skip list */
	if (Option(skip_list))
	{
		if (Option(verbose)) printf("Read skip list\n");
		read_named_dict(skipname, &skip_dict, -1);
	}

	/* Read unknown word rules */
	if (Option(unknown_rules))
	{
		if (Option(verbose)) printf("Read unknown word rules\n");
		read_unknown_rules(ukwname);
	}

	/* Set up dictionary [note]:it costs a few seconds*/
	if (dictname[0] == 0)
	{
		create_dict(&dict, dict_size);
		clear_dict(&dict);
	}
	else
	{
		if (Option(verbose)) printf("Read dictionary\n");
		read_named_dict(dictname, &dict, -1);
		if (infername[0] != 0)
		{
			if (Option(verbose)) printf("Read inference rules\n");
			infer_tags((char *)infername, &dict);

		}
	}

	/* Set up transitions [note] it costs a few seconds*/
	if (tranname[0] == 0)
	{
		create_trans(&trans, tags_all);
		clear_trans_all(&trans);
	}
	else
	{
		if (Option(verbose)) printf("Read transitions\n");
		read_named_ascii_trans(tranname, &trans);

		/* Analyze selected features of lexicon to generate tag probabilities for unknown words. */
		if ( Option(unknown_morph) || Option(unknown_rules))
		{
			/* Initialize feature values */

			Allocate(features->featuretags, sizeof(FeatureTagSt), "features->featuretags: main");
			features->featuretags->next_open_slot = 0;

			features->gamma = trans.gamma;

			if ( features->maxsuffix == 0 )
			  features->maxsuffix = MinSuffixLen;
			if ( features->maxunkwords == 0 )
			  features->maxunkwords = MAXUNKWORDS;
			if ( features->maxprefcut == 0 )
			  features->maxprefcut = MinPrefixLen;
			if ( features->maxsuffcut == 0 )
			  features->maxsuffcut = MinSuffixLen;

			unknown_word_handling_initialization();
			gather_unigram_freqs( &dict );
		}

		if ( Option(unknown_morph) )
		{
			analyze_features( &dict, ofeaturesname, obadwordname, &trans, dbp, &dict, runkstatname );
		}
	}

	set_special_words(&dict, features );

	/* Create space for re-estimation or training */
	if (Option(reestimate) || Option(training))
	{
		c_newtrans.gamma = trans.gamma; /* Share arrays */
		create_trans(&c_newtrans, tags_all);
	}

	if (odictname[0] != 0)
	  odictfile = open_file(odictname, "w");
	if (otranname[0] != 0)
	  otranfile = open_file(otranname, "w");

	/* Set up anchor word */
	set_anchor(&dict);

	adjust_dict(&dict, trans.gamma, FALSE);
	adjust_trans(&trans, NULL);
}
Exemplo n.º 7
0
command(TableUI *tui, int cmd) {

    switch (cmd) {
    
    case CmdClearFile: clear_file(tui); break;
    case CmdOpenFile:
        clear_and_open(tui, tui->filename);
        if (row_count(tui->table) < MAX_ROWS_FOR_FIT
         && max_col_count(tui->table) < MAX_COLS_FOR_FIT) {
            unsigned i;
            for (i = 0; i < max_col_count(tui->table); i++)
                auto_resize_col(tui, i);
        }
        break;
    case CmdSaveFile: save_csv(tui, tui->filename); break;
    
    case CmdSetAnchor: set_anchor(tui); break;
    case CmdClearAnchor: clear_anchor(tui); break;
    
    case CmdClearRow: clear_selected_rows(tui); break;
    case CmdDeleteRow: delete_selected_rows(tui); break;
    case CmdDeleteCell: delete_selected_cells(tui); break;
    case CmdClearCell: clear_selected_cells(tui); break;
    
    case CmdCopy: copy_to_clipboard(tui); break;
    case CmdCutClear: copy_to_clipboard(tui); clear_selected_cells(tui); break;
    case CmdCutDelete: copy_to_clipboard(tui); delete_selected_cells(tui); break;
    case CmdPaste: clear_anchor(tui); paste_clipboard(tui); break;
    
    case CmdReturn: clear_anchor(tui); move_cursor(tui, 1, 0); break;
    case CmdTab: clear_anchor(tui); move_cursor(tui, 0, 1); break;
    case CmdUnReturn: clear_anchor(tui); move_cursor(tui, -1, 0); break;
    case CmdUnTab: clear_anchor(tui); move_cursor(tui, 0, -1); break;
    
    case CmdEditCell: start_edit(tui, 1); break;
    case CmdEditCellClear: start_edit(tui, 0); break;
    case CmdCommitEdit: end_edit(tui); break;
    case CmdCancelEdit: cancel_edit(tui); break;
    
    case CmdMoveUp: move_cursor(tui, -1, 0); break;
    case CmdMoveDown: move_cursor(tui, 1, 0); break;
    case CmdMoveLeft: move_cursor(tui, 0, -1); break;
    case CmdMoveRight: move_cursor(tui, 0, 1); break;
    
    case CmdScrollUp: scroll(tui, -1, 0); break;
    case CmdScrollDown: scroll(tui, 1, 0); break;
    case CmdScrollLeft: scroll(tui, 0, -1); break;
    case CmdScrollRight: scroll(tui, 0, 1); break;
    
    case CmdHomeCol: jump_cursor(tui, 0, tui->cur_col); break;
    case CmdHomeRow: jump_cursor(tui, tui->cur_row, 0); break;
    case CmdEndCol: jump_cursor(tui, row_count(tui->table) - 1, tui->cur_col); break;
    case CmdEndRow: jump_cursor(tui, tui->cur_row, col_count(tui->table, tui->cur_row) - 1); break;
    
    case CmdInsertDate: insert_datetime(tui, 0); break;
    case CmdInsertDateTime: insert_datetime(tui, 1); break;
    
    case CmdInsertCell:
        insert_cells(tui->table, tui->cur_row, tui->cur_col, 1);
        redraw_rows(tui, tui->cur_row, tui->cur_row);
        break;
    case CmdInsertRow:
        insert_rows(tui->table, tui->cur_row, 1);
        redraw_rows(tui, tui->cur_row, -1);
        break;
    
    case CmdFindColumn:
        find_cell_text_col(tui, tui->cur_row, tui->cur_col, tui->find_text);
        break;
        
    case CmdFindRow:
        find_cell_text_row(tui, tui->cur_row, tui->cur_col, tui->find_text);
        break;
    
    }

}
Exemplo n.º 8
0
	bool shape_record_factory(bit_stream_ptr bits, int version, unsigned& fill_bits, unsigned& line_bits, std::vector<shape_record_ptr>* records)
	{
		bool edge_record = bits->read_unsigned_bits(1) ? true : false;
		unsigned flags = unsigned(bits->read_unsigned_bits(5));
		if(flags == 0) {
			bits->force_byte_align();
			return false;
		}
		if(edge_record) {
			if(flags & 16) {
				// straight
				auto srp = std::make_shared<shape_record>(ShapeRecordTypes::LINE);
				unsigned num_bits = (flags & 0x0f) + 2;
				bool general_line = bits->read_unsigned_bits(1) ? true : false;
				delta_record dr;
				if(general_line) {
					dr.delta_x = int32_t(bits->read_unsigned_bits(num_bits));
					dr.delta_y = int32_t(bits->read_unsigned_bits(num_bits));
				} else {
					bool vertical_line = bits->read_unsigned_bits(1) ? true : false;
					if(vertical_line) {
						dr.delta_x = int32_t(bits->read_signed_bits(num_bits));
						dr.delta_y = 0;
					} else {
						dr.delta_x = 0;
						dr.delta_y = int32_t(bits->read_signed_bits(num_bits));
					}
				}
				srp->set_delta(dr);
				records->emplace_back(srp);
				return true;
			} else {
				auto cer = std::make_shared<curve_edge_record>();
				unsigned num_bits = (flags & 0x0f) + 2;
				delta_record dr;
				dr.delta_x = int32_t(bits->read_signed_bits(num_bits));
				dr.delta_y = int32_t(bits->read_signed_bits(num_bits));
				cer->set_control(dr);
				dr.delta_x = int32_t(bits->read_signed_bits(num_bits));
				dr.delta_y = int32_t(bits->read_signed_bits(num_bits));
				cer->set_anchor(dr);
				records->emplace_back(cer);
				return true;
			}
		} else {
			if(flags & 1) {
				std::shared_ptr<move_record> mrp = std::make_shared<move_record>();
				delta_record moves;
				unsigned move_bits = unsigned(bits->read_unsigned_bits(5));
				moves.delta_x = int32_t(bits->read_signed_bits(move_bits));
				moves.delta_y = int32_t(bits->read_signed_bits(move_bits));
				mrp->set_delta(moves);
				records->emplace_back(mrp);
			}
			if(flags & (2|4|8|16)) {
				std::shared_ptr<style_change_record> srp = std::make_shared<style_change_record>();
				if(flags & 2) {
					srp->set_fillstyle0_index(bits->read_unsigned_bits(fill_bits));
				}
				if(flags & 4) {
					srp->set_fillstyle1_index(bits->read_unsigned_bits(fill_bits));
				}
				if(flags & 8) {
					srp->set_linestyle_index(bits->read_unsigned_bits(line_bits));
				}
				if(flags & 16) {
					styles ss;
					ss.fill_styles_ = bits->read_fillstyle_array(version);
					ss.line_styles_ = bits->read_linestyle_array(version);
					fill_bits = ss.fill_bits_ = bits->read_unsigned_bits(4);
					line_bits = ss.line_bits_ = bits->read_unsigned_bits(4);
					srp->set_styles(ss);
				}
				records->emplace_back(srp);
			}
			return true;
		}
	}