示例#1
0
void put_template(char *template_name, int x, int y)
{
	printf("Placing \"%s\" template at (%d, %d)\n", template_name, x, y);
	int i = 0;
	int j = 0;
	Template *t = get_template(template_name);

	if (t->width > width || t->height > height)
	{
		printf("The game field is too small to put the \"%s\" template.\n", template_name);
		delete_data();
		exit(3);
	}

	for (i = 0; i < t->height; i++)
	{
		for (j = 0; j < t->width; j++)
		{
			if (t->picture[i][j])
			{
				field[(y + i) % height][(x + j) % width] = 1;
			}
		}
	}

	delete_template(t);
}
示例#2
0
/**
 * @brief method for rendering a template
 *
 * @param tmplate template to render as raw std::string or file path
 * @param ctx context object
 *
 * @return rendered std::string
 */
std::string template_t::render(const std::string& tmplate, const Context& ctx)
{
    // get template
    std::string tmp = get_template(tmplate);

    std::string first = template_t::render_sections(tmp, ctx);
    std::string second = template_t::render_tags(first, ctx);
    return second;
}
示例#3
0
void
test_template_generate_dependencies(void)
{
    gchar *tmpl = get_template("foo.html");
    gchar *rv = balde_template_generate_dependencies(tmpl);
    g_assert_cmpstr(rv, ==, tmpl);
    g_free(tmpl);
    g_free(rv);
}
示例#4
0
void
test_template_generate_source_with_if_and_ws_cleaner(void)
{
    gchar *tmpl = get_template("base8.html");
    gchar *exp = get_expected_template("base8.c");
    gchar *rv = balde_template_generate_source("bola", tmpl);
    g_free(tmpl);
    balde_assert_template_equal(rv, exp);
    g_free(rv);
    g_free(exp);
}
示例#5
0
void
test_template_generate_source_with_multiple_if(void)
{
    gchar *tmpl = get_template("base4.html");
    gchar *exp = get_expected_template("base4.c");
    gchar *rv = balde_template_generate_source("bola", tmpl);
    g_free(tmpl);
    balde_assert_template_equal(rv, exp);
    g_free(rv);
    g_free(exp);
}
示例#6
0
void
test_template_generate_source_with_include_with_url_for(void)
{
    gchar *tmpl = get_template("base2.html");
    gchar *exp = get_expected_template("base2.c");
    gchar *rv = balde_template_generate_source("bola", tmpl);
    g_free(tmpl);
    balde_assert_template_equal(rv, exp);
    g_free(rv);
    g_free(exp);
}
示例#7
0
void
test_template_generate_source_with_percent(void)
{
    gchar *tmpl = get_template("foo9.html");
    gchar *exp = get_expected_template("foo9.c");
    gchar *rv = balde_template_generate_source("bola", tmpl);
    g_free(tmpl);
    balde_assert_template_equal(rv, exp);
    g_free(rv);
    g_free(exp);
}
示例#8
0
void
test_template_generate_source_multiple_vars_and_lines_with_function_calls_and_single_quotes(void)
{
    gchar *tmpl = get_template("foo8.html");
    gchar *exp = get_expected_template("foo8.c");
    gchar *rv = balde_template_generate_source("bola", tmpl);
    g_free(tmpl);
    balde_assert_template_equal(rv, exp);
    g_free(rv);
    g_free(exp);
}
示例#9
0
void
test_template_generate_source_multiple_vars_and_lines(void)
{
    gchar *tmpl = get_template("foo6.html");
    gchar *exp = get_expected_template("foo6.c");
    gchar *rv = balde_template_generate_source("bola", tmpl);
    g_free(tmpl);
    balde_assert_template_equal(rv, exp);
    g_free(rv);
    g_free(exp);
}
示例#10
0
void
test_template_generate_source_single_var_with_single_quoted_imports(void)
{
    gchar *tmpl = get_template("foo4.html");
    gchar *exp = get_expected_template("foo4.c");
    gchar *rv = balde_template_generate_source("bola", tmpl);
    g_free(tmpl);
    balde_assert_template_equal(rv, exp);
    g_free(rv);
    g_free(exp);
}
void RxCheckManager::DumpTemplateFull(FILE *fd){
    int i;
    for (i=0; i<MAX_TEMPLATES_STATS;i++ ) {
        CPerTemplateInfo * lp=get_template(i);
        fprintf(fd," template_id_%2d , errors:%8llu,  jitter: %llu  rx : %llu \n",
                i,
                (unsigned long long)lp->get_error_counter(),
                (unsigned long long)lp->get_jitter_usec(),
                (unsigned long long)lp->get_rx_counter() );
    }
}
uint32_t RxCheckManager::getTemplateMaxJitter(){
    uint32_t res=0;
    int i;
    for (i=0; i<MAX_TEMPLATES_STATS;i++ ) {
        CPerTemplateInfo * lp=get_template(i);
        uint32_t jitter=lp->get_jitter_usec();
        if ( jitter > res ) {
            res =jitter;
        }
    }
    return ( res );
}
示例#13
0
/**
 * @brief method for rendering a template
 *
 * @param tmplate template to render as raw std::string or filepath
 * @param ctx map of values
 *
 * @return rendered std::string
 */
std::string template_t::render(const std::string& tmplate,
                               const ObjectType& ctx)
{
    // get template
    std::string tmp = get_template(tmplate);
    Context contxt;
    contxt.add(ctx);

    std::string first = template_t::render_sections(tmp, contxt);
    std::string second = template_t::render_tags(first, contxt);
    return second;
}
示例#14
0
void
test_template_generate_dependencies_with_include(void)
{
    gchar *tmpl = get_template("base2.html");
    gchar *rv = balde_template_generate_dependencies(tmpl);
    gchar *dir = g_path_get_dirname(tmpl);
    gchar *include = g_build_filename(dir, "body2.html", NULL);
    g_free(dir);
    gchar *dependencies = g_strdup_printf("%s %s", tmpl, include);
    g_free(include);
    g_free(tmpl);
    g_assert_cmpstr(rv, ==, dependencies);
    g_free(dependencies);
    g_free(rv);
}
示例#15
0
bool wpl_value_array::set_strong (wpl_value *value) {
	/* This is important to unmask the auto type */
	value = value->dereference();

	wpl_value_array *value_array =
		dynamic_cast<wpl_value_array*>(value);

	if (!value_array) {
		return false;
	}

	if (get_template() != value_array->get_template()) {
		return false;
	}

	replace(*value_array);

	return true;
}
void RxCheckManager::template_dump_json(std::string & json){
    json+="\"template\" : [";
    int i;
    bool is_first=true;
    for (i=0; i<MAX_TEMPLATES_STATS;i++ ) {
        CPerTemplateInfo * lp=get_template(i);
        if ( is_first==true ){
            is_first=false;
        }else{
            json+=",";
        }
        json+="{";
        json+=add_json("id",(uint32_t)i);
        json+=add_json("val",(uint64_t)lp->get_error_counter());
        json+=add_json("rx_pkts",(uint64_t)lp->get_rx_counter());
        json+=add_json("jitter",(uint64_t)lp->get_jitter_usec(),true);
        json+="}";
    }
    json+="],";

}
void RxCheckManager::DumpTemplate(FILE *fd,bool verbose){
    int i;
    bool has_template=false;
    int cnt=0;
    for (i=0; i<MAX_TEMPLATES_STATS;i++ ) {
        CPerTemplateInfo * lp=get_template(i);
        if (verbose || (lp->get_error_counter()>0)) {
            has_template=true;
            if (cnt==0){
                fprintf(fd,"\n");
            }
            fprintf(fd,"[id:%2d val:%8llu,rx:%8llu], ",i, (unsigned long long)lp->get_error_counter(), (unsigned long long)lp->get_rx_counter());
            cnt++;
            if (cnt>5) {
                cnt=0;
            }
        }
    }
    if ( has_template ){
        fprintf(fd,"\n");
    }
}
示例#18
0
bool wpl_value_array::set_strong (wpl_value *value) {
	value = value->dereference();

	/*
	   TODO
	   create copy_to_array(wpl_value_array *target) or something in wpl_value
	   */
	if (!value->isArray()) {
		return false;
	}

	wpl_value_array *value_array =
		static_cast<wpl_value_array*>(value);

	if (get_template() != value_array->get_template()) {
		return false;
	}

	replace(*value_array);

	return true;
}
void GstPropertiesModule::show_pad_properties()
{
	auto pad = std::dynamic_pointer_cast<PadModel>(controller->get_selected_object());

	if (!pad)
	{
		return;
	}

	PadPropertyModelColumns cols;
	auto model = Gtk::TreeStore::create(cols);
	Gtk::TreeView *tree = Gtk::manage(new Gtk::TreeView());
	tree->append_column(_("Property Name"), cols.m_col_name);
	tree->append_column(_("Property Value"), cols.m_col_value);
	tree->set_model(model);

#define APPEND_ROW(name, value) \
	do { \
		row = *(model->append()); \
		row[cols.m_col_name] = name; \
		row[cols.m_col_value] = value; \
	} while (false);

	std::string peer_pad = pad->get_peer() ? ElementPathProcessor::get_object_path(pad->get_peer()) : std::string("NO PEER PAD");

	Gtk::TreeModel::Row row;
	APPEND_ROW(_("Name"), pad->get_name());

	if (pad->get_template())
	{
		display_template_info(pad->get_template(), model, cols.m_col_name, cols.m_col_value);
	}

	APPEND_ROW(_("Presence"), get_presence_str(pad->get_presence()));
	APPEND_ROW(_("Direction"), get_direction_str(pad->get_direction()));
	APPEND_ROW(_("Peer pad"), peer_pad);

	if (pad->get_current_caps())
	{
		APPEND_ROW(_("Current caps"), "");
		display_caps(pad->get_current_caps(), model, cols.m_col_name, cols.m_col_value, row);
	}
	else
	{
		APPEND_ROW(_("Current caps"), _("unknown"));
	}

	if (pad->get_allowed_caps())
	{
		APPEND_ROW(_("Allowed caps"), "");
		display_caps(pad->get_allowed_caps(), model, cols.m_col_name, cols.m_col_value, row);
	}
	else
	{
		APPEND_ROW(_("Allowed caps"), _("unknown"));
	}

#undef APPEND_ROW

	tree->show();
	properties_box->pack_start(*tree, true, true, 0);
}
示例#20
0
template <> bool CBuffer::get<long double>(long double* data, size_t n) { return get_template(data,n) ;}  
示例#21
0
template <> bool CBuffer::get<float>(float* data, size_t n) { return get_template(data,n) ; }  
示例#22
0
template <> bool CBuffer::get<ulong>(ulong* data, size_t n) { return get_template(data,n) ; }  
示例#23
0
template <> bool CBuffer::get<ushort>(ushort* data, size_t n) { return get_template(data,n) ; }  
示例#24
0
template <> bool CBuffer::get<int>(int* data, size_t n)   { return get_template(data,n) ; }
示例#25
0
template <> bool CBuffer::get<char>(char* data, size_t n) { return get_template(data,n) ; }  
示例#26
0
template <> bool CBuffer::get<long double>(long double& data) { return get_template(data) ;}  
示例#27
0
template <> bool CBuffer::get<float>(float& data) { return get_template(data) ; }  
示例#28
0
template <> bool CBuffer::get<ulong>(ulong& data) { return get_template(data) ; }  
示例#29
0
        void Fibre::Tractlet::Tensor::add_section_hessian(
                const Tractlet& tractlet, const Tractlet::Section& section,
                const Strand::BasicSection& gradient, const Strand::BasicSection::Tensor& hessian) {
            
            Fibre::Tractlet d2_intensity = get_template();
            
            Strand pos_gradient = Strand::outer_product(section.position_coeffs,
                    gradient.position() / section.intensity());
            
            if (has_var_acs())
                d2_intensity.set_acs(0.0);
            
//      d2_intensity.set_base_width(0.0);
            
//Add position gradient.
            d2_intensity[0] += pos_gradient;
            d2_intensity[1] += pos_gradient * section.ax1_fraction;
            d2_intensity[2] += pos_gradient * section.ax2_fraction;
            
            //Add tangent gradient.
            
            Strand tang_gradient = Strand::outer_product(section.tangent_coeffs,
                    gradient.tangent() * (section.length_fraction / section.intensity()));
            
            d2_intensity[0] += tang_gradient;
            d2_intensity[1] += tang_gradient * section.ax1_fraction;
            d2_intensity[2] += tang_gradient * section.ax2_fraction;
            
            Fibre::Tractlet acs_gradient = d2_intensity * section.intensity();
            
            if (true) {    //Needs some serious rewriting.
            
                throw Exception(
                        "tied_width hessian needs to be adjusted after accounting for tractlet sheer.");
                
                double norm1 = tractlet[1][0].norm();
                double norm2 = tractlet[2][0].norm();
                
                Coord d_intensity_d1 = tractlet.acs()
                        * ((norm2 / norm1) * tractlet(1, 0) - tractlet(2, 0));
                Coord d_intensity_d2 = tractlet.acs()
                        * ((norm1 / norm2) * tractlet(2, 0) - tractlet(1, 0));
                
                for (size_t dim_i1 = 0; dim_i1 < 3; dim_i1++) {
                    
                    operator()(1, 0, dim_i1, 2, 0, dim_i1) -= gradient.intensity() * tractlet.acs();
                    operator()(2, 0, dim_i1, 1, 0, dim_i1) -= gradient.intensity() * tractlet.acs();
                    
                    operator()(1, 0, dim_i1, 1, 0, dim_i1) += gradient.intensity() * tractlet.acs()
                                                              * norm2
                                                              / norm1;
                    operator()(2, 0, dim_i1, 2, 0, dim_i1) += gradient.intensity() * tractlet.acs()
                                                              * norm1
                                                              / norm2;
                    
                    for (size_t dim_i2 = 0; dim_i2 < 3; dim_i2++) {
                        
                        operator()(1, 0, dim_i1, 1, 0, dim_i2) -= tractlet.acs()
                                * gradient.intensity() * tractlet[1][0][dim_i1]
                                * tractlet[1][0][dim_i2] * (norm2 / MR::Math::pow3(norm1));
                        operator()(2, 0, dim_i1, 2, 0, dim_i2) -= tractlet.acs()
                                * gradient.intensity() * tractlet[2][0][dim_i1]
                                * tractlet[2][0][dim_i2] * (norm1 / MR::Math::pow3(norm2));
                        
                        operator()(1, 0, dim_i1, 2, 0, dim_i2) += tractlet.acs()
                                * gradient.intensity() * tractlet[2][0][dim_i2]
                                * tractlet[1][0][dim_i1]
                                                                  / (norm1 * norm2);
                        operator()(2, 0, dim_i1, 1, 0, dim_i2) += tractlet.acs()
                                * gradient.intensity() * tractlet[1][0][dim_i2]
                                * tractlet[2][0][dim_i1]
                                                                  / (norm2 * norm1);
                        
                        for (size_t ax_i = 0; ax_i < 3; ++ax_i)
                            for (size_t degree_i = 0; degree_i < tractlet.degree(); ++degree_i) {
                                
                                operator()(ax_i, degree_i, dim_i1, 1, 0, dim_i2) += tractlet.acs()
                                        * d2_intensity(ax_i, degree_i)[dim_i1]
                                        * d_intensity_d1[dim_i2];
                                operator()(ax_i, degree_i, dim_i1, 2, 0, dim_i2) += tractlet.acs()
                                        * d2_intensity(ax_i, degree_i)[dim_i1]
                                        * d_intensity_d2[dim_i2];
                                
                                operator()(1, 0, dim_i1, ax_i, degree_i, dim_i2) += tractlet.acs()
                                        * d2_intensity(ax_i, degree_i)[dim_i2]
                                        * d_intensity_d1[dim_i1];
                                operator()(2, 0, dim_i1, ax_i, degree_i, dim_i2) += tractlet.acs()
                                        * d2_intensity(ax_i, degree_i)[dim_i2]
                                        * d_intensity_d2[dim_i1];
                                
                            }
                        
                    }
                    
                }
                
                if (has_var_acs()) {
                    acs_gradient(1, 0) += gradient.intensity() * d_intensity_d1;
                    acs_gradient(2, 0) += gradient.intensity() * d_intensity_d2;
                }
                
            }
            
            if (has_var_acs())
                acs() += acs_gradient;
            
            for (size_t degree_i1 = 0; degree_i1 < degree(); degree_i1++)
                for (size_t dim_i1 = 0; dim_i1 < 3; dim_i1++) {
                    
                    Fibre::Tractlet ax0 = row(0, degree_i1, dim_i1);
                    Fibre::Tractlet ax1 = row(1, degree_i1, dim_i1);
                    Fibre::Tractlet ax2 = row(2, degree_i1, dim_i1);
                    
                    if (has_var_acs()) {
                        ax0.alpha() += acs_gradient.operator()(0, degree_i1)[dim_i1];
                        ax1.alpha() += acs_gradient.operator()(1, degree_i1)[dim_i1];
                        ax2.alpha() += acs_gradient.operator()(2, degree_i1)[dim_i1];
                    }
                    
                    for (size_t degree_i2 = 0; degree_i2 < degree(); degree_i2++)
                        for (size_t dim_i2 = 0; dim_i2 < 3; dim_i2++) {
                            
                            double ax0_ax0 =
                                    section.position_coeffs[degree_i1] * section.position_coeffs[degree_i2]
                                    * hessian.position(dim_i1).position(dim_i2)
                                    + section.position_coeffs[degree_i1] * section.tangent_coeffs[degree_i2]
                                      * hessian.position(dim_i1).tangent(dim_i2)
                                      * section.length_fraction
                                    + section.tangent_coeffs[degree_i1] * section.position_coeffs[degree_i2]
                                      * hessian.tangent(dim_i1).position(dim_i2)
                                      * section.length_fraction
                                    + section.tangent_coeffs[degree_i1] * section.tangent_coeffs[degree_i2]
                                      * hessian.tangent(dim_i1).tangent(dim_i2)
                                      * MR::Math::pow2(section.length_fraction);
                            
                            ax0[0][degree_i2][dim_i2] += ax0_ax0;
                            ax0[1][degree_i2][dim_i2] += ax0_ax0 * section.ax1_fraction;
                            ax1[0][degree_i2][dim_i2] += ax0_ax0 * section.ax1_fraction;
                            ax0[2][degree_i2][dim_i2] += ax0_ax0 * section.ax2_fraction;
                            ax2[0][degree_i2][dim_i2] += ax0_ax0 * section.ax2_fraction;
                            
                            ax1[1][degree_i2][dim_i2] += ax0_ax0
                                    * MR::Math::pow2(section.ax1_fraction);
                            ax1[2][degree_i2][dim_i2] += ax0_ax0 * section.ax1_fraction
                                                         * section.ax2_fraction;
                            ax2[1][degree_i2][dim_i2] += ax0_ax0 * section.ax1_fraction
                                                         * section.ax2_fraction;
                            
                            ax2[2][degree_i2][dim_i2] += ax0_ax0
                                    * MR::Math::pow2(section.ax2_fraction);
                            
                        }
                    
                }
            
        }
示例#30
0
template <> bool CBuffer::get<ushort>(ushort& data) { return get_template(data) ; }