Clang(#928): adjustments regarding scope and visibility

Clang doesn't allow to declare a private nested class as friend.
This is unfortunate, but likely correct to the letter of the standard.

As a workaround, now we're creating the instances within a static
function of DependencyFactory -- in the end this improves readability


A second issue fixed with this changeset is the scope of the
marker function. Clang is right, this isn't ADL, thus an inline
friend definition is simply not visible outside the class.
This commit is contained in:
Fischlurch 2013-10-20 21:51:28 +02:00
parent bfba22f41a
commit a344604f1b
13 changed files with 50 additions and 28 deletions

View file

@ -64,7 +64,7 @@ namespace engine {
EngineConfig();
~EngineConfig();
friend class lib::DependencyFactory::InstanceHolder<EngineConfig>;
friend class lib::DependencyFactory;
public:
/** access point to the Engine Interface.

View file

@ -73,7 +73,7 @@ namespace lumiera {
private:
Config();
~Config();
friend class lib::DependencyFactory::InstanceHolder<Config>;
friend class lib::DependencyFactory;
};

View file

@ -115,6 +115,9 @@ namespace lib {
private:
/** pointer to the concrete function
* used for building new service instances */
@ -122,6 +125,21 @@ namespace lib {
/** function to build service instances.
* A service class with private ctor can declare DependencyFactory as friend,
* to indicate this is the expected way to create instances */
template<typename TAR>
static TAR*
create_in_buffer (void* buffer)
{
return new(buffer) TAR;
}
/**
* @internal Helper to manage a service instance within an embedded buffer.
* This helper and thus the service instance will be allocated into static memory.
*/
template<typename TAR>
class InstanceHolder
: boost::noncopyable
@ -156,7 +174,7 @@ namespace lib {
buildInstance ()
{
// place new instance into embedded buffer
TAR* newInstance = new(buff_) TAR;
TAR* newInstance = create_in_buffer<TAR>(buff_);
try
{
@ -189,26 +207,30 @@ namespace lib {
}
/**
* DSL-style marker function for client code
* to configure the usage of a specific subclass.
* Typically this function is used right within the
* Constructor call for lib::Depend; this allows to
* confine the actual service implementation class
* to a single compilation unit, without the need
* for clients of the respective service to know
* the actual concrete implementation class
*/
template<class TAR>
friend InstanceConstructor
buildSingleton()
{
return & createSingletonInstance<TAR>;
}
friend InstanceConstructor buildSingleton();
};
/**
* DSL-style marker function for client code
* to configure the usage of a specific subclass.
* Typically this function is used right within the
* Constructor call for lib::Depend; this allows to
* confine the actual service implementation class
* to a single compilation unit, without the need
* for clients of the respective service to know
* the actual concrete implementation class
*/
template<class TAR>
inline DependencyFactory::InstanceConstructor
buildSingleton()
{
return & DependencyFactory::createSingletonInstance<TAR>;
}
} // namespace lib
#endif

View file

@ -102,7 +102,7 @@ namespace asset {
clear();
}
friend class lib::DependencyFactory::InstanceHolder<DB>;
friend class lib::DependencyFactory;
public:

View file

@ -126,7 +126,7 @@ namespace asset {
AssetManager ();
friend class lib::DependencyFactory::InstanceHolder<AssetManager>;
friend class lib::DependencyFactory;
};

View file

@ -79,7 +79,7 @@ namespace control {
STypeManager() ;
~STypeManager();
friend class lib::DependencyFactory::InstanceHolder<STypeManager>;
friend class lib::DependencyFactory;
/** Lifecycle: reset all type registration information
* to the <i>generic pristine default</i> state. This includes

View file

@ -73,7 +73,7 @@ namespace engine {
DiagnosticBufferProvider();
~DiagnosticBufferProvider();
friend class lib::DependencyFactory::InstanceHolder<DiagnosticBufferProvider>;
friend class lib::DependencyFactory;
public:
/** build a new Diagnostic Buffer Provider instance,

View file

@ -283,7 +283,7 @@ namespace session {
{
protected:
MockConfigRules (); ///< to be used only by the singleton factory
friend class lib::DependencyFactory::InstanceHolder<MockConfigRules>;
friend class lib::DependencyFactory;
virtual ~MockConfigRules() {}

View file

@ -94,7 +94,7 @@ namespace session {
protected:
ScopeLocator();
friend class lib::DependencyFactory::InstanceHolder<ScopeLocator>;
friend class lib::DependencyFactory;
private:
lumiera::QueryResolver const& theResolver();

View file

@ -47,7 +47,7 @@ namespace session {
scoped_ptr<LifecycleAdvisor> lifecycle_;
SessManagerImpl() throw();
friend class lib::DependencyFactory::InstanceHolder<SessManagerImpl>;
friend class lib::DependencyFactory;
~SessManagerImpl() ;

View file

@ -88,7 +88,7 @@ namespace play {
private:
OutputDirector() ;
~OutputDirector() ;
friend class lib::DependencyFactory::InstanceHolder<OutputDirector>;
friend class lib::DependencyFactory;
void bringDown (SigTerm completedSignal);

View file

@ -62,7 +62,7 @@ namespace test{
Interface () : TestTargetObj(cnt) {}
virtual ~Interface() {}
friend class DependencyFactory::InstanceHolder<Interface>;
friend class lib::DependencyFactory;
};
int Interface::cnt = 0;

View file

@ -58,7 +58,7 @@ namespace test{
protected:
TargetObj () : TestTargetObj(cnt) {}
friend class DependencyFactory::InstanceHolder<TargetObj>;
friend class lib::DependencyFactory;
};
int TargetObj::cnt = 0;