void assert_error( const char *expected_error, char *actual_error, const string &test_name, int line_num) { if (actual_error == NULL) { stringstream str; str << "ERROR: In '" << test_name << "' at line " << line_num << ": Expected error did not occur: Expected '" << expected_error << "'"; free(actual_error); throw logic_error(str.str()); } if (strcmp(expected_error, actual_error) != 0) { stringstream str; str << "ERROR: In '" << test_name << "' at line " << line_num << ": Did not get expected error message: Expected '" << expected_error << "', but got '" << actual_error << "'"; free(actual_error); throw logic_error(str.str()); } }
const option::map::builder& option::map::builder::operator() (const utsushi::key& name_space, option::map::ptr m) const { if (&owner_ == m.get ()) BOOST_THROW_EXCEPTION (logic_error ("cannot add option::map to self")); container< utsushi::key, value::ptr >::const_iterator it; for (it = m->values_.begin (); m->values_.end () != it; ++it) { utsushi::key k = name_space / it->first; if (owner_.values_.count (k)) { BOOST_THROW_EXCEPTION (logic_error (k)); } owner_.values_[k] = it->second; owner_.constraints_[k] = m->constraints_.find (it->first)->second; owner_.descriptors_[k] = m->descriptors_.find (it->first)->second; } owner_.submaps_.insert (std::make_pair (name_space, m)); m->parent_ = &owner_; m->name_space_ = name_space; return *this; }
listNode* common_node(listNode *a, listNode *b){ if(a == NULL || b == NULL){ throw logic_error("invalide parameter"); } int alen = 1, blen = 1; while(a->m_next){ ++alen; a = a->m_next; } while(b->m_next){ ++blen; b = b->m_next; } listNode *sh = a, *lo = b; int delta = blen - alen; if(alen > blen){ sh = b; lo = a; delta = alen - blen; } for(int i=0;i<delta;i++) lo = lo->m_next; while(lo){ if(sh == lo) return sh; else{ sh = sh->m_next; lo = sh->m_next; } } throw logic_error("no common node"); }
void SQL_handler::add_mdata(const Md_store & md_store) { // sanity checks if (!conn_open_) throw runtime_error("there is no open data base connection"); // make sure there is not already an open transaction if(!trans_open_) throw runtime_error("there is no open transaction"); int comp_key; md_store.get_value("comp_key",comp_key); if (comp_key != comp_key_) throw runtime_error("comp key from creation and the md_store do not match"); // switch on trans_type_. Farm actual work out to local functions // to keep this function clean and readable switch(trans_type_) { case F_NOFUNCTION: throw logic_error("should never get to this point with out a real function type"); case F_IDEN_AVG: case F_IDEN: iden_md_fun(md_store); break; case F_TRACKING: tracking_md_fun(md_store); break; case F_MSD: msd_md_fun(md_store); break; case F_MSD_SWEEP: msd_sweep_md_fun(md_store); break; case F_GOFR: gofr_md_fun(md_store); break; case F_VANHOVE: vanHove_md_fun(md_store); break; case F_GOFR_BY_PLANE: gofr_by_plane_md_fun(md_store); break; case F_PHI6: phi6_md_fun(md_store); break; case F_GOFR3D: case F_LINK3D: case F_TRACK_STATS: throw logic_error("not implemented yet"); } }
Variable & FunctionMapping::get_variable_by_pointer ( const Value & value ) const { if ( ! value.getType()->isPointerTy() ) throw logic_error ( "Not a pointer type" ); auto * found = get_variable_by_pointer_noexcept ( value ); if ( found ) return *found; throw logic_error ( "Pointer does not point to any known variable" ); }
void ExpoContr::launchFreq(const Request& request, const SendCallback& send) { if(mFreqFuture || mExposition) throw logic_error("ExpoContr::stopRead process is active"); assert(!*mExposition); auto delay = request.inputs.at(0).get<int>(); if(delay <= 0) throw logic_error("ExpoContr::launchFreq invalid delay value"); mFreqFuture = ::launchFreq(mDevice, microseconds(delay)); send({ name(), __func__ }); handleRequest({ name(), "type"}, mBroadcast); }
void SwathSegment::moveForward(long l) throw (logic_error) { if (l < grid.getMinInMemoryL()) { BOOST_THROW_EXCEPTION( logic_error("Class: " + className + ": l < grid.getStartL().")); } if (l > grid.getMinInMemoryL() + grid.getSizeL()) { BOOST_THROW_EXCEPTION( logic_error("Class: " + className + ": l > grid.getStartL() + grid.getSizeL().")); } if (l + grid.getSizeL() - 1 > grid.getMaxL()) { l = grid.getMaxL() - grid.getSizeL() + 1; } for (size_t i = 0; i < accessorList.size(); i++) { accessorList[i]->shift(l - grid.getMinInMemoryL(), grid.getStrideK(), grid.getStrideL()); } grid.moveForward(l); }
std::string utilities::ftype_to_str(F_TYPE f) { switch(f) { case F_NOFUNCTION : throw runtime_error("no function given"); case F_IDEN: return "iden"; case F_IDEN_AVG: return "iden_avg"; case F_MSD: return "msd"; case F_TRACKING: return "tracking"; case F_MSD_SWEEP: return "msd_sweep"; case F_GOFR: return "gofr"; case F_VANHOVE: return "vanHove"; case F_GOFR3D: case F_GOFR_BY_PLANE: case F_LINK3D: case F_PHI6: case F_TRACK_STATS: throw logic_error("not implemented"); } return ""; }
void Generic_wrapper_hdf::add_meta_data(const Md_store * md_store,const string & dset) { unsigned int num_entries = md_store->size(); int tmpi; float tmpf; string tmps; for(unsigned int j = 0; j<num_entries; ++j) { string key = md_store->get_key(j); switch(md_store->get_type(j)) { // integer data case V_INT: add_meta_data_priv(key,md_store->get_value(j,tmpi),dset); break; // float data case V_FLOAT: add_meta_data_priv(key,md_store->get_value(j,tmpf),dset); break; // complex data case V_STRING: add_meta_data_priv(key,md_store->get_value(j,tmps),dset); break; default: throw logic_error("should not have hit default"); } } }
void gen_aux(const Grammar& g, const string& word, vector<string>& ret, const int depth) { if (depth > 3) { return; } if (!bracketed(word)) { ret.push_back(word); } else { // locate rule that corresponds to word Grammar::const_iterator it = g.find(word); if (it == g.end()) { throw logic_error("empty rule"); } // fetch the set of possible rules const Rule_collection& c = it->second; int index = nrand(c.size()); const Rule& r = c[index]; // recursively expand the selected rule for (Rule::const_iterator i = r.begin(); i != r.end(); ++i) { gen_aux(g, *i, ret, depth + 1); } } }
std::function<ChannelFreq()> launchFreq(shared_ptr<Tdc> tdc, microseconds delay) { using Future = std::future<ChannelFreq>; if(!tdc->isOpen()) throw logic_error("measureFreq tdc is not open"); auto active = make_shared<atomic_bool>(true); auto future = make_shared<Future>(std::async(std::launch::async, [=] { ChannelFreq freq; auto duration = microseconds::zero(); vector<Tdc::Hit> buffer; while(active->load()) { tdc->clear(); auto s = system_clock::now(); std::this_thread::sleep_for(delay); duration += duration_cast<microseconds>(system_clock::now() - s); tdc->readHits(buffer); handleBuffer(buffer, freq); } for(auto& countPair : freq) countPair.second *= (1000000.0/duration.count()); return freq; })); return [=] { active->store(false); return future->get(); }; }
void FunctionMapping::ins_pointer ( const Value & llval, Variable & var ) { if ( ! llval.getType()->isPointerTy() ) throw logic_error ( "Value must be of pointer type" ); m_pointers.insert ( make_pair ( &llval, &var ) ); }
void gen_aux(const Grammar& g, const string& word, vector<string>& ret) { if (!bracketed(word)) { ret.push_back(word); } else { // locate the rule that corresponds to word Grammar::const_iterator it = g.find(word); if (it == g.end()) throw logic_error("empty rule"); // fetch the set of possible rules const Rule_collection& c = it->second; // from which we select one at random const Rule& r = c[nrand(c.size())]; // recursively expand the selected rule for (Rule::const_iterator i = r.begin(); i != r.end(); ++i) gen_aux(g, *i, ret); } }
T Generic_wrapper_hdf::get_meta_data_priv(const std::string & key, T& val) { if(!group_open_) throw logic_error("generic_wrapper_hdf:: can't add to a closed group"); group_attrs_->get_value(key,val); return val; }
Variable & FunctionMapping::get_variable ( const Value & value ) const { auto v = get_variable_noexcept ( value ); if ( v ) return *v; throw logic_error ( "No such variable exists" ); }
StateInfo & FunctionMapping::get_bb_start ( const BasicBlock & block ) const { const auto s = m_block_start.lookup ( & block ); if ( !s ) throw logic_error ( "Start of basic block not found" ); return *s; }
void SMTConfig::setODEBwdTimeout(double const ode_bwd_timeout) { if (ode_bwd_timeout <= 0.0) { ostringstream os; os << "ERROR: argument for --ode-backward-timeout option should be positive number. " << "It gets " << ode_bwd_timeout << "."; throw logic_error(os.str()); } nra_ODE_bwd_timeout = ode_bwd_timeout; }
byte error_code () const { if (error_code_) { return buffer_[size (true) - 1]; } BOOST_THROW_EXCEPTION (logic_error ("")); }
void ExpoContr::stopFreq(const Request& request, const SendCallback& send) { if(!mFreqFuture) throw logic_error("ExpoContr::stopFreq process is not active"); mFreq = ::convertFreq(mFreqFuture(), mChannelConfig); mFreqFuture = nullptr; handleRequest({ name(), "type"}, mBroadcast); send({ name(), __func__ }); }
void ExpoContr::stopRead(const Request& request, const SendCallback& send) { if(!mExposition) throw logic_error("ExpoContr::stopRead process is not active"); assert(*mExposition); mExposition.reset(); handleRequest({ name(), "type"}, mBroadcast); ++mConfig.nRun; mOnNewRun(mConfig.nRun); send({ name(), __func__ }); }
const T & Queue<T>::front() const { if (empty()) { throw logic_error("front of empty const queue"); } else { return v_[vhead_]; } }
Accessor& SwathSegment::addVariableAlias(const string& alias, const Segment& segment, const string& name) throw (logic_error) { if (segment.hasVariable(name)) { if (segment.getGrid().getSizeK() == getGrid().getSizeK() && segment.getGrid().getSizeL() == getGrid().getSizeL() && segment.getGrid().getSizeM() == getGrid().getSizeM()) { unique(alias); shared_ptr<Accessor> accessor = segment.getSharedAccessor(name); accessorMap[alias] = accessor; return *accessor; } } BOOST_THROW_EXCEPTION( logic_error("Alias for variable '" + name + "' from segment '" + segment.getId() + "' cannot be added to segment '" + segment.getId() + "'.")); }
void ExpoContr::launchRead(const Request& request, const SendCallback& send) { if(mFreqFuture || mExposition) throw logic_error("ExpoContr::launchRead process is active"); assert(!mExposition); mExposition = make_unique<Exposition>(mDevice, mConfig, mChannelConfig, [this](TrekFreq freq) { mBroadcast({name(), "freq", {convertFreq(freq)}}); }); send({ name(), __func__ }); handleRequest({ name(), "type"}, mBroadcast); handleRequest({ name(), "run"}, mBroadcast); }
int possible_failing(int n) { if (n == 0) { throw logic_error("n = 0"); } if (n == 1) { throw 5; } return n; }
void assert_equals( const T &expected, const T &actual, const string &test_name, int line_num) { if (actual != expected) { stringstream str; str << "ERROR: In '" << test_name << "' at line " << line_num << ": Expected '" << expected << "', but got '" << actual << "'"; throw logic_error(str.str()); } }
void assert_equals_no_print_diff( const T &expected, const T &actual, const string &test_name, int line_num) { if (actual != expected) { stringstream str; str << "ERROR: Equals mismatch in '" << test_name << "' at line " << line_num; throw logic_error(str.str()); } }
Data_map:: Data_map(const std::map<utilities::D_TYPE,int>& in) { for(int j = 0;j<D_SENTRY;++j) data_layout_[j] = -1; int count = 0; for(std::map<utilities::D_TYPE,int>::const_iterator it = in.begin(); it!= in.end(); ++it) { if(!((*it).first<D_SENTRY)) { throw logic_error("constants wrong, type out of array bounds"); } data_layout_[(*it).first] = (*it).second; ++count; if(!(count<D_SENTRY)) { throw logic_error("out of array spaces"); } } }
Md_store& Generic_wrapper_hdf::get_meta_data(Md_store & md) { list<string> keys = group_attrs_->contents(); int tmpi; unsigned int tmpui; float tmpf; string tmps; list<string>::const_iterator end = keys.end(); for(list<string>::const_iterator it = keys.begin(); it != end; ++it) { string key = *it; V_TYPE type = group_attrs_->get_type(key); switch(type) { // integer data case V_INT: md.set_value(key,group_attrs_->get_value(key,tmpi)); break; // float data case V_FLOAT: md.set_value(key,group_attrs_->get_value(key,tmpf)); break; // complex data case V_STRING: md.set_value(key,group_attrs_->get_value(key,tmps)); break; case V_UINT: md.set_value(key,group_attrs_->get_value(key,tmpui)); break; case V_COMPLEX: case V_ERROR: case V_BOOL: case V_TIME: case V_GUID: throw logic_error("type not implemented"); } } return md; }
void assert_no_error( char *error, const string &test_name, int line_num, const string &context) { if (error != NULL) { stringstream str; str << "ERROR: In '" << test_name << "' at line " << line_num << ": Got C API error message when trying to " << context << ": " << error; free(error); throw logic_error(str.str()); } }
void gen_aux(const Grammar& g, const string& word, vector<string>& ret) { if (!bracketed(word)) { ret.push_back(word); } else { Grammar::const_iterator it = g.find(word); if (it == g.end()) throw logic_error("empty rule"); const Rule_collection& c = it->second; const Rule& r = c[nrand(c.size())]; for (Rule::const_iterator i = r.begin(); i != r.end(); i++) gen_aux(g, *i, ret); } }