예제 #1
0
    inline bool
    try_merge(Run& run, Iterator iter, Range const& range)
    {
        // if *iter intersects with, or is adjacent to, 'range'...
        if (can_merge(*iter, range))
        {
            typedef typename Range::value_type value_type;
            typedef integer_traits<value_type> integer_traits;

            // merge range and *iter
            merge(*iter, range);

            // collapse all subsequent ranges that can merge with *iter:
            Iterator i = iter+1;
            // 1. skip subsequent ranges completely included in *iter
            while (i != run.end() && i->last <= iter->last)
                ++i;
            // 2. collapse next range if adjacent or overlapping with *iter
            if (i != run.end() && i->first-1 <= iter->last)
            {
                iter->last = i->last;
                ++i;
            }

            // erase all ranges that were collapsed
            run.erase(iter+1, i);
            return true;
        }
        return false;
    }
예제 #2
0
char*
TextSelection::GetText ()
{
    if (anchor.GetParent() == moving.GetParent() &&
            anchor.GetLocation () == moving.GetLocation())
        return g_strdup ("");

    GString *gstr = g_string_new ("");
    TextPointer tp = anchor;

    while (tp.CompareTo_np (moving) < 0) {
        if (tp.GetParent()->Is (Type::RUN)) {
            Run *run = (Run*)tp.GetParent();
            if (tp.GetParent() == moving.GetParent()) {
                // tp and moving are in the same element, so we append the substring and set tp = moving.
                g_string_append_len (gstr, run->GetText() + tp.ResolveLocation(), moving.ResolveLocation() - tp.ResolveLocation());
                tp = moving;
            }
            else {
                g_string_append (gstr, run->GetText());
                tp = run->GetContentEnd_np();
                tp = tp.GetPositionAtOffset_np (1, tp.GetLogicalDirection());
            }
        }
        else {
            tp = tp.GetPositionAtOffset_np (1, tp.GetLogicalDirection());
        }
    }

    printf ("returning %s from TextSelection::GetText\n", gstr->str);

    return g_string_free (gstr, FALSE);
}
예제 #3
0
void VTTScanner::skipRun(const Run& run)
{
    ASSERT(run.start() <= end());
    ASSERT(run.end() >= run.start());
    ASSERT(run.end() <= end());
    seekTo(run.end());
}
예제 #4
0
/*!\brief Estimating the necessary number of steps for each benchmark.
//
// \param run The parameters for the benchmark run.
// \return void
//
// This function estimates the necessary number of steps for the given benchmark based on the
// performance of the Blaze library.
*/
void estimateSteps( Run& run )
{
   using blazemark::element_t;
   using blaze::columnVector;

   ::blaze::setSeed( ::blazemark::seed );

   const size_t N( run.getSize() );

   blaze::DynamicVector<element_t,columnVector> a( N ), b( N ), c( N );
   blaze::timing::WcTimer timer;
   double wct( 0.0 );
   size_t steps( 1UL );

   blazemark::blaze::init( a );
   blazemark::blaze::init( b );

   while( true ) {
      timer.start();
      for( size_t i=0UL; i<steps; ++i ) {
         c = a * b;
      }
      timer.end();
      wct = timer.last();
      if( wct >= 0.2 ) break;
      steps *= 2UL;
   }

   if( c.size() != N )
      std::cerr << " Line " << __LINE__ << ": ERROR detected!!!\n";

   run.setSteps( blaze::max( 1UL, ( blazemark::runtime * steps ) / timer.last() ) );
}
예제 #5
0
bool operator<(const Run& run1, const Run& run2)
{
    Run::RunStatus s1 = run1.getStatus();
    Run::RunStatus s2 = run2.getStatus();
    fptype t1 = run1.getTotalTime(); // time in seconds
    fptype t2 = run2.getTotalTime();

    // add penalties
    if (s1 == Run::DQF)
    {
	t1 += 200000;
    }
    else if (s1 == Run::DNF)
    {
	t1 += 100000;
    }

    if (s2 == Run::DQF)
    {
	t2 += 200000;
    }
    else if (s2 == Run::DNF)
    {
	t2 += 100000;
    }

    return t1 < t2;
}
예제 #6
0
		void Paragraph::AddSpace(const size_t count)
		{
			Run run;
			RunItemBase* text = new Text(std::string(count, ' '));
			run.add(text);
			Items->push_back(run);
		}
