Ejemplo n.º 1
0
 def UpdateInitMethod(self):
     """Update the init methods"""
     from app.utils import cached_type
     method = self.init_methods
     aggregates = [x for x in self.relations_from if x._minCardinal]
     #if there are not relations we must delete init method
     if not aggregates:
         for x in method:
             x.Delete()
         return
     #ok, if there are not method we must create it and if
     #exists, unlist it
     if not method:
         method = model.cc.InitMethod(parent=self,
             type=model.cc.typeinst(type=cached_type(self.project, 'void')))
     else:
         method = method[0]
         method.SaveState()
         # remove all the arguments from the method
         k = method[model.cc.Argument]
         while k:
             k[0].Delete()
     #ok, we need to create a map for parent types
     code = ''
     for x in aggregates:
         cls = x._FROM
         #create required arguments
         name = x._fromPtr._name
         kwargs = {
             'parent': method,
             'name': name,
             'type': copy.copy(x._fromPtr._typei),
             'note': 'pointer to parent class {0}'.format(cls._name)}
         model.cc.Argument(**kwargs)
         alias = x._key._TO._name
         code += '\t{name}->Add{alias}Last(this);\n'.format(
             name=name, alias=alias)
     method._content = code
Ejemplo n.º 2
0
    def UpdateExitMethod(self):
        """update the exit methods"""
        from app.utils import cached_type
        method = self.exit_methods
        parent_relations = self.relations_to
        child_relations = self.relations_from
        #if there are not relations we must delete init method
        if not parent_relations and not child_relations:
            for x in method:
                x.Delete()
            return
        #ok, if there are not method we must create it and if
        #exists, unlist it
        if not method:
            method = model.cc.ExitMethod(parent=self,
                type=model.cc.typeinst(type=cached_type(self.project, 'void')))
        else:
            method = method[0]
            method.SaveState()
        # computing the contents
        # for the aggregated relations, we must delete all the elements
        code = ''
        # first of all, remove the child part
        relations = []
        aggregated = []
        for x in child_relations:
            if x._minCardinal:
                aggregated.append(x)
            else:
                relations.append(x)
        for x in relations:
            name = x._fromPtr.prefixed_name
            alias = x._key._TO._name
            s = '\tif ( {name} != nullptr )\n'
            s += '\t{\n\t\t{name}->Remove{alias}(this);\n\t}\n'
            code += s.format(name=name, alias=alias)

        for x in aggregated:
            name = x._fromPtr.prefixed_name
            alias = x._key._TO._name
            s = '\t{name}->Remove{alias}(this);\n'
            code += s.format(name=name, alias=alias)

        relations = []
        aggregated = []

        for x in parent_relations:
            if x._key._FROM._minCardinal:
                aggregated.append(x)
            else:
                relations.append(x)
        # only agreggated may be releseaded first
        for x in relations:
            name = x._firstToPtr._name
            alias = x._name
            s = '\twhile ( {name} != nullptr )\n'
            s += '\t{\n\t\tRemove{alias}({name});\n\t}\n'
            code += s.format(name=name, alias=alias)
        #ok, we need to create a map for parent types
        for x in aggregated:
            alias = x._name
            code += '\tDeleteAll{alias}();\n'.format(alias=alias)
        method._content = code