void SkFontDescriptor::serialize(SkWStream* stream) {
    stream->writePackedUInt(fStyle);

    write_string(stream, fFamilyName, kFontFamilyName);
    write_string(stream, fFullName, kFullName);
    write_string(stream, fPostscriptName, kPostscriptName);
    if (fFontData.get()) {
        if (fFontData->getIndex()) {
            write_uint(stream, fFontData->getIndex(), kFontIndex);
        }
        if (fFontData->getAxisCount()) {
            write_uint(stream, fFontData->getAxisCount(), kFontAxes);
            for (int i = 0; i < fFontData->getAxisCount(); ++i) {
                stream->writePackedUInt(fFontData->getAxis()[i]);
            }
        }
    }

    stream->writePackedUInt(kSentinel);

    if (fFontData.get() && fFontData->hasStream()) {
        SkAutoTDelete<SkStreamAsset> fontData(fFontData->detachStream());
        size_t length = fontData->getLength();
        stream->writePackedUInt(length);
        stream->writeStream(fontData, length);
    } else {
        stream->writePackedUInt(0);
    }
}
Exemplo n.º 2
0
	size_t StartMessage::serialize(unsigned char *write_buffer){
		size_t len = getSize();
		write_uint(write_buffer, 0, &len);
		write_uint(write_buffer, 4, &_msg_type);
		write_uint(write_buffer, 8, &_client_id);
		return len;
	}
Exemplo n.º 3
0
static bool write_range(
    char **string, size_t *length,
    unsigned int start, unsigned int end, bool first)
{
    return
        IF_(!first, write_string(string, length, ","))  &&
        write_uint(string, length, start)  &&
        IF_(end > start,
            write_string(string, length, "-")  &&
            write_uint(string, length, end));
}
Exemplo n.º 4
0
		size_t PerspectiveMessage::serialize(unsigned char *write_buffer) {
			size_t len = getSize();
			write_uint(write_buffer, 0, &len);
			write_uint(write_buffer, 4, &_msg_type);
			write_uint(write_buffer, 8, &_client_id);

			write_float(write_buffer, 12, &_perspective._fov);
			write_float(write_buffer, 16, &_perspective._aspect);
			write_float(write_buffer, 20, &_perspective._near);
			write_float(write_buffer, 24, &_perspective._far);
			return len;
		}
Exemplo n.º 5
0
		size_t TouchEventMessage::serialize(unsigned char *write_buffer) {

			size_t len = getSize();
			write_uint(write_buffer, 0, &len);
			write_uint(write_buffer, 4, &_msg_type);
			write_uint(write_buffer, 8, &_client_id);

			write_uchar(write_buffer, 12, &_touch_event._event_type);
			write_float(write_buffer, 13, &_touch_event._x1);
			write_float(write_buffer, 17, &_touch_event._y1);
			write_float(write_buffer, 21, &_touch_event._x2);
			write_float(write_buffer, 25, &_touch_event._y2);
			return len;
		}
Exemplo n.º 6
0
void lbm_write_state_binary(FILE * handle, const LbmState * lbm_state)
{
	size_t i;

	write_uint(handle, lbm_state->lx);
	write_uint(handle, lbm_state->ly);

	size_t nodes = lbm_state->lx * lbm_state->ly;

	for(i = 0; i < Q; ++i)
		write_n_doubles(handle, lbm_state->f[i], nodes);

	for(i = 0; i < Q; ++i)
		write_n_doubles(handle, lbm_state->f_next[i], nodes);
}
Exemplo n.º 7
0
static inline void		write_format_pos(uintmax_t nbr, t_pfflags *flags,
							char *buff, int *index)
{
	int					n;

	n = init(nbr, flags) - 1;
	if (!FT_BIT_VAL(flags->flg, FTPF_ZERO_PADDING))
		while (++n < flags->nformat)
			buff[++*index] = ' ';
	if ((nbr || FT_BIT_VAL(flags->flg, FTPF_FORCE_PREFIX_)) &&
			FT_BIT_VAL(flags->flg, FTPF_PREFIX))
	{
		if ((flags->base == 8) || (flags->base == 16))
			buff[++*index] = '0';
		else
			write_base(buff, index, flags);
		if (flags->base == 16)
			buff[++*index] =
				(FT_BIT_VAL(flags->flg, FTPF_HEX_UPCASE) ? 'X' : 'x');
	}
	if (FT_BIT_VAL(flags->flg, FTPF_ZERO_PADDING))
		while (++n < flags->nformat)
			buff[++*index] = '0';
	write_uint(nbr, buff, flags, index);
}
Exemplo n.º 8
0
/* Test writing single values of various types to board's global memory.
 * The test passes if we read back what we wrote. */
