Example #1
0
std::string formatBalance(bigint const& _b)
{
    ostringstream ret;
    u256 b;
    if (_b < 0)
    {
        ret << "-";
        b = (u256)-_b;
    }
    else
        b = (u256)_b;

    if (b > units()[0].first * 10000)
    {
        ret << (b / units()[0].first) << " " << units()[0].second;
        return ret.str();
    }
    ret << setprecision(5);
    for (auto const& i: units())
        if (i.first != 1 && b >= i.first * 100)
        {
            ret << (double(b / (i.first / 1000)) / 1000.0) << " " << i.second;
            return ret.str();
        }
    ret << b << " wei";
    return ret.str();
}
Example #2
0
bool 
Block::flag (const symbol key) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return flag (expand_reference (key));

  //Handle primitive flags.
  Attribute::type type = lookup (key);
  if (type != Attribute::Model)
    return frame.flag (key); 

  // Handle boolean objects.
  daisy_assert (type == Attribute::Model);
  daisy_assert (frame.component (key) == Boolean::component);
  daisy_assert (frame.check (*this));
  std::unique_ptr<Boolean> boolean (Librarian::build_frame<Boolean> 
                                (*this, frame.model (key), key));
  daisy_assert (boolean.get ());
  daisy_assert (boolean->initialize (units (), *this, msg ()));
  daisy_assert (boolean->check (units (), *this, msg ()));
  boolean->tick (units (), *this, msg ());
  daisy_assert (!boolean->missing (*this));
  return boolean->value (*this);
}
Example #3
0
symbol
Block::name (const symbol key) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return name (expand_reference (key));

  //Handle primitive names.
  Attribute::type type = lookup (key);
  if (type != Attribute::Model)
    return expand_string (frame.name (key)); 

  // Handle stringer objects.
  daisy_assert (type == Attribute::Model);
  daisy_assert (frame.component (key) == Stringer::component);
  daisy_assert (frame.check (*this));
  std::unique_ptr<Stringer> stringer (Librarian::build_frame<Stringer> 
                                (*this, frame.model (key), key));
  daisy_assert (stringer.get ());
  daisy_assert (stringer->initialize (units (), *this, msg ()));
  daisy_assert (stringer->check (units (), *this, msg ()));
  stringer->tick (units (), *this, msg ());
  daisy_assert (!stringer->missing (*this));
  return symbol (stringer->value (*this));
}
OSQuantityVector& OSQuantityVector::operator+=(OSQuantityVector rVector) {
  if (this == &rVector) {
    (*this) *= 2.0;
    return *this;
  }

  if (units() != rVector.units()) {
    LOG_AND_THROW("Cannot add OSQuantityVectors with different units (" << units()
                  << " and " << rVector.units() << ").");
  }

  unsigned n = size();
  if (rVector.size() != n) {
    LOG_AND_THROW("Cannot add vectors of different sizes.");
  }

  if (scale() != rVector.scale()) {
    rVector.setScale(scale().exponent);
  }

  DoubleVector rValues = rVector.values();
  for (unsigned i = 0; i < n; ++i) {
    m_values[i] += rValues[i];
  }

  if (isTemperature() && rVector.isTemperature()) {
    if (!isAbsolute() && rVector.isAbsolute()) {
      setAsAbsolute();
    }
  }

  return *this;
}
Example #5
0
int
main(int argc, char **argv)
{
	register int i;
	register char *file;
	struct unit u1, u2;
	double f;

	if(argc>1 && *argv[1]=='-') {
		argc--;
		argv++;
		dumpflg++;
	}
	file = dfile;
	if(argc > 1)
		file = argv[1];
	if ((inp = fopen(file, "r")) == NULL) {
		printf("no table\n");
		exit(1);
	}
	sigset(SIGFPE, fperr);
	init();

loop:
	fperrc = 0;
	printf("you have: ");
	if(convr(&u1))
		goto loop;
	if(fperrc)
		goto fp;
loop1:
	printf("you want: ");
	if(convr(&u2))
		goto loop1;
	for(i=0; i<NDIM; i++)
		if(u1.dim[i] != u2.dim[i])
			goto conform;
	f = u1.factor/u2.factor;
	if(fperrc)
		goto fp;
	printf("\t* %e\n", f);
	printf("\t/ %e\n", 1./f);
	goto loop;

conform:
	if(fperrc)
		goto fp;
	printf("conformability\n");
	units(&u1);
	units(&u2);
	goto loop;

fp:
	printf("underflow or overflow\n");
	goto loop;
}
Example #6
0
void OSQuantityVector::push_back(Quantity q) {
  if (!(q.units() == units())) {
    LOG_AND_THROW("Quantity " << q << " is incompatible with this OSQuantityVector, which has "
                  "units " << units() << ".");
  }
  else if (q.scale() != scale()) {
    q.setScale(scale().exponent);
  }
  m_values.push_back(q.value());
}
Example #7
0
/* return offset of the body of @idx-th entry in @coord */
static unsigned int offset_of(const coord_t * coord /* coord of item */ ,
			      int idx /* index of unit */ )
{
	if (idx < units(coord))
		return le16_to_cpu(get_unaligned(&header_at(coord, idx)->offset));
	else if (idx == units(coord))
		return item_length_by_coord(coord);
	else
		impossible("nikita-1308", "Wrong idx");
	return 0;
}
Example #8
0
/* cde_check ->check() method for compressed directory items

   used for debugging, every item should have here the most complete
   possible check of the consistency of the item that the inventor can
   construct
*/
int reiser4_check_cde(const coord_t * coord /* coord of item to check */,
		      const char **error /* where to store error message */)
{
	int i;
	int result;
	char *item_start;
	char *item_end;
	reiser4_key key;

	coord_t c;

	assert("nikita-1357", coord != NULL);
	assert("nikita-1358", error != NULL);

	if (!ergo(coord->item_pos != 0,
		  is_dot_key(item_key_by_coord(coord, &key)))) {
		*error = "CDE doesn't start with dot";
		return -1;
	}
	item_start = item_body_by_coord(coord);
	item_end = item_start + item_length_by_coord(coord);

	coord_dup(&c, coord);
	result = 0;
	for (i = 0; i < units(coord); ++i) {
		directory_entry_format *entry;

		if ((char *)(header_at(coord, i) + 1) >
		    item_end - units(coord) * sizeof *entry) {
			*error = "CDE header is out of bounds";
			result = -1;
			break;
		}
		entry = entry_at(coord, i);
		if ((char *)entry < item_start + sizeof(cde_item_format)) {
			*error = "CDE header is too low";
			result = -1;
			break;
		}
		if ((char *)(entry + 1) > item_end) {
			*error = "CDE header is too high";
			result = -1;
			break;
		}
	}

	return result;
}
Example #9
0
std::vector<Quantity> OSQuantityVector::quantities() const {
  QuantityVector result;
  for (double value : values()) {
    result.push_back(Quantity(value,units()));
  }
  return result;
}
Example #10
0
void LogicAnalyzerDisplay::updateHeaders(void)
{
    const size_t numElems = _tableView->columnCount();

    double factor = 1.0;
    QString units("s");
    double timeSpan = numElems/_sampleRate;
    if (timeSpan <= 100e-9)
    {
        factor = 1e9;
        units = "ns";
    }
    else if (timeSpan <= 100e-6)
    {
        factor = 1e6;
        units = "us";
    }
    else if (timeSpan <= 100e-3)
    {
        factor = 1e3;
        units = "ms";
    }

    if (_xAxisMode == "INDEX") for (size_t i = 0; i < numElems; i++)
    {
        _tableView->setHorizontalHeaderItem(i, new QTableWidgetItem(QString::number(i)));
    }

    if (_xAxisMode == "TIME") for (size_t i = 0; i < numElems; i++)
    {
        double t = i*_sampleRate/factor;
        _tableView->setHorizontalHeaderItem(i, new QTableWidgetItem(QString::number(t)+units));
    }
}
Example #11
0
OSQuantityVector& OSQuantityVector::operator-=(Quantity rQuantity) {

  if (isTemperature() && rQuantity.isTemperature()) {
    if (isAbsolute() && rQuantity.isAbsolute()) {
      // units must be the same, check that exponent on this is 1
      std::vector<std::string> bus = m_units.baseUnits();
      assert(bus.size() == 1);
      if (m_units.baseUnitExponent(bus[0]) == 1) {
        setAsRelative();
        rQuantity.setAsRelative();
      }
    } else if (!isAbsolute() && rQuantity.isAbsolute()) {
      setAsAbsolute();
    } else if (isAbsolute() && !rQuantity.isAbsolute()) {
      rQuantity.setAsAbsolute();
    }
  }

  if (units() != rQuantity.units()) {
    LOG_AND_THROW("Cannot subtract OSQuantityVector and Quantity with different units (" << units()
                  << " and " << rQuantity.units() << ").");
  }

  if (scale() != rQuantity.scale()) {
    rQuantity.setScale(scale().exponent);
  }

  double value = rQuantity.value();
  for (unsigned i = 0, n = size(); i < n; ++i) {
    m_values[i] -= value;
  }

  return *this;
}
Example #12
0
OSQuantityVector& OSQuantityVector::operator+=(Quantity rQuantity) {

  if (isTemperature() && rQuantity.isTemperature()) {
    if (!isAbsolute() && rQuantity.isAbsolute()) {
      setAsAbsolute();
    } else if (isAbsolute() && !rQuantity.isAbsolute()) {
      rQuantity.setAsAbsolute();
    }
  }

  if (units() != rQuantity.units()) {
    LOG_AND_THROW("Cannot add OSQuantityVector and Quantity with different units (" << units()
                  << " and " << rQuantity.units() << ").");
  }

  if (scale() != rQuantity.scale()) {
    rQuantity.setScale(scale().exponent);
  }

  double value = rQuantity.value();
  for (unsigned i = 0, n = size(); i < n; ++i) {
    m_values[i] += value;
  }

  return *this;
}
bool display_context::would_be_discovered(const map_location & loc, int side_num, bool see_all)
{
	map_location adjs[6];
	get_adjacent_tiles(loc,adjs);

	for (const map_location &u_loc : adjs)
	{
		unit_map::const_iterator u_it = units().find(u_loc);
		if (!u_it.valid()) {
			continue;
		}
		const unit & u = *u_it;
		if (get_team(side_num).is_enemy(u.side()) && !u.incapacitated()) {
			// Enemy spotted in adjacent tiles, check if we can see him.
			// Watch out to call invisible with see_all=true to avoid infinite recursive calls!
			if(see_all) {
				return true;
			} else if (!get_team(side_num).fogged(u_loc)
			&& !u.invisible(u_loc, *this, true)) {
				return true;
			}
		}
	}
	return false;
}
ModelEntry DataStore::findModelEntryByName(std::string name) {
  const char *q = sqlite3_mprintf("select name, data, units from model where name = '%q'", name.c_str());
  sqlite3_stmt *stmt = query(q);

  int rc;
  while((rc = sqlite3_step(stmt)) != SQLITE_DONE) {
    switch(rc) {
      case SQLITE_ROW:
        std::string name(reinterpret_cast<char const*>(sqlite3_column_text(stmt, 0)));
        int len = sqlite3_column_bytes(stmt, 1);
        void *data = std::malloc(len);
        std::memcpy(data, sqlite3_column_blob(stmt, 1), len);
        std::string units(reinterpret_cast<char const*>(sqlite3_column_text(stmt, 2)));

        ModelEntry entry(name, data, len, units);

        sqlite3_free((void *) q);
        sqlite3_finalize(stmt);

        return entry;
    }
  }

  throw std::runtime_error("No model for given id");
}
void telemetryDataPoint::storeFieldData(int field, double value, int unitType){
  long double cuVal=units(value,unitType,fieldUnit(field));
  if (field==fieldIndex("Time"))              time=cuVal;
  if (field==fieldIndex("Frequency"))         frequency=cuVal;
  if (field==fieldIndex("Acceleration (X)"))  accX=cuVal;
  if (field==fieldIndex("Acceleration (Y)"))  accY=cuVal;
  if (field==fieldIndex("Acceleration (Z)"))  accZ=cuVal;
  if (field==fieldIndex("Gyroscope (X)"))     gyrX=cuVal;
  if (field==fieldIndex("Gyroscope (Y)"))     gyrY=cuVal;
  if (field==fieldIndex("Gyroscope (Z)"))     gyrZ=cuVal;
  if (field==fieldIndex("Magnetometer (X)"))  magX=cuVal;
  if (field==fieldIndex("Magnetometer (Y)"))  magY=cuVal;
  if (field==fieldIndex("Magnetometer (Z)"))  magZ=cuVal;
  if (field==fieldIndex("Roll"))              roll=cuVal;
  if (field==fieldIndex("Pitch"))             pitch=cuVal;
  if (field==fieldIndex("Yaw"))               yaw=cuVal;
  if (field==fieldIndex("Latitude"))          latitude=cuVal;
  if (field==fieldIndex("Longitude"))         longitude=cuVal;
  if (field==fieldIndex("Altitude"))          altitude=cuVal;
  if (field==fieldIndex("Track"))             track=cuVal;
  if (field==fieldIndex("Speed"))             speed=cuVal;
  if (field==fieldIndex("hDOP"))              hDOP=cuVal;
  if (field==fieldIndex("vDOP"))              vDOP=cuVal;
  if (field==fieldIndex("mDOP"))              mDOP=cuVal;
  if (field==fieldIndex("Temperature"))       temperature=cuVal;
  if (field==fieldIndex("Voltage"))           voltage=cuVal;
}
bool display_context::unit_can_move(const unit &u) const
{
	if(!u.attacks_left() && u.movement_left()==0)
		return false;

	// Units with goto commands that have already done their gotos this turn
	// (i.e. don't have full movement left) should have red globes.
	if(u.has_moved() && u.has_goto()) {
		return false;
	}

	const team &current_team = get_team(u.side());

	map_location locs[6];
	get_adjacent_tiles(u.get_location(), locs);
	for(int n = 0; n != 6; ++n) {
		if (map().on_board(locs[n])) {
			const unit_map::const_iterator i = units().find(locs[n]);
			if (i.valid() && !i->incapacitated() &&
			    current_team.is_enemy(i->side())) {
				return true;
			}

			if (u.movement_cost(map()[locs[n]]) <= u.movement_left()) {
				return true;
			}
		}
	}

	return false;
}
Example #17
0
void addDisplacementAboutAxisParams(InputParameters& params)
{
  MooseEnum units("degrees radians");
  params.addRequiredParam<FunctionName>("function", "The function providing the angle of rotation.");
  params.addRequiredParam<MooseEnum>("angle_units",units,"The units of the angle of rotation. Choices are:" + units.getRawNames());
  params.addRequiredParam<RealVectorValue>("axis_origin","Origin of the axis of rotation");
  params.addRequiredParam<RealVectorValue>("axis_direction","Direction of the axis of rotation");
}
Example #18
0
// ---------------------------------------------------------------------------
/// Initializes spectrum using tag_photoDF_parameters(int param, void *pntr) to get parameter of the photo-DF.
// ---------------------------------------------------------------------------
// XXX static
void
modes_init (int m1, int m2, double gamma_cutOff, double phase)
{
  int    mz;
  double V0, omega2_pe; 												// Parameters of the photo-DF.
  char name[50];

  tag_photoDF_parameters (mc_photoDF_V0, &V0);										// Takes photo-DF parameters from creator.
  tag_photoDF_parameters (mc_photoDF_omega2_pe, &omega2_pe);

  modeN = m2 - m1 + 1;
  modeM1 = m1;
  modePhase = (double*) calloc (modeN, sizeof (double));
  modeGamma = (double*) calloc (modeN, sizeof (double));

  const double unit_alpha = units (mc_r0)/(units (mc_t0)*units (mc_v0));						// [omega/kV] with k = 2\pi/\lambda.
  const double omega_pe = sqrt (omega2_pe);
  for (mz = m1 ; mz <= m2 ; mz++)
  {
    double kz, gammaDivOmegaPE;												// Parameters of the mode.
    kz = 2.0*mc_pi*mz/Lz;
    gammaDivOmegaPE = kz*V0/(unit_alpha*omega_pe)*dispFunc_s (unit_alpha*omega_pe/(kz*V0));

    if (gammaDivOmegaPE < gamma_cutOff)
      continue;

    modeGamma[mz-modeM1] = gammaDivOmegaPE;
    modePhase[mz-modeM1] = (phase < 0) ? 2.0*mc_pi*rand ()/(double) RAND_MAX : phase;
  }

  MPI_Bcast (modePhase, modeN, MPI_DOUBLE, 0, MPI_COMM_WORLD);								// Syncronizes global random parameters.

  sprintf (name, "output/tag_seed_PITS(%03d).dat", cpu_here);
  FILE *fp = cfg_open (name, "wt", "tag_seed2Stream_singleMode");
  fprintf (fp, "variables = mode, E<sub>0</sub>, <greek>f/p</greek>, <greek>g/w</greek><sub>pe</sub>, ");
  fprintf (fp, "<greek>g</greek><sub>WE</sub>, k<sub>z</sub>, \"2.0/(h3*kz)*sin (kz*h3/2.0) - 1.0\"\n");
  fprintf (fp, "zone t = \"L_z = %e, `w_p_e = %e\", f = point\n", Lz, sqrt (omega2_pe));
  for (mz = m1 ; mz <= m2 ; mz++)											// Prints spectrum of initial seed.
  {
    double kz, gamma;													// Parameters of the mode.
    kz = 2*mc_pi*mz/Lz;
    gamma = modeGamma[mz-modeM1];
    fprintf (fp, "%d %e %e %e %e %e %e\n", mz, dEz, modePhase[mz-modeM1]/mc_pi, gamma, 2.0*gamma*omega_pe, kz, 2.0/(h3*kz)*sin (kz*h3/2.0) - 1.0);
  }
  fclose (fp);
}
int display_context::side_units(int side) const
{
	int res = 0;
	for (const unit &u : units()) {
		if (u.side() == side) ++res;
	}
	return res;
}
int display_context::side_upkeep(int side) const
{
	int res = 0;
	for (const unit &u : units()) {
		if (u.side() == side) res += u.upkeep();
	}
	return res;
}
Example #21
0
void HudSettingsPage::LoadSettings()
{
    ConVarRef units("mom_speedometer_units"), sync_type("mom_strafesync_type"),
        sync_color("mom_strafesync_colorize");
    m_pSpeedometerUnits->ActivateItemByRow(units.GetInt() - 1);
    m_pSyncType->ActivateItemByRow(sync_type.GetInt() - 1);
    m_pSyncColorize->ActivateItemByRow(sync_color.GetInt());
}
void MXPImporter::loadIngredients( QTextStream &stream, Recipe &recipe )
{
	//============ingredients=================//
	stream.skipWhiteSpace();
	( void ) stream.readLine();
	QString current = stream.readLine();
	if ( !current.contains( "NONE" ) && !current.isEmpty() ) {
		while ( !current.isEmpty() && !stream.atEnd() ) {
			Ingredient new_ingredient;

			//amount
			QString amount_str = current.mid( 0, 9 ).simplified();
			if ( !amount_str.isEmpty() )  // case of amount_str.isEmpty() correctly handled by class default
			{
				MixedNumber amount;
				QValidator::State state;
				state = MixedNumber::fromString( amount_str, amount, false );
				if ( state != QValidator::Acceptable )
				{
					addWarningMsg( i18n( "While loading recipe \"%1\" Invalid amount \"%2\" in the line \"%3\"" , recipe.title, amount_str , current.trimmed() ) );
					current = stream.readLine();
					continue;
				}
				new_ingredient.amount = amount.toDouble();
			}

			//units
			QString units( current.mid( 9, 13 ) );
			new_ingredient.units = Unit( units.simplified(), new_ingredient.amount );

			//name
			int dash_index = current.indexOf( "--" );

			int length;
			if ( dash_index == -1 || dash_index == 24 )  //ignore a dash in the first position (index 24)
				length = current.length();
			else
				length = dash_index - 22;

			QString ingredient_name( current.mid( 22, length ) );
			new_ingredient.name = ingredient_name.trimmed();

			//prep method
			if ( dash_index != -1 && dash_index != 24 )  //ignore a dash in the first position (index 24)
				new_ingredient.prepMethodList.append( Element(current.mid( dash_index + 2, current.length() ).trimmed()) );

			recipe.ingList.append( new_ingredient );
			//kDebug()<<"Found ingredient: amount="<<new_ingredient.amount
			//  <<", unit:"<<new_ingredient.units
			//  <<", name:"<<new_ingredient.name
			//  <<", prep_method:"<<prep_method;

			current = stream.readLine();
		}
	}
	//else
	//	kDebug()<<"No ingredients found.";
}
Example #23
0
OSQuantityVector& OSQuantityVector::operator-=(OSQuantityVector rVector) {

  unsigned n = size();
  if (this == &rVector) {
    clear();
    resize(n,0.0);
    return *this;
  }

  if (isTemperature() && rVector.isTemperature()) {
    if (isAbsolute() && rVector.isAbsolute()) {
      // units must be the same, check that exponent on this is 1
      std::vector<std::string> bus = m_units.baseUnits();
      assert(bus.size() == 1);
      if (m_units.baseUnitExponent(bus[0]) == 1) {
        setAsRelative();
        rVector.setAsRelative();
      }
    } else if (!isAbsolute() && rVector.isAbsolute()) {
      setAsAbsolute();
    } else if (isAbsolute() && !rVector.isAbsolute()) {
      rVector.setAsAbsolute();
    }
  }

  if (units() != rVector.units()) {
    LOG_AND_THROW("Cannot subtract OSQuantityVectors with different units (" << units()
                  << " and " << rVector.units() << ").");
  }

  if (rVector.size() != n) {
    LOG_AND_THROW("Cannot subtract vectors of different sizes.");
  }

  if (scale() != rVector.scale()) {
    rVector.setScale(scale().exponent);
  }

  DoubleVector rValues = rVector.values();
  for (unsigned i = 0; i < n; ++i) {
    m_values[i] -= rValues[i];
  }

  return *this;
}
const unit * display_context::get_visible_unit(const map_location & loc, const team &current_team, bool see_all) const
{
	if (!map().on_board(loc)) return nullptr;
	const unit_map::const_iterator u = units().find(loc);
	if (!u.valid() || !u->is_visible_to_team(current_team, *this, see_all)) {
		return nullptr;
	}
	return &*u;
}
Example #25
0
/* expand @coord as to accommodate for insertion of @no new entries starting
   from @pos, with total bodies size @size. */
