|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55978 - in sandbox/pinhole: boost/pinhole libs/pinhole/test
From: jmcintyre_at_[hidden]
Date: 2009-09-02 12:16:18
Author: jared
Date: 2009-09-02 12:16:18 EDT (Wed, 02 Sep 2009)
New Revision: 55978
URL: http://svn.boost.org/trac/boost/changeset/55978
Log:
Pinhole - add metadata to actions
Text files modified:
sandbox/pinhole/boost/pinhole/action_info.hpp | 1 +
sandbox/pinhole/boost/pinhole/property_group.hpp | 30 +++++++++++++++++++++++++-----
sandbox/pinhole/libs/pinhole/test/test_actions.cpp | 10 +++++++++-
3 files changed, 35 insertions(+), 6 deletions(-)
Modified: sandbox/pinhole/boost/pinhole/action_info.hpp
==============================================================================
--- sandbox/pinhole/boost/pinhole/action_info.hpp (original)
+++ sandbox/pinhole/boost/pinhole/action_info.hpp 2009-09-02 12:16:18 EDT (Wed, 02 Sep 2009)
@@ -33,6 +33,7 @@
action_type m_action;
std::string m_name;
+ boost::any m_metadata;
/**
* Calls the appropriate action function for this parameter.
Modified: sandbox/pinhole/boost/pinhole/property_group.hpp
==============================================================================
--- sandbox/pinhole/boost/pinhole/property_group.hpp (original)
+++ sandbox/pinhole/boost/pinhole/property_group.hpp 2009-09-02 12:16:18 EDT (Wed, 02 Sep 2009)
@@ -477,10 +477,9 @@
}
/**
- * Gets a property's Editor object.
+ * Gets a property's metadata object.
* @param property The name of the property.
- * @return The Editor of the property.
- * @throw no_metadata_defined_error There isn't a property editor associated with this property.
+ * @return The metadata object of the property.
* @throw std::out_of_range The property requested does not exist.
*/
const boost::any& get_metadata(const std::string &property) const
@@ -616,7 +615,26 @@
<< ::boost::pinhole::exception_action_name(action);
}
}
-
+
+ /**
+ * Gets an anction's metadata object.
+ * @param property The name of the property.
+ * @return The metadata object of the property.
+ * @throw std::out_of_range The property requested does not exist.
+ */
+ const boost::any& get_action_metadata(const std::string &action) const
+ {
+ action_collection::const_iterator itemItr = m_actions.find(action);
+
+ if( itemItr != m_actions.end() )
+ {
+ return( (*itemItr).second->m_metadata );
+ }
+ else
+ {
+ throw ::boost::enable_error_info(std::out_of_range("The requested action does not exist.")) << ::boost::pinhole::exception_action_name(action);
+ }
+ }
//@}
/**
@@ -689,12 +707,14 @@
* @param action The function used to trigger the action.
*/
void add_action( std::string name,
- boost::function<void ()> action )
+ boost::function<void ()> action,
+ boost::any metadata = boost::any() )
{
detail::action_info *action_info = new detail::action_info();
action_info->m_name = name;
action_info->m_action = action;
+ action_info->m_metadata = metadata;
action_collection::iterator previousInstance = m_actions.find(name);
if( m_actions.end() != previousInstance )
Modified: sandbox/pinhole/libs/pinhole/test/test_actions.cpp
==============================================================================
--- sandbox/pinhole/libs/pinhole/test/test_actions.cpp (original)
+++ sandbox/pinhole/libs/pinhole/test/test_actions.cpp 2009-09-02 12:16:18 EDT (Wed, 02 Sep 2009)
@@ -33,7 +33,7 @@
bTriggeredAction2 = false;
add_action(ACTION_1, BOOST_ACTION(&TestActionsFixture::Action1));
- add_action(ACTION_2, BOOST_ACTION(&TestActionsFixture::Action2));
+ add_action(ACTION_2, BOOST_ACTION(&TestActionsFixture::Action2), string("some info"));
}
#if defined(BOOST_MSVC)
#pragma warning(pop)
@@ -69,6 +69,7 @@
TestActionsFixture testFixture;
BOOST_CHECK_THROW( testFixture.trigger("NonExistent Action"), std::out_of_range );
+ BOOST_CHECK_THROW( testFixture.get_action_metadata( "NonExistent Action" ), std::out_of_range );
}
BOOST_AUTO_TEST_CASE( TestGetActionCollection )
@@ -84,4 +85,11 @@
BOOST_CHECK_EQUAL( *itr, ACTION_2 );
++itr;
BOOST_CHECK( itr == itrEnd );
+}
+
+BOOST_AUTO_TEST_CASE( TestActionMetadata )
+{
+ TestActionsFixture testFixture;
+
+ BOOST_CHECK_EQUAL( any_cast<string>(testFixture.get_action_metadata(ACTION_2)), string("some info") );
}
\ No newline at end of file
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk