示例#1
0
void denseMatrix<T>::setsize(const int size)
{
  if (size < 0)
  {
    throw out_of_range("Invalid setsize param");
  }
  m_dimentions = size;
  m_data.setsize(size);

  for (int i=0; i < size; i++)
  {
    m_data[i].setsize(size);
  }
  return;
}
示例#2
0
int wstring::compare(const wstring& str, size_t pos, size_t n) const {
    if (pos > length())
        throw out_of_range("pos > length()");
    size_t rlen = length() - pos;
    if (rlen > n)
        rlen = n;
    if (rlen > str.length())
        rlen = str.length();
    int r = wchar_traits::compare(data() + pos, str.data(), rlen);
    if (r != 0)
        return r;
    if (rlen == n)
        return 0;
    return(length() - pos) - str.length();
}
    std::pair<R, RO> operator()(T& t, R r, RO ro)
    {
        if (!r) return throw_t<_except_>( t, unexpected_end_fragment(), r );

        string_range< typename TChars::value_type > rr = srange( tchars()() );

        for ( ; rr; ++rr ) if ( *r == *rr )
            {
                if (!ro)
                    return throw_t<_except_>( t, out_of_range( tchars()(), distance(r) ), r, ro );
                *(ro++) = *rr;
                return std::make_pair(++r, ro);
            }

        return throw_t<_except_>( t, expected_of( tchars()(), distance(r) ), r, ro );
    }
CRef<IQueryFactory>
CQuerySplitter::GetQueryFactoryForChunk(Uint4 chunk_num)
{
    if (chunk_num >= m_NumChunks) {
        string msg("Invalid query chunk number: ");
        msg += NStr::IntToString(chunk_num) + " out of " +
            NStr::IntToString(m_NumChunks);
        throw out_of_range(msg);
    }

    if (m_SplitBlk.Empty()) {
        Split();
    }

    return m_QueryChunkFactories[chunk_num];
}
  std::pair<R, RO> _copy(T& t, R r, RR rr, RO ro)
  {
    for ( ;r && rr && ro && *r==*rr; ++r, ++rr)
      *(ro++) = *r;
    
    if (rr && !r)
      return throw_t<_except_>( t, unexpected_end_fragment(), r, ro );

    if (rr && !ro)
      return throw_t<_except_>( t, out_of_range( distance(r) ), r, ro );

    if (rr)
      return throw_t<_except_>( t, expected_of( typename string_list::left_type()(), distance(r) ), r, ro);
    
    return std::make_pair(r, ro);
  }
示例#6
0
    /**
     * Check if specified index is within range.
     *
     * This check is 1-indexed by default. This behavior can be
     * changed by setting <code>stan::error_index::value</code>.
     *
     * @param function Function name (for error messages)
     * @param name Variable name (for error messages)
     * @param max Maximum size of the variable
     * @param index Index to check
     * @param nested_level Nested level (for error messages)
     * @param error_msg Additional error message (for error messages)
     *
     * @throw <code>std::out_of_range</code> if the index is not in range
     */
    inline void check_range(const char* function,
                            const char* name,
                            int max,
                            int index,
                            int nested_level,
                            const char* error_msg) {
      if ((index >= stan::error_index::value)
          && (index < max + stan::error_index::value))
        return;

      std::stringstream msg;
      msg << "; index position = " << nested_level;
      std::string msg_str(msg.str());

      out_of_range(function, max, index, msg_str.c_str(), error_msg);
    }
