=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tao / PI / PolicyFactory_Registry.cpp
blobfc8d396aece4b95ed703c9072fbd13e47832382c
1 #include "tao/PI/PolicyFactory_Registry.h"
2 #include "tao/PI/PolicyFactoryC.h"
3 #include "tao/ORB_Constants.h"
4 #include "tao/PolicyC.h"
5 #include "tao/SystemException.h"
7 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
9 TAO_PolicyFactory_Registry::TAO_PolicyFactory_Registry ()
10 : factories_ (TAO_DEFAULT_POLICY_FACTORY_REGISTRY_SIZE)
14 TAO_PolicyFactory_Registry::~TAO_PolicyFactory_Registry ()
16 const TABLE::iterator end (this->factories_.end ());
18 for (TABLE::iterator i = this->factories_.begin (); i != end; ++i)
20 ::CORBA::release ((*i).int_id_);
23 this->factories_.close ();
26 void
27 TAO_PolicyFactory_Registry::register_policy_factory (
28 CORBA::PolicyType type,
29 PortableInterceptor::PolicyFactory_ptr policy_factory)
31 if (CORBA::is_nil (policy_factory))
33 throw ::CORBA::BAD_PARAM (
34 CORBA::SystemException::_tao_minor_code (
36 EINVAL),
37 CORBA::COMPLETED_NO);
40 PortableInterceptor::PolicyFactory_ptr factory =
41 PortableInterceptor::PolicyFactory::_duplicate (policy_factory);
43 const int result = this->factories_.bind (type, factory);
45 if (result != 0)
47 // Release the duplicated factory to prevent a memory leak
48 ::CORBA::release (factory);
50 if (result == 1)
52 // PolicyFactory of given type already exists.
53 throw ::CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 16,
54 CORBA::COMPLETED_NO);
56 else
58 // Could not add PolicyFactory due to internal bind failures.
59 throw ::CORBA::INTERNAL ();
64 CORBA::Policy_ptr
65 TAO_PolicyFactory_Registry::create_policy (CORBA::PolicyType type,
66 const CORBA::Any &value)
68 PortableInterceptor::PolicyFactory_ptr policy_factory =
69 PortableInterceptor::PolicyFactory::_nil ();
71 if (this->factories_.find (type, policy_factory) == -1)
73 // Policy factory corresponding to given policy type does not
74 // exist in policy factory map.
75 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_TYPE);
78 return policy_factory->create_policy (type, value);
81 CORBA::Policy_ptr
82 TAO_PolicyFactory_Registry::_create_policy (CORBA::PolicyType type)
84 PortableInterceptor::PolicyFactory_ptr policy_factory =
85 PortableInterceptor::PolicyFactory::_nil ();
87 if (this->factories_.find (type, policy_factory) == -1)
89 // Policy factory corresponding to given policy type does not
90 // exist in policy factory map.
91 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_TYPE);
94 return policy_factory->_create_policy (type);
97 bool
98 TAO_PolicyFactory_Registry::factory_exists (CORBA::PolicyType & type) const
100 return (this->factories_.find (type) == 0);
104 TAO_END_VERSIONED_NAMESPACE_DECL