Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
Add to Processor non-throwing methods to get plugins
Browse files Browse the repository at this point in the history
Complement the existing methods to access plugins in the class Processor
with non-throwing versions. Instead of raising an exception they return
a null pointer in a state of error.
  • Loading branch information
andrey-popov committed Jan 27, 2014
1 parent fb1cfea commit d6e5def
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
18 changes: 18 additions & 0 deletions core/include/Processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ class Processor
*/
Plugin const *GetPlugin(std::string const &name) const;

/**
* \brief Returns a pointer to plugin with given name
*
* The behaviour is identical to GetPlugin, but it does not throw an exeption if the plugin
* is not found. Instead a null pointer is returned.
*/
Plugin const *GetPluginQuiet(std::string const &name) const noexcept;

/**
* \brief Returns a pointer to plugin with given name. In addition checks that the plugin
* is placed in the path before a plugin with name dependentName.
Expand All @@ -107,6 +115,16 @@ class Processor
*/
Plugin const *GetPluginBefore(std::string const &name, std::string const &dependentName)
const;

/**
* \brief Returns a pointer to plugin with given name. In addition checks that the plugin
* is placed in the path before a plugin with name dependentName.
*
* Behaviour is identical to GetPluginBefore, but it does not throw an exception if the
* requested plugin is not found. Instead the method returns a null pointer.
*/
Plugin const *GetPluginBeforeQuiet(std::string const &name,
std::string const &dependentName) const noexcept;

private:
/// Retuns index in the path of a plugin with given name. Throws an exception if not found
Expand Down
27 changes: 27 additions & 0 deletions core/src/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ Plugin const *Processor::GetPlugin(string const &name) const
}


Plugin const *Processor::GetPluginQuiet(string const &name) const noexcept
{
try
{
return GetPlugin(name);
}
catch (...)
{
return nullptr;
}
}


Plugin const *Processor::GetPluginBefore(string const &name, string const &dependentName) const
{
unsigned const indexInterest = GetPluginIndex(name);
Expand All @@ -153,6 +166,20 @@ Plugin const *Processor::GetPluginBefore(string const &name, string const &depen
}


Plugin const *Processor::GetPluginBeforeQuiet(string const &name, string const &dependentName) const
noexcept
{
try
{
return GetPluginBefore(name, dependentName);
}
catch (...)
{
return nullptr;
}
}


unsigned Processor::GetPluginIndex(string const &name) const
{
unsigned index;
Expand Down

0 comments on commit d6e5def

Please sign in to comment.