示例#7
0
//removes next person from queue
void BookTracker::sellBook(string bookNameIn) {
    try {
        BookNode *node = findBook(bookNameIn);
        WaitList *list = node->getList();
        //if the list is not empty
        if (list->peek() != nullptr) {
            throw out_of_range("There are people waiting for this book. ");
        }
        node->addToHaveValue(-1);
    } catch (invalid_argument e) {
        //rethrow error
        throw e;
    } catch (out_of_range x) {
        //rethrow error
        throw x;
    }
}
示例#8
0
bool repository::extractor::need_update(
    const boost::filesystem::path &destination, const std::time_t lifetime) {
  try {
    BUNSAN_LOG_DEBUG << "Starting " << destination << " " << __func__;
    const boost::filesystem::path meta =
        destination / m_config.installation.meta;
    return !boost::filesystem::is_regular_file(meta) ||
           out_of_range(std::time(nullptr), lifetime,
                        boost::filesystem::last_write_time(meta));
  } catch (std::exception &) {
    BOOST_THROW_EXCEPTION(
        extractor_need_update_error()
        << extractor_need_update_error::destination(destination)
        << extractor_need_update_error::lifetime(lifetime)
        << enable_nested_current());
  }
}
示例#9
0
    inline bool check_row_index(const char* function,
                                const char* name,
                                const Eigen::Matrix<T_y, R, C>& y,
                                size_t i) {
      if (i >= stan::error_index::value
          && i < static_cast<size_t>(y.rows()) + stan::error_index::value)
        return true;

      std::stringstream msg;
      msg << " for rows of " << name;
      std::string msg_str(msg.str());
      out_of_range(function,
                   y.rows(),
                   i,
                   msg_str.c_str());
      return false;
    }
示例#10
0
文件: string.cpp 项目: themiwi/libcxx
unsigned long long
stoull(const wstring& str, size_t* idx, int base)
{
    wchar_t* ptr;
    const wchar_t* const p = str.c_str();
    unsigned long long r = wcstoull(p, &ptr, base);
    if (ptr == p)
    {
#ifndef _LIBCPP_NO_EXCEPTIONS
        if (r == 0)
            throw invalid_argument("stoull: no conversion");
        throw out_of_range("stoull: out of range");
#endif  // _LIBCPP_NO_EXCEPTIONS
    }
    if (idx)
        *idx = static_cast<size_t>(ptr - p);
    return r;
}
示例#11
0
long double
stold(const string& str, size_t* idx)
{
    char* ptr;
    const char* const p = str.c_str();
    typename remove_reference<decltype(errno)>::type errno_save = errno;
    errno = 0;
    long double r = strtold(p, &ptr);
    swap(errno, errno_save);
#ifndef _LIBCPP_NO_EXCEPTIONS
    if (errno_save == ERANGE)
        throw out_of_range("stold: out of range");
    if (ptr == p)
        throw invalid_argument("stold: no conversion");
#endif  // _LIBCPP_NO_EXCEPTIONS
    if (idx)
        *idx = static_cast<size_t>(ptr - p);
    return r;
}
示例#12
0
long
stol(const wstring& str, size_t* idx, int base)
{
    wchar_t* ptr;
    const wchar_t* const p = str.c_str();
    typename remove_reference<decltype(errno)>::type errno_save = errno;
    errno = 0;
    long r = wcstol(p, &ptr, base);
    swap(errno, errno_save);
#ifndef _LIBCPP_NO_EXCEPTIONS
    if (errno_save == ERANGE)
        throw out_of_range("stol: out of range");
    if (ptr == p)
        throw invalid_argument("stol: no conversion");
#endif  // _LIBCPP_NO_EXCEPTIONS
    if (idx)
        *idx = static_cast<size_t>(ptr - p);
    return r;
}
示例#13
0
// addedge(x1, y1, x2, y2, angle = 0, marker = "none")
void pythonAddEdge(double x1, double y1, double x2, double y2, double angle, char *marker)
{
    logMessage("pythonAddEdge()");

    if (angle > 90.0 || angle < 0.0)
        throw out_of_range(QObject::tr("Angle '%1' is out of range.").arg(angle).toStdString());

    SceneBoundary *boundary = Util::scene()->getBoundary(QString(marker));
    if (!boundary)
        throw invalid_argument(QObject::tr("Boundary '%1' is not defined.").arg(marker).toStdString());

    // start node
    SceneNode *nodeStart = Util::scene()->addNode(new SceneNode(Point(x1, y1)));
    // end node
    SceneNode *nodeEnd = Util::scene()->addNode(new SceneNode(Point(x2, y2)));

    // FIXME 0 -> variable
    Util::scene()->addEdge(new SceneEdge(nodeStart, nodeEnd, boundary, angle, 0));
}
  RR operator()(T& t, RR rr)
  {
    for (register int i=0; i < 4; ++i)
    {
      if ( !this->peek(t, rr.first) )
      {
        if (rr.first)
          return throw_<_except_>( t, parse_error( distance(rr.first) ), rr);
        else
          return throw_<_except_>( t, unexpected_end_fragment(), rr);
      }

      if ( !rr.second )
        return throw_<_except_>( t, out_of_range( distance(rr.first) ), rr );

      *(rr.second++)= *(rr.first++);
    }
    return rr;
  }
