|
Boost-Commit : |
From: jmcintyre_at_[hidden]
Date: 2008-01-04 15:00:41
Author: jared
Date: 2008-01-04 15:00:40 EST (Fri, 04 Jan 2008)
New Revision: 42460
URL: http://svn.boost.org/trac/boost/changeset/42460
Log:
a little closer to removing the singleton
Text files modified:
sandbox/pinhole/boost/pinhole/property_group.hpp | 53 +++++++++++++++++++++++++--------------
sandbox/pinhole/boost/pinhole/property_manager.hpp | 13 ++++++---
sandbox/pinhole/libs/pinhole/test/test_property_groups.cpp | 2
3 files changed, 43 insertions(+), 25 deletions(-)
Modified: sandbox/pinhole/boost/pinhole/property_group.hpp
==============================================================================
--- sandbox/pinhole/boost/pinhole/property_group.hpp (original)
+++ sandbox/pinhole/boost/pinhole/property_group.hpp 2008-01-04 15:00:40 EST (Fri, 04 Jan 2008)
@@ -113,14 +113,13 @@
m_name( name ),
m_parent( parent )
{
- setup_parent_and_category_and_manager();
+ setup_parent_and_category_and_manager();
}
- explicit property_group( const property_group& old_property_group )
+ explicit property_group( const property_group& old_property_group ) :
+ m_name( old_property_group.m_name ),
+ m_parent( old_property_group.m_parent )
{
- m_name = old_property_group.m_name;
- m_parent = old_property_group.m_parent;
-
setup_parent_and_category_and_manager();
}
@@ -143,10 +142,10 @@
m_parent->remove_child(this);
}
- if ( property_manager::instance() != NULL )
+ if ( m_manager != NULL )
{
// Unregister this group with this property manager...
- property_manager::instance()->unregister_property_group( this, m_category_collection );
+ m_manager->unregister_property_group( this, m_category_collection );
}
// cleanup all the property_manager classes
@@ -186,10 +185,11 @@
*/
void set_parent(property_group* new_parent)
{
- if( NULL != property_manager::instance() )
+ if( m_manager )
{
// Register this group with this property manager...
- property_manager::instance()->unregister_property_group(this, m_category_collection);
+ m_manager->unregister_property_group(this, m_category_collection);
+ m_manager.reset();
}
if ( NULL != m_parent )
@@ -203,12 +203,21 @@
if ( NULL != m_parent )
{
m_parent->add_child(this);
+
+ if( new_parent->m_manager )
+ {
+ m_manager = new_parent->m_manager;
+ }
}
-
- if( NULL != property_manager::instance() )
+ else
+ {
+ m_manager = property_manager::instance();
+ }
+
+ if( m_manager )
{
// Register this group with this property manager...
- property_manager::instance()->register_property_group(this);
+ m_manager->register_property_group(this);
}
}
@@ -699,9 +708,9 @@
m_category_collection.insert( category_name );
// notify the Property Manager of this new category
- if ( property_manager::instance() != NULL )
+ if ( m_manager )
{
- property_manager::instance()->add_category( category_name, this );
+ m_manager->add_category( category_name, this );
}
}
@@ -775,19 +784,25 @@
if ( NULL != m_parent )
{
m_parent->add_child(this);
+ m_manager = m_parent->m_manager;
}
-
- add_category( "All" );
-
- if ( property_manager::instance() != NULL )
+ else
+ {
+ m_manager = property_manager::instance();
+ }
+
+ if ( m_manager != NULL )
{
// Register this group with this property manager...
- property_manager::instance()->register_property_group( this );
+ m_manager->register_property_group( this );
}
+
+ add_category( "All" );
}
std::string m_name;
property_group *m_parent;
+ property_manager::instance_type m_manager;
};
}}
Modified: sandbox/pinhole/boost/pinhole/property_manager.hpp
==============================================================================
--- sandbox/pinhole/boost/pinhole/property_manager.hpp (original)
+++ sandbox/pinhole/boost/pinhole/property_manager.hpp 2008-01-04 15:00:40 EST (Fri, 04 Jan 2008)
@@ -71,6 +71,9 @@
class BOOST_PINHOLE_DECL property_manager
{
+ public:
+ typedef boost::shared_ptr<property_manager> instance_type;
+
private:
static void deleter(property_manager* manager)
{
@@ -82,24 +85,24 @@
typedef map_value_iterator<category_to_property_group_map::iterator> iterator;
typedef map_value_iterator<category_to_property_group_map::const_iterator> const_iterator;
- static property_manager* instance()
+ static instance_type instance()
{
- if ( m_instance.get() == NULL ) // is it the first call?
+ if ( !m_instance ) // is it the first call?
{
m_instance.reset( new property_manager, property_manager::deleter ); // create sole instance
}
- return m_instance.get(); // address of sole instance
+ return m_instance; // address of sole instance
}
static bool exists()
{
- return m_instance.get() != NULL;
+ return m_instance;
}
static void delete_instance()
{
- if( m_instance.get() != NULL )
+ if( m_instance )
{
m_instance.reset();
}
Modified: sandbox/pinhole/libs/pinhole/test/test_property_groups.cpp
==============================================================================
--- sandbox/pinhole/libs/pinhole/test/test_property_groups.cpp (original)
+++ sandbox/pinhole/libs/pinhole/test/test_property_groups.cpp 2008-01-04 15:00:40 EST (Fri, 04 Jan 2008)
@@ -261,7 +261,7 @@
TestPropertyManagerGuard gaurd;
TestPropertyManager *p_manager = gaurd.p_manager;
- BOOST_CHECK( property_manager::instance() == p_manager );
+ BOOST_CHECK( property_manager::instance().get() == p_manager );
}
BOOST_AUTO_TEST_CASE( TestSetParent )
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