예제 #7
0
파일: pprof.cpp 프로젝트: CIB/polli
const Run<PPEvent>::iterator
getMatchingExit(Run<PPEvent>::iterator It, const Run<PPEvent>::iterator &End) {
  using namespace fmt;
  const Run<PPEvent>::iterator Cur = It;

  while (It != End) {
    PPEventType T = It->event();
    if (It->id() == Cur->id()) {
      switch(Cur->event()) {
        case RegionEnter:
          if (T == RegionExit) {
            return It;
          }
          break;
        case ScopEnter:
          if (T == ScopExit) {
            return It;
          }
          break;
        default:
          break;
      }
    }
    ++It;
  }

  //FIXME: Record an error event, this should not happen.
  static_assert("BUG: No matching Exit to this Entry", "");
  return Cur;
}
예제 #8
0
파일: awk25.cpp 프로젝트: apense/qse
	int sleep (
		Run& run, Value& ret, Value* args, size_t nargs, 
		const char_t* name, size_t len)
	{
		if (args[0].isIndexed()) 
		{
			run.setError (QSE_AWK_EINVAL);
			return -1;
		}

		Awk::int_t x = args[0].toInt();

		/*Value arg;
		if (run.getGlobal(idLastSleep, arg) == 0)
			qse_printf (QSE_T("GOOD: [%d]\n"), (int)arg.toInt());
		else { qse_printf (QSE_T("BAD:\n")); }
		*/

		if (run.setGlobal (idLastSleep, x) <= -1) return -1;

	#if defined(_WIN32)
		::Sleep ((DWORD)(x * 1000));
		return ret.setInt (0);
	#elif defined(__OS2__)
		::DosSleep ((ULONG)(x * 1000));
		return ret.setInt (0);
	#else
		return ret.setInt (::sleep (x));
	#endif
	}
예제 #9
0
/*!\brief Estimating the necessary number of steps for each benchmark.
//
// \param run The parameters for the benchmark run.
// \return void
//
// This function estimates the necessary number of steps for the given benchmark based on the
// performance of the Blaze library.
*/
void estimateSteps( Run& run )
{
   using blazemark::element_t;
   using blaze::columnMajor;

   ::blaze::setSeed( ::blazemark::seed );

   const size_t N( run.getSize() );
   const size_t F( run.getNonZeros() );

   blaze::DynamicMatrix<element_t,columnMajor> A( N, N ), C( N, N );
   blaze::CompressedMatrix<element_t,columnMajor> B( N, N, N*F );
   blaze::timing::WcTimer timer;
   double wct( 0.0 );
   size_t steps( 1UL );

   blazemark::blaze::init( A );
   blazemark::blaze::init( B, F );

   while( true ) {
      timer.start();
      for( size_t i=0UL; i<steps; ++i ) {
         C = A + B;
      }
      timer.end();
      wct = timer.last();
      if( wct >= 0.2 ) break;
      steps *= 2UL;
   }

   if( C.rows() != N )
      std::cerr << " Line " << __LINE__ << ": ERROR detected!!!\n";

   run.setSteps( blaze::max( 1UL, ( blazemark::runtime * steps ) / timer.last() ) );
}
예제 #10
0
/** Add a sample log (property) with value as string
 * @brief AddSampleLog::addStringLog
 * @param theRun
 * @param propName
 * @param propValue
 * @param propUnit
 */
void AddSampleLog::addStringLog(Run &theRun, const std::string &propName,
                                const std::string &propValue,
                                const std::string &propUnit) {
  theRun.addLogData(new PropertyWithValue<std::string>(propName, propValue));
  theRun.getProperty(propName)->setUnits(propUnit);
  return;
}
예제 #11
0
/*!\brief Estimating the necessary number of floating point operations.
//
// \param run The parameters for the benchmark run.
// \return void
//
// This function estimates the number of floating point operations required for a single
// computation of the (composite) arithmetic operation.
*/
void estimateFlops( Run& run )
{
   const size_t N( run.getSize()     );
   const size_t F( run.getNonZeros() );

   run.setFlops( N*F );
}
예제 #12
0
		Paragraph::Paragraph(const RId& rId, const OOX::CPath& filename, const long xEmu, const std::string& hRelativeFrom, const long yEmu, const std::string& vRelativeFrom, const long widthEmu, const long heightEmu)

		{
			RunItemBase* drawing = new Drawing(rId, filename, xEmu, hRelativeFrom, yEmu, vRelativeFrom, widthEmu, heightEmu);
			Run run;
			run.add(drawing);
			Items->push_back(run);
		}
