Пример #1
0
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    {
        std::istringstream ss0(" 123 456");
        std::istringstream ss(std::move(ss0));
        assert(ss.rdbuf() != 0);
        assert(ss.good());
        assert(ss.str() == " 123 456");
        int i = 0;
        ss >> i;
        assert(i == 123);
        ss >> i;
        assert(i == 456);
    }
    {
        std::wistringstream ss0(L" 123 456");
        std::wistringstream ss(std::move(ss0));
        assert(ss.rdbuf() != 0);
        assert(ss.good());
        assert(ss.str() == L" 123 456");
        int i = 0;
        ss >> i;
        assert(i == 123);
        ss >> i;
        assert(i == 456);
    }
#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}
Пример #2
0
int main(int, char**)
{
    {
        std::ostringstream ss0(" 123 456");
        std::ostringstream ss;
        ss = std::move(ss0);
        assert(ss.rdbuf() != 0);
        assert(ss.good());
        assert(ss.str() == " 123 456");
        int i = 234;
        ss << i << ' ' << 567;
        assert(ss.str() == "234 5676");
    }
    {
        std::wostringstream ss0(L" 123 456");
        std::wostringstream ss;
        ss = std::move(ss0);
        assert(ss.rdbuf() != 0);
        assert(ss.good());
        assert(ss.str() == L" 123 456");
        int i = 234;
        ss << i << ' ' << 567;
        assert(ss.str() == L"234 5676");
    }

  return 0;
}
Пример #3
0
int xmp_access(const char *path, int mask)
{
    char *path_copy=strdup(path);
  if(strcmp(path,"/")==0) {
    //log_msg("at root");
    return 0;
  }
//  if(strcmp(path,"/")==0) {
        //log_msg("at root");
        return 0;
//  }

  string dirs=database_getval("alldirs","paths");
  string temptok="";
  stringstream dd(dirs);
  while(getline(dd,temptok,':')){
    if(strcmp(temptok.c_str(),path)==0){
      return 0;
    }
  }

  int c=0;
  for(int i=0; path[i]!='\0'; i++){
    if(path[i]=='/') c++;
  }

  //decompose path
  stringstream ss0(path+1);
  string type, attr, val, file, more;
  void* tint=getline(ss0, type, '/');
  void* fint=getline(ss0, file, '/');
  void* mint=getline(ss0, more, '/');
  int reta=0;

  //check for filetype
  if(tint){
    string types = database_getval("allfiles","types");
    stringstream ss(types.c_str());
    string token;
    while(getline(ss,token,':')){
      if(strcmp(type.c_str(),token.c_str())==0){
        reta=1;
      }
    }
    int found=0;

    do{
      //get attr and val
      found=0;
      void *aint=fint;
      string attr=file;
      void *vint=mint;
      string val=more;
      fint=getline(ss0, file, '/');
      mint=getline(ss0, more, '/');

      //check for attr
      if(reta && aint) {
        //cout << attr << endl;
        string attrs= database_getval(type,"attrs");
        stringstream ss3(attrs.c_str());
        reta=0;
        while(getline(ss3,token,':')){
          if(strcmp(attr.c_str(), token.c_str())==0){
            reta=1;
          }
        }

        //check for val
        if(reta && vint) {
          //cout << val << endl;
          if(strcmp(attr.c_str(),("all_"+type+"s").c_str())==0) {
            return 0;
          }
          string vals=database_getvals(attr);
          stringstream ss4(vals.c_str());
          reta=0;
          while(getline(ss4,token,':')){
            //cout << val << token << endl;
            if(strcmp(val.c_str(), token.c_str())==0){
              reta=1;
            }
          }

          //check for file
          if(reta && fint) {
            //cout << file << endl;
            string files=database_getval(attr, val);
            stringstream ss4(files.c_str());
            if(!mint) {
              reta=0;
              while(getline(ss4,token,':')){
                token=database_getval(token,"name");
                if(strcmp(file.c_str(), token.c_str())==0){
                  reta=1;
                }
              }
              stringstream ss5(attrs.c_str());
              while(getline(ss5,token,':')){
                if(strcmp(file.c_str(),token.c_str())==0){
                  reta=1;
                }
              }
            } else {
              found=1;
            }
          }
        }
      }
    }while(found);
  }

  if(reta && !getline(ss0, val, '/')) {
    return 0;
  }
    path=append_path(path);
    int ret = access(path, mask);
    return ret;
}
Пример #4
0
// -------------------------------------------------------------------------- //
//
void Test_Specswap::testSetup()
{
    // Setup a specswap object.
    int sample = 250;
    Mlrnd rand;
    std::string path("./testfiles/testlibSmall");
    Specswap ss0(sample, rand, path);
    // Set the initial chi2_ value to some thing unreasonable.
    ss0.chi2_ = -1.123;
    // Call the setup function.
    ss0.setup();
    // Check that the chi2 value has been updated.
    CPPUNIT_ASSERT_DOUBLES_EQUAL( ss0.chi2_, 0.0, 1.0e-12 );

    // Setup a specswap object with many different data sets.
    path = "./testfiles/testlibLarge";
    Specswap ss1(sample, rand, path);

    // Mean scalar.
    std::string scalarname("VP-Volume");
    double target = 0.5;
    double sigma = 1.0;
    ss1.add_scalar_mean(scalarname, target, sigma);
    sigma = 0.0012;
    ss1.add_scalar_mean(scalarname, target, sigma);

    // Value scalar.
    scalarname = "VP-Area";
    double value_low = 0.5;
    double value_high = 1.0;
    double fraction = 0.6;
    sigma = 0.0001;
    ss1.add_scalar_value(scalarname, value_low, value_high, fraction, sigma);
    fraction = 0.1;
    sigma = 0.0001;
    ss1.add_scalar_value(scalarname, value_low, value_high, fraction, sigma);
    value_low = 0.0;
    value_high = 1.3;
    fraction = 0.99;
    sigma = 0.01;
    ss1.add_scalar_value(scalarname, value_low, value_high, fraction, sigma);

    // Scalar distribution.
    scalarname = "VP-Volume";
    std::string filename("./testfiles/vvol_ref.data");
    sigma = 0.0002;
    ss1.add_scalar_distribution(scalarname, filename, sigma);
    sigma = 0.0099;
    ss1.add_scalar_distribution(scalarname, filename, sigma);

    // Curve.
    std::string curve_name("bas");
    filename = "./testfiles/exafs_ref.data";
    sigma = 0.0002;
    bool area_renorm = true;
    ss1.add_curve(sigma, area_renorm, curve_name, filename);
    area_renorm = false;
    ss1.add_curve(sigma, area_renorm, curve_name, filename);

    // Setup input for adding a pcf.
    double rmin = 0.0;
    double rmax = 5.0;
    double dr = 0.02;
    double numberdensity = 0.4;
    std::pair<double,double> fit_interval(1.3, 3.0);
    int nbins = 250;
    std::pair<int,int> partial(0,1);
    std::string ref_path("./testfiles/gr_ref.data");
    sigma = 0.01;
    ss1.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path);
    sigma = 0.0123;
    ss1.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path);


    // Set the initial chi2_ value to some thing unreasonable.
    ss1.chi2_ = -1.123;
    // Call the setup function.
    ss1.setup();
    // Check that the chi2 value has been updated.
    double ref_chi2 = 680957954.387089;
    CPPUNIT_ASSERT_DOUBLES_EQUAL( ss1.chi2_, ref_chi2, 1.0e-12 );

}
Пример #5
0
void parse_config_xml(Parameters &params, const std::string &fname)
{
    static bool initxml = false;
    if(!initxml)
    {
        xmlInitParser();
        xmlXPathInit();
        atexit(xmlCleanupParser);

        initxml = true;
    }

    xmlDoc *doc = NULL;
    xmlXPathContext *ctx = NULL;

    try
    {
        doc = xmlParseFile(fname.c_str());
        if(!doc)
            throw std::runtime_error("Syntax error in "+fname);

        if(!doc->children)
            throw std::runtime_error("Semantic error in "+fname);

        ctx = xmlXPathNewContext(doc);
        if(!ctx)
            throw std::runtime_error("Unable to create XPath context");

        params.fname0 = get_data(ctx, "//project/images/@image1",params.fname0);
        params.fname1 = get_data(ctx, "//project/images/@image2",params.fname1);

        // circumvent MdiEditor's notion that relative files must begin with '/'
        if(!params.fname0.empty() && (params.fname0[0] == '/' || params.fname0[0] == '\\'))
            params.fname0 = params.fname0.substr(1);
        if(!params.fname1.empty() && (params.fname1[0] == '/' || params.fname1[0]=='\\'))
            params.fname1 = params.fname1.substr(1);

	int slash = fname.find_last_of("/\\");
	std::string root_path;

	if(slash != fname.npos)
	{
	    root_path = fname.substr(0,slash+1); // root_path includes final slash
	    params.fname0 = root_path + params.fname0;
	    params.fname1 = root_path + params.fname1;
	}

        std::string base = "/project/layers";

        params.w_tps
            = get_data(ctx, base+"/l0/parameters/weight/@tps", params.w_tps);

        params.w_ssim
            = get_data(ctx, base+"/l0/parameters/weight/@ssim", params.w_ssim);

        params.w_ui
            = get_data(ctx, base+"/l0/parameters/weight/@ui", params.w_ui);

        params.ssim_clamp
            = 1-get_data(ctx, base+"/l0/parameters/weight/@ssimclamp", 1-params.ssim_clamp);

        int bound;
        switch(params.bcond)
        {
        case BCOND_NONE:
            bound = 0;
            break;
        case BCOND_CORNER:
            bound = 1;
            break;
        case BCOND_BORDER:
            bound = 2;
            break;
        }

        bound = get_data(ctx, base+"/l0/parameters/boundary/@lock", bound);

        switch(bound)
        {
        case 0:
            params.bcond = BCOND_NONE;
            break;
        case 1:
            params.bcond = BCOND_CORNER;
            break;
        case 2:
            params.bcond = BCOND_BORDER;
            break;
        default:
            throw std::runtime_error("Bad boundary value");
        }

        params.eps
            = get_data(ctx, base+"/l0/parameters/debug/@eps", params.eps);
        params.start_res
            = get_data(ctx, base+"/l0/parameters/debug/@startres", params.start_res);
        params.max_iter
            = get_data(ctx, base+"/l0/parameters/debug/@iternum", params.max_iter);
        params.max_iter_drop_factor
            = get_data(ctx, base+"/l0/parameters/debug/@dropfactor", params.max_iter_drop_factor);

        std::string pts0
            = get_data(ctx, base+"/l0/parameters/points/@image1", "");

        std::string pts1
            = get_data(ctx, base+"/l0/parameters/points/@image2", "");

        if(!pts0.empty())
        {
            params.ui_points.clear();

            std::istringstream ss0(pts0), ss1(pts1);

            while(ss0 && ss1)
            {
                ConstraintPoint cpt;

                float2 pt;
                ss0 >> pt.x >> pt.y;
                cpt.lp = make_double2(pt.x, pt.y);

                ss1 >> pt.x >> pt.y;
                cpt.rp = make_double2(pt.x, pt.y);

                if(ss0 && ss1)
                    params.ui_points.push_back(cpt);
            }

            if(ss0.eof() && !ss1.eof() || !ss0.eof() && ss1.eof())
                throw std::runtime_error("Control point parsing error");
        }

        xmlXPathFreeContext(ctx);
        xmlFreeDoc(doc);
    }