T BinarySearchTree<T>::search(T value, Node<T>* subtree) const throw(ValueNotFoundException){ T temp; if(subtree == nullptr){ throw ValueNotFoundException("The value is not in the tree\n");//first, make sure we aren't at a dead end } else if((subtree->getValue())==value){//then, check current root value return value; } if(value < (subtree->getValue())){// try to check the left side try{ temp = search(value, subtree->getLeft());//this may throw and exception, which will //continue upstream and be caught immdeiately above } catch(std::exception e){ throw ValueNotFoundException("The value is not in the tree\n"); } } else{//check the right if necessary if(!((subtree->getValue())< value)){//the value is not in the left, so if it is not >= root, //then it isn't here throw ValueNotFoundException("The value is not in the tree\n"); } try{ temp = search(value, subtree->getRight()); } catch(std::exception e){//at this point, throw the exception upstream because we have //exhausted the tree throw ValueNotFoundException("The value is not in the tree\n"); } } return temp; }
Type getExtension(const ValueType::Type &argValueType) const { std::map<ValueType::Type, boost::any>::const_iterator it = extensions_.find(argValueType); if(it != extensions_.end()) { switch(argValueType) { case ValueType::VAL_INT: if(boost::is_same<EnumFooType::Type, Type>::value) { return (boost::any_cast<ValueHolder<Type> >((*it).second)).getValue(); } else { std::cout << "Wrong type for this value" << std::endl; } break; case ValueType::VAL_STR_1: case ValueType::VAL_STR_2: if(boost::is_same<const char *, typename boost::decay<Type>::type>::value) { return (boost::any_cast<ValueHolder<Type> >((*it).second)).getValue(); } else { std::cout << "Wrong type value for this Holder" << std::endl; } break; default: std::cout << "Unhandled type of value, skipping..." << std::endl; break; } } throw ValueNotFoundException("Could not find a value for this subscriber extension"); }
QScriptValue EnvWrap::evalExp( const QString& nm ) { if (!constStatement(nm)) throw NotConstException(nm); QScriptValue result = env->evaluate(nm); if (result.isError()) throw ValueNotFoundException(nm); return result; }
float DeliveryPredictabilityMap::get(const dtn::data::EID &neighbor) const throw (ValueNotFoundException) { predictmap::const_iterator it; if ((it = _predictmap.find(neighbor)) != _predictmap.end()) { return it->second; } throw ValueNotFoundException(); }
T BinarySearchTree<T>::search(T value)const throw(ValueNotFoundException){ T temp; try{ temp = search(value, m_root); return temp; } catch(std::exception e){ throw ValueNotFoundException("The value is not in the tree\n"); } return temp; }
T BinarySearchTree<T>::search(T value, Node<T> *subTree) const throw (ValueNotFoundException) { if (subTree != nullptr) { if (value == subTree->getValue()) { return value; } else if (value < subTree->getValue()) { search(value, subTree->getLeft()); } else { search(value, subTree->getRight()); } } else { throw (ValueNotFoundException("Value not found in tree")); } }