예제 #13
0
		Paragraph::Paragraph(const RId& rId, const OOX::CPath& filename, const long width, const long height)

		{
			RunItemBase* drawing = new Drawing(rId, filename, width, height);
			Run run;
			run.add(drawing);
			Items->push_back(run);
		}
예제 #14
0
		void Paragraph::AddSpace(const size_t count, const nullable__<Logic::RunProperty>& property)
		{
			Run run;
			RunItemBase* text = new Text(std::string(count, ' '));
			run.Property = property;
			run.add(text);
			Items->push_back(run);
		}
예제 #15
0
/**
 * Copy logs from the input workspace to the output workspace
 * and don't replace any mathcing logs in the output workspace.
 */
void CopyLogs::mergeKeepExisting(
    const std::vector<Kernel::Property *> &inputLogs, Run &outputRun) {
  for (auto prop : inputLogs) {
    // add the log only if it doesn't already exist
    if (!outputRun.hasProperty(prop->name())) {
      outputRun.addLogData(prop->clone());
    }
  }
}
예제 #16
0
/**
 * Copy logs from the input workspace to the output workspace
 * and don't replace any mathcing logs in the output workspace.
 */
void CopyLogs::mergeKeepExisting(
    const std::vector<Kernel::Property *> &inputLogs, Run &outputRun) {
  for (auto iter = inputLogs.begin(); iter != inputLogs.end(); ++iter) {
    Kernel::Property *prop = *iter;
    // add the log only if it doesn't already exist
    if (!outputRun.hasProperty(prop->name())) {
      outputRun.addLogData(prop->clone());
    }
  }
}
예제 #17
0
/**
 * Copy logs from the input workspace to the output workspace
 * and replace any matching logs with the ones from the input workspace.
 */
void CopyLogs::mergeReplaceExisting(
    const std::vector<Kernel::Property *> &inputLogs, Run &outputRun) {
  for (auto prop : inputLogs) {
    // if the log exists, remove and replace it
    if (outputRun.hasProperty(prop->name())) {
      outputRun.removeLogData(prop->name());
    }
    outputRun.addLogData(prop->clone());
  }
}
예제 #18
0
// merge two runs and store info in first run.
void Run::merge (Run& run) { 
    // merge bucket ranges
    buckets.splice(buckets.end(), run.getBuckets());    
    totalFreq += run.getTotalFreq();
    freqBounds.first = std::min(getLoFreq(), run.getLoFreq());
    freqBounds.second = std::max(getHiFreq(), run.getHiFreq());
    
    Bounds extBounds = run.getRangeBounds();
    rangeBounds.first = std::min(extBounds.first, rangeBounds.first);
    rangeBounds.second = std::max(extBounds.second, rangeBounds.second);
}
예제 #19
0
		void Paragraph::AddBreak(const std::string& type)
		{
			if (type == "page" || type == "line" || type == "column")
			{
				Run run;
				Break* br = new Break();
				br->Type = type;
				run.add(br);
				Items->push_back(run);
			}
		}
예제 #20
0
char*
TextSelection::GetText ()
{
	GString *gstr;
	TextPointer tp;


	if (text)
		goto done;

	if (anchor.GetParent() == NULL ||
	    moving.GetParent() == NULL) {
		text = g_strdup ("");
		goto done;
	}

	if (anchor.GetParent() == moving.GetParent() &&
	    anchor.GetLocation () == moving.GetLocation()) {
		text = g_strdup ("");
		goto done;
	}

	gstr = g_string_new ("");
	tp = anchor;

	while (tp.CompareTo_np (moving) < 0) {
		DependencyObject *parent = tp.GetParent ();

		if (parent && parent->Is (Type::RUN)) {
			Run *run = (Run*)parent;
			if (parent == moving.GetParent()) {
				// tp and moving are in the same element, so we append the substring and set tp = moving.
				g_string_append_len (gstr, run->GetText() + tp.ResolveLocation(), moving.ResolveLocation() - tp.ResolveLocation());
				tp = moving;
			}
			else {
				g_string_append (gstr, run->GetText());
				tp = run->GetContentEnd_np();
				tp = tp.GetPositionAtOffset_np (1, tp.GetLogicalDirection());
			}
		}
		else {
			TextPointer new_tp = tp.GetPositionAtOffset_np (1, tp.GetLogicalDirection());
			if (new_tp.CompareTo_np (tp) == 0)
				break;
			tp = new_tp;
		}
	}

	text = g_string_free (gstr, FALSE);

 done:
	return g_strdup (text);
}
예제 #21
0
/**
 * Copy logs from the input workspace to the output workspace
 * and replace any matching logs with the ones from the input workspace.
 */
