Exemplo n.º 1
0
PackageCanvas * PackageCanvas::read(char * & st, UmlCanvas * canvas, char * k) {
  if (!strcmp(k, "packagecanvas_ref"))
    return ((PackageCanvas *) dict_get(read_id(st), "packagecanvas", canvas));
  else if (!strcmp(k, "packagecanvas")) {
    int id = read_id(st);
    BrowserNode * br = BrowserPackage::read_ref(st);
    UmlColor color = UmlDefaultColor;
    Uml3States in_tab = UmlDefaultState;
    ShowContextMode context = DefaultShowContextMode;
    Uml3States show_stereotype_properties = UmlDefaultState;;
    
    k = read_keyword(st);
    
    if (!strcmp(k, "name_in_tab")) {
      in_tab = state(read_keyword(st));
      k = read_keyword(st);
    }
    
    if (!strcmp(k, "show_context_mode")) {
      context = context_mode(read_keyword(st));
      k = read_keyword(st);
    }

    if (!strcmp(k, "show_stereotype_properties")) {
      show_stereotype_properties = state(read_keyword(st));
      k = read_keyword(st);
    }

    read_color(st, "color", color, k);
    
    if (strcmp(k, "xyzwh"))
      wrong_keyword(k, "xyzwh");
    
    int x = (int) read_double(st);
    PackageCanvas * result =
      new PackageCanvas(br, canvas, x, (int) read_double(st), id);
    
    read_zwh(st, result);
    
    if (read_file_format() >= 58) {
      k = read_keyword(st);
      result->read_stereotype_property(st, k);	// updates k
      if (strcmp(k, "end"))
	wrong_keyword(k, "end");
    }
    
    result->name_in_tab = in_tab;
    result->show_context_mode = context;
    result->show_stereotype_properties = show_stereotype_properties;
    result->itscolor = color;
    result->check_size();
    result->set_center100();
    result->show();
    result->check_stereotypeproperties();
    
    return result;
  }
  else
    return 0;
}
Exemplo n.º 2
0
int readParameters(int *xlength, double *tau, double *velocityWall, int *timesteps, int *timestepsPerPlotting, int argc, char *argv[]){
        // argument handling
        if (argc !=2 ) {
                printf("When running the simulation, please give a valid file name to read from!\n");
                return 1;
        }

	// get file name
	const char *FileName = NULL;
	FileName = argv[1];

	// read parameters, using read functions from helper
	read_int ( FileName, "xlength", xlength );

	read_double ( FileName, "tau", tau );

	read_double ( FileName, "velocityWallx", &velocityWall[0] );
	read_double ( FileName, "velocityWally", &velocityWall[1] );
	read_double ( FileName, "velocityWallz", &velocityWall[2] );

	read_int ( FileName, "timesteps", timesteps );
	read_int ( FileName, "timestepsPerPlotting", timestepsPerPlotting );

	return 0;
}
Exemplo n.º 3
0
bool
gs_image_size_sub (string buf, int& w_pt, int& h_pt) {
  int pos= search_forwards ("\n%%BoundingBox: ", buf);
  if (pos < 0) pos = search_forwards ("%%BoundingBox: ", buf);
  if (pos < 0) return false;
  if (buf[pos] == '\n') pos++;
  bool ok= read (buf, pos, "%%BoundingBox: ");
  double X1, Y1, X2, Y2;
  int x1, y1, x2, y2;
  skip_spaces (buf, pos);
  ok= read_double (buf, pos, X1) && ok;
  x1= (int) floor (X1);
  skip_spaces (buf, pos);
  ok= read_double (buf, pos, Y1) && ok;
  y1= (int) floor (Y1);
  skip_spaces (buf, pos);
  ok= read_double (buf, pos, X2) && ok;
  x2= (int) ceil (X2);
  skip_spaces (buf, pos);
  ok= read_double (buf, pos, Y2) && ok;
  y2= (int) ceil (Y2);
  if (!ok) return false;
  w_pt= x2-x1;
  h_pt= y2-y1;
  return true;
}
Exemplo n.º 4
0
AssocContainCanvas * AssocContainCanvas::read(char * & st, UmlCanvas * canvas, char * k)
{
  if (!strcmp(k, "containcanvas_ref"))
    return ((AssocContainCanvas *) dict_get(read_id(st), "contain canvas", canvas));
  else if (!strcmp(k, "containcanvas")) {
    int id = read_id(st);    
    LineGeometry geo;
    bool fixed;
    
    k = read_keyword(st);	// may read id
    if (!strcmp(k, "geometry")) {
      geo = line_geometry(read_keyword(st));
      k = read_keyword(st);
      if (! strcmp(k, "unfixed")) {
	k = read_keyword(st);
	fixed = FALSE;
      }
      else
	fixed = TRUE;
    }
    else {
      geo = NoGeometry;
      fixed = FALSE;
    }
    
    float dbegin;
    float dend;

    if (! strcmp(k, "decenter_begin")) {
      dbegin = read_double(st) / 1000;
      k = read_keyword(st);
    }
    else
      dbegin = -1;

    if (! strcmp(k, "decenter_end")) {
      dend = read_double(st) / 1000;
      k = read_keyword(st);
    }
    else
      dend = -1;
    
    unread_keyword(k, st);
    
    AssocContainCanvas * r = (AssocContainCanvas *)
      read_list(st, canvas, UmlContain, geo, fixed, dbegin, dend, id, &make);
    
    // remove association between components available in the
    // 2.0 deployment diagrams
    if (r->begin->type() == UmlComponent)
      Undefined.append(r);
    else if (read_file_format() == 30)
      // to remove redondant transitions made by release 2.22
      RelsToCheck.append(r);
    
    return r;
  }
  else
    return 0;
}
Exemplo n.º 5
0
static void
collect_memory (CockpitSamples *samples,
                const gchar *path,
                const gchar *cgroup)
{
  double mem_usage_in_bytes;
  double mem_limit_in_bytes;
  double memsw_usage_in_bytes;
  double memsw_limit_in_bytes;

  if (access (path, F_OK) == 0)
    {
      mem_usage_in_bytes = read_double (path, "memory.usage_in_bytes");
      mem_limit_in_bytes = read_double (path, "memory.limit_in_bytes");
      memsw_usage_in_bytes = read_double (path, "memory.memsw.usage_in_bytes");
      memsw_limit_in_bytes = read_double (path, "memory.memsw.limit_in_bytes");

      /* If at max for arch, then unlimited => zero */
      if (mem_limit_in_bytes == (double)G_MAXSIZE ||
          mem_limit_in_bytes == (double)G_MAXSSIZE)
        mem_limit_in_bytes = 0;
      if (memsw_limit_in_bytes == (double)G_MAXSIZE ||
          memsw_limit_in_bytes == (double)G_MAXSSIZE)
        memsw_limit_in_bytes = 0;

      cockpit_samples_sample (samples, "cgroup.memory.usage", cgroup, mem_usage_in_bytes);
      cockpit_samples_sample (samples, "cgroup.memory.limit", cgroup, mem_limit_in_bytes);
      cockpit_samples_sample (samples, "cgroup.memory.sw-usage", cgroup, memsw_usage_in_bytes);
      cockpit_samples_sample (samples, "cgroup.memory.sw-limit", cgroup, memsw_limit_in_bytes);
    }
}
Exemplo n.º 6
0
/**
 * Reads the parameters for the lid driven cavity scenario from a config file.
 * Throws an error if number of program arguments does not equal 2.
 **/