static int expand_item(const coord_t * coord /* coord of item */ ,
		       int pos /* unit position */ , int no	/* number of new
								 * units*/ ,
		       int size /* total size of new units' data */ ,
		       unsigned int data_size	/* free space already reserved
						 * in the item for insertion */ )
{
	int entries;
	cde_unit_header *header;
	char *dent;
	int i;

	assert("nikita-1310", coord != NULL);
	assert("nikita-1311", pos >= 0);
	assert("nikita-1312", no > 0);
	assert("nikita-1313", data_size >= no * sizeof(directory_entry_format));
	assert("nikita-1343",
	       item_length_by_coord(coord) >=
	       (int)(size + data_size + no * sizeof *header));

	entries = units(coord);

	if (pos == entries)
		dent = address(coord, size);
	else
		dent = (char *)entry_at(coord, pos);
	/* place where new header will be in */
	header = header_at(coord, pos);
	/* free space for new entry headers */
	memmove(header + no, header,
		(unsigned)(address(coord, size) - (char *)header));
	/* if adding to the end initialise first new header */
	if (pos == entries) {
		set_offset(coord, pos, (unsigned)size);
	}

	/* adjust entry pointer and size */
	dent = dent + no * sizeof *header;
	size += no * sizeof *header;
	/* free space for new entries */
	memmove(dent + data_size, dent,
		(unsigned)(address(coord, size) - dent));

	/* increase counter */
	entries += no;
	put_unaligned(cpu_to_le16((__u16) entries), &formatted_at(coord)->num_of_entries);

	/* [ 0 ... pos ] entries were shifted by no * ( sizeof *header )
	   bytes.  */
	for (i = 0; i <= pos; ++i)
		adj_offset(coord, i, no * sizeof *header);
	/* [ pos + no ... +\infty ) entries were shifted by ( no *
	   sizeof *header + data_size ) bytes */
	for (i = pos + no; i < entries; ++i)
		adj_offset(coord, i, no * sizeof *header + data_size);
	return 0;
}
Example #26
0
bool MERefValue<DimValue>::setValue(QVariant value,QString unit)
{
    int iUnit = units().indexOf(unit);
    if(iUnit==-1)
        return false;
    else
        setValue(value,iUnit);
    return true;
}
Example #27
0
/* find position where entry with @entry_key would be inserted into @coord */
static int find(const coord_t * coord /* coord of item */ ,
		const reiser4_key * entry_key /* key to look for */ ,
		cmp_t * last /* result of last comparison */ )
{
	int entries;

	int left;
	int right;

	cde_unit_header *header;

	assert("nikita-1295", coord != NULL);
	assert("nikita-1296", entry_key != NULL);
	assert("nikita-1297", last != NULL);

	entries = units(coord);
	left = 0;
	right = entries - 1;
	while (right - left >= REISER4_SEQ_SEARCH_BREAK) {
		int median;

		median = (left + right) >> 1;

		header = header_at(coord, median);
		*last = de_id_key_cmp(&header->hash, entry_key);
		switch (*last) {
		case LESS_THAN:
			left = median;
			break;
		case GREATER_THAN:
			right = median;
			break;
		case EQUAL_TO:{
				do {
					median--;
					header--;
				} while (median >= 0 &&
					 de_id_key_cmp(&header->hash,
						       entry_key) == EQUAL_TO);
				return median + 1;
			}
		}
	}
	header = header_at(coord, left);
	for (; left < entries; ++left, ++header) {
		prefetch(header + 1);
		*last = de_id_key_cmp(&header->hash, entry_key);
		if (*last != LESS_THAN)
			break;
	}
	if (left < entries)
		return left;
	else
		return RETERR(-ENOENT);

}
Example #28
0
AMDetector::operator AMMeasurementInfo() {
    return AMMeasurementInfo(name(), description(), units(), axes());
    // This is code included from the previous AMDetector(Info) system. This may be important for the transition. [DKC January 14th, 2013]
    /*
    if(!description().isEmpty())
    	return AMMeasurementInfo(description().remove(" "), description(), units(), axes());
    else
    	return AMMeasurementInfo(name(), name(), units(), axes());
    */
}
Example #29
0
bool MERefValue<DimValue>::setUnit(QString unit)
{
    int iUnit = units().indexOf(unit);
    if(iUnit==-1)
        return false;
    else
        setUnit(iUnit);
    return true;
    
}
Example #30
0
void HudSettingsPage::OnApplyChanges()
{
    BaseClass::OnApplyChanges();

    ConVarRef units("mom_speedometer_units"), sync_type("mom_strafesync_type"),
        sync_color("mom_strafesync_colorize");

    units.SetValue(m_pSpeedometerUnits->GetActiveItem() + 1);
    sync_type.SetValue(m_pSyncType->GetActiveItem() + 1); // Sync type needs +1 added to it before setting convar!
    sync_color.SetValue(m_pSyncColorize->GetActiveItem());
}