void CopyLogs::mergeReplaceExisting(
    const std::vector<Kernel::Property *> &inputLogs, Run &outputRun) {
  for (auto iter = inputLogs.begin(); iter != inputLogs.end(); ++iter) {
    Kernel::Property *prop = *iter;
    // if the log exists, remove and replace it
    if (outputRun.hasProperty(prop->name())) {
      outputRun.removeLogData(prop->name());
    }
    outputRun.addLogData(prop->clone());
  }
}
예제 #22
0
파일: thread.hpp 프로젝트: MGKhKhD/easy-IP
 inline void
 Thread::run(Runnable* r) {
   m()->acquire();
   if (idle != NULL) {
     Run* i = idle;
     idle = idle->n;
     m()->release();
     i->run(r);
   } else {
     m()->release();
     (void) new Run(r);
   }
 }
예제 #23
0
/**
 * Wipe any existing logs in the output workspace and replace
 * them with the logs from the input workspace.
 */
void CopyLogs::wipeExisting(const std::vector<Kernel::Property *> &inputLogs,
                            Run &outputRun) {
  auto outputLogs = outputRun.getLogData();

  // remove each of the logs from the second workspace
  for (auto iter = outputLogs.begin(); iter != outputLogs.end(); ++iter) {
    outputRun.removeLogData((*iter)->name());
  }

  // add all the logs from the new workspace
  for (auto iter = inputLogs.begin(); iter != inputLogs.end(); ++iter) {
    outputRun.addLogData((*iter)->clone());
  }
}
예제 #24
0
/**
 * Wipe any existing logs in the output workspace and replace
 * them with the logs from the input workspace.
 */
void CopyLogs::wipeExisting(const std::vector<Kernel::Property *> &inputLogs,
                            Run &outputRun) {
  auto outputLogs = outputRun.getLogData();

  // remove each of the logs from the second workspace
  for (auto &outputLog : outputLogs) {
    outputRun.removeLogData(outputLog->name());
  }

  // add all the logs from the new workspace
  for (auto inputLog : inputLogs) {
    outputRun.addLogData(inputLog->clone());
  }
}
예제 #25
0
파일: run.cpp 프로젝트: globox1/toaster
/**
 * Main function using class run
 */
int main(int argc, char **argv) {
    ros::init(argc, argv, "Run");

    Run c = Run();


    ros::Rate loop_rate(30);

    while (ros::ok()) {
        c.send();
        loop_rate.sleep();
    }

    return 0;
}
예제 #26
0
/** Add a single value property
 * @brief AddSampleLog::addSingleValueProperty
 * @param theRun
 * @param propName
 * @param propValue
 * @param propUnit
 * @param propNumberType
 */
