void check_indexes(const ITYPE &index,const STYPE &shape, const exception_record &record) { //check size - if it does not match throw an exception if(!check_equal_size(index,shape)) { std::stringstream ss; ss<<"Rank of index vector ("<<index.size()<<") does not match "; ss<<"the rank of the shape vector ("<<shape.size()<<")!"; throw shape_mismatch_error(record,ss.str()); } //if sizes of the vectors match check the individual ranges. if(!check_indexes(index,shape)) { std::stringstream ss; ss<<"Indexes "; print_vector(ss,index); ss<<" do not match shape "; print_vector(ss,shape); ss<<std::endl; throw index_error(record,ss.str()); } }
//------------------------------------------------------------------------- void check_index_in_dim(size_t index,size_t dimsize, const exception_record &i) { if(!check_index_in_dim(index,dimsize)) { std::stringstream ss; ss<<"Index ("<<index<<") exceeds dimension range ("<<dimsize<<")!"; throw index_error(i,ss.str()); } }
int list_deleteAt(list* p_list, int index) { if (index_error(index, p_list->size)) return 0; int i; for (i = index; i < p_list->size - 1; i++) { p_list->data[i] = p_list->data[i + 1]; } p_list->size--; p_list->data = (int *)realloc(p_list->data, (p_list->size - 1) * 4); return 1; }
//----------------------------------------------------------------- //! //! \brief get value at i //! //! Return the value of element i. This method //! performs index checking. //! \throws index_error if i exceeds array size //! \param i linear index of element //! \return value at i //! value_type at(size_t i) const { try { return _data.at(i); } catch(std::out_of_range &) { std::stringstream ss; ss<<"Index "<<i<<" is out of range ("<<size()<<")!"; throw index_error(EXCEPTION_RECORD,ss.str()); } }