void test_small_writes  (ssize_t f) {

  unsigned char     uc;
  unsigned short    us;
  unsigned int      ui;
  unsigned long int uli;

  write_uchar     (f, 0, 0, 19);
  uc = read_uchar (f, 0, 0);
  assert (uc == 19);
  
  write_ushort    (f, 0, 0, 13);
  us = read_ushort(f, 0, 0);
  assert (us == 13);

  write_ulong      (f, 0, 0, 0x3037383633352030);
  uli = read_ulong (f, 0, 0);
  assert (uli == 0x3037383633352030);
  
  write_uint     (f, 0, 0, 18987983);
  ui = read_uint (f, 0, 0);
  assert (ui == 18987983);
  
  printf ("test_small_writes PASSED\n");
}
Exemplo n.º 9
0
void MyEeprom::writeUInt (uint16_t l, uint16_t relative_address) {
  if (rotateEeprom == true) {
    write_uint(l, relative_address);
  } else {
    simple_write_uint(l, relative_address);
  }
}
Exemplo n.º 10
0
		size_t CameraMessage::serialize(unsigned char *write_buffer) {
			/*
			  长度,类型,id,内容
			*/
			size_t len = getSize();
			write_uint(write_buffer, 0, &len);
			write_uint(write_buffer, 4, &_msg_type);
			write_uint(write_buffer, 8, &_client_id);

			write_float(write_buffer, 12, &_camera._eyex);
			write_float(write_buffer, 16, &_camera._eyey);
			write_float(write_buffer, 20, &_camera._eyez);

			write_float(write_buffer, 24, &_camera._centerx);
			write_float(write_buffer, 28, &_camera._centery);
			write_float(write_buffer, 32, &_camera._centerz);

			write_float(write_buffer, 36, &_camera._upx);
			write_float(write_buffer, 40, &_camera._upy);
			write_float(write_buffer, 44, &_camera._upz);

			return len;
		}