示例#15
0
文件: string.cpp 项目: themiwi/libcxx
float
stof(const string& str, size_t* idx)
{
    char* ptr;
    const char* const p = str.c_str();
    int errno_save = errno;
    errno = 0;
    double r = strtod(p, &ptr);
    swap(errno, errno_save);
#ifndef _LIBCPP_NO_EXCEPTIONS
    if (errno_save == ERANGE)
        throw out_of_range("stof: out of range");
    if (ptr == p)
        throw invalid_argument("stof: no conversion");
#endif  // _LIBCPP_NO_EXCEPTIONS
    if (idx)
        *idx = static_cast<size_t>(ptr - p);
    return static_cast<float>(r);
}
示例#16
0
文件: string.cpp 项目: themiwi/libcxx
long double
stold(const wstring& str, size_t* idx)
{
    wchar_t* ptr;
    const wchar_t* const p = str.c_str();
    int errno_save = errno;
    errno = 0;
    long double r = wcstold(p, &ptr);
    swap(errno, errno_save);
#ifndef _LIBCPP_NO_EXCEPTIONS
    if (errno_save == ERANGE)
        throw out_of_range("stold: out of range");
    if (ptr == p)
        throw invalid_argument("stold: no conversion");
#endif  // _LIBCPP_NO_EXCEPTIONS
    if (idx)
        *idx = static_cast<size_t>(ptr - p);
    return r;
}
示例#17
0
  RR operator()(T& t, RR rr)
  {
    tstring_range sr = tstring_range( tstring()() );
    for (;sr;++sr)
    {
      if (!rr.second)
        return throw_<_except_>( t, out_of_range( distance(rr.first) ), rr );

      if ( !rr.first )
        return throw_<_except_>( t, unexpected_end_fragment(), rr );

      if ( *rr.first != *sr )
        return throw_<_except_>( t, expected_of(tstring()(),  distance(rr.first) ), rr );

      *(rr.second++) = *(rr.first++);
    }

    return rr;
  }
示例#18
0
文件: lexer.cpp 项目: storance/dcpu16
	token lexer::parse_number(location_ptr &start, const string &value) {
		string unprefixedValue;

		uint8_t base = 10;
		if (istarts_with(value, "0x")) {
			base = 16;
			unprefixedValue = value.substr(2);
		} else if (istarts_with(value, "0o")) {
			base = 8;
			unprefixedValue = value.substr(2);
		} else if (istarts_with(value, "0b")) {
			base = 2;
			unprefixedValue = value.substr(2);
		} else {
			unprefixedValue = value;
		}

		// prefix without an actual value
		if (unprefixedValue.length() == 0) {
			return token(start, token_type::INVALID_INTEGER, value);
		}

		size_t pos;
		try {
			unsigned long parsed_value = stoul(unprefixedValue, &pos, base);
			if (pos != unprefixedValue.size()) {
				return token(start, token_type::INVALID_INTEGER, value);
			}

			if (parsed_value > numeric_limits<uint32_t>::max()) {
				throw out_of_range(value);
			}

			return token(start, token_type::INTEGER, value, (uint32_t)parsed_value);
		} catch (invalid_argument &ia) {
			return token(start, token_type::INVALID_INTEGER, value);
		} catch (out_of_range &oor) {
			logger.warning(start, format("overflow converting '%s' to a 32-bit integer") % value);

			return token(start, token_type::INTEGER, value, numeric_limits<uint32_t>::max());
		}
	}