int readParameters(
    int *xlength,                       /* reads domain size. Parameter name: "xlength" */
    double *tau,                        /* relaxation parameter tau. Parameter name: "tau" */
    double *velocityWall,               /* velocity of the lid. Parameter name: "characteristicvelocity" */
    int *timesteps,                     /* number of timesteps. Parameter name: "timesteps" */
    int *timestepsPerPlotting,          /* timesteps between subsequent VTK plots. Parameter name: "vtkoutput" */
    int argc,                           /* number of arguments. Should equal 2 (program + name of config file */
    char *argv[]                        /* argv[1] shall contain the path to the config file */
    ){

    const char *szFileName = argv[1];

    if (argc != 2) {
        ERROR("number of arguments is incorrect");
    }

    read_int(szFileName, "xlength", xlength);
    read_double(szFileName,"tau", tau);
    read_double(szFileName, "characteristicvelocity_x", &velocityWall[0]);
    read_double(szFileName, "characteristicvelocity_y", &velocityWall[1]);
    read_double(szFileName, "characteristicvelocity_z", &velocityWall[2]);
    read_int(szFileName, "timesteps", timesteps);
    read_int(szFileName, "vtkoutput", timestepsPerPlotting);

    return 0;
}
Exemplo n.º 7
0
void 
Squeezer_file_header_t::read_from_file(FILE * in)
{
    file_type_mark[0] = read_uint8(in);
    file_type_mark[1] = read_uint8(in);
    file_type_mark[2] = read_uint8(in);
    file_type_mark[3] = read_uint8(in);

    floating_point_check = read_double(in);

    date_year = read_uint16(in);
    date_month = read_uint8(in);
    date_day = read_uint8(in);

    time_hour = read_uint8(in);
    time_minute = read_uint8(in);
    time_second = read_uint8(in);

    radiometer.horn = read_uint8(in);
    radiometer.arm = read_uint8(in);
    od = read_uint16(in);
    first_obt = read_double(in);
    last_obt = read_double(in);
    first_scet_in_ms = read_double(in);
    last_scet_in_ms = read_double(in);
    number_of_chunks = read_uint32(in);
}
template<> std::unique_ptr<Result>
DataServer::command(ReadSalesStatsUserCmd* cmd)
{
    if( cmd->user > 0 ) {
        sql << "select emp, sum(amt), count(amt) as sale_count from sales where amt > 0 and emp = " << cmd->user;
    }
    else {
        sql << "select distinct on (emp) emp, sum(amt), count(amt) as sale_count from sales where amt > 0;";
    }
    run_sql();

    std::unique_ptr<Result> result(new Result);

    for( int i = 0; i < tuple_count(); i++ ) {
        Item* sale_stat = new Item;
        sale_stat->push_property("user", read_int(i, "emp"));
        sale_stat->push_property("total", read_double(i, "sum"));
        sale_stat->push_property("sale_count", read_double(i, "sale_count"));
        result->items.push_back( std::unique_ptr<Item>(sale_stat) );
    }

    clr_sql();

    return result;
}
Exemplo n.º 9
0
DeploymentNodeCanvas * DeploymentNodeCanvas::read(char * & st, UmlCanvas * canvas, char * k) {
  if (!strcmp(k, "deploymentnodecanvas_ref"))
    return ((DeploymentNodeCanvas *) dict_get(read_id(st), "deploymentnodecanvas", canvas));
  else if (!strcmp(k, "deploymentnodecanvas")) {
    int id = read_id(st);
    BrowserNode * br = BrowserDeploymentNode::read_ref(st);
    QString iname;
    Uml3States write_horizontally = UmlDefaultState;
    Uml3States show_stereotype_properties = UmlDefaultState;
    
    k = read_keyword(st);
    
    if (!strcmp(k, "name")) {
      iname = read_string(st);
      k = read_keyword(st);
    }
    if (!strcmp(k, "write_horizontally") ||
	!strcmp(k, "write_horizontaly")) {
      write_horizontally = state(read_keyword(st));
      k = read_keyword(st);
    }
    if (!strcmp(k, "show_stereotype_properties")) {
      show_stereotype_properties = state(read_keyword(st));
      k = read_keyword(st);
    }
    
    UmlColor color = UmlDefaultColor;
    
    read_color(st, "color", color, k);
    
    if (strcmp(k, "xyzwh"))
      wrong_keyword(k, "xyzwh");
    
    int x = (int) read_double(st);
    DeploymentNodeCanvas * result =
      new DeploymentNodeCanvas(br, canvas, x, (int) read_double(st), id);
    
    read_zwh(st, result);
    
    if (read_file_format() >= 58) {
      k = read_keyword(st);
      result->read_stereotype_property(st, k);	// updates k
      if (strcmp(k, "end"))
	wrong_keyword(k, "end");
    }
    
    result->iname = iname;
    result->write_horizontally = write_horizontally;
    result->show_stereotype_properties = show_stereotype_properties;
    result->itscolor = color;
    result->check_size();
    result->set_center100();
    result->show();
    result->check_stereotypeproperties();
    
    return result;
  }
  else
    return 0;
}
Exemplo n.º 10
0
void
Error_t::read_from_file(FILE * in)
{
    min_abs_error = read_double(in);
    max_abs_error = read_double(in);
    mean_abs_error = read_double(in);
    mean_error = read_double(in);
}
Exemplo n.º 11
0
Arquivo: wkb.cpp Projeto: rjw57/mapnik
 void read_point(boost::ptr_vector<geometry_type> & paths)
 {
     geometry_type* pt = new geometry_type(Point);
     double x = read_double();
     double y = read_double();
     pt->move_to(x, y);
     paths.push_back(pt);
 }