Exemplo n.º 11
0
int double_correlation_write_data_to_file(const double_correlation* self, const char * filename, bool binary){
  FILE* fp=0;
  fp=fopen(filename, "w");
  if (!fp) {
    return 1;
  }
  for (unsigned int i=0; i<self->hierarchy_depth; i++) {
    for (unsigned int j=0; j<self->tau_lin+1; j++) {
      write_double(fp,self->A[i][j],self->dim_A,binary);
    }
  }
  if (!self->autocorrelation){
    for (unsigned int i=0; i<self->hierarchy_depth; i++) {
      for (unsigned int j=0; j<self->tau_lin+1; j++) {
	write_double(fp,self->B[i][j],self->dim_B,binary);
      }
    } 
  }
  for (unsigned int i=0; i<self->n_result; i++) {
    write_double(fp,self->result[i],self->dim_corr,binary);
  }
  write_uint(fp,self->n_sweeps,self->n_result       ,binary);
  write_uint(fp,self->n_vals  ,self->hierarchy_depth,binary);
  write_uint(fp,self->newest  ,self->hierarchy_depth,binary);
  
  write_double(fp,self->A_accumulated_average ,self->dim_A,binary);
  write_double(fp,self->A_accumulated_variance,self->dim_A,binary);
  if (!self->autocorrelation){
    write_double(fp,self->B_accumulated_average ,self->dim_B,binary);
    write_double(fp,self->B_accumulated_variance,self->dim_B,binary);
  }
  write_uint(fp,&(self->n_data),1,binary);
  write_uint(fp,&(self->t     ),1,binary);
  write_double(fp,&(self->last_update),1,binary);
  fclose(fp);
  return 0;
}
void write(adt_type& tok_str, token tok) {
	if (tok.kind == tk_err) {
		write_str(tok_str, "<error token>");
	} else if (tok.kind == tk_eof) {
		write_str(tok_str, "<end of file>");
	} else if (tok.kind == tk_special) {
		write(tok_str, tok.special_id);
	} else if (tok.kind == tk_uint) {
		write_char(tok_str, '#');
		write_uint(tok_str, tok.uint_val);
	} else {
		fox_assert(tok.kind == tk_name && "invalid token kind");
		write_str(tok_str, tok.str_val);
	}
}
Exemplo n.º 13
0
void
Model::save(std::ostream & ofs) {
  // write a signature into the file
  char chunk[16];
  if (full) {
    strncpy(chunk, SEGMENTOR_MODEL_FULL, 16);
  } else {
    strncpy(chunk, SEGMENTOR_MODEL_MINIMAL, 16);
  }

  ofs.write(chunk, 16);

  if (full) {
    ofs.write(reinterpret_cast<const char *>(&end_time), sizeof(int));
  }

  int off = ofs.tellp();

  unsigned labels_offset    = 0;
  unsigned lexicon_offset   = 0;
  unsigned feature_offset   = 0;
  unsigned parameter_offset   = 0;

  write_uint(ofs, 0); //  the label offset
  write_uint(ofs, 0); //  the internal lexicon offset
  write_uint(ofs, 0); //  the features offset
  write_uint(ofs, 0); //  the parameter offset

  labels_offset = ofs.tellp();
  labels.dump(ofs);

  lexicon_offset = ofs.tellp();
  internal_lexicon.dump(ofs);

  feature_offset = ofs.tellp();
  space.dump(ofs);

  parameter_offset = ofs.tellp();
  param.dump(ofs, full);

  ofs.seekp(off);
  write_uint(ofs, labels_offset);
  write_uint(ofs, lexicon_offset);
  write_uint(ofs, feature_offset);
  write_uint(ofs, parameter_offset);
}
Exemplo n.º 14
0
static void wbSandbox_report(int nr, siginfo_t *info, void *void_context) {
	char buf[128];
	ucontext_t *ctx = (ucontext_t *)(void_context);
	unsigned int syscall;
	if (info->si_code != SYS_SECCOMP)
		return;
	if (!ctx)
		return;
	syscall = ctx->uc_mcontext.gregs[REG_SYSCALL];
	strcpy(buf, msg_needed);
	if (syscall < sizeof(syscall_names)) {
		strcat(buf, syscall_names[syscall]);
		strcat(buf, "(");
	}
	write_uint(buf + strlen(buf), syscall);
	if (syscall < sizeof(syscall_names))
		strcat(buf, ")");
	strcat(buf, "\n");
	size_t w = write(STDOUT_FILENO, buf, strlen(buf));
	exit(1);
}
Exemplo n.º 15
0
void	write_maj_arg(t_env *e, va_list ap)
{
	if (e->type == 's' && e->modificator.m != L)
		write_string(e, ap);
	else if (e->type == 's' && e->modificator.m == L)
		write_wstr(e, ap);
	if (e->type == 'S')
		write_wstr(e, ap);
	else if (e->type == 'D')
	{
		e->modificator.m = L;
		write_int(e, ap);
	}
	else if (e->type == 'O')
		write_octal(e, ap);
	else if (e->type == 'X')
		write_hexam(e, ap);
	else if (e->type == 'U')
		write_uint(e, ap);
	else if (e->type == 'C')
		write_wchar(e, ap);
}
Exemplo n.º 16
0
void	write_min_arg(t_env *e, va_list ap)
{
	if (e->type == 'd')
		write_int(e, ap);
	else if (e->type == 'p')
		write_pointor(e, ap);
	else if (e->type == 'i')
		write_int(e, ap);
	else if (e->type == 'o')
		write_octal(e, ap);
	else if (e->type == 'u')
		write_uint(e, ap);
	else if (e->type == 'x')
		write_hexa(e, ap);
	else if (e->type == 'c')
	{
		if (e->modificator.m == L)
			write_wchar(e, ap);
		else
			write_char(e, ap);
	}
}
Exemplo n.º 17
0
void
Model::save(std::ostream & ofs) {
  // write a signature into the file
  char chunk[16] = {'o','t','n','e','r', '\0'};
  ofs.write(chunk, 16);

  int off = ofs.tellp();

  unsigned labels_offset    = 0;
  unsigned lexicon_offset   = 0;
  unsigned feature_offset   = 0;
  unsigned parameter_offset   = 0;

  write_uint(ofs, 0); //  the label offset
  write_uint(ofs, 0); //  the cluster lexicon offset
  write_uint(ofs, 0); //  the features offset
  write_uint(ofs, 0); //  the parameter offset

  labels_offset = ofs.tellp();
  labels.dump(ofs);

  lexicon_offset = ofs.tellp();
  cluster_lexicon.dump(ofs);

  feature_offset = ofs.tellp();
  space.dump(ofs);

  parameter_offset = ofs.tellp();
  param.dump(ofs);

  ofs.seekp(off);
  write_uint(ofs, labels_offset);
  write_uint(ofs, lexicon_offset);
  write_uint(ofs, feature_offset);
  write_uint(ofs, parameter_offset);
}
Exemplo n.º 18
0
void write_uints(int x, int y){
  write_uint(x);
  putchar_unlocked(' ');
  write_uint(y);
  putchar_unlocked('\n');
}
Exemplo n.º 19
0
void solve(void * args) {
	unsigned int it, iterations;
	char checkpoint_file_name[512];

	// Structs for the parameters
	InputParameters * params = (InputParameters *) args;
	FlowParams flow_params;
	FsiParams fsi_params;
	OutputParams output_params;

	// Parse input parameters
	input_parse_input_params(params, &flow_params, &fsi_params, &output_params);

	// Allocate state structs for the flow and particle
	FlowState * flow_state = flow_alloc_state(flow_params.lx, flow_params.ly);
	ParticleState * particle_state = fsi_alloc_state(fsi_params.nodes);
	LbmState * lbm_state = lbm_alloc_state(flow_params.lx, flow_params.ly);

	// State structs for Lyapunov calculation
	LyapunovState * lya_state = NULL;
	FlowState * lya_flow_state = NULL;
	ParticleState * lya_particle_state = NULL;
	LbmState * lya_lbm_state = NULL;

	// Setup output
	output_init(&output_params);

	// Try to initialize the solution from a checkpoint file
	sprintf(checkpoint_file_name, "%s/checkpoint.dat", output_params.output_folder);
	FILE * cp_handle = fopen(checkpoint_file_name, "r");

	if(cp_handle) {
		// Checkpoint file existed, read the file and initialize the states
		int lya_exists;

		read_uint(cp_handle, &it);
		fsi_read_state_binary(cp_handle, particle_state);
		flow_read_state_unformatted(cp_handle, flow_state);
		lbm_read_state_binary(cp_handle, lbm_state);

		read_uint(cp_handle, &lya_exists);
		if(lya_exists) {
			lya_particle_state = fsi_alloc_state(fsi_params.nodes);
			fsi_read_state_binary(cp_handle, lya_particle_state);
			lya_flow_state = flow_alloc_state(flow_params.lx, flow_params.ly);
			flow_read_state_unformatted(cp_handle, lya_flow_state);
			lya_lbm_state = lbm_alloc_state(flow_params.lx, flow_params.ly);
			lbm_read_state_binary(cp_handle, lya_lbm_state);

			lya_state = malloc(sizeof(LyapunovState));
			read_double(cp_handle, &lya_state->d0);
			read_double(cp_handle, &lya_state->cum_sum);
			read_double(cp_handle, &lya_state->lambda);
			read_uint(cp_handle, &lya_state->t0);
		}

		fclose(cp_handle);
	} else {
		// No checkpoint file, initialize normally

		// Print parameter file
		output_write_parameters_to_file(&output_params, params);

		// Initialize from base state
		it = 0;
		fsi_init_state(&fsi_params, particle_state);
		flow_init_state(&flow_params, flow_state);
		lbm_init_state(flow_state, lbm_state);

		// Print initial state
		output_write_state_to_file(0, &output_params, flow_state, particle_state, lya_state);
	}

	// Number of iterations
	iterations = it + output_params.timesteps;

	// Main loop
	while(it < iterations) {
		// Advance the solution
		it += 1;
		if( ! lbm_ebf_step(it, &flow_params, flow_state, particle_state, lbm_state))
			break;

		// Check if the Lyapunov exponent should be calculated
		if(output_params.print_lyapunov) {
			double d, alpha;

			// Initialize Lyapunov calculation stuff, if not already done
			if( ! lya_state) {
				lya_state = malloc(sizeof(LyapunovState));
				lya_state->d0 = 1.0e-4;
				lya_state->cum_sum = 0;
				lya_state->t0 = it;
				lya_state->lambda = 0;

				// Copy states
				lya_lbm_state = lbm_clone_state(lbm_state);
				lya_flow_state = flow_clone_state(flow_state);
				lya_particle_state = fsi_clone_state(particle_state);

				// Perturb the particle state
				lya_particle_state->angle += lya_state->d0;
				fsi_update_particle_nodes(lya_particle_state);

			} else {
				// Advance the perturbed state
				if( ! lbm_ebf_step(it, &flow_params, lya_flow_state, lya_particle_state, lya_lbm_state))
					break;

				// Calculate the distance between the original and perturbed orbit
				double ang_vel = particle_state->ang_vel / flow_params.G;
				double lya_ang_vel = lya_particle_state->ang_vel / flow_params.G;

				d = pow(lya_particle_state->angle - particle_state->angle, 2) + pow((lya_ang_vel - ang_vel), 2);
				alpha = sqrt(d / pow(lya_state->d0, 2));

				//printf("%.18g %.18g\n", (it - lya_state->t0)*flow_params.f / (2*PI), alpha);

				if(((it - lya_state->t0) % output_params.lyapunov_calc_step) == 0 && it != lya_state->t0) {
					// Push the perturbed orbit towards the base orbit
					lya_particle_state->angle = particle_state->angle + (lya_particle_state->angle - particle_state->angle) / alpha;
					lya_particle_state->ang_vel = flow_params.G * (ang_vel + (lya_ang_vel - ang_vel) / alpha);

					// Update particle node positions and reset the flow and lbm state to that of the base state
					unsigned int i;
					#pragma omp parallel
					{
						fsi_update_particle_nodes(lya_particle_state);
						#pragma omp for
						for(i = 0; i < lya_flow_state->lx*lya_flow_state->ly; ++i) {
							lya_flow_state->u[0][i] = flow_params.u_max * ((flow_state->u[0][i]/flow_params.u_max) +
														((lya_flow_state->u[0][i]/flow_params.u_max) - (flow_state->u[0][i]/flow_params.u_max)) / alpha);
							lya_flow_state->u[1][i] = flow_params.u_max * ((flow_state->u[1][i]/flow_params.u_max) +
														((lya_flow_state->u[1][i]/flow_params.u_max) - (flow_state->u[1][i]/flow_params.u_max)) / alpha);
							lya_flow_state->rho[i] = flow_state->rho[i] + (lya_flow_state->rho[i] - flow_state->rho[i]) / alpha;
						}
						lbm_init_state(lya_flow_state, lya_lbm_state);
					}

					// Update the lyapunov exponent
					lya_state->cum_sum += log(alpha);
					lya_state->lambda = lya_state->cum_sum / (lya_flow_state->G*(it - lya_state->t0));
					printf("%d %.12g\n", it-lya_state->t0, lya_state->lambda);
				}
			}
		}

		// Post process the result
		if((it % output_params.output_step) == 0)
			output_write_state_to_file(it, &output_params, flow_state, particle_state, lya_state);
	}

	// Write a checkpoint file so the simulation can be resumed at later times
	cp_handle = fopen(checkpoint_file_name, "w");
	write_uint(cp_handle, it);
	fsi_write_state_binary(cp_handle, particle_state);
	flow_write_state_unformatted(cp_handle, flow_state);
	lbm_write_state_binary(cp_handle, lbm_state);
	if( ! lya_state) {
		write_uint(cp_handle, 0);
	} else {
		write_uint(cp_handle, 1);
		fsi_write_state_binary(cp_handle, lya_particle_state);
		flow_write_state_unformatted(cp_handle, lya_flow_state);
		lbm_write_state_binary(cp_handle, lya_lbm_state);

		write_double(cp_handle, lya_state->d0);
		write_double(cp_handle, lya_state->cum_sum);
		write_double(cp_handle, lya_state->lambda);
		write_uint(cp_handle, lya_state->t0);
	}
	fclose(cp_handle);

	// Clean up
	output_destroy(&output_params);
	fsi_free_state(particle_state);
	lbm_free_state(lbm_state);
	flow_free_state(flow_state);

	if(lya_state) {
		fsi_free_state(lya_particle_state);
		lbm_free_state(lya_lbm_state);
		flow_free_state(lya_flow_state);
		free(lya_state);
	}
}
Exemplo n.º 20
0
int main(int argc, char const *argv[]) {
  // Usage statements
  if (argc < 2) {
    usage();
    return -1;
  }

  // Option handler
  int option = atoi(argv[1]);
  if (option < 1 || option > 7) {
    usage();
    return -1;
  }

  int res = 0;
  float f1 = -187.33667, f2 = 0.0, f3 = 0.0;
  int i3 = 0;
  uint u3 = 0;

  res = read_float(&f2);
  if (res) return -1;

  switch (option) {
    case 1:
      //fadd
      f3 = f1 + f2;
      res = write_float(&f3);
      break;
    case 2:
      //fsub
      f3 = f1 - f2;
      res = write_float(&f3);
      break;
    case 3:
      //fmul
      f3 = f1 * f2;
      res = write_float(&f3);
      break;
    case 4:
      //fdiv
      f3 = f1 / f2;
      res = write_float(&f3);
      break;
    case 5:
      //fcmp
      f3 = (f1 < f2);
      res = write_float(&f3);
      break;
    case 6:
      //fptosi
      i3 = static_cast<int>(f2);
      res = write_int(&i3);
      break;
    case 7:
      //fptoui
      u3 = static_cast<uint>(f2);
      res = write_uint(&u3);
      break;
    default:
      //ERROR should not happen
      return -1;
      break;
  }
  
  if (res) return -1;

  return 0;
}
Exemplo n.º 21
0
void Model::save(ostream & out) {
  // write a signature
  char chunk[16] = {'l','g','d','p', 'j', 0};
  out.write(chunk, 16);
  unsigned int tmp;

  int off = out.tellp();

  unsigned basic_offset =  0;
  unsigned postag_offset = 0;
  unsigned deprels_offset = 0;
  unsigned feature_offset = 0;
  unsigned parameter_offset = 0;

  // write pseduo position
  write_uint(out, 0); //  basic offset
  write_uint(out, 0); //  postag offset
  write_uint(out, 0); //  deprels offset
  write_uint(out, 0); //  features offset
  write_uint(out, 0); //  parameters offset

  // model and feature information
  // labeled model
  basic_offset = out.tellp();
  tmp = model_opt.labeled;
  write_uint(out, tmp);

  // decode order
  strncpy(chunk, model_opt.decoder_name.c_str(), 16);
  out.write(chunk, 16);

  // use dependency
  tmp = feat_opt.use_dependency;
  write_uint(out, tmp);

  // use dependency unigram
  tmp = feat_opt.use_dependency_unigram;
  write_uint(out, tmp);

  // use dependency bigram
  tmp = feat_opt.use_dependency_bigram;
  write_uint(out, tmp);

  // use dependency surrounding
  tmp = feat_opt.use_dependency_surrounding;
  write_uint(out, tmp);

  // use dependency between
  tmp = feat_opt.use_dependency_between;
  write_uint(out, tmp);

  // use sibling
  tmp = feat_opt.use_sibling;
  write_uint(out, tmp);

  // use sibling basic
  tmp = feat_opt.use_sibling_basic;
  write_uint(out, tmp);

  // use sibling linear
  tmp = feat_opt.use_sibling_linear;
  write_uint(out, tmp);

  // use grand
  tmp = feat_opt.use_grand;
  write_uint(out, tmp);

  // use grand basic
  tmp = feat_opt.use_grand_basic;
  write_uint(out, tmp);

  // use grand linear
  tmp = feat_opt.use_grand_linear;
  write_uint(out, tmp);

  // save postag lexicon
  postag_offset = out.tellp();
  postags.dump(out);

  // save dependency relation lexicon
  deprels_offset = out.tellp();
  deprels.dump(out);

  feature_offset = out.tellp();
  space.save(out);

  parameter_offset = out.tellp();
  param.dump(out);

  out.seekp(off);
  write_uint(out, basic_offset);
  write_uint(out, postag_offset);
  write_uint(out, deprels_offset);
  write_uint(out, feature_offset);
  write_uint(out, parameter_offset);

  // out.seekp(0, std::ios::end);
}