Exemplo n.º 1
0
NT2_TEST_CASE_TPL( of_size, NT2_TYPES)
{
  typedef std::complex<T> cT;
  nt2::table<cT> in, ref, out;

  in  = nt2::rif(nt2::of_size(1), nt2::meta::as_<cT>());
  ref = nt2::ones(nt2::of_size(3), nt2::meta::as_<cT>());
  out = expand_to(in, nt2::of_size(3));
  NT2_TEST_EQUAL(out,ref);
  out = expand_to(cT(1), nt2::of_size(3));
  NT2_TEST_EQUAL(out,ref);

  in  = nt2::rif(nt2::of_size(3,1), nt2::meta::as_<cT>());
  ref = nt2::rif(nt2::of_size(3, 4), nt2::meta::as_<cT>());
  out = expand_to(in, nt2::of_size(3, 4));
  NT2_TEST_EQUAL(out,ref);

  in  = nt2::cif(nt2::of_size(1,4), nt2::meta::as_<cT>());
  ref = nt2::cif(nt2::of_size(3, 4), nt2::meta::as_<cT>());
  out = expand_to(in, nt2::of_size(3, 4));
  NT2_TEST_EQUAL(out,ref);

  in  = nt2::cif(nt2::of_size(1,2,1), nt2::meta::as_<cT>());
  ref = nt2::cif(nt2::of_size(3,2,3), nt2::meta::as_<cT>());
  out = expand_to(in, nt2::of_size(3, 2,3));
  NT2_TEST_EQUAL(out,ref);
}
Exemplo n.º 2
0
NT2_TEST_CASE_TPL( of_size, NT2_TYPES)
{
    nt2::table<T> in, ref, out;

    in  = nt2::rif(nt2::of_size(1), nt2::meta::as_<T>());
    ref = nt2::ones(nt2::of_size(3), nt2::meta::as_<T>());
    out = expand_to(in, nt2::of_size(3));
    NT2_TEST_EQUAL(out,ref);
    out = expand_to(T(1), nt2::of_size(3));
    NT2_TEST_EQUAL(out,ref);

    in  = nt2::rif(nt2::of_size(3,1), nt2::meta::as_<T>());
    ref = nt2::rif(nt2::of_size(3, 4), nt2::meta::as_<T>());
    out = expand_to(in, nt2::of_size(3, 4));
    NT2_TEST_EQUAL(out,ref);

    in  = nt2::cif(nt2::of_size(1,4), nt2::meta::as_<T>());
    ref = nt2::cif(nt2::of_size(3, 4), nt2::meta::as_<T>());
    out = expand_to(in, nt2::of_size(3, 4));
    NT2_TEST_EQUAL(out,ref);

    in  = nt2::cif(nt2::of_size(1,2,1), nt2::meta::as_<T>());
    ref = nt2::cif(nt2::of_size(3,2,3), nt2::meta::as_<T>());
    out = expand_to(in, nt2::of_size(3, 2,3));
    NT2_TEST_EQUAL(out,ref);
}
Exemplo n.º 3
0
static int
found_exit(char *keybuf, int hx, int cc)
{				/* return true if the user wants to exit */
    int j;
    char *s;

    if (scan_mode) {
	if (*keybuf == '\0') {
	    return TRUE;
	}
    } else {
	int k;

	/* break is a special case */
	if (*keybuf == '\0') {
	    fresh_line();
	    tty_set();
	    ptext("Hit X to exit: ");
	    if (wait_here() == 'X') {
		return TRUE;
	    }
	    keys_tested(0, 1, hx);
	    tty_raw(cc, char_mask);
	    return FALSE;
	}
	/* is this the end? */
	for (k = 0; (j = (keybuf[k] & STRIP_PARITY)); k++) {
	    if (end_funky(j)) {
		return TRUE;
	    }
	}

	j = TRUE;		/* does he need an updated list? */
	for (k = 0; keybuf[k]; k++) {
	    j &= (keybuf[k] & STRIP_PARITY) == '?';
	}
	if (j || end_state == '?') {
	    keys_tested(0, 1, hx);
	    tty_raw(cc, char_mask);
	    end_state = 0;
	    return FALSE;
	}
    }

    put_cr();
    if (hx) {
	s = hex_expand_to(keybuf, 10);
    } else {
	s = expand_to(keybuf, 10);
    }
    sprintf(temp, "%s Unknown", s);
    put_str(temp);
    for (j = 0; j < MAX_FK_UNK; j++) {
	if (j == funk) {
	    fk_length[funk] = expand_chars;
	    if ((fk_unknown[funk] = (char *) malloc(strlen(s) + 1))) {
		strcpy(fk_unknown[funk++], s);
	    }
	    break;
	}
	if (fk_length[j] == expand_chars) {
	    if (!strcmp(fk_unknown[j], s)) {
		break;
	    }
	}
    }
    return FALSE;
}
Exemplo n.º 4
0
static int
found_match(char *s, int hx, int cc)
{				/* return true if this string is a match */
    int j, f;

    alloc_strings();
    if (!*s) {
	return 0;
    }
    if (scan_mode) {
	for (j = f = 0; scan_down[j]; j++) {
	    if (scan_length[j] == 0) {
		continue;
	    }
	    if (!strncmp(s, scan_down[j], scan_length[j])) {
		if (!f) {	/* first match */
		    put_cr();
		    if (hx) {
			put_str(hex_expand_to(s, 10));
		    } else {
			put_str(expand_to(s, 10));
		    }
		    f = 1;
		}
		(void) end_funky(scan_name[j][0]);
		put_str(" ");
		put_str(scan_name[j]);
		scan_tested[j] = 1;
		s += scan_length[j];
		if (strncmp(s, scan_up[j], scan_length[j])) {
		    put_str(" scan down");
		} else {
		    s += scan_length[j];
		}
		if (!*s) {
		    break;
		}
		j = -1;
	    }
	    if (!strncmp(s, scan_up[j], scan_length[j])) {
		if (!f) {	/* first match */
		    put_cr();
		    if (hx) {
			put_str(hex_expand_to(s, 10));
		    } else {
			put_str(expand_to(s, 10));
		    }
		    f = 1;
		}
		put_str(" ");
		put_str(scan_name[j]);
		put_str(" scan up");
		s += scan_length[j];
		if (!*s) {
		    break;
		}
		j = -1;
	    }
	}
    } else {
	for (j = f = 0; j < key_count; j++) {
	    if (fkval[j] && !strcmp(s, fkval[j])) {
		char outbuf[256];

		if (!f) {	/* first match */
		    put_cr();
		    if (hx) {
			put_str(hex_expand_to(s, 10));
		    } else {
			put_str(expand_to(s, 10));
		    }
		    f = 1;
		}
		sprintf(outbuf, " (%s)", fk_name[j]);
		put_str(outbuf);
		if (fk_label[j]) {
		    sprintf(outbuf, " <%s>", fk_label[j]);
		    put_str(outbuf);
		}
		fk_tested[j] = 1;
	    }
	}
    }
    if (end_state == '?') {
	keys_tested(0, 1, hx);
	tty_raw(cc, char_mask);
	end_state = 0;
    }
    return f;
}
Exemplo n.º 5
0
 // Using memory copy method to append a C array to buffer, 
 inline void append(const void * c, int size){ // size unit is byte
     expand_to(content_size() + size) ;
     memcpy(current, c, size);
     current = current + size;
 }