示例#19
0
int
stoi(const string& str, size_t* idx, int base)
{
    char* ptr;
    const char* const p = str.c_str();
    typename remove_reference<decltype(errno)>::type errno_save = errno;
    errno = 0;
    long r = strtol(p, &ptr, base);
    swap(errno, errno_save);
#ifndef _LIBCPP_NO_EXCEPTIONS
    if (errno_save == ERANGE || r < numeric_limits<int>::min() ||
                                numeric_limits<int>::max() < r)
        throw out_of_range("stoi: out of range");
    if (ptr == p)
        throw invalid_argument("stoi: no conversion");
#endif  // _LIBCPP_NO_EXCEPTIONS
    if (idx)
        *idx = static_cast<size_t>(ptr - p);
    return static_cast<int>(r);
}
示例#20
0
void Candidate::init_can(int numvar, /*!<number of variables*/
                         int fit_size /*!< the number of objective functions*/
                        ) {
    if(numvar <= 0) {
        throw out_of_range("numvar must be positive.");
        }
    if(fit_size <= 0) {
        throw invalid_argument("num_fit must be positive.");
        }
    num = numvar;
    can_best = new double[num];
    contender = new double[num];
    global_best = new double[num];

    num_fit = fit_size;
    best_fit = new double[num_fit];
    cont_fit = new double[num_fit];
    global_fit = new double[num_fit];
    is_candidate_initialized = true;
    }
