예제 #1
0
void Layout::UpdateBehaviorsSharedData(gd::Project & project)
{
    std::vector < gd::String > allBehaviorsTypes;
    std::vector < gd::String > allBehaviorsNames;

    //Search in objects for the type and the name of every behaviors.
    for (std::size_t i = 0;i<initialObjects.size();++i)
    {
        std::vector < gd::String > objectBehaviors = initialObjects[i]->GetAllBehaviorNames();
        for (unsigned int j = 0;j<objectBehaviors.size();++j)
        {
            gd::Behavior & behavior = initialObjects[i]->GetBehavior(objectBehaviors[j]);
            allBehaviorsTypes.push_back(behavior.GetTypeName());
            allBehaviorsNames.push_back(behavior.GetName());
        }
    }
    for (std::size_t i = 0;i<project.GetObjectsCount();++i)
    {
        std::vector < gd::String > objectBehaviors = project.GetObject(i).GetAllBehaviorNames();
        for (std::size_t j = 0;j<objectBehaviors.size();++j)
        {
            gd::Behavior & behavior = project.GetObject(i).GetBehavior(objectBehaviors[j]);
            allBehaviorsTypes.push_back(behavior.GetTypeName());
            allBehaviorsNames.push_back(behavior.GetName());
        }
    }

    //Create non existing shared data
    for (std::size_t i = 0;i<allBehaviorsTypes.size() && i < allBehaviorsNames.size();++i)
    {
        if ( behaviorsInitialSharedDatas.find(allBehaviorsNames[i]) == behaviorsInitialSharedDatas.end() )
        {
            std::shared_ptr<gd::BehaviorsSharedData> behaviorsSharedDatas = project.CreateBehaviorSharedDatas(allBehaviorsTypes[i]);
            if ( behaviorsSharedDatas )
            {
                behaviorsSharedDatas->SetName(allBehaviorsNames[i]);
                behaviorsInitialSharedDatas[behaviorsSharedDatas->GetName()] = behaviorsSharedDatas;
            }
        }
    }

    //Remove useless shared data:
    //First construct the list of existing shared data.
    std::vector < gd::String > allSharedData;
    for (std::map < gd::String, std::shared_ptr<gd::BehaviorsSharedData> >::const_iterator it = behaviorsInitialSharedDatas.begin();
         it != behaviorsInitialSharedDatas.end();++it)
    {
        allSharedData.push_back(it->first);
    }

    //Then delete shared data not linked to a behavior
    for (std::size_t i = 0;i<allSharedData.size();++i)
    {
        if ( std::find(allBehaviorsNames.begin(), allBehaviorsNames.end(), allSharedData[i]) == allBehaviorsNames.end() )
            behaviorsInitialSharedDatas.erase(allSharedData[i]);
    }
}
예제 #2
0
gd::String GD_CORE_API GetTypeOfBehavior(const gd::Project & project, const gd::Layout & layout, gd::String name, bool searchInGroups)
{
    for (std::size_t i = 0;i<layout.GetObjectsCount();++i)
    {
        vector < gd::String > behaviors = layout.GetObject(i).GetAllBehaviorNames();
        for (std::size_t j = 0;j<behaviors.size();++j)
        {
            if ( layout.GetObject(i).GetBehavior(behaviors[j]).GetName() == name )
                return layout.GetObject(i).GetBehavior(behaviors[j]).GetTypeName();
        }
    }

    for (std::size_t i = 0;i<project.GetObjectsCount();++i)
    {
        vector < gd::String > behaviors = project.GetObject(i).GetAllBehaviorNames();
        for (std::size_t j = 0;j<behaviors.size();++j)
        {
            if ( project.GetObject(i).GetBehavior(behaviors[j]).GetName() == name )
                return project.GetObject(i).GetBehavior(behaviors[j]).GetTypeName();
        }
    }

    return "";
}