Exemplo n.º 12
0
Arquivo: wkb.cpp Projeto: bblu/mapnik
 mapnik::geometry::point<double> read_point()
 {
     double x = read_double();
     double y = read_double();
     if (Z) pos_ += 8;
     if (M) pos_ += 8;
     return mapnik::geometry::point<double>(x, y);
 }
Exemplo n.º 13
0
 geometry_ptr read_point()
 {
     geometry_ptr pt(new point<vertex2d>(srid_));
     double x = read_double();
     double y = read_double();
     pt->move_to(x,y);
     return pt;
 }
Exemplo n.º 14
0
 void read_point(boost::ptr_vector<geometry_type> & paths)
 {
     double x = read_double();
     double y = read_double();
     std::unique_ptr<geometry_type> pt(new geometry_type(geometry_type::types::Point));
     pt->move_to(x, y);
     paths.push_back(pt.release());
 }
Exemplo n.º 15
0
static readstat_error_t read_variable_count_record(readstat_por_ctx_t *ctx) {
    double value;
    if (read_double(ctx, &value) == -1) {
        return READSTAT_ERROR_PARSE;
    }
    ctx->var_count = (int)value;
    ctx->varinfo = calloc(ctx->var_count, sizeof(spss_varinfo_t));
    if (read_double(ctx, NULL) == -1) {
        return READSTAT_ERROR_PARSE;
    }
    return READSTAT_OK;
}
Exemplo n.º 16
0
UcUseCaseCanvas * UcUseCaseCanvas::read(char * & st, UmlCanvas * canvas, char * k)
{
  if (!strcmp(k, "usecasecanvas_ref"))
    return ((UcUseCaseCanvas *) dict_get(read_id(st), "usecasecanvas", canvas));
  else if (!strcmp(k, "usecasecanvas")) {
    int id = read_id(st);
    BrowserNode * br = BrowserUseCase::read_ref(st);
    UmlColor color = UmlDefaultColor;
    
    k = read_keyword(st);
    read_color(st, "color", color, k);
    
    if (strcmp(k, "xyzwh"))
      wrong_keyword(k, "xyzwh");
    
    int x = (int) read_double(st);
    UcUseCaseCanvas * result =
      new UcUseCaseCanvas(br, canvas, x, (int) read_double(st), id);
    
    result->itscolor = color;
    read_zwh(st, result);
    result->width_scale100 = result->width();
    result->height_scale100 = result->height();
    result->set_center100();

    k = read_keyword(st);
    result->update_name();
    read_xy(st, result->label);
    result->label->setZ(result->z() + 0.5);
    result->label->set_center100();
    
    if (!strcmp(k, "label_xyz"))
      // old version
      read_double(st);
    else if (strcmp(k, "label_xy"))
      wrong_keyword(k, "label_xy/label_xyz");
    
    if (read_file_format() >= 58) {
      k = read_keyword(st);
      result->read_stereotype_property(st, k);	// updates k
      
      if (strcmp(k, "end"))
	wrong_keyword(k, "end");
    }
    
    result->show();
    result->check_stereotypeproperties();
    return result;
  }
  else
    return 0;
}
Exemplo n.º 17
0
 geometry_ptr read_multipoint()
 {
     geometry_ptr pt(new point<vertex2d>(srid_));
     int num_points = read_integer();
     for (int i=0;i<num_points;++i) 
     {
         pos_+=5; 
         double x = read_double();
         double y = read_double();
         pt->move_to(x,y);
     }
     return pt; 
 }