示例#21
0
文件: string.cpp 项目: themiwi/libcxx
int
stoi(const wstring& str, size_t* idx, int base)
{
    wchar_t* ptr;
    const wchar_t* const p = str.c_str();
    long r = wcstol(p, &ptr, base);
    if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
        ptr = const_cast<wchar_t*>(p);
    if (ptr == p)
    {
#ifndef _LIBCPP_NO_EXCEPTIONS
        if (r == 0)
            throw invalid_argument("stoi: no conversion");
        throw out_of_range("stoi: out of range");
#endif  // _LIBCPP_NO_EXCEPTIONS
    }
    if (idx)
        *idx = static_cast<size_t>(ptr - p);
    return static_cast<int>(r);
}
示例#22
0
void readExpression(istream& is, bitset* minterms, bitset* donotcare, uint8_t* varsCount) {
    char temp = '0';
    long long number;
    bitset* currentSet = minterms;
    is >> number;
    *varsCount = number;
    cout << *varsCount << endl;
    if (is.fail() || int(*varsCount) > int(16))
        throw logic_error("Variables count could not be read or invalid");
    is >> temp;
    if (is.fail() || is.eof() || temp != ';')
        throw logic_error("Syntax error: expected ';'");
    _t_minterm maxValue = (pow(2, *varsCount) - 1);
    minterms->resize(maxValue + 1);
    donotcare->resize(maxValue + 1);
    is >> number;
    if (!is.eof()) {
        while (true) {
            if (is.fail())
                throw logic_error("Syntax error");
            if (number > maxValue)
                throw out_of_range("Invalid min-term value: given value is greater than maximum");
            currentSet->set(number);
            temp = '0';
            is >> temp;
            if (is.fail() || is.eof() || (temp != ';' && temp != ','))
                throw logic_error("Syntax error: expected ';'");
            if (temp == ',') {
                is >> number;
            } else if (temp == ';') {
                if (currentSet == donotcare)
                    break;
                else {
                    currentSet = donotcare;
                    is >> number;
                    if (is.eof())
                        break;
                }
            } else {
                throw logic_error("Unhandled weird exception");
示例#23
0
/** @fn void ApptList::remove(int index)
 *  @brief Remove an Appt Object from the list and delete it.
 *  @param index int Intager referencing index position to delete
 *  @exception out_of_range Index out of Bounds
 *  @warning Does NOT check size of list before removal. DOES NOT free the memory
 *           that Appt * references.
 *  @return void
 *
 *  Remove an Appt * from the list (This does NOT free the memory the Appt * referenced. 
 *  Can be used in a loop like in the deconstructor to empty the list. 
 *  However, be sure to check the size because if you remove and the list is empty out_of_range
 *  exception will occur. And be sure you are freeing the memory Appt * references
 */
void ApptList::remove(int index)
{
	ApptListNode *curr = NULL;
	ApptListNode *prev = NULL;

	if(!isEmpty() && index < size())
	{

		if(index == 0)
		{
			prev = head;
			head = head->getNext();

			delete prev;
			prev = NULL;
			curr = NULL;
			numItems--;
		}
		else
		{
			curr = head;
			for(int i = 0; i < index; i++)
			{
				prev = curr;
				curr = curr->getNext(); 
			}
			prev->setNext(curr->getNext());
			delete curr;
			numItems--;
		}
	}
	else 
	{
		ostringstream indexpos;
		ostringstream listsize;
		indexpos << index;
		listsize << size();
		throw out_of_range("ApptList is empty or item " + indexpos.str() + " is out of bounds\n List size is " + listsize.str() + " so item should be at most -1 of list size\n");
	}
}
示例#24
0
wstring& wstring::replace(size_t pos, size_t n1, const wchar_t* s, size_t n2) {
    const size_t len = length();
    if (pos > len)
        throw out_of_range("pos > len");
    if (n1 > len - pos)
        n1 = len - pos;
    if (len - n1 > max_size() - n2)
        throw length_error("len - n1 > max_size() - n2");
    size_t newlen = len - n1 + n2;
    if (check_realloc(newlen)) {
        Rep *p = Rep::create(newlen);
        p->copy(0, data(), pos);
        p->copy(pos + n2, data() + pos + n1, len -(pos + n1));
        p->copy(pos, s, n2);
        repup(p);
    }
    else {
        rep()->move(pos + n2, data() + pos + n1, len -(pos + n1));
        rep()->copy(pos, s, n2);
    }
    rep()->len = newlen;
    return *this;
}
void bad()
{
    if(staticTrue)
    {
        try
        {
            if (rand()%2 == 0)
            {
                throw out_of_range("err1");
            }
            if (rand()%2 == 0)
            {
                throw domain_error("err2");
            }
        }
        catch (exception &)
        {
            /* FLAW: this catches err1 and err2 */
            printLine("exception");
        }
        printLine("ok");
    }
}
void bad()
{
    if(globalFive==5)
    {
        try
        {
            if (rand()%2 == 0)
            {
                throw out_of_range("err1");
            }
            if (rand()%2 == 0)
            {
                throw domain_error("err2");
            }
        }
        catch (...)
        {
            /* FLAW: this catches _everything_, STL exceptions or otherwise */
            printLine("exception");
        }
        printLine("ok");
    }
}
示例#27
0
int main(int argc, char *argv[]){
	if(argc < 3) {
		usage();
		return 1;
	}
	int dr, dc;
	dr = atoi(argv[1]);
	dc = atoi(argv[2]);
	if((dr >= CHESS_SIZE) || (dc >= CHESS_SIZE) || (dr < 0) || (dc < 0)){
		out_of_range();
		return 1;
	}
	int i,j;
	chess_cover(0, 0, dr, dc, CHESS_SIZE);
	for(i = 0; i < CHESS_SIZE; i++) {
		for(j = 0; j < CHESS_SIZE; j++) {
			printf("%d  ", chess[i][j]);
		}
		printf("\n");
	}
	printf("\n");
	return 0;
}
void AP_RangeFinder_PX4_PWM::update(void)
{
    if (_fd == -1) {
        set_status(RangeFinder::RangeFinder_NotConnected);
        return;
    }

    struct pwm_input_s pwm;
    float sum_cm = 0;
    uint16_t count = 0;
    const float scaling = state.scaling;
    uint32_t now = AP_HAL::millis();

    while (::read(_fd, &pwm, sizeof(pwm)) == sizeof(pwm)) {
        // report the voltage as the pulse width, so we get the raw
        // pulse widths in the log
        state.voltage_mv = pwm.pulse_width;

        _last_pulse_time_ms = now;

        // setup for scaling in meters per millisecond
        float distance_cm = pwm.pulse_width * 0.1f * scaling + state.offset;

        float distance_delta_cm = fabsf(distance_cm - _last_sample_distance_cm);
        _last_sample_distance_cm = distance_cm;

        if (distance_delta_cm > 100) {
            // varying by more than 1m in a single sample, which means
            // between 50 and 100m/s vertically - discard
            _good_sample_count = 0;
            continue;
        }

        if (_good_sample_count > 1) {
            count++;
            sum_cm += distance_cm;
            _last_timestamp = pwm.timestamp;
        } else {
            _good_sample_count++;
        }
    }

    // if we haven't received a pulse for 1 second then we may need to
    // reset the timer
    int8_t stop_pin = state.stop_pin;
    uint16_t settle_time_ms = (uint16_t)state.settle_time_ms;

    if (stop_pin != -1 && out_of_range()) {
        // we are above the power saving range. Disable the sensor
        hal.gpio->pinMode(stop_pin, HAL_GPIO_OUTPUT);
        hal.gpio->write(stop_pin, false);
        set_status(RangeFinder::RangeFinder_NoData);
        state.distance_cm = 0;
        state.voltage_mv = 0;
        return;
    }

    // if we have not taken a reading in the last 0.2s set status to No Data
    if (AP_HAL::micros64() - _last_timestamp >= 200000) {
        set_status(RangeFinder::RangeFinder_NoData);
    }

    /* if we haven't seen any pulses for 0.5s then the sensor is
       probably dead. Try resetting it. Tests show the sensor takes
       about 0.2s to boot, so 500ms offers some safety margin
    */
    if (now - _last_pulse_time_ms > 500U && _disable_time_ms == 0) {
        ioctl(_fd, SENSORIOCRESET, 0);
        _last_pulse_time_ms = now;

        // if a stop pin is configured then disable the sensor for the
        // settle time
        if (stop_pin != -1) {
            hal.gpio->pinMode(stop_pin, HAL_GPIO_OUTPUT);
            hal.gpio->write(stop_pin, false);            
            _disable_time_ms = now;
        }
    }

    /* the user can configure a settle time. This controls how 
       long the sensor is disabled for using the stop pin when it is
       reset. This is used both to make sure the sensor is properly
       reset, and also to allow for power management by running a low
       duty cycle when it has no signal 
    */
    if (stop_pin != -1 && _disable_time_ms != 0 && 
        (now - _disable_time_ms > settle_time_ms)) {
        hal.gpio->write(stop_pin, true);        
        _disable_time_ms = 0;
        _last_pulse_time_ms = now;
    }

    if (count != 0) {
        state.distance_cm = sum_cm / count;

        // update range_valid state based on distance measured
        update_status();
    }
}
示例#29
0
Log::Log(Number* base, Number* argument) {
	if (argument->getFloatValue() <= 0 || base->getFloatValue() <= 0)
		throw out_of_range("The argument and base of log must be greater than zero.");
	this->base = base;
	this->argument = argument;
}
示例#30
0
 static void validate_range ( argument_type s )
   { OverflowHandler()( out_of_range(s) ) ; }