Skip to content

Commit

Permalink
WIP: changed IO option handling to provide helper functions : correct…
Browse files Browse the repository at this point in the history
…ly interpret <source>/<accessor> data : remove process() function except on InstanceElments

git-svn-id: https://opensg.vrsource.org/svn/trunk@2245 4683daeb-ad0f-0410-a623-93161e962ae5
  • Loading branch information
cneumann committed Dec 29, 2009
1 parent cbb7d57 commit 44c2bfc
Show file tree
Hide file tree
Showing 31 changed files with 2,005 additions and 160 deletions.
44 changes: 24 additions & 20 deletions Source/System/FileIO/Base/OSGIOFileTypeBase.cpp
Expand Up @@ -120,55 +120,59 @@ void
}
}

/*! Sets the option \a name to \a value overwriting any previous value.
/*! Sets the option \a name to \a value in \a optSet overwriting
any previous value.
\param[in] optSet OptionSet to modify.
\param[in] name Name of the option.
\param[in[ value Value of the option.
*/
void
IOFileTypeBase::setOption(
const std::string &name, const std::string &value)
IOFileTypeBase::setOption(
OptionSet &optSet, const std::string &name, const std::string &value)
{
_optStack.top()[name] = IOOption(name, value);
optSet[name] = IOOption(name, value);
}

/*! Removes the option \a name. If the option is not present \c false is
returned, \c true otherwise.
/*! Removes the option \a name from \a optSet. If the option is not present
\c false is returned, \c true otherwise.
\param[in] name Name of the option.
\param[in] optSet OptionSet to modify.
\param[in] name Name of the option.
\return Whether the option was successfully removed.
*/
bool
IOFileTypeBase::unsetOption(const std::string &name)
IOFileTypeBase::unsetOption(OptionSet &optSet, const std::string &name)
{
bool retVal = false;
OptionSet::iterator oIt = _optStack.top().find(name);
OptionSet::iterator oIt = optSet.find(name);

if(oIt != _optStack.top().end())
if(oIt != optSet.end())
{
_optStack.top().erase(oIt);
optSet.erase(oIt);
retVal = true;
}

return retVal;
}