void AddSampleLog::addSingleValueProperty(Run &theRun,
                                          const std::string &propName,
                                          const std::string &propValue,
                                          const std::string &propUnit,
                                          const std::string &propNumberType) {
  // add a single value property, integer or double
  bool value_is_int(false);
  if (propNumberType != autoTypeOption) {
    value_is_int = (propNumberType == intTypeOption);
  } else {
    int intVal;
    if (Strings::convert(propValue, intVal)) {
      value_is_int = true;
    }
  }

  // set value
  if (value_is_int) {
    // convert to integer
    int intVal;
    int convert_to_int = Strings::convert(propValue, intVal);
    if (convert_to_int == 0) {
      // spit out error message and set to default value
      g_log.error() << "Error interpreting string '" << propValue
                    << "' as NumberType Int.";
      throw std::runtime_error("Invalie integer input");
    }
    theRun.addLogData(new PropertyWithValue<int>(propName, intVal));
  } else {
    // convert to double
    double dblVal;
    int convert_to_dbl = Strings::convert(propValue, dblVal);
    if (convert_to_dbl == 0) {
      g_log.error() << "Error interpreting string '" << propValue
                    << "' as NumberType Double.";
      throw std::runtime_error("Invalid double input.");
    }
    theRun.addLogData(new PropertyWithValue<double>(propName, dblVal));
    g_log.information() << "added property " << propName << " with value "
                        << dblVal << "\n";
  }

  // add unit
  theRun.getProperty(propName)->setUnits(propUnit);

  return;
}
bool VTTScanner::scanFloat(float& number)
{
    Run integerRun = collectWhile<isASCIIDigit>();
    seekTo(integerRun.end());
    Run decimalRun(getPosition(), getPosition(), m_is8Bit);
    if (scan('.')) {
        decimalRun = collectWhile<isASCIIDigit>();
        seekTo(decimalRun.end());
    }

    // At least one digit required.
    if (integerRun.isEmpty() && decimalRun.isEmpty()) {
        // Restore to starting position.
        seekTo(integerRun.start());
        return false;
    }

    size_t lengthOfFloat = Run(integerRun.start(), getPosition(), m_is8Bit).length();
    bool validNumber;
    if (m_is8Bit)
        number = charactersToFloat(integerRun.start(), lengthOfFloat, &validNumber);
    else
        number = charactersToFloat(reinterpret_cast<const UChar*>(integerRun.start()), lengthOfFloat, &validNumber);

    if (!validNumber)
        number = std::numeric_limits<float>::max();
    return true;
}
예제 #28
0
bool VTTScanner::scanRun(const Run& run, const String& toMatch)
{
    ASSERT(run.start() == position());
    ASSERT(run.start() <= end());
    ASSERT(run.end() >= run.start());
    ASSERT(run.end() <= end());
    size_t matchLength = run.length();
    if (toMatch.length() > matchLength)
        return false;
    bool matched;
    if (m_is8Bit)
        matched = WTF::equal(toMatch.impl(), m_data.characters8, matchLength);
    else
        matched = WTF::equal(toMatch.impl(), m_data.characters16, matchLength);
    if (matched)
        seekTo(run.end());
    return matched;
}
예제 #29
0
/**
 * Extracts a property from run information
 *
 * This method extracts the property with the supplied name from the run
 *information,
 * using the appropriate AbstractDoubleValueExtractor. If the property is not
 *found,
 * an std::runtime_error exception is thrown. If there is no extractor for the
 *requested
 * data type, an std::invalid_argument exception is thrown.
 *
 * @param runInformation :: Run information that cotains the property with
 *propertyName
 * @param propertyName :: Property name that should be extracted
 * @return Value of property as double
 */
double PoldiInstrumentAdapter::extractPropertyFromRun(
    const Run &runInformation, const std::string &propertyName) const {
  if (!runInformation.hasProperty(propertyName)) {
    throw std::runtime_error("Cannot construct instrument without " +
                             propertyName + "-property in log. Aborting.");
  }

  Kernel::Property *property = runInformation.getProperty(propertyName);

  AbstractDoubleValueExtractor_sptr extractor =
      getExtractorForProperty(property);

  if (!extractor) {
    throw std::invalid_argument(
        "Cannot extract chopper speed from run information.");
  }

  return (*extractor)(runInformation, propertyName);
}
예제 #30
0
  void renderPclPlot(PclPlot *pclPlot) {
    PclInstr *xInstr = NULL, *yInstr = NULL, *pixlenInstr = NULL, *dataInstr = NULL;
    Run *run = new Run();
    RasterDecoder raster(this->bitmapPlotter);
    Point origin;

    while (pclPlot->good()) {
        if (
            (yInstr = nextPclInstr(pclPlot,PCL_Y))
            && (xInstr = nextPclInstr(pclPlot,PCL_X))
            && (pixlenInstr = nextPclInstr(pclPlot,PCL_PIXEL_LEN))
            && (dataInstr = nextPclInstr(pclPlot,PCL_RLE_DATA))) {
          run->init(yInstr, xInstr, pixlenInstr, dataInstr);

          while (raster.decode(run))
            run->nextRun();
      }
    }
  }