|
Boost-Commit : |
From: sixtrillion_at_[hidden]
Date: 2007-05-29 22:04:20
Author: sixtrillion
Date: 2007-05-29 22:04:18 EDT (Tue, 29 May 2007)
New Revision: 4359
URL: http://svn.boost.org/trac/boost/changeset/4359
Log:
The registry class is functional. There is a failing unit test having to do with closing libraries that are no longer needed. This appears to be an OS feature - it doesn't close a library immediately when you call dlclose, in case it is reopened soon thereafter. This will take more investigation.
Added:
sandbox/libs/extension/examples/registry/
sandbox/libs/extension/examples/registry/registry_example.cpp
sandbox/libs/extension/examples/registry/registry_library.cpp
Text files modified:
sandbox/boost/extension/counted_factory.hpp | 189 +++++++++++++++++++++++++++++----------
sandbox/boost/extension/counted_factory_map.hpp | 40 ++++---
sandbox/boost/extension/factory.hpp | 14 +-
sandbox/boost/extension/factory_map.hpp | 2
sandbox/boost/extension/registry.hpp | 34 +++++-
sandbox/boost/extension/shared_library.hpp | 16 +-
sandbox/libs/extension/examples/Jamfile.v2 | 18 +-
sandbox/libs/extension/scripts/GenerateHeaders.py | 66 ++++++++-----
sandbox/libs/extension/test/registry_test.cpp | 36 ++++++
9 files changed, 289 insertions(+), 126 deletions(-)
Modified: sandbox/boost/extension/counted_factory.hpp
==============================================================================
--- sandbox/boost/extension/counted_factory.hpp (original)
+++ sandbox/boost/extension/counted_factory.hpp 2007-05-29 22:04:18 EDT (Tue, 29 May 2007)
@@ -10,14 +10,14 @@
template <class Interface, class Info, class Param1 = void, class Param2 = void, class Param3 = void, class Param4 = void, class Param5 = void, class Param6 = void>
class counted_factory
{
-private:
+protected:
int * counter_;
std::string library_;
class generic_factory_function
{
public:
virtual ~generic_factory_function(){}
- virtual Interface * operator()(Param1, Param2, Param3, Param4, Param5, Param6) = 0;
+ virtual Interface * operator()(int * counter, Param1, Param2, Param3, Param4, Param5, Param6) = 0;
virtual generic_factory_function * copy() const = 0;
};
template <class T>
@@ -42,12 +42,23 @@
virtual ~factory_function(){}
virtual Interface * operator()
(int * counter, Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6)
- {return new counted_object(counter_, p1, p2, p3, p4, p5, p6);}
+ { // A compilation error here usually indicates that the
+ // class you are adding is not derived from the base class
+ // that you indicated.
+ return static_cast<Interface*>(new counted_object(counter, p1, p2, p3, p4, p5, p6));}
virtual generic_factory_function * copy() const {return new factory_function<T>;}
};
std::auto_ptr<generic_factory_function> factory_func_ptr_;
Info info_;
public:
+ void set_library(const char * library_name)
+ {
+ library_ = library_name;
+ }
+ void set_counter(int * counter)
+ {
+ counter_ = counter;
+ }
const char * library()
{
return library_.c_str();
@@ -61,26 +72,28 @@
info_(info)
{}
counted_factory(const counted_factory & first)
- :factory_func_ptr_(first.factory_func_ptr_->copy()),
+ :counter_(first.counter_),
+ library_(first.library_),
+ factory_func_ptr_(first.factory_func_ptr_->copy()),
info_(first.info_)
{}
- Interface * operator()(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6)
- {return create(p1, p2, p3, p4, p5, p6);}
+ Interface * operator()(int * counter, Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6)
+ {return create(counter, p1, p2, p3, p4, p5, p6);}
Interface * create(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6){return (*factory_func_ptr_)
- (p1, p2, p3, p4, p5, p6);}
+ (counter_, p1, p2, p3, p4, p5, p6);}
Info & get_info(){return info_;}
};
template <class Interface, class Info, class Param1, class Param2, class Param3, class Param4, class Param5>
class counted_factory<Interface, Info, Param1, Param2, Param3, Param4, Param5>
{
-private:
+protected:
int * counter_;
std::string library_;
class generic_factory_function
{
public:
virtual ~generic_factory_function(){}
- virtual Interface * operator()(Param1, Param2, Param3, Param4, Param5) = 0;
+ virtual Interface * operator()(int * counter, Param1, Param2, Param3, Param4, Param5) = 0;
virtual generic_factory_function * copy() const = 0;
};
template <class T>
@@ -105,12 +118,23 @@
virtual ~factory_function(){}
virtual Interface * operator()
(int * counter, Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5)
- {return new counted_object(counter_, p1, p2, p3, p4, p5);}
+ { // A compilation error here usually indicates that the
+ // class you are adding is not derived from the base class
+ // that you indicated.
+ return static_cast<Interface*>(new counted_object(counter, p1, p2, p3, p4, p5));}
virtual generic_factory_function * copy() const {return new factory_function<T>;}
};
std::auto_ptr<generic_factory_function> factory_func_ptr_;
Info info_;
public:
+ void set_library(const char * library_name)
+ {
+ library_ = library_name;
+ }
+ void set_counter(int * counter)
+ {
+ counter_ = counter;
+ }
const char * library()
{
return library_.c_str();
@@ -124,26 +148,28 @@
info_(info)
{}
counted_factory(const counted_factory & first)
- :factory_func_ptr_(first.factory_func_ptr_->copy()),
+ :counter_(first.counter_),
+ library_(first.library_),
+ factory_func_ptr_(first.factory_func_ptr_->copy()),
info_(first.info_)
{}
- Interface * operator()(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5)
- {return create(p1, p2, p3, p4, p5);}
+ Interface * operator()(int * counter, Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5)
+ {return create(counter, p1, p2, p3, p4, p5);}
Interface * create(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5){return (*factory_func_ptr_)
- (p1, p2, p3, p4, p5);}
+ (counter_, p1, p2, p3, p4, p5);}
Info & get_info(){return info_;}
};
template <class Interface, class Info, class Param1, class Param2, class Param3, class Param4>
class counted_factory<Interface, Info, Param1, Param2, Param3, Param4>
{
-private:
+protected:
int * counter_;
std::string library_;
class generic_factory_function
{
public:
virtual ~generic_factory_function(){}
- virtual Interface * operator()(Param1, Param2, Param3, Param4) = 0;
+ virtual Interface * operator()(int * counter, Param1, Param2, Param3, Param4) = 0;
virtual generic_factory_function * copy() const = 0;
};
template <class T>
@@ -168,12 +194,23 @@
virtual ~factory_function(){}
virtual Interface * operator()
(int * counter, Param1 p1, Param2 p2, Param3 p3, Param4 p4)
- {return new counted_object(counter_, p1, p2, p3, p4);}
+ { // A compilation error here usually indicates that the
+ // class you are adding is not derived from the base class
+ // that you indicated.
+ return static_cast<Interface*>(new counted_object(counter, p1, p2, p3, p4));}
virtual generic_factory_function * copy() const {return new factory_function<T>;}
};
std::auto_ptr<generic_factory_function> factory_func_ptr_;
Info info_;
public:
+ void set_library(const char * library_name)
+ {
+ library_ = library_name;
+ }
+ void set_counter(int * counter)
+ {
+ counter_ = counter;
+ }
const char * library()
{
return library_.c_str();
@@ -187,26 +224,28 @@
info_(info)
{}
counted_factory(const counted_factory & first)
- :factory_func_ptr_(first.factory_func_ptr_->copy()),
+ :counter_(first.counter_),
+ library_(first.library_),
+ factory_func_ptr_(first.factory_func_ptr_->copy()),
info_(first.info_)
{}
- Interface * operator()(Param1 p1, Param2 p2, Param3 p3, Param4 p4)
- {return create(p1, p2, p3, p4);}
+ Interface * operator()(int * counter, Param1 p1, Param2 p2, Param3 p3, Param4 p4)
+ {return create(counter, p1, p2, p3, p4);}
Interface * create(Param1 p1, Param2 p2, Param3 p3, Param4 p4){return (*factory_func_ptr_)
- (p1, p2, p3, p4);}
+ (counter_, p1, p2, p3, p4);}
Info & get_info(){return info_;}
};
template <class Interface, class Info, class Param1, class Param2, class Param3>
class counted_factory<Interface, Info, Param1, Param2, Param3>
{
-private:
+protected:
int * counter_;
std::string library_;
class generic_factory_function
{
public:
virtual ~generic_factory_function(){}
- virtual Interface * operator()(Param1, Param2, Param3) = 0;
+ virtual Interface * operator()(int * counter, Param1, Param2, Param3) = 0;
virtual generic_factory_function * copy() const = 0;
};
template <class T>
@@ -231,12 +270,23 @@
virtual ~factory_function(){}
virtual Interface * operator()
(int * counter, Param1 p1, Param2 p2, Param3 p3)
- {return new counted_object(counter_, p1, p2, p3);}
+ { // A compilation error here usually indicates that the
+ // class you are adding is not derived from the base class
+ // that you indicated.
+ return static_cast<Interface*>(new counted_object(counter, p1, p2, p3));}
virtual generic_factory_function * copy() const {return new factory_function<T>;}
};
std::auto_ptr<generic_factory_function> factory_func_ptr_;
Info info_;
public:
+ void set_library(const char * library_name)
+ {
+ library_ = library_name;
+ }
+ void set_counter(int * counter)
+ {
+ counter_ = counter;
+ }
const char * library()
{
return library_.c_str();
@@ -250,26 +300,28 @@
info_(info)
{}
counted_factory(const counted_factory & first)
- :factory_func_ptr_(first.factory_func_ptr_->copy()),
+ :counter_(first.counter_),
+ library_(first.library_),
+ factory_func_ptr_(first.factory_func_ptr_->copy()),
info_(first.info_)
{}
- Interface * operator()(Param1 p1, Param2 p2, Param3 p3)
- {return create(p1, p2, p3);}
+ Interface * operator()(int * counter, Param1 p1, Param2 p2, Param3 p3)
+ {return create(counter, p1, p2, p3);}
Interface * create(Param1 p1, Param2 p2, Param3 p3){return (*factory_func_ptr_)
- (p1, p2, p3);}
+ (counter_, p1, p2, p3);}
Info & get_info(){return info_;}
};
template <class Interface, class Info, class Param1, class Param2>
class counted_factory<Interface, Info, Param1, Param2>
{
-private:
+protected:
int * counter_;
std::string library_;
class generic_factory_function
{
public:
virtual ~generic_factory_function(){}
- virtual Interface * operator()(Param1, Param2) = 0;
+ virtual Interface * operator()(int * counter, Param1, Param2) = 0;
virtual generic_factory_function * copy() const = 0;
};
template <class T>
@@ -294,12 +346,23 @@
virtual ~factory_function(){}
virtual Interface * operator()
(int * counter, Param1 p1, Param2 p2)
- {return new counted_object(counter_, p1, p2);}
+ { // A compilation error here usually indicates that the
+ // class you are adding is not derived from the base class
+ // that you indicated.
+ return static_cast<Interface*>(new counted_object(counter, p1, p2));}
virtual generic_factory_function * copy() const {return new factory_function<T>;}
};
std::auto_ptr<generic_factory_function> factory_func_ptr_;
Info info_;
public:
+ void set_library(const char * library_name)
+ {
+ library_ = library_name;
+ }
+ void set_counter(int * counter)
+ {
+ counter_ = counter;
+ }
const char * library()
{
return library_.c_str();
@@ -313,26 +376,28 @@
info_(info)
{}
counted_factory(const counted_factory & first)
- :factory_func_ptr_(first.factory_func_ptr_->copy()),
+ :counter_(first.counter_),
+ library_(first.library_),
+ factory_func_ptr_(first.factory_func_ptr_->copy()),
info_(first.info_)
{}
- Interface * operator()(Param1 p1, Param2 p2)
- {return create(p1, p2);}
+ Interface * operator()(int * counter, Param1 p1, Param2 p2)
+ {return create(counter, p1, p2);}
Interface * create(Param1 p1, Param2 p2){return (*factory_func_ptr_)
- (p1, p2);}
+ (counter_, p1, p2);}
Info & get_info(){return info_;}
};
template <class Interface, class Info, class Param1>
class counted_factory<Interface, Info, Param1>
{
-private:
+protected:
int * counter_;
std::string library_;
class generic_factory_function
{
public:
virtual ~generic_factory_function(){}
- virtual Interface * operator()(Param1) = 0;
+ virtual Interface * operator()(int * counter, Param1) = 0;
virtual generic_factory_function * copy() const = 0;
};
template <class T>
@@ -357,12 +422,23 @@
virtual ~factory_function(){}
virtual Interface * operator()
(int * counter, Param1 p1)
- {return new counted_object(counter_, p1);}
+ { // A compilation error here usually indicates that the
+ // class you are adding is not derived from the base class
+ // that you indicated.
+ return static_cast<Interface*>(new counted_object(counter, p1));}
virtual generic_factory_function * copy() const {return new factory_function<T>;}
};
std::auto_ptr<generic_factory_function> factory_func_ptr_;
Info info_;
public:
+ void set_library(const char * library_name)
+ {
+ library_ = library_name;
+ }
+ void set_counter(int * counter)
+ {
+ counter_ = counter;
+ }
const char * library()
{
return library_.c_str();
@@ -376,26 +452,28 @@
info_(info)
{}
counted_factory(const counted_factory & first)
- :factory_func_ptr_(first.factory_func_ptr_->copy()),
+ :counter_(first.counter_),
+ library_(first.library_),
+ factory_func_ptr_(first.factory_func_ptr_->copy()),
info_(first.info_)
{}
- Interface * operator()(Param1 p1)
- {return create(p1);}
+ Interface * operator()(int * counter, Param1 p1)
+ {return create(counter, p1);}
Interface * create(Param1 p1){return (*factory_func_ptr_)
- (p1);}
+ (counter_, p1);}
Info & get_info(){return info_;}
};
template <class Interface, class Info>
class counted_factory<Interface, Info>
{
-private:
+protected:
int * counter_;
std::string library_;
class generic_factory_function
{
public:
virtual ~generic_factory_function(){}
- virtual Interface * operator()() = 0;
+ virtual Interface * operator()(int * counter) = 0;
virtual generic_factory_function * copy() const = 0;
};
template <class T>
@@ -420,12 +498,23 @@
virtual ~factory_function(){}
virtual Interface * operator()
(int * counter)
- {return new counted_object(counter_);}
+ { // A compilation error here usually indicates that the
+ // class you are adding is not derived from the base class
+ // that you indicated.
+ return static_cast<Interface*>(new counted_object(counter));}
virtual generic_factory_function * copy() const {return new factory_function<T>;}
};
std::auto_ptr<generic_factory_function> factory_func_ptr_;
Info info_;
public:
+ void set_library(const char * library_name)
+ {
+ library_ = library_name;
+ }
+ void set_counter(int * counter)
+ {
+ counter_ = counter;
+ }
const char * library()
{
return library_.c_str();
@@ -439,13 +528,15 @@
info_(info)
{}
counted_factory(const counted_factory & first)
- :factory_func_ptr_(first.factory_func_ptr_->copy()),
+ :counter_(first.counter_),
+ library_(first.library_),
+ factory_func_ptr_(first.factory_func_ptr_->copy()),
info_(first.info_)
{}
- Interface * operator()()
- {return create();}
+ Interface * operator()(int * counter)
+ {return create(counter);}
Interface * create(){return (*factory_func_ptr_)
- ();}
+ (counter_);}
Info & get_info(){return info_;}
};
}}
Modified: sandbox/boost/extension/counted_factory_map.hpp
==============================================================================
--- sandbox/boost/extension/counted_factory_map.hpp (original)
+++ sandbox/boost/extension/counted_factory_map.hpp 2007-05-29 22:04:18 EDT (Tue, 29 May 2007)
@@ -23,19 +23,21 @@
class generic_factory_container
{
public:
- virtual bool erase(const char * library_name) = 0;
+ virtual bool remove_library(const char * library_name) = 0;
virtual ~generic_factory_container(){}
};
template <class Interface, class Info, class Param1 = void, class Param2 = void, class Param3 = void, class Param4 = void, class Param5 = void, class Param6 = void>
class factory_container : public std::list<counted_factory<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> >, public generic_factory_container
{
public:
- virtual bool erase(const char * library_name)
+ virtual bool remove_library(const char * library_name)
{
- for (typename std::list<counted_factory<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> >::iterator it = this->begin(); it != this->end(); ++it)
+ for (typename std::list<counted_factory<Interface, Info, Param1, Param2, Param3,
+ Param4, Param5, Param6> >::iterator it = this->begin();
+ it != this->end(); ++it)
{
if (strcmp(it->library(), library_name) == 0)
- erase(it);
+ this->erase(it);
}
return this->size() == 0;
}
@@ -47,8 +49,10 @@
typedef std::map<TypeInfo, generic_factory_container *> FactoryMap;
FactoryMap factories_;
std::string current_library_;
+ int default_counter_;
int * current_counter_;
public:
+ basic_counted_factory_map() : default_counter_(0), current_counter_(&default_counter_){}
~basic_counted_factory_map(){
for(typename FactoryMap::iterator it = factories_.begin(); it != factories_.end(); ++it)
delete it->second;
@@ -84,11 +88,11 @@
typedef std::list<counted_factory<Interface, Info> > ListType;
ListType & s = this->get<Interface, Info>();
counted_factory<Interface, Info> f(info);
+ f.set_library(current_library_.c_str());
+ f.set_counter(current_counter_);
//f.set_type<Actual>();
f.set_type_special((Actual*)0);
s.push_back(f);
- f.set_library(current_library_);
- f.set_counter(current_counter_);
//it->set_type<Actual>();
}
template <class Interface, class Info, class Param1>
@@ -121,11 +125,11 @@
typedef std::list<counted_factory<Interface, Info, Param1> > ListType;
ListType & s = this->get<Interface, Info, Param1>();
counted_factory<Interface, Info, Param1> f(info);
+ f.set_library(current_library_.c_str());
+ f.set_counter(current_counter_);
//f.set_type<Actual>();
f.set_type_special((Actual*)0);
s.push_back(f);
- f.set_library(current_library_);
- f.set_counter(current_counter_);
//it->set_type<Actual>();
}
template <class Interface, class Info, class Param1, class Param2>
@@ -158,11 +162,11 @@
typedef std::list<counted_factory<Interface, Info, Param1, Param2> > ListType;
ListType & s = this->get<Interface, Info, Param1, Param2>();
counted_factory<Interface, Info, Param1, Param2> f(info);
+ f.set_library(current_library_.c_str());
+ f.set_counter(current_counter_);
//f.set_type<Actual>();
f.set_type_special((Actual*)0);
s.push_back(f);
- f.set_library(current_library_);
- f.set_counter(current_counter_);
//it->set_type<Actual>();
}
template <class Interface, class Info, class Param1, class Param2, class Param3>
@@ -195,11 +199,11 @@
typedef std::list<counted_factory<Interface, Info, Param1, Param2, Param3> > ListType;
ListType & s = this->get<Interface, Info, Param1, Param2, Param3>();
counted_factory<Interface, Info, Param1, Param2, Param3> f(info);
+ f.set_library(current_library_.c_str());
+ f.set_counter(current_counter_);
//f.set_type<Actual>();
f.set_type_special((Actual*)0);
s.push_back(f);
- f.set_library(current_library_);
- f.set_counter(current_counter_);
//it->set_type<Actual>();
}
template <class Interface, class Info, class Param1, class Param2, class Param3, class Param4>
@@ -232,11 +236,11 @@
typedef std::list<counted_factory<Interface, Info, Param1, Param2, Param3, Param4> > ListType;
ListType & s = this->get<Interface, Info, Param1, Param2, Param3, Param4>();
counted_factory<Interface, Info, Param1, Param2, Param3, Param4> f(info);
+ f.set_library(current_library_.c_str());
+ f.set_counter(current_counter_);
//f.set_type<Actual>();
f.set_type_special((Actual*)0);
s.push_back(f);
- f.set_library(current_library_);
- f.set_counter(current_counter_);
//it->set_type<Actual>();
}
template <class Interface, class Info, class Param1, class Param2, class Param3, class Param4, class Param5>
@@ -269,11 +273,11 @@
typedef std::list<counted_factory<Interface, Info, Param1, Param2, Param3, Param4, Param5> > ListType;
ListType & s = this->get<Interface, Info, Param1, Param2, Param3, Param4, Param5>();
counted_factory<Interface, Info, Param1, Param2, Param3, Param4, Param5> f(info);
+ f.set_library(current_library_.c_str());
+ f.set_counter(current_counter_);
//f.set_type<Actual>();
f.set_type_special((Actual*)0);
s.push_back(f);
- f.set_library(current_library_);
- f.set_counter(current_counter_);
//it->set_type<Actual>();
}
template <class Interface, class Info, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
@@ -306,11 +310,11 @@
typedef std::list<counted_factory<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> > ListType;
ListType & s = this->get<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6>();
counted_factory<Interface, Info, Param1, Param2, Param3, Param4, Param5, Param6> f(info);
+ f.set_library(current_library_.c_str());
+ f.set_counter(current_counter_);
//f.set_type<Actual>();
f.set_type_special((Actual*)0);
s.push_back(f);
- f.set_library(current_library_);
- f.set_counter(current_counter_);
//it->set_type<Actual>();
}
};
Modified: sandbox/boost/extension/factory.hpp
==============================================================================
--- sandbox/boost/extension/factory.hpp (original)
+++ sandbox/boost/extension/factory.hpp 2007-05-29 22:04:18 EDT (Tue, 29 May 2007)
@@ -10,7 +10,7 @@
template <class Interface, class Info, class Param1 = void, class Param2 = void, class Param3 = void, class Param4 = void, class Param5 = void, class Param6 = void>
class factory
{
-private:
+protected:
class generic_factory_function
{
public:
@@ -52,7 +52,7 @@
template <class Interface, class Info, class Param1, class Param2, class Param3, class Param4, class Param5>
class factory<Interface, Info, Param1, Param2, Param3, Param4, Param5>
{
-private:
+protected:
class generic_factory_function
{
public:
@@ -94,7 +94,7 @@
template <class Interface, class Info, class Param1, class Param2, class Param3, class Param4>
class factory<Interface, Info, Param1, Param2, Param3, Param4>
{
-private:
+protected:
class generic_factory_function
{
public:
@@ -136,7 +136,7 @@
template <class Interface, class Info, class Param1, class Param2, class Param3>
class factory<Interface, Info, Param1, Param2, Param3>
{
-private:
+protected:
class generic_factory_function
{
public:
@@ -178,7 +178,7 @@
template <class Interface, class Info, class Param1, class Param2>
class factory<Interface, Info, Param1, Param2>
{
-private:
+protected:
class generic_factory_function
{
public:
@@ -220,7 +220,7 @@
template <class Interface, class Info, class Param1>
class factory<Interface, Info, Param1>
{
-private:
+protected:
class generic_factory_function
{
public:
@@ -262,7 +262,7 @@
template <class Interface, class Info>
class factory<Interface, Info>
{
-private:
+protected:
class generic_factory_function
{
public:
Modified: sandbox/boost/extension/factory_map.hpp
==============================================================================
--- sandbox/boost/extension/factory_map.hpp (original)
+++ sandbox/boost/extension/factory_map.hpp 2007-05-29 22:04:18 EDT (Tue, 29 May 2007)
@@ -19,7 +19,7 @@
template <class TypeInfo>
class basic_factory_map
{
-private:
+protected:
class generic_factory_container
{
public:
Modified: sandbox/boost/extension/registry.hpp
==============================================================================
--- sandbox/boost/extension/registry.hpp (original)
+++ sandbox/boost/extension/registry.hpp 2007-05-29 22:04:18 EDT (Tue, 29 May 2007)
@@ -25,20 +25,42 @@
it->second.first.close();
}
}
+ bool clear() {
+ bool ret_val = false;
+ for (library_iterator it = libraries_.begin(); it != libraries_.end();)
+ {
+ if (!it->second.second) {
+ ret_val = true;
+ close((it++)->first.c_str());
+ }
+ else
+ {
+ ++it;
+ }
+ }
+ return ret_val;
+ }
bool open(const char * library_location, const char * function_name =
- "boost_extension_load_function") {
+ "boost_extension_registry_function") {
library_iterator it = libraries_.find(library_location);
if (it == libraries_.end()) {
it = libraries_.insert(std::make_pair(std::string(library_location),
- std::make_pair(shared_library(library_location, false), int(0)))).first;
+ std::make_pair(shared_library(library_location, false), int(0)))).first;
this->current_library_ = library_location;
- basic_counted_factory_map<TypeInfo>::current_counter_ = &it->second.second;
+ this->current_counter_ = &it->second.second;
it->second.first.open();
if (it->second.first.is_open() == false) {
libraries_.erase(it);
return false;
}
- return true;
+ functor<void, counted_factory_map &> load_func =
+ it->second.first.get_functor<void, counted_factory_map &>(function_name);
+ if (load_func.is_valid())
+ {
+ load_func(*this);
+ return true;
+ }
+ return false;
}
return false;
}
@@ -47,11 +69,11 @@
library_iterator it = libraries_.find(library_location);
if (it == libraries_.end())
return false;
- it->second.first.close();
for (typename basic_counted_factory_map<TypeInfo>::FactoryMap::iterator it = this->factories_.begin();
it != this->factories_.end(); ++it) {
- it->second->erase(library_location);
+ it->second->remove_library(library_location);
}
+ it->second.first.close();
libraries_.erase(it);
return true;
}
Modified: sandbox/boost/extension/shared_library.hpp
==============================================================================
--- sandbox/boost/extension/shared_library.hpp (original)
+++ sandbox/boost/extension/shared_library.hpp 2007-05-29 22:04:18 EDT (Tue, 29 May 2007)
@@ -13,7 +13,7 @@
template <class ReturnValue, class Param1 = void, class Param2 = void, class Param3 = void, class Param4 = void, class Param5 = void, class Param6 = void>
class functor
{
-private:
+protected:
typedef ReturnValue (*FunctionType)(Param1, Param2, Param3, Param4, Param5, Param6);
FunctionType func_;
public:
@@ -33,7 +33,7 @@
template <class ReturnValue, class Param1, class Param2, class Param3, class Param4, class Param5>
class functor<ReturnValue, Param1, Param2, Param3, Param4, Param5>
{
-private:
+protected:
typedef ReturnValue (*FunctionType)(Param1, Param2, Param3, Param4, Param5);
FunctionType func_;
public:
@@ -53,7 +53,7 @@
template <class ReturnValue, class Param1, class Param2, class Param3, class Param4>
class functor<ReturnValue, Param1, Param2, Param3, Param4>
{
-private:
+protected:
typedef ReturnValue (*FunctionType)(Param1, Param2, Param3, Param4);
FunctionType func_;
public:
@@ -73,7 +73,7 @@
template <class ReturnValue, class Param1, class Param2, class Param3>
class functor<ReturnValue, Param1, Param2, Param3>
{
-private:
+protected:
typedef ReturnValue (*FunctionType)(Param1, Param2, Param3);
FunctionType func_;
public:
@@ -93,7 +93,7 @@
template <class ReturnValue, class Param1, class Param2>
class functor<ReturnValue, Param1, Param2>
{
-private:
+protected:
typedef ReturnValue (*FunctionType)(Param1, Param2);
FunctionType func_;
public:
@@ -113,7 +113,7 @@
template <class ReturnValue, class Param1>
class functor<ReturnValue, Param1>
{
-private:
+protected:
typedef ReturnValue (*FunctionType)(Param1);
FunctionType func_;
public:
@@ -133,7 +133,7 @@
template <class ReturnValue>
class functor<ReturnValue>
{
-private:
+protected:
typedef ReturnValue (*FunctionType)();
FunctionType func_;
public:
@@ -152,7 +152,7 @@
class shared_library
{
-private:
+protected:
std::string location_;
library_handle handle_;
bool auto_close_;
Modified: sandbox/libs/extension/examples/Jamfile.v2
==============================================================================
--- sandbox/libs/extension/examples/Jamfile.v2 (original)
+++ sandbox/libs/extension/examples/Jamfile.v2 2007-05-29 22:04:18 EDT (Tue, 29 May 2007)
@@ -30,17 +30,17 @@
<link>shared
;
exe MultipleInheritance : multiple_inheritance/main_mi.cpp Computer Vehicle ;
-stage ../stage :
- HelloWorld HelloWorldLib Vehicle Car
- Plane Boat Computer FlyingCar
- CarOfTheFuture MultipleInheritance ;
+
+lib RegistryLibrary : registry/registry_library.cpp : <link>shared ;
+exe RegistryExample : registry/registry_example.cpp ;
install ../bin :
HelloWorld HelloWorldLib Vehicle Boat FlyingCar
- CarOfTheFuture MultipleInheritance
+ CarOfTheFuture MultipleInheritance RegistryLibrary
+ RegistryExample
:
- <install-dependencies>on
- <install-type>EXE
- <install-type>SHARED_LIB
- <install-type>LIB
+ # <install-dependencies>on
+ # <install-type>EXE
+ # <install-type>SHARED_LIB
+ # <install-type>LIB
;
Added: sandbox/libs/extension/examples/registry/registry_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/examples/registry/registry_example.cpp 2007-05-29 22:04:18 EDT (Tue, 29 May 2007)
@@ -0,0 +1,68 @@
+/* (C) Copyright Jeremy Pack 2007
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ */
+#include "../word.hpp"
+#include <boost/extension/registry.hpp>
+#include <iostream>
+using namespace boost::extensions;
+
+int main(int argc, char * argv[])
+{
+ registry reg;
+ reg.open("../bin/libRegistryLibrary.extension");
+ {
+ std::list<counted_factory<word, int> > & factory_list = reg.get<word, int>();
+ if (factory_list.size() != 1) {
+ std::cout << "Expected to see one class available - found: "
+ << factory_list.size() << std::endl;
+ return -1;
+ }
+ {
+ std::auto_ptr<word> w(factory_list.begin()->create());
+ const char * value;
+ if (strcmp(value = w->get_val(), "First Time") != 0)
+ {
+ std::cout << "The string's value should have been \"First Time\" but was: "
+ << value << std::endl;
+ return -1;
+ }
+ if (strcmp(value = w->get_val(), "Second Time") != 0)
+ {
+ std::cout << "The string's value should have been \"Second Time\" but was: "
+ << value << std::endl;
+ return -1;
+ }
+ }
+ }
+ reg.clear(); // This closes libregistry_library.extension, since none of its
+ // classes are instantiated any more.
+ // Now we can repeat the above - with the same results.
+ {
+ reg.open("../bin/libRegistryLibrary.extension");
+ std::list<counted_factory<word, int> > & factory_list = reg.get<word, int>();
+ if (factory_list.size() != 1)
+ {
+ std::cout << "Expected to see one class available - found: "
+ << factory_list.size() << std::endl;
+ return -1;
+ }
+ {
+ std::auto_ptr<word> w(factory_list.begin()->create());
+ const char * value;
+ if (strcmp(value = w->get_val(), "First Time") != 0)
+ {
+ std::cout << "The string's value should have been \"First Time\" but was: "
+ << value << std::endl;
+ return -1;
+ }
+ if (strcmp(value = w->get_val(), "Second Time") != 0)
+ {
+ std::cout << "The string's value should have been \"Second Time\" but was: "
+ << value << std::endl;
+ return -1;
+ }
+ }
+ }
+}
\ No newline at end of file
Added: sandbox/libs/extension/examples/registry/registry_library.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/extension/examples/registry/registry_library.cpp 2007-05-29 22:04:18 EDT (Tue, 29 May 2007)
@@ -0,0 +1,43 @@
+/* (C) Copyright Jeremy Pack 2007
+* Distributed under the Boost Software License, Version 1.0. (See
+* accompanying file LICENSE_1_0.txt or copy at
+* http://www.boost.org/LICENSE_1_0.txt)
+*/
+
+#include <boost/extension/counted_factory_map.hpp>
+#include <boost/extension/extension.hpp>
+// Notice that we don't need to include the registry file - just the class
+// it's derived from. This keeps us from pulling the shared_library headers
+// into this shared library.
+#include "../word.hpp"
+using namespace boost::extensions;
+class counting_word : public word
+{
+public:
+ virtual ~counting_word(){}
+ virtual const char * get_val()
+ {
+ static int times_called = 0;
+ ++times_called;
+ switch (times_called)
+ {
+ case 1:
+ return "First Time";
+ break;
+ case 2:
+ return "Second Time";
+ break;
+ default:
+ return "Many times";
+ break;
+ }
+ }
+};
+// Using the default function name for loading registries:
+extern "C" void BOOST_EXTENSION_EXPORT_DECL boost_extension_registry_function(counted_factory_map & fm)
+{
+ // 5 is just an identifier - not used in this example.
+ // Arbitrary information (not just an int) can be stored
+ // with the factory.
+ fm.add<counting_word, word, int>(5);
+}
Modified: sandbox/libs/extension/scripts/GenerateHeaders.py
==============================================================================
--- sandbox/libs/extension/scripts/GenerateHeaders.py (original)
+++ sandbox/libs/extension/scripts/GenerateHeaders.py 2007-05-29 22:04:18 EDT (Tue, 29 May 2007)
@@ -13,18 +13,21 @@
self.generate_shared_library_hpp()
self.generate_factory_map_hpp("factory", "", "")
self.generate_factory_map_hpp("counted_factory",
- "\n f.set_library(current_library_);\n f.set_counter(current_counter_);",
- "\n std::string current_library_;\n int * current_counter_;",
- "\n virtual bool erase(const char * library_name) = 0;", """
- virtual bool erase(const char * library_name)
+ "\n f.set_library(current_library_.c_str());\n f.set_counter(current_counter_);",
+ "\n std::string current_library_;\n int default_counter_;\n int * current_counter_;",
+ "\n virtual bool remove_library(const char * library_name) = 0;", """
+ virtual bool remove_library(const char * library_name)
{
- for (iterator it = begin(); it != end(); ++it)
+ for (typename std::list<counted_factory<Interface, Info, Param1, Param2, Param3,
+ Param4, Param5, Param6> >::iterator it = this->begin();
+ it != this->end(); ++it)
{
if (strcmp(it->library(), library_name) == 0)
- erase(it);
+ this->erase(it);
}
- return size() == 0;
- }""")
+ return this->size() == 0;
+ }""",
+ "\n basic_counted_factory_map() : default_counter_(0), current_counter_(&default_counter_){}")
def template_header(self, start_string, start, count, add_void):
if add_void:
@@ -71,7 +74,7 @@
out.write("".join(["class factory",
factory_template,
"""{
-private:
+protected:
class generic_factory_function
{
public:
@@ -155,7 +158,7 @@
out.write("".join(["class counted_factory",
factory_template,
"""{
-private:
+protected:
int * counter_;
std::string library_;
class generic_factory_function
@@ -163,7 +166,7 @@
public:
virtual ~generic_factory_function(){}
virtual Interface * operator()(""",
- self.nameless_param_list(i, []),
+ self.nameless_param_list(i, ["int * counter"]),
""") = 0;
virtual generic_factory_function * copy() const = 0;
};
@@ -194,14 +197,25 @@
(""",
self.named_param_list(i, ["int * counter"]),
""")
- {return new counted_object(""",
- self.param_names(i, ["counter_"]),
- """);}
+ { // A compilation error here usually indicates that the
+ // class you are adding is not derived from the base class
+ // that you indicated.
+ return static_cast<Interface*>(new counted_object(""",
+ self.param_names(i, ["counter"]),
+ """));}
virtual generic_factory_function * copy() const {return new factory_function<T>;}
};
std::auto_ptr<generic_factory_function> factory_func_ptr_;
Info info_;
public:
+ void set_library(const char * library_name)
+ {
+ library_ = library_name;
+ }
+ void set_counter(int * counter)
+ {
+ counter_ = counter;
+ }
const char * library()
{
return library_.c_str();
@@ -215,20 +229,22 @@
info_(info)
{}
counted_factory(const counted_factory & first)
- :factory_func_ptr_(first.factory_func_ptr_->copy()),
+ :counter_(first.counter_),
+ library_(first.library_),
+ factory_func_ptr_(first.factory_func_ptr_->copy()),
info_(first.info_)
{}
Interface * operator()(""",
- self.named_param_list(i, []),
+ self.named_param_list(i, ["int * counter"]),
""")
{return create(""",
- self.param_names(i, []),
+ self.param_names(i, ["counter"]),
""");}
Interface * create(""",
self.named_param_list(i, []),
"""){return (*factory_func_ptr_)
(""",
- self.param_names(i, []),
+ self.param_names(i, ["counter_"]),
""");}
Info & get_info(){return info_;}
};
@@ -267,7 +283,7 @@
out.write("".join(["class functor",
functor_template,
"""{
-private:
+protected:
typedef ReturnValue (*FunctionType)(""",
self.nameless_param_list(i, []),
""");
@@ -294,7 +310,7 @@
# end for loop
out.write("""class shared_library
{
-private:
+protected:
std::string location_;
library_handle handle_;
bool auto_close_;
@@ -333,7 +349,7 @@
def generate_factory_map_hpp(self, factory_type, factory_type_add, new_members,
generic_factory_container_additions = "",
- factory_container_additions = ""):
+ factory_container_additions = "", new_public_members = ""):
out = open(''.join(['../../../boost/extension/',factory_type,'_map.hpp']), mode='w')
out.write(''.join(["""/* (C) Copyright Jeremy Pack 2007
* Distributed under the Boost Software License, Version 1.0. (See
@@ -356,7 +372,7 @@
template <class TypeInfo>
class basic_""",factory_type,"""_map
{
-private:
+protected:
class generic_factory_container
{
public:""", generic_factory_container_additions, """
@@ -373,7 +389,7 @@
};
typedef std::map<TypeInfo, generic_factory_container *> FactoryMap;
FactoryMap factories_;""", new_members,"""
-public:
+public:""", new_public_members,"""
~basic_""", factory_type, """_map(){
for(typename FactoryMap::iterator it = factories_.begin(); it != factories_.end(); ++it)
delete it->second;
@@ -438,10 +454,10 @@
""">();
""",factory_type,"""<""",
self.nameless_param_list(i, ["Interface", "Info"]),
- """> f(info);
+ """> f(info);""",factory_type_add,"""
//f.set_type<Actual>();
f.set_type_special((Actual*)0);
- s.push_back(f);""",factory_type_add,"""
+ s.push_back(f);
//it->set_type<Actual>();
}
"""]))
Modified: sandbox/libs/extension/test/registry_test.cpp
==============================================================================
--- sandbox/libs/extension/test/registry_test.cpp (original)
+++ sandbox/libs/extension/test/registry_test.cpp 2007-05-29 22:04:18 EDT (Tue, 29 May 2007)
@@ -3,20 +3,50 @@
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
-
+#include <string>
#include <boost/extension/registry.hpp>
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
+#include "../examples/word.hpp"
+
using namespace boost::extensions;
BOOST_AUTO_TEST_CASE(registry_construction)
{
registry reg;
BOOST_CHECK_EQUAL(reg.num_libraries(), size_t(0));
- reg.open("../bin/libbasic_reg.extension");
+ BOOST_CHECK(reg.open("../bin/libRegistryLibrary.extension"));
BOOST_CHECK_EQUAL(reg.num_libraries(), size_t(1));
- reg.close("../bin/libbasic_reg.extension");
+ BOOST_CHECK(reg.close("../bin/libRegistryLibrary.extension"));
+ BOOST_CHECK_EQUAL(reg.num_libraries(), size_t(0));
+}
+
+BOOST_AUTO_TEST_CASE(library_closing)
+{ // this tests the requirements of the registry example
+ registry reg;
+ BOOST_ASSERT(reg.open("../bin/libRegistryLibrary.extension"));
+ {
+ std::list<counted_factory<word, int> > & factory_list = reg.get<word, int>();
+ BOOST_CHECK_EQUAL(factory_list.size(), size_t(1));
+ {
+ std::auto_ptr<word> w(factory_list.begin()->create());
+ BOOST_CHECK_EQUAL(std::string(w->get_val()), std::string("First Time"));
+ BOOST_CHECK_EQUAL(std::string(w->get_val()), std::string("Second Time"));
+ }
+ }
+ BOOST_CHECK(reg.clear());
+ BOOST_ASSERT(reg.open("../bin/libRegistryLibrary.extension"));
+ {
+ std::list<counted_factory<word, int> > & factory_list = reg.get<word, int>();
+ BOOST_CHECK_EQUAL(factory_list.size(), size_t(1));
+ {
+ std::auto_ptr<word> w(factory_list.begin()->create());
+ BOOST_CHECK_EQUAL(std::string(w->get_val()), std::string("First Time"));
+ BOOST_CHECK_EQUAL(std::string(w->get_val()), std::string("Second Time"));
+ }
+ }
+ BOOST_CHECK(reg.clear());
BOOST_CHECK_EQUAL(reg.num_libraries(), size_t(0));
}
\ 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