Changeset 147:52628eaefd06 in finroc_plugins_runtime_construction


Ignore:
Timestamp:
18.10.2020 07:36:00 (4 days ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
17.03
Children:
148:242e5df867d6, 149:e8db5f6b5275
Phase:
public
Message:

Adds create actions for conditional includes (for use in XML structure files). Moves 'include' element to separate file for this purpose.

Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • make.xml

    r114 r147  
    2323      tGroup.cpp 
    2424      tGroupInterface.cpp 
     25      tInclude.cpp 
    2526      tPortCreationList.cpp 
    2627    </sources> 
  • tFinstructable.cpp

    r146 r147  
    4545#include "plugins/runtime_construction/tEditableInterfaces.h" 
    4646#include "plugins/runtime_construction/dynamic_loading.h" 
    47 #include "plugins/runtime_construction/tConstructorCreateModuleAction.h" 
     47#include "plugins/runtime_construction/tInclude.h" 
    4848 
    4949//---------------------------------------------------------------------- 
     
    6969typedef core::tFrameworkElement tFrameworkElement; 
    7070typedef tFrameworkElement::tFlag tFlag; 
     71typedef tInclude tIncludeElement; 
    7172 
    7273//---------------------------------------------------------------------- 
     
    141142} 
    142143 
    143  
    144 /*! Framework element with create action for inclusion of finstructable XML files */ 
    145 class tIncludeElement : public core::tFrameworkElement 
    146 { 
    147 public: 
    148   tIncludeElement(core::tFrameworkElement* parent, const std::string& name, const std::string& xml_file) : 
    149     tFrameworkElement(GetIncludesParent(parent, true), xml_file), 
    150     xml_file(xml_file) 
    151   { 
    152     tFinstructable::Include(*parent, xml_file, this); 
    153   } 
    154  
    155   std::string xml_file; 
    156  
    157   void OnManagedDelete() override 
    158   { 
    159     // Remove the whole included structure 
    160     auto parent = GetParent(); 
    161     parent = parent ? parent->GetParent() : parent; 
    162     if (parent && parent->IsReady()) 
    163     { 
    164       for (auto it = parent->SubElementsBegin(); it != parent->SubElementsEnd(); ++it) 
    165       { 
    166         tOriginDataAnnotation* annotation = it->GetAnnotation<tOriginDataAnnotation>(); 
    167         if (annotation && annotation->Data().origin == this) 
    168         { 
    169           it->ManagedDelete(); 
    170         } 
    171       } 
    172     } 
    173   } 
    174  
    175   static core::tFrameworkElement* GetIncludesParent(core::tFrameworkElement* parent, bool create_if_it_does_not_exist) 
    176   { 
    177     auto result = parent->GetChild("Includes"); 
    178     if ((!result) && create_if_it_does_not_exist) 
    179     { 
    180       result = new core::tFrameworkElement(parent, "Includes"); 
    181       result->Init(); 
    182     } 
    183     return result; 
    184   } 
    185 }; 
    186  
    187 tConstructorCreateModuleAction<tIncludeElement, std::string> cINCLUDE_CREATE_ACTION("Include", "File"); 
    188  
    189  
    190144bool HasNonDefaultFinstructInfo(const parameters::internal::tParameterInfo& info) 
    191145{ 
     
    302256  try 
    303257  { 
    304     name = node.GetStringAttribute("name"); 
    305258    std::string group = node.GetStringAttribute("group"); 
    306259    std::string type = node.GetStringAttribute("type"); 
     260    if (node.HasAttribute("name")) 
     261    { 
     262      name = node.GetStringAttribute("name"); 
     263    } 
    307264 
    308265    // find action 
     
    12071164    { 
    12081165      rrlib::xml::tNode& n = node.AddChildNode("include"); 
    1209       n.SetAttribute("file", static_cast<tIncludeElement*>(child)->xml_file); 
     1166      n.SetAttribute("file", static_cast<tIncludeElement*>(child)->IncludeFile()); 
    12101167      continue; 
    12111168    } 
     
    12161173    // serialize framework element 
    12171174    rrlib::xml::tNode& n = node.AddChildNode("element"); 
    1218     n.SetAttribute("name", child->GetName()); 
     1175    if (child->GetParent() != include_parent) 
     1176    { 
     1177      n.SetAttribute("name", child->GetName()); 
     1178    } 
    12191179    assert(spl); 
    12201180    tCreateFrameworkElementAction* cma = tCreateFrameworkElementAction::GetConstructibleElements()[spl->GetCreateAction()]; 
Note: See TracChangeset for help on using the changeset viewer.