Exemplo n.º 18
0
static readstat_error_t read_value_label_record(readstat_por_ctx_t *ctx) {
    double dval;
    int i;
    char string[256];
    int count = 0, label_count = 0;
    char label_name_buf[256];
    char label_buf[256];
    snprintf(label_name_buf, sizeof(label_name_buf), POR_LABEL_NAME_PREFIX "%d", ctx->labels_offset);
    readstat_types_t value_type = READSTAT_TYPE_DOUBLE;
    if (read_double(ctx, &dval) == -1) {
        return READSTAT_ERROR_PARSE;
    }
    count = (int)dval;
    for (i=0; i<count; i++) {
        if (read_string(ctx, string, sizeof(string)) == -1) {
            return READSTAT_ERROR_PARSE;
        }
        spss_varinfo_t *info = (spss_varinfo_t *)ck_str_hash_lookup(string, ctx->var_dict);
        if (info) {
            value_type = info->type;
            info->labels_index = ctx->labels_offset;
        }
    }
    if (read_double(ctx, &dval) == -1) {
        return READSTAT_ERROR_PARSE;
    }
    label_count = (int)dval;
    for (i=0; i<label_count; i++) {
        readstat_value_t value = { .type = value_type };
        if (value_type == READSTAT_TYPE_STRING) {
            if (read_string(ctx, string, sizeof(string)) == -1) {
                return READSTAT_ERROR_PARSE;
            }
            if (read_string(ctx, label_buf, sizeof(label_buf)) == -1) {
                return READSTAT_ERROR_PARSE;
            }
            value.v.string_value = string;
        } else {
            if (read_double(ctx, &dval) == -1) {
                return READSTAT_ERROR_PARSE;
            }
            if (read_string(ctx, label_buf, sizeof(label_buf)) == -1) {
                return READSTAT_ERROR_PARSE;
            }
            value.v.double_value = dval;
        }
        ctx->value_label_handler(label_name_buf, value, label_buf, ctx->user_ctx);
    }
    ctx->labels_offset++;
    return READSTAT_OK;
}
Exemplo n.º 19
0
ifstream* CovOptimData::read(const char* filename, CovOptimData& cov, std::stack<unsigned int>& format_id, std::stack<unsigned int>& format_version) {

	ifstream* f = CovList::read(filename, cov, format_id, format_version);

	if (format_id.empty() || format_id.top()!=subformat_number || format_version.top()!=FORMAT_VERSION) {
		cov.data->_optim_optimizer_status = (unsigned int) Optimizer::SUCCESS;
		cov.data->_optim_is_extended_space = false;
		cov.data->_optim_uplo = NEG_INFINITY;
		cov.data->_optim_loup = POS_INFINITY;
		cov.data->_optim_loup_point.resize((int) cov.n);
		cov.data->_optim_loup_point = IntervalVector::empty(cov.n);
		cov.data->_optim_time = -1;
		cov.data->_optim_nb_cells = 0;
	}
	else {
		format_id.pop();
		format_version.pop();

		read_vars(*f, cov.n, cov.data->_optim_var_names);

		unsigned int status = read_pos_int(*f);

		switch (status) {
		case 0: cov.data->_optim_optimizer_status = (unsigned int) Optimizer::SUCCESS;           break;
		case 1: cov.data->_optim_optimizer_status = (unsigned int) Optimizer::INFEASIBLE;        break;
		case 2: cov.data->_optim_optimizer_status = (unsigned int) Optimizer::NO_FEASIBLE_FOUND; break;
		case 3: cov.data->_optim_optimizer_status = (unsigned int) Optimizer::UNBOUNDED_OBJ;     break;
		case 4: cov.data->_optim_optimizer_status = (unsigned int) Optimizer::TIME_OUT;     		break;
		case 5: cov.data->_optim_optimizer_status = (unsigned int) Optimizer::UNREACHED_PREC;    break;
		default: ibex_error("[CovOptimData]: invalid optimizer status.");
		}

		cov.data->_optim_is_extended_space = (bool) read_pos_int(*f);
		cov.data->_optim_uplo              = read_double(*f);
		cov.data->_optim_uplo_of_epsboxes  = read_double(*f);
		cov.data->_optim_loup              = read_double(*f);

		unsigned int loup_found   = read_pos_int(*f);
		unsigned int nb_var   = cov.is_extended_space() ? cov.n-1 : cov.n;
		cov.data->_optim_loup_point.resize((int) nb_var);
		// TODO: we assume here that the goal var is n-1
		cov.data->_optim_loup_point 		  = loup_found==1? cov[0].subvector(0,nb_var-1) : IntervalVector::empty(nb_var);

		cov.data->_optim_time              = read_double(*f);
		cov.data->_optim_nb_cells          = read_pos_int(*f);
	}

	return f;
}
Exemplo n.º 20
0
ArrowPointCanvas * ArrowPointCanvas::read(char *& st, UmlCanvas * canvas,
                                          char * k)
{
    if (strcmp(k, "point"))
        return 0;

    int x = (int) read_double(st);

    ArrowPointCanvas * result =
            new ArrowPointCanvas(canvas, x, (int) read_double(st));

    result->show();

    return result;
}
Exemplo n.º 21
0
void ComponentDiagramView::read(char * st, char * k) {
  UmlCanvas * canvas = the_canvas();
  
  // reads first component package icons notes junctions text and images
  while (ComponentCanvas::read(st, canvas, k) ||
	 NoteCanvas::read(st, canvas, k) ||
	 TextCanvas::read(st, canvas, k) ||
	 IconCanvas::read(st, canvas, k) ||
	 PackageCanvas::read(st, canvas, k) ||
	 FragmentCanvas::read(st, canvas, k) ||
	 ArrowJunctionCanvas::read(st, canvas, k) ||
	 ImageCanvas::read(st, canvas, k))
    k = read_keyword(st);
  
  // then reads relations and anchors
  ArrowCanvas * a;
  
  while (((a = ArrowCanvas::read(st, canvas, k)) != 0) ||
	 ((a = SimpleRelationCanvas::read(st, canvas, k)) != 0)) {
    a->get_start()->check_line(a);
    k = read_keyword(st);
  }
  
  if (!strcmp(k, "preferred_whz") || !strcmp(k, "prefered_whz")) {
    preferred_size.setWidth(read_unsigned(st));
    preferred_size.setHeight(read_unsigned(st));
    preferred_zoom = read_double(st);
    k = read_keyword(st);
  }
  
  if (strcmp(k, "end"))
    wrong_keyword(k, "end");
}
Exemplo n.º 22
0
void ObjectDiagramView::read(char * st, char * k) {
  UmlCanvas * canvas = the_canvas();
  
  // reads first the instances, package, fragment notes, icons text and image
  while (OdClassInstCanvas::read(st, canvas, k) ||
	 NoteCanvas::read(st, canvas, k) ||
	 TextCanvas::read(st, canvas, k) ||
	 IconCanvas::read(st, canvas, k) ||
	 PackageCanvas::read(st, canvas, k) ||
	 FragmentCanvas::read(st, canvas, k) ||
	 ImageCanvas::read(st, canvas, k))
    k = read_keyword(st);
  
  // then reads links 
  while (ObjectLinkCanvas::read(st, canvas, k))
    k = read_keyword(st);
  
  // then reads anchors
  while (ArrowCanvas::read(st, canvas, k))
    k = read_keyword(st);
  
  if (!strcmp(k, "preferred_whz") || !strcmp(k, "prefered_whz")) {
    preferred_size.setWidth(read_unsigned(st));
    preferred_size.setHeight(read_unsigned(st));
    preferred_zoom = read_double(st);
    k = read_keyword(st);
  }
  
  if (strcmp(k, "end"))
    wrong_keyword(k, "end");
}
Exemplo n.º 23
0
template<> std::unique_ptr<Result> DataServer::command(DateReportHourCmd* cmd)
{
    sql << "select distinct extract(hour from start_t) as hour, sum(amt) as total, count(amt) as sale_count"
        << " from sales where amt > 0 ";
    if( cmd->y > -1 ) sql << "and extract(year from start_t) = " << cmd->y;
    if( cmd->m > -1 ) sql << " and extract(month from start_t) = " << cmd->m;
    if( cmd->d > -1 ) sql << " and extract(day from start_t) = " << cmd->d;

    sql << " group by hour order by total desc;";

    run_sql();
    std::unique_ptr<Result> result(new Result);

    for( int i = 0; i < tuple_count(); i++ ) {
        Item* hour_stat = new Item;
        hour_stat->push_property("name", read_int(i, "hour"));
        hour_stat->push_property("total", read_double(i, "total"));
        hour_stat->push_property("sale_count", read_int(i, "sale_count"));

        result->items.push_back( std::unique_ptr<Item>(hour_stat) );
    }

    clr_sql();

    return result;
}
Exemplo n.º 24
0
template<> std::unique_ptr<Result> DataServer::command(DateReportItemCmd* cmd)
{
    sql << "select distinct menu_id, sum(amount), count(amount) from sold_items where extract(year from tstamp) = " << cmd->y;
    if( cmd->m != -1 )
        sql << " and extract(month from tstamp) = " << cmd->m;
    if( cmd->d != -1 )
        sql << " and extract(day from tstamp) = " << cmd->d;

    sql << " group by menu_id order by sum desc;";

    run_sql();

    std::unique_ptr<Result> result(new Result);

    for( int i = 0; i < tuple_count(); i++ ) {
        Item* sold_item = new Item;
        sold_item->push_property("name", "");//read_cstring(i, "name"));
        sold_item->push_property("menu_id", read_int(i, "menu_id"));
        sold_item->push_property("total", read_double(i, "sum"));
        sold_item->push_property("count", read_int(i, "count"));

        result->items.push_back( std::unique_ptr<Item>(sold_item) );
    }

    clr_sql();

    return result;
}
Exemplo n.º 25
0
template<> std::unique_ptr<Result> DataServer::command(DateReportUserCmd* cmd)
{
    sql << "select distinct on (emp) emp, sum(amt), count(amt) as sale_count from sales where amt > 0";
    if( cmd->y != -1 )
        sql << " and extract(year from start_t) = " << cmd->y;
    if( cmd->m != -1 )
        sql << " and extract(month from start_t) = " << cmd->m;
    if( cmd->d != -1 )
        sql << " and extract(day from start_t) = " << cmd->d;

    sql << " group by emp;";

    run_sql();

    std::unique_ptr<Result> result(new Result);

    for( int i = 0; i < tuple_count(); i++ ) {
        Item* sale_stat = new Item;
        sale_stat->push_property("id", read_int(i, "emp"));
        sale_stat->push_property("total", read_double(i, "sum"));
        sale_stat->push_property("sale_count", read_int(i, "sale_count"));
        result->items.push_back( std::unique_ptr<Item>(sale_stat) );
    }

    clr_sql();

    return result;
}
Exemplo n.º 26
0
static struct value *
read_value(struct _field *f, struct atom * a, uint8_t *buffer) {
	struct value * v;

	switch (f->type) {
	case PTYPE_DOUBLE:
		v = malloc(SIZE_VAR);
		v->v.var->real = read_double(a);
		break;
	case PTYPE_FLOAT:
		v = malloc(SIZE_VAR);
		v->v.var->real = (double) read_float(a);
		break;
	case PTYPE_ENUM:
		v = malloc(SIZE_VAR);
		v->v.var->e.id = a->v.i.low;
		v->v.var->e.name = _pbcM_ip_query(f->type_name.e->id , a->v.i.low);
		break;
	case PTYPE_INT64:
	case PTYPE_UINT64:
	case PTYPE_INT32:
	case PTYPE_UINT32:
	case PTYPE_FIXED32:
	case PTYPE_FIXED64:
	case PTYPE_SFIXED32:
	case PTYPE_SFIXED64:
	case PTYPE_BOOL:
		v = malloc(SIZE_VAR);
		v->v.var->integer = a->v.i;
		break;
	case PTYPE_SINT32: 
		v = malloc(SIZE_VAR);
		v->v.var->integer = a->v.i;
		varint_dezigzag32(&(v->v.var->integer));
		break;
	case PTYPE_SINT64:
		v = malloc(SIZE_VAR);
		v->v.var->integer = a->v.i;
		varint_dezigzag64(&(v->v.var->integer));
		break;
	case PTYPE_STRING:
		v = read_string(a,f,buffer);
		break;
	case PTYPE_BYTES:
		v = malloc(SIZE_VAR);
		v->v.var->s.str = (const char *)(buffer + a->v.s.start);
		v->v.var->s.len = a->v.s.end - a->v.s.start;
		break;
	case PTYPE_MESSAGE:
		v = malloc(SIZE_MESSAGE);
		_pbc_rmessage_new(&(v->v.message), f->type_name.m , 
			buffer + a->v.s.start , 
			a->v.s.end - a->v.s.start);
		break;
	default:
		return NULL;
	}
	v->type = f;
	return v;
}
Exemplo n.º 27
0
void ClassDiagramView::read(char * st, char * k) {
  UmlCanvas * canvas = the_canvas();
  
  // reads first the classes package icons text notes and images
  while (CdClassCanvas::read(st, canvas, k) ||
	 NoteCanvas::read(st, canvas, k) ||
	 TextCanvas::read(st, canvas, k) ||
	 IconCanvas::read(st, canvas, k) ||
	 PackageCanvas::read(st, canvas, k) ||
	 FragmentCanvas::read(st, canvas, k) ||
	 ImageCanvas::read(st, canvas, k))
    k = read_keyword(st);
  
  // then reads relations and anchors
  while (ArrowCanvas::read(st, canvas, k) ||
	 RelationCanvas::read(st, canvas, k) ||
	 SimpleRelationCanvas::read(st, canvas, k))
    k = read_keyword(st);
  
  if (!strcmp(k, "preferred_whz") || !strcmp(k, "prefered_whz")) {
    preferred_size.setWidth(read_unsigned(st));
    preferred_size.setHeight(read_unsigned(st));
    preferred_zoom = read_double(st);
    k = read_keyword(st);
  }
  
  if (strcmp(k, "end"))
    wrong_keyword(k, "end");
}
Exemplo n.º 28
0
void DeploymentDiagramView::read(char * st, char * k) {
  UmlCanvas * canvas = the_canvas();
  
  // reads first deploymentnode component icons text notes and image
  while (DeploymentNodeCanvas::read(st, canvas, k) ||
	 // reads artifact before component to manage component -> artifact
	 ArtifactCanvas::read(st, canvas, k) ||
	 ComponentCanvas::read(st, canvas, k) ||
	 HubCanvas::read(st, canvas, k) ||
	 NoteCanvas::read(st, canvas, k) ||
	 TextCanvas::read(st, canvas, k) ||
	 IconCanvas::read(st, canvas, k) ||
	 PackageCanvas::read(st, canvas, k) ||
	 FragmentCanvas::read(st, canvas, k) ||
	 ImageCanvas::read(st, canvas, k))
    k = read_keyword(st);
  
  // then reads relations and anchors
  while (ArrowCanvas::read(st, canvas, k) ||
	 AssocContainCanvas::read(st, canvas, k) ||
	 SimpleRelationCanvas::read(st, canvas, k))
    k = read_keyword(st);
  
  if (!strcmp(k, "preferred_whz") || !strcmp(k, "prefered_whz")) {
    preferred_size.setWidth(read_unsigned(st));
    preferred_size.setHeight(read_unsigned(st));
    preferred_zoom = read_double(st);
    k = read_keyword(st);
  }
  
  if (strcmp(k, "end"))
    wrong_keyword(k, "end");
}
Exemplo n.º 29
0
//
// read a double value from the storage set
PyObject *PyStorageSet_readDouble(PyObject *self, PyObject *args) {
  char *key = PyStorageSet_readParseKey(args);
  if(key != NULL) 
    return Py_BuildValue("d", read_double(((PyStorageSet *)self)->set, key));
  else
    return NULL;
}
Exemplo n.º 30
0
Arquivo: inifile.c Projeto: LinLL/ipc
int main (void)
{
	printf ("Hello World\n");
	OpenIniFile ("Test.Ini");
#ifdef INIFILE_TEST_READ_AND_WRITE
	write_string  ("Test", "Name", "Value");
	write_string  ("Test", "Name", "OverWrittenValue");
	write_string  ("Test", "Port", "COM1");
	write_string  ("Test", "User", "James Brown jr.");
	write_string  ("Configuration", "eDriver", "MBM2.VXD");
	write_string  ("Configuration", "Wrap", "LPT.VXD");
	write_int 	 ("IO-Port", "Com", 2);
	write_bool 	 ("IO-Port", "IsValid", 0);
	write_double  ("TheMoney", "TheMoney", 67892.00241);
	write_int     ("Test"    , "ToDelete", 1234);
	WriteIniFile ("Test.Ini");
	printf ("Key ToDelete created. Check ini file. Any key to continue");
	while (!kbhit());
	OpenIniFile  ("Test.ini");
	delete_key    ("Test"	  , "ToDelete");
	WriteIniFile ("Test.ini");
#endif
	printf ("[Test] Name = %s\n", read_string ("Test", "Name", "NotFound"));
	printf ("[Test] Port = %s\n", read_string ("Test", "Port", "NotFound"));
	printf ("[Test] User = %s\n", read_string ("Test", "User", "NotFound"));
	printf ("[Configuration] eDriver = %s\n", read_string ("Configuration", "eDriver", "NotFound"));
	printf ("[Configuration] Wrap = %s\n", read_string ("Configuration", "Wrap", "NotFound"));
	printf ("[IO-Port] Com = %d\n", read_int ("IO-Port", "Com", 0));
	printf ("[IO-Port] IsValid = %d\n", read_bool ("IO-Port", "IsValid", 0));
	printf ("[TheMoney] TheMoney = %1.10lf\n", read_double ("TheMoney", "TheMoney", 111));
	CloseIniFile ();
	return 0;
}