本文整理汇总了C++中IObject::Init方法的典型用法代码示例。如果您正苦于以下问题:C++ IObject::Init方法的具体用法?C++ IObject::Init怎么用?C++ IObject::Init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IObject
的用法示例。
在下文中一共展示了IObject::Init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: typed
rcc::shared_ptr<IMessageReader> IMessageReader::create(const std::string& topic)
{
std::map<int, IObjectConstructor*> constructor_priority;
auto constructors = mo::MetaObjectFactory::instance()->getConstructors(IMessageReader::s_interfaceID);
for(auto constructor : constructors)
{
if(auto info = dynamic_cast<MessageReaderInfo*>(constructor->GetObjectInfo()))
{
constructor_priority[info->CanHandleTopic(topic)] = constructor;
}
}
if(constructor_priority.size())
{
if(constructor_priority.rbegin()->first > 0)
{
IObject* obj = constructor_priority.rbegin()->second->Construct();
if(obj)
{
obj->Init(true);
rcc::shared_ptr<IMessageReader> typed(obj);
if(typed)
{
if(typed->subscribe(topic))
{
return typed;
}
}else
{
delete obj;
}
}
}
}
return rcc::shared_ptr<IMessageReader>();
}
示例2: bSingletonConstructed
//.........这里部分代码省略.........
{
old_objects.push_back(old_object);
auto state = pOldConstructor->GetState(objId);
pConstructor->Construct(state);
}
else
{
pConstructor->ConstructNull();
}
}
m_ConstructorsReplaced.push_back( pOldConstructor );
}
else
{
ConstructorId id = constructorsNew.size();
m_pObjectFactorySystem->m_ConstructorIds[ pConstructor->GetName() ] = id;
constructorsNew.push_back( pConstructor );
pConstructor->SetConstructorId( id );
}
}
if( m_pLogger ) m_pLogger->LogInfo( "Serialising in...");
//serialize back
m_ProtectedPhase = PHASE_SERIALIZEIN;
m_Serializer.SetIsLoading( true );
for( size_t i = 0; i < constructorsNew.size(); ++i )
{
IObjectConstructor* pConstructor = constructorsNew[i];
for( PerTypeObjectId objId = 0; objId < pConstructor->GetNumberConstructedObjects(); ++ objId )
{
// Serialize new object
IObject* pObject = pConstructor->GetConstructedObject( objId );
if (pObject)
{
m_Serializer.Serialize( pObject );
}
}
}
// auto construct singletons
// now in 2 phases - construct then init
m_ProtectedPhase = PHASE_AUTOCONSTRUCTSINGLETONS;
std::vector<bool> bSingletonConstructed( constructorsNew.size(), false );
if( m_pLogger ) m_pLogger->LogInfo( "Auto Constructing Singletons...");
for( size_t i = 0; i < constructorsNew.size(); ++i )
{
IObjectConstructor* pConstructor = constructorsNew[i];
if( pConstructor->GetIsAutoConstructSingleton() )
{
if( 0 == pConstructor->GetNumberConstructedObjects() )
{
pConstructor->GetSingleton();
bSingletonConstructed[i] = true;
}
}
}
// Do a second pass, initializing objects now that they've all been serialized
// and testing serialization if required
m_ProtectedPhase = PHASE_INITANDSERIALIZEOUTTEST;
if( m_bTestSerialization )
{
if( m_pLogger ) m_pLogger->LogInfo( "Initialising and testing new serialisation...");
}
else
{
if( m_pLogger ) m_pLogger->LogInfo( "Initialising...");
}
for( size_t i = 0; i < constructorsNew.size(); ++i )
{
IObjectConstructor* pConstructor = constructorsNew[i];
for( PerTypeObjectId objId = 0; objId < pConstructor->GetNumberConstructedObjects(); ++ objId )
{
IObject* pObject = pConstructor->GetConstructedObject( objId );
if (pObject)
{
// if a singleton was newly constructed in earlier phase, pass true to init.
pObject->Init( bSingletonConstructed[i] );
if( m_bTestSerialization && ( m_ConstructorsOld.size() <= i || m_ConstructorsOld[ i ] != constructorsNew[ i ] ) )
{
//test serialize out for all new objects, we assume old objects are OK.
SimpleSerializer tempSerializer;
tempSerializer.SetIsLoading( false );
tempSerializer.Serialize( pObject );
}
}
}
}
m_ProtectedPhase = PHASE_DELETEOLD;
//delete old objects which have been replaced
for(auto pOldObject: old_objects)
{
pOldObject->_isRuntimeDelete = true;
delete pOldObject;
}
}
示例3: CompleteConstructorSwap
void ObjectFactorySystem::CompleteConstructorSwap( ProtectedObjectSwapper& swapper )
{
if( swapper.HasHadException() && PHASE_DELETEOLD != swapper.m_ProtectedPhase )
{
if( m_pLogger )
{
m_pLogger->LogError( "Exception during object swapping, switching back to previous objects." );
switch( swapper.m_ProtectedPhase )
{
case PHASE_NONE:
AU_ASSERT( false );
break;
case PHASE_SERIALIZEOUT:
m_pLogger->LogError( "\tError occured during serialize out old objects phase." );
break;
case PHASE_CONSTRUCTNEW:
m_pLogger->LogError( "\tError occured during constructing new objects phase." );
break;
case PHASE_SERIALIZEIN:
m_pLogger->LogError( "\tError occured during serialize into the new objects phase." );
break;
case PHASE_AUTOCONSTRUCTSINGLETONS:
m_pLogger->LogError( "\tError occured during auto construct singletons phase." );
break;
case PHASE_INITANDSERIALIZEOUTTEST:
if( m_bTestSerialization )
{
m_pLogger->LogError( "\tError occured during Initialization and serialize test of new objects phase." );
}
else
{
m_pLogger->LogError( "\tError occured during Initialization phase." );
}
break;
case PHASE_DELETEOLD:
break;
}
}
//swap back to new constructors before everything is serialized back in
m_Constructors = swapper.m_ConstructorsOld;
if( PHASE_SERIALIZEOUT != swapper.m_ProtectedPhase )
{
//serialize back with old objects - could cause exception which isn't handled, but hopefully not.
swapper.m_Serializer.SetIsLoading( true );
for( size_t i = 0; i < m_Constructors.size(); ++i )
{
IObjectConstructor* pConstructor = m_Constructors[i];
for( PerTypeObjectId objId = 0; objId < pConstructor->GetNumberConstructedObjects(); ++ objId )
{
// Iserialize new object
IObject* pObject = pConstructor->GetConstructedObject( objId );
if (pObject)
{
swapper.m_Serializer.Serialize( pObject );
}
}
}
// Do a second pass, initializing objects now that they've all been serialized
for( size_t i = 0; i < m_Constructors.size(); ++i )
{
IObjectConstructor* pConstructor = m_Constructors[i];
for( PerTypeObjectId objId = 0; objId < pConstructor->GetNumberConstructedObjects(); ++ objId )
{
IObject* pObject = pConstructor->GetConstructedObject( objId );
if (pObject)
{
pObject->Init(false);
}
}
}
}
}
else
{
if( m_pLogger ) m_pLogger->LogInfo( "Object swap completed");
if( swapper.HasHadException() && PHASE_DELETEOLD == swapper.m_ProtectedPhase )
{
if( m_pLogger ) m_pLogger->LogError( "Exception during object destruction of old objects, leaking." );
}
}
// Notify any listeners that constructors have changed
TObjectFactoryListeners::iterator it = m_Listeners.begin();
TObjectFactoryListeners::iterator itEnd = m_Listeners.end();
while (it != itEnd)
{
(*it)->OnConstructorsAdded();
++it;
}
}