void WinRegistryKey::open() { if (!_hKey) { #if defined(POCO_WIN32_UTF8) std::wstring usubKey; Poco::UnicodeConverter::toUTF16(_subKey, usubKey); if (_readOnly) { if (RegOpenKeyExW(_hRootKey, usubKey.c_str(), 0, KEY_READ | _extraSam, &_hKey) != ERROR_SUCCESS) throw NotFoundException("Cannot open registry key: ", key()); } else { if (RegCreateKeyExW(_hRootKey, usubKey.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE | _extraSam, NULL, &_hKey, NULL) != ERROR_SUCCESS) throw SystemException("Cannot open registry key: ", key()); } #else if (_readOnly) { if (RegOpenKeyExA(_hRootKey, _subKey.c_str(), 0, KEY_READ | _extraSam, &_hKey) != ERROR_SUCCESS) throw NotFoundException("Cannot open registry key: ", key()); } else { if (RegCreateKeyExA(_hRootKey, _subKey.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE | _extraSam, NULL, &_hKey, NULL) != ERROR_SUCCESS) throw SystemException("Cannot open registry key: ", key()); } #endif } }
void ProcessImpl::killImpl(PIDImpl pid) { HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, pid); if (hProc) { if (TerminateProcess(hProc, 0) == 0) { CloseHandle(hProc); throw SystemException("cannot kill process"); } CloseHandle(hProc); } else { switch (GetLastError()) { case ERROR_ACCESS_DENIED: throw NoPermissionException("cannot kill process"); case ERROR_NOT_FOUND: throw NotFoundException("cannot kill process"); case ERROR_INVALID_PARAMETER: throw NotFoundException("cannot kill process"); default: throw SystemException("cannot kill process"); } } }
void WinRegistryKey::deleteKey() { Keys keys; subKeys(keys); close(); for (Keys::iterator it = keys.begin(); it != keys.end(); ++it) { std::string subKey(_subKey); subKey += "\\"; subKey += *it; WinRegistryKey subRegKey(_hRootKey, subKey); subRegKey.deleteKey(); } // NOTE: RegDeleteKeyEx is only available on Windows XP 64-bit SP3, Windows Vista or later. // We cannot call it directly as this would prevent the code running on Windows XP 32-bit. // Therefore, if we need to call RegDeleteKeyEx (_extraSam != 0) we need to check for // its existence in ADVAPI32.DLL and call it indirectly. #if defined(POCO_WIN32_UTF8) std::wstring usubKey; Poco::UnicodeConverter::toUTF16(_subKey, usubKey); typedef LONG (WINAPI *RegDeleteKeyExWFunc)(HKEY hKey, const wchar_t* lpSubKey, REGSAM samDesired, DWORD Reserved); if (_extraSam != 0) { AutoHandle advAPI32(LoadLibraryW(L"ADVAPI32.DLL")); if (advAPI32.handle()) { RegDeleteKeyExWFunc pRegDeleteKeyExW = reinterpret_cast<RegDeleteKeyExWFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExW")); if (pRegDeleteKeyExW) { if ((*pRegDeleteKeyExW)(_hRootKey, usubKey.c_str(), _extraSam, 0) != ERROR_SUCCESS) throw NotFoundException(key()); return; } } } if (RegDeleteKeyW(_hRootKey, usubKey.c_str()) != ERROR_SUCCESS) throw NotFoundException(key()); #else typedef LONG (WINAPI *RegDeleteKeyExAFunc)(HKEY hKey, const char* lpSubKey, REGSAM samDesired, DWORD Reserved); if (_extraSam != 0) { AutoHandle advAPI32(LoadLibraryA("ADVAPI32.DLL")); if (advAPI32.handle()) { RegDeleteKeyExAFunc pRegDeleteKeyExA = reinterpret_cast<RegDeleteKeyExAFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExA")); if (pRegDeleteKeyExA) { if ((*pRegDeleteKeyExA)(_hRootKey, _subKey.c_str(), _extraSam, 0) != ERROR_SUCCESS) throw NotFoundException(key()); return; } } } if (RegDeleteKey(_hRootKey, _subKey.c_str()) != ERROR_SUCCESS) throw NotFoundException(key()); #endif }
void WinRegistryKey::deleteValue(const std::string& name) { open(); #if defined(POCO_WIN32_UTF8) std::wstring uname; Poco::UnicodeConverter::toUTF16(name, uname); if (RegDeleteValueW(_hKey, uname.c_str()) != ERROR_SUCCESS) throw NotFoundException(key(name)); #else if (RegDeleteValueA(_hKey, name.c_str()) != ERROR_SUCCESS) throw NotFoundException(key(name)); #endif }
/** * Gets an object from the cache; the database is not accessed. * * @param id the ID of the object * @return a copy of the object * @throw NotFoundException if the object is not found or id is invalid */ template<class T> T Cache::getObject (dbId id) { if (idInvalid (id)) throw NotFoundException (id); synchronized (dataMutex) { const QHash<dbId, T> &hash=objectsByIdHash<T> (); if (!hash.contains (id)) throw NotFoundException (id); return hash.value (id); } assert (!notr ("Not returned yet")); throw NotFoundException (id); }
BufferFrame* BPlusSegment<K,V>::fixLeafFor(const K& key, const bool exclusive) const{ BufferFrame* pageOfKey = &bm.fixPage(segmentId, root, exclusive); while(!isLeaf(pageOfKey->getData())){ BPlusPage<K, PageID> page(pageOfKey->getData(), pageSize, cmp); PageID nextPage; try{ nextPage = page.lookupSmallestGreaterThan(key).value; }catch(NotFoundException e){ //upper exists? if (page.getUpperExists()){ nextPage = page.getUpper(); }else{ bm.unfixPage(*pageOfKey, false); throw NotFoundException(); } } BufferFrame* oldBF = pageOfKey; pageOfKey = &bm.fixPage(segmentId, nextPage, exclusive); bm.unfixPage(*oldBF, false); } return pageOfKey; }
BundleMetadata const& BundleLoader::createBundleEx( std::string const& path, void ( *MetainfoFunc )( bundle::BundleMetainfo & ) ) { Metainfo *info = new Metainfo(); try { BundleInfo bundleInfo; bundle::BundleMetainfo metainfo( *info ); MetainfoFunc( metainfo ); bundleInfo.metainfo = info; bundleInfo.metainfo->setInstallDirectory( path ); bundleInfo.metainfo->cleanup(); m_LoadedBundles.insert( make_pair( path, bundleInfo ) ); } catch ( Exception &e ) { delete info; throw e; } BundleMetadata const& meta = info->getBundleData(); if ( meta.getName() == "undefined" ) { ostringstream msg; msg << "bundle " << meta.getInstallDirectory() << " does not define a name"; throw NotFoundException( msg.str() ); } return meta; }
RowFilter::Comparison RowFilter::getComparison(const std::string& comp) const { Comparisons::const_iterator it = _comparisons.find(toUpper(comp)); if (it == _comparisons.end()) throw NotFoundException("Comparison not found", comp); return it->second; }
const std::string& NameValueCollection::operator [] (const std::string& name) const { ConstIterator it = _map.find(name); if (it != _map.end()) return it->second; else throw NotFoundException(name); }
TextEncoding& TextEncoding::byName(const std::string& encodingName) { TextEncoding* pEncoding = manager().find(encodingName); if (pEncoding) return *pEncoding; else throw NotFoundException(encodingName); }
void* SharedLibrary::getSymbol(const std::string& name) { void* result = findSymbolImpl(name); if (result) return result; else throw NotFoundException(name); }
buffer_ptr Mesh::attrib(const attribid_t& attribid_) { Attribs::iterator it = _attribs.find(attribid_); if(it == _attribs.end()){ throw(NotFoundException("Attrib not found")); } return buffer_ptr((*it).second); }
std::string WinRegistryKey::getStringExpand(const std::string& name) { open(); DWORD type; DWORD size; #if defined(POCO_WIN32_UTF8) std::wstring uname; Poco::UnicodeConverter::toUTF16(name, uname); if (RegQueryValueExW(_hKey, uname.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS || type != REG_SZ && type != REG_EXPAND_SZ) throw NotFoundException(key(name)); if (size > 0) { DWORD len = size/2; wchar_t* buffer = new wchar_t[len + 1]; RegQueryValueExW(_hKey, uname.c_str(), NULL, NULL, (BYTE*) buffer, &size); buffer[len] = 0; wchar_t temp; DWORD expSize = ExpandEnvironmentStringsW(buffer, &temp, 1); wchar_t* expBuffer = new wchar_t[expSize]; ExpandEnvironmentStringsW(buffer, expBuffer, expSize); std::string result; UnicodeConverter::toUTF8(expBuffer, result); delete [] buffer; delete [] expBuffer; return result; } #else if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS || type != REG_SZ && type != REG_EXPAND_SZ) throw NotFoundException(key(name)); if (size > 0) { char* buffer = new char[size + 1]; RegQueryValueExA(_hKey, name.c_str(), NULL, NULL, (BYTE*) buffer, &size); buffer[size] = 0; char temp; DWORD expSize = ExpandEnvironmentStringsA(buffer, &temp, 1); char* expBuffer = new char[expSize]; ExpandEnvironmentStringsA(buffer, expBuffer, expSize); std::string result(expBuffer); delete [] buffer; delete [] expBuffer; return result; } #endif return std::string(); }
T& getElement(const std::string& key) const { const std::map<std::string, NAbstract*>::const_iterator iter (_children.find(key)); if (iter == _children.end()) { throw NotFoundException("Key " + key); } T* obj = dynamic_cast<T*>(iter->second); if (!obj) { throw NotFoundException("Key " + key); } return *obj; }
Poco::Int64 WinRegistryKey::getInt64(const std::string& name) { open(); DWORD type; Poco::Int64 data; DWORD size = sizeof(data); #if defined(POCO_WIN32_UTF8) std::wstring uname; Poco::UnicodeConverter::toUTF16(name, uname); if (RegQueryValueExW(_hKey, uname.c_str(), NULL, &type, (BYTE*) &data, &size) != ERROR_SUCCESS || type != REG_DWORD) throw NotFoundException(key(name)); #else if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, (BYTE*) &data, &size) != ERROR_SUCCESS || type != REG_DWORD) throw NotFoundException(key(name)); #endif return data; }
typename DomainEnumerate<Val>::ValueId DomainEnumerate<Val>::find(const typename Val::Value& value) const { Val attr(value, const_cast<DomainEnumerate<Val>*>(this)); //ValueNominal requires non-const pointer to domain const_iterator found = std::find( values_.begin(), values_.end(), attr ); if( found != values_.end() ) { return getValueId( found); } throw NotFoundException( getId().c_str() ); }
Poco::Any SessionPool::getProperty(const std::string& name) { PropertyMap::ConstIterator it = _propertyMap.find(name); if (_propertyMap.end() == it) throw NotFoundException("Property not found:" + name); return it->second; }
DecisionTreeNode* DecisionTree::GetNode(int i_id) const { auto it = std::find_if(m_nodes.begin(), m_nodes.end(), FindNode_Id(i_id)); if (it == m_nodes.end()) throw NotFoundException("Node does not find"); return (*it).get(); }
std::string::size_type StringTokenizer::find(const std::string& token, std::string::size_type pos) const { TokenVec::const_iterator it = std::find(_tokens.begin() + pos, _tokens.end(), token); if (it != _tokens.end()) { return it - _tokens.begin(); } throw NotFoundException(token); }
int TypeInfo::sqlDataType(int cDataType) const { DataTypeMap::const_iterator it = _sqlDataTypes.find(cDataType); if (_sqlDataTypes.end() == it) throw NotFoundException(format("SQL data type not found for C data type: %d", cDataType)); return it->second; }
Channel* LoggingRegistry::channelForName(const std::string& name) const { FastMutex::ScopedLock lock(_mutex); ChannelMap::const_iterator it = _channelMap.find(name); if (it != _channelMap.end()) return const_cast<Channel*>(it->second.get()); else throw NotFoundException("logging channel", name); }
bool SessionPool::getFeature(const std::string& name) { FeatureMap::ConstIterator it = _featureMap.find(name); if (_shutdown) throw InvalidAccessException("Session pool has been shut down."); if (_featureMap.end() == it) throw NotFoundException("Feature not found:" + name); return it->second; }
std::string EnvironmentImpl::getImpl(const std::string& name) { FastMutex::ScopedLock lock(_mutex); const char* val = getenv(name.c_str()); if (val) return std::string(val); else throw NotFoundException(name); }
shared_ptr<Object> Object::getProperty(const string& propName) const { auto property = impl->properties.find(propName); if (property != impl->properties.end()) { return property->second->get(); } else { throw NotFoundException(propName); } }
void LoggingRegistry::unregisterFormatter(const std::string& name) { FastMutex::ScopedLock lock(_mutex); FormatterMap::iterator it = _formatterMap.find(name); if (it != _formatterMap.end()) _formatterMap.erase(it); else throw NotFoundException("logging formatter", name); }
ItemType BinaryNodeTree<ItemType>::getEntry(const ItemType& anEntry) const throw(NotFoundException) { bool isSuccessful = false; BinaryNode<ItemType>* binaryNodePtr = findNode(rootPtr, anEntry, isSuccessful); if (isSuccessful) return binaryNodePtr->getItem(); else throw NotFoundException("Entry not found in tree!"); } // end getEntry
std::string AbstractConfiguration::getString(const std::string& key) const { Mutex::ScopedLock lock(_mutex); std::string value; if (getRaw(key, value)) return internalExpand(value); else throw NotFoundException(key); }
Formatter* LoggingRegistry::formatterForName(const std::string& name) const { FastMutex::ScopedLock lock(_mutex); FormatterMap::const_iterator it = _formatterMap.find(name); if (it != _formatterMap.end()) return const_cast<Formatter*>(it->second.get()); else throw NotFoundException("logging formatter", name); }
void LoggingRegistry::unregisterChannel(const std::string& name) { FastMutex::ScopedLock lock(_mutex); ChannelMap::iterator it = _channelMap.find(name); if (it != _channelMap.end()) _channelMap.erase(it); else throw NotFoundException("logging channel", name); }
std::string EnvironmentImpl::getImpl(const std::string& name) { DWORD len = GetEnvironmentVariableA(name.c_str(), 0, 0); if (len == 0) throw NotFoundException(name); char* buffer = new char[len]; GetEnvironmentVariableA(name.c_str(), buffer, len); std::string result(buffer); delete [] buffer; return result; }