示例#1
0
文件: 1.c 项目: akydd/practicalc
int main(void)
{
	/* here are some profile records */
	profile_list[0] = create_profile("Mrs", "Kydd", "1428-330 Fake Street",
			"Unit 1428", "Edmonton", "Alberta", "A1B2C3");
	profile_list[1] = create_profile("Mr", "Kydd", "94 Fake Street",
			"Unit 505", "Edmonton", "Alberta", "A1B2C3");
	profile_list[2] = create_profile("Mr", "Kydd", "43 Fake Street",
			"Unit 227", "Sherwood Park", "Alberta", "D4E5F6");
	profile_list[3] = create_profile("Leeroy", "Jenkins",
			"1943 Fake Avenue", "Apt 123", "Sherwood Park",
			"Alberta", "D4E5F6");

	/* sort the profiles */
	(void)qsort(&profile_list, MAX_RECORDS, sizeof(struct profile *),
			profilecmp);
	
	/* print them out! */
	int i = 0;
	for(i = 0; i < MAX_RECORDS; i++) {
		(void)print_profile(profile_list[i]);
	}

	/* free memory */
	for(i = 0; i < MAX_RECORDS; i++) {
		(void)free_profile(profile_list[i]);
	}
	
	return 0;
}
示例#2
0
void ProfileWizard::createProfile(int result)
{
  if (_profile_edit->isComplete() )
  {
    bts::profile_config conf;
    conf.firstname  = _profile_edit->ui.first_name->text().toUtf8().constData();
    conf.firstname  = fc::trim( conf.firstname );
    conf.middlename = _profile_edit->ui.middle_name->text().toUtf8().constData();
    conf.middlename = fc::trim( conf.middlename );
    conf.lastname   = _profile_edit->ui.last_name->text().toUtf8().constData();
    conf.lastname   = fc::trim( conf.lastname );
    conf.brainkey   = _profile_edit->ui.brainkey->text().toUtf8().constData();
    conf.brainkey   = fc::trim( conf.brainkey );

    std::string                      password = _profile_edit->ui.local_password1->text().toUtf8().constData();

    std::string profile_name         = conf.firstname + " " + conf.lastname;
    auto                             app = bts::application::instance();
    fc::thread* main_thread = &fc::thread::current();
    QProgressBar* progress = new QProgressBar();
    progress->setWindowTitle( "Creating Profile" );
    progress->setMaximum(1000);
    progress->resize( 640, 20 );
    progress->show();
    auto                             profile = app->create_profile(profile_name, conf, password, 
                                               [=]( double p )
                                               {
                                                  main_thread->async( [=](){ 
                                                                      progress->setValue( 1000*p );
                                                                      qApp->sendPostedEvents();
                                                                      qApp->processEvents();
                                                                      if( p >= 1.0 ) progress->deleteLater();
                                                                      } ).wait();
                                               }
                                               );
    assert(profile != nullptr);

    //store myself as contact
  /*
    std::string dac_id_string = _nym_page->_profile_nym_ui.keyhotee_id->text().toStdString();
    bts::addressbook::wallet_contact myself;
    myself.wallet_index = 0;
    myself.first_name = conf.firstname;
    myself.last_name = conf.lastname;
    myself.set_dac_id(dac_id_string);
    auto priv_key = profile->get_keychain().get_identity_key(myself.dac_id_string);
    myself.public_key = priv_key.get_public_key();
    profile->get_addressbook()->store_contact(myself);

    //store myself as identity
    bts::addressbook::wallet_identity new_identity;
    static_cast<bts::addressbook::contact&>(new_identity) = myself;
    profile->store_identity(new_identity);

    bts::application::instance()->add_receive_key(priv_key);
    */

    _mainApp.displayMainWindow();
  }
}
示例#3
0
void ProfileWizard::createProfile()
{
  if (_profile_edit->isComplete() )
  {
    ilog( "." );
    bts::profile_config conf;
    conf.firstname  = _profile_edit->ui.first_name->text().toUtf8().constData();
    conf.firstname  = fc::trim( conf.firstname );
    conf.middlename = _profile_edit->ui.middle_name->text().toUtf8().constData();
    conf.middlename = fc::trim( conf.middlename );
    conf.lastname   = _profile_edit->ui.last_name->text().toUtf8().constData();
    conf.lastname   = fc::trim( conf.lastname );
    conf.brainkey   = _profile_edit->ui.brainkey->text().toUtf8().constData();
    conf.brainkey   = fc::trim( conf.brainkey );

    std::string password = _profile_edit->ui.local_password1->text().toUtf8().constData();

    //set profile name from first and last name
    std::string profile_name = conf.firstname;
    if (!conf.lastname.empty())
      profile_name += " " + conf.lastname;

    const unsigned int progressWidth = 640;
    const unsigned int progressHeight = 20;
    const unsigned int progressMax = 1000;
    int x=(qApp->desktop()->width() - progressWidth)/2;
    int y=(qApp->desktop()->height() - progressHeight)/2;

    TAutoUpdateProgressBar* progress = TAutoUpdateProgressBar::create(QRect(x, y, progressWidth,
      progressHeight), tr("Creating Profile"), progressMax);

    /** \warning Copy mainApp pointer to local variable, since lambda needs its copy
        this object is destroyed while executing create_profile action.
    */
    TKeyhoteeApplication* mainApp = &_mainApp;

    auto app = bts::application::instance();

    progress->doTask(
      [=]() 
      {
      auto profile = app->create_profile(profile_name, conf, password, 
        [=]( double p )
        {
          progress->updateValue(progressMax*p);
        });

        assert(profile != nullptr);
      },
      [=]() 
      {
        mainApp->displayMainWindow();
      }
    );
  }
  else
    {
    ilog( "createProfile: Incomplete profile" );
    }
}
static GstEncodingProfile *
create_profile_from_string (gchar * format, gchar * vformat, gchar * aformat)
{
    GstEncodingProfile *prof = NULL;
    GstCaps *cf = NULL, *vf = NULL, *af = NULL;

    if (format)
        cf = gst_caps_from_string (format);
    if (vformat)
        vf = gst_caps_from_string (vformat);
    if (aformat)
        af = gst_caps_from_string (aformat);

    if (G_UNLIKELY ((vformat && (vf == NULL)) || (aformat && (af == NULL))))
        goto beach;

    prof = create_profile (cf, vf, af);

beach:
    if (cf)
        gst_caps_unref (cf);
    if (vf)
        gst_caps_unref (vf);
    if (af)
        gst_caps_unref (af);

    return prof;
}
GrTexture* GrCircleBlurFragmentProcessor::CreateCircleBlurProfileTexture(
                                                                GrTextureProvider* textureProvider,
                                                                const SkRect& circle,
                                                                float sigma,
                                                                float* offset) {
    float halfWH = circle.width() / 2.0f;

    int size;
    compute_profile_offset_and_size(halfWH, sigma, offset, &size);

    GrSurfaceDesc texDesc;
    texDesc.fWidth = size;
    texDesc.fHeight = 1;
    texDesc.fConfig = kAlpha_8_GrPixelConfig;

    static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
    GrUniqueKey key;
    GrUniqueKey::Builder builder(&key, kDomain, 2);
    // The profile curve varies with both the sigma of the Gaussian and the size of the
    // disk. Quantizing to 16.16 should be close enough though.
    builder[0] = SkScalarToFixed(sigma);
    builder[1] = SkScalarToFixed(halfWH);
    builder.finish();

    GrTexture *blurProfile = textureProvider->findAndRefTextureByUniqueKey(key);

    if (!blurProfile) {
        SkAutoTDeleteArray<uint8_t> profile(create_profile(halfWH, sigma));

        blurProfile = textureProvider->createTexture(texDesc, SkBudgeted::kYes, profile.get(), 0);
        if (blurProfile) {
            textureProvider->assignUniqueKeyToTexture(key, blurProfile);
        }
    }

    return blurProfile;
}
int
main (int argc, char **argv)
{
    GError *err = NULL;
    gchar *outputuri = NULL;
    gchar *format = NULL;
    gchar *aformat = NULL;
    gchar *vformat = NULL;
    gboolean allmissing = FALSE;
    gboolean listcodecs = FALSE;
    GOptionEntry options[] = {
        {   "silent", 's', 0, G_OPTION_ARG_NONE, &silent,
            "Don't output the information structure", NULL
        },
        {   "outputuri", 'o', 0, G_OPTION_ARG_STRING, &outputuri,
            "URI to encode to", "URI (<protocol>://<location>)"
        },
        {   "format", 'f', 0, G_OPTION_ARG_STRING, &format,
            "Container format", "<GstCaps>"
        },
        {   "vformat", 'v', 0, G_OPTION_ARG_STRING, &vformat,
            "Video format", "<GstCaps>"
        },
        {   "aformat", 'a', 0, G_OPTION_ARG_STRING, &aformat,
            "Audio format", "<GstCaps>"
        },
        {   "allmissing", 'm', 0, G_OPTION_ARG_NONE, &allmissing,
            "encode to all matching format/codec that aren't specified", NULL
        },
        {   "list-codecs", 'l', 0, G_OPTION_ARG_NONE, &listcodecs,
            "list all available codecs and container formats", NULL
        },
        {NULL}
    };
    GOptionContext *ctx;
    GstEncodingProfile *prof;
    gchar *inputuri;

    ctx = g_option_context_new ("- encode URIs with GstProfile and encodebin");
    g_option_context_add_main_entries (ctx, options, NULL);
    g_option_context_add_group (ctx, gst_init_get_option_group ());

    if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
        g_print ("Error initializing: %s\n", err->message);
        exit (1);
    }

    if (listcodecs) {
        list_codecs ();
        g_option_context_free (ctx);
        exit (0);
    }

    if (outputuri == NULL || argc != 2) {
        g_print ("%s", g_option_context_get_help (ctx, TRUE, NULL));
        g_option_context_free (ctx);
        exit (-1);
    }

    g_option_context_free (ctx);

    /* Fixup outputuri to be a URI */
    inputuri = ensure_uri (argv[1]);
    outputuri = ensure_uri (outputuri);

    if (allmissing) {
        GList *muxers;
        GstCaps *formats = NULL;
        GstCaps *vformats = NULL;
        GstCaps *aformats = NULL;
        guint f, v, a, flen, vlen, alen;

        if (!format)
            formats = gst_caps_list_container_formats (GST_RANK_NONE);
        else
            formats = gst_caps_from_string (format);

        if (!vformat)
            vformats = gst_caps_list_video_encoding_formats (GST_RANK_NONE);
        else
            vformats = gst_caps_from_string (vformat);

        if (!aformat)
            aformats = gst_caps_list_audio_encoding_formats (GST_RANK_NONE);
        else
            aformats = gst_caps_from_string (aformat);
        muxers =
            gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_MUXER,
                    GST_RANK_NONE);

        flen = gst_caps_get_size (formats);

        for (f = 0; f < flen; f++) {
            GstCaps *container =
                gst_caps_new_full (gst_caps_steal_structure (formats, 0), NULL);
            GstCaps *compatv =
                gst_caps_list_compatible_codecs (container, vformats, muxers);
            GstCaps *compata =
                gst_caps_list_compatible_codecs (container, aformats, muxers);

            vlen = gst_caps_get_size (compatv);
            alen = gst_caps_get_size (compata);


            for (v = 0; v < vlen; v++) {
                GstCaps *vcodec =
                    gst_caps_new_full (gst_structure_copy (gst_caps_get_structure
                                       (compatv, v)), NULL);
                for (a = 0; a < alen; a++) {
                    GstCaps *acodec =
                        gst_caps_new_full (gst_structure_copy (gst_caps_get_structure
                                           (compata, a)), NULL);

                    prof =
                        create_profile ((GstCaps *) container, (GstCaps *) vcodec,
                                        (GstCaps *) acodec);
                    if (G_UNLIKELY (prof == NULL)) {
                        g_print ("Wrong arguments\n");
                        break;
                    }
                    outputuri =
                        ensure_uri (generate_filename (container, vcodec, acodec));
                    transcode_file (inputuri, outputuri, prof);
                    gst_encoding_profile_unref (prof);

                    gst_caps_unref (acodec);
                }
                gst_caps_unref (vcodec);
            }
            gst_caps_unref (container);
        }

    } else {

        /* Create the profile */
        prof = create_profile_from_string (format, vformat, aformat);
        if (G_UNLIKELY (prof == NULL)) {
            g_print ("Encoding arguments are not valid !\n");
            return 1;
        }

        /* Transcode file */
        transcode_file (inputuri, outputuri, prof);

        /* cleanup */
        gst_encoding_profile_unref (prof);

    }
    return 0;
}
示例#7
0
/*MAIN FUNCTION*/
int main(int argc, char * * argv){
    /******************FILE READ******************/
    FILE * fp = fopen(argv[1],"r");
    int id,age,sex,marry,race,place,lang,job,money;
    int population,given_id;
    float delta1,delta2,alpha;
    fscanf(fp,"%d,%f,%f,%d,%f", &population,&delta1,&delta2,&given_id,&alpha);
    
    int index = 0;
    profile users[population];
    while(!feof(fp)){
        fscanf(fp, "%d,%d,%d,%d,%d,%d,%d,%d,%d", &id,&age,&sex,&marry,&race,&place,&lang,&job,&money);
        users[index] = create_profile(id,age,sex,marry,race,place,lang,job,money);
        index++;
    }
    /******************GRAPH MATRIX******************/
    double matrix[population][population];
    double matrix_weight[population][population];
    int dense[population][population];
    int sparse[population][population];
    int k = 0;
    //MATRIX
    int i = 0, j = 0;
    for(i = 0; i < population; i++){
        for(j = 0; j < population; j++){
            if(i == j){
                matrix[i][j] = 0;
            }else{
                matrix[i][j] = euclidean(users[i], users[j]);
            }
        }
    }
    
    //MATRIX_WEIGHT
    double max = findmax(population, matrix);
    for(i = 0; i < population; i++){
        for(j = 0; j < population; j++){
            matrix_weight[i][j] = 1 - matrix[i][j]/max;
        }
    }
    
    //DENSE
    for(i = 0; i < population; i++){
        for(j = 0; j < population; j++){
            if(i == j){
                dense[i][j] = -1;
            }else if((int)(matrix_weight[i][j]*100) > delta1*100){
                dense[i][j] = (int)(matrix_weight[i][j]*100);
            }else{
                dense[i][j] = -1;
            }
        }
    }
    
    //SPARSE
    for(i = 0; i < population; i++){
        for(j = 0; j < population; j++){
            if(i == j){
                sparse[i][j] = -1;
            }else if((int)(matrix_weight[i][j]*100) > delta2*100){
                sparse[i][j] = (int)(matrix_weight[i][j]*100);
            }else{
                sparse[i][j] = -1;
            }
        }
    }
    /******************DENSE PART******************/
    /*QUERY1*/
    int id_index = given_id - 1;
    int shortest = 100;
    int buffer[2048];
    for(i = 0; i < population; i++){
        buffer[i] = 0;
    }
    for(j = 0; j < population; j++){
        if(j != id_index && dense[id_index][j] > 0 && dense[id_index][j] < shortest){
            shortest = dense[id_index][j];
        }
    }
    for(j = 0; j < population; j++){
        if(j != id_index && dense[id_index][j] > 0 && dense[id_index][j] == shortest){
            buffer[j] = 1;
        }
    }
    printf("%.2f", shortest/100.00);
    for(j = 0; j < population; j++){
        if(buffer[j]){
            printf(",%d", j+1);
        }
    }
    printf("\n");
    /*QUERY2*/
    dijkstra(population, id_index, dense, (int)(alpha*100));
    /*QUERY3*/
    int immediate = find_im(population, id_index, dense, 3);
    /*QUERY4*/
    int twohop = find_2h(population, id_index, dense, 4);
    /*QUERY5*/
    immediate = 0;
    for(i = 0; i < population; i++){
        immediate += find_im(population, i, dense, 5);
    }
    printf("%.2f\n", immediate/(float)population);
    /*QUERY6*/
    twohop = 0;
    for(i = 0; i < population; i++){
        twohop += find_2h(population, i, dense, 5);
    }
    printf("%.2f\n", twohop/(float)population);
    /******************SPARSE PART******************/
    /*QUERY1*/
    printf("\n");
    shortest = 100;
    for(i = 0; i < population; i++){
        buffer[i] = 0;
    }
    for(j = 0; j < population; j++){
        if(j != id_index && sparse[id_index][j] > 0 && sparse[id_index][j] < shortest){
            shortest = sparse[id_index][j];
        }
    }
    for(j = 0; j < population; j++){
        if(j != id_index && sparse[id_index][j] > 0 && sparse[id_index][j] == shortest){
            buffer[j] = 1;
        }
    }
    printf("%.2f", shortest/100.00);
    for(j = 0; j < population; j++){
        if(buffer[j]){
            printf(",%d", j+1);
        }
    }
    printf("\n");
    /*QUERY2*/
    dijkstra(population, id_index, sparse, (int)(alpha*100));
    /*QUERY3*/
    immediate = find_im(population, id_index, sparse, 3);
    /*QUERY4*/
    twohop = find_2h(population, id_index, sparse, 4);
    /*QUERY5*/
    immediate = 0;
    for(i = 0; i < population; i++){
        immediate += find_im(population, i, sparse, 5);
    }
    printf("%.2f\n", immediate/(float)population);
    /*QUERY6*/
    twohop = 0;
    for(i = 0; i < population; i++){
        twohop += find_2h(population, i, sparse, 6);
    }
    printf("%.2f\n", twohop/(float)population);
    
    fclose(fp);
    return EXIT_SUCCESS;
}
示例#8
0
 static bool is_invalid(viennacl::ocl::device const & dev, std::map<std::string, viennacl::generator::autotune::tuning_param> const & params) {
     profile_t prof = create_profile(params);
     return prof.is_invalid(dev, sizeof(ScalarType));
 }