/*! Attempts to return the value associated with option \a name in \a value.
If the option is not present \c false is returned, \c true otherwise and
only in this case value is being set.
/*! Attempts to return the \a value associated with option \a name
in \a optSet. If the option is not present \c false is returned,
\c true otherwise and only in this case value is being set.
\param[in] name Name of the option.
\param[out] value Value of option.
\param[in] optSet OptionSet to read.
\param[in] name Name of the option.
\param[out] value Value of option.
\return Whether the option is present.
*/
bool
IOFileTypeBase::getOption(
std::string const &name, std::string &value) const
IOFileTypeBase::getOption(
const OptionSet &optSet, std::string const &name, std::string &value)
{
bool retVal = false;
OptionSet::const_iterator oIt = _optStack.top().find(name);
OptionSet::const_iterator oIt = optSet.find(name);

if(oIt != _optStack.top().end())
if(oIt != optSet.end())
{
value = oIt->second.optValue;
retVal = true;
Expand Down
27 changes: 27 additions & 0 deletions Source/System/FileIO/Base/OSGIOFileTypeBase.h
Expand Up @@ -90,6 +90,33 @@ class OSG_SYSTEM_DLLMAPPING IOFileTypeBase

UInt32 getFlags(void) const;

/*! \} */
/*---------------------------------------------------------------------*/
/*! \name Option Handling Helpers */
/*! \{ */

static bool hasOption (const OptionSet &optSet,
const std::string &name );

template <class ValueTypeT>
static bool setOptionAs( OptionSet &optSet,
const std::string &name,
const ValueTypeT &value );
static void setOption ( OptionSet &optSet,
const std::string &name,
const std::string &value );

static bool unsetOption( OptionSet &optSet,
const std::string &name );

template <class ValueTypeT>
static bool getOptionAs(const OptionSet &optSet,
const std::string &name,
ValueTypeT &value );
static bool getOption (const OptionSet &optSet,
const std::string &name,
std::string &value );

/*! \} */
/*---------------------------------------------------------------------*/
/*! \name Option Handling */
Expand Down
160 changes: 126 additions & 34 deletions Source/System/FileIO/Base/OSGIOFileTypeBase.inl
Expand Up @@ -38,10 +38,96 @@

OSG_BEGIN_NAMESPACE

/*! Returns whether an option with the given \a name is present in \a optSet.
\param[in] optSet OptionSet to check.
\param[in] name Name of the option.
\return Whether the option is present.
*/
inline bool
IOFileTypeBase::hasOption(const OptionSet &optSet, const std::string &name)
{
return (optSet.find(name) != optSet.end());
}

/*! Attempts to set option \a name to \a value in \a optSet.
If successful \c true is returned, false otherwise.
For the operation to succeed a \c boost::lexical_cast<> from the given type
has to succeed, usually that means an appropriate overload of
\c operator<< has to be available.
\param[in] optSet OptionSet to modify.
\param[in] name Name of the option.
\param[in] value Value of the option.
\return Whether the value was set successfully.
*/
template <class ValueTypeT>
inline bool
IOFileTypeBase::setOptionAs(
OptionSet &optSet, const std::string &name, const ValueTypeT &value)
{
bool retVal = false;

try
{
setOption(optSet, name, boost::lexical_cast<std::string>(value));
retVal = true;
}
catch(boost::bad_lexical_cast &blc)
{
SWARNING << "IOFileTypeBase::setOptionAs: Failed to store value "
<< "for option [" << name << "] : "
<< blc.what() << std::endl;
}

return retVal;
}

/*! Attempts to return the \a value associated with option \a name in \a optSet
as the requested type.
If the option is not present \c false is returned, \c true otherwise and
only in this case value is being set.
For the operation to succeed a \c boost::lexical_cast<> to the requested
type has to succeed, usually that means an appropriate overload of
\c operator>> has to be available.
\param[in] optSet OptionSet to read.
\param[in] name Name of the option.
\param[out] value Value of option.
\return Whether the option is present.
*/
template <class ValueTypeT>
inline bool
IOFileTypeBase::getOptionAs(
const OptionSet &optSet, const std::string &name, ValueTypeT &value)
{
bool retVal = false;
std::string valueStr;

if(getOption(optSet, name, valueStr) == true)
{
try
{
value = boost::lexical_cast<ValueTypeT>(valueStr);
retVal = true;
}
catch(boost::bad_lexical_cast &blc)
{
SWARNING << "IOFileTypeBase::getOptionAs: Failed to extract "
<< "value of option [" << name << "] from string ["
<< valueStr << "] : "
<< blc.what() << std::endl;
}
}

return retVal;
}


/*! Returns the currently active option set, i.e. the top of the options stack.
*/
inline IOFileTypeBase::OptionSet const &
IOFileTypeBase::getOptions (void) const
IOFileTypeBase::getOptions(void) const
{
return _optStack.top();
}
Expand All @@ -62,7 +148,7 @@ inline IOFileTypeBase::OptionSet &
inline bool
IOFileTypeBase::hasOption(std::string const &name) const
{
return (_optStack.top().find(name) != _optStack.top().end());
return hasOption(_optStack.top(), name);
}

/*! Attempts to set option \a name to \a value.
Expand All @@ -80,21 +166,30 @@ inline bool
IOFileTypeBase::setOptionAs(
const std::string &name, const ValueTypeT &value)
{
bool retVal = false;

try
{
_optStack.top()[name] =
IOOption(name, boost::lexical_cast<std::string>(value));
retVal = true;
}
catch(boost::bad_lexical_cast &)
{
FWARNING(("IOFileTypeBase::setOptionAs: Failed to store value "
"for option [%s].\n", name.c_str()));
}

return retVal;
return setOptionAs(_optStack.top(), name, value);
}

/*! Sets the option \a name to \a value overwriting any previous value.
\param[in] name Name of the option.
\param[in[ value Value of the option.
*/
inline void
IOFileTypeBase::setOption(const std::string &name, const std::string &value)
{
setOption(_optStack.top(), name, value);
}

/*! Removes the option \a name. If the option is not present
\c false is returned, \c true otherwise.
\param[in] name Name of the option.
\return Whether the option was successfully removed.
*/
inline bool
IOFileTypeBase::unsetOption(const std::string &name)
{
return unsetOption(_optStack.top(), name);
}

/*! Attempts to return the value associated with option \a name in \a value
Expand All @@ -114,24 +209,21 @@ inline bool
IOFileTypeBase::getOptionAs(
const std::string &name, ValueTypeT &value) const
{
bool retVal = false;
OptionSet::const_iterator oIt = _optStack.top().find(name);

if(oIt != _optStack.top().end())
{
try
{
value = boost::lexical_cast<ValueTypeT>(oIt->second.optValue);
retVal = true;
}
catch(boost::bad_lexical_cast &)
{
FWARNING(("IOFileTypeBase::getOptionAs: Failed to extract value "
"of option [%s].\n", name.c_str()));
}
}
return getOptionAs(_optStack.top(), name, value);
}

/*! Attempts to return the \a value associated with option \a name.
If the option is not present \c false is returned,
\c true otherwise and only in this case value is being set.
return retVal;
\param[in] name Name of the option.
\param[out] value Value of option.
\return Whether the option is present.
*/
inline bool
IOFileTypeBase::getOption(const std::string &name, std::string &value) const
{
return getOption(_optStack.top(), name, value);
}

OSG_END_NAMESPACE

0 comments on commit 44c2bfc

Please sign in to comment.