[gme-users] Controlling the order in which children are returned, decorators

Jacques Kerner jacques.kerner at oktal.fr
Thu Jul 8 10:44:29 CDT 2004


About order :

I don't know if this can help, but I have had a similar problem while 
writing an interpreter (that, among other things, resulted in IDL files 
generated). I was working at the time with version 4.3.17, and I 
modified the code so that I could call set getter methods as templated 
functions, with, as template parameter, the Comparison functor for the 
objects contained in the model and being returned as a set. For 
instance, instead of :

std::set<BON_SOME_PARADIGM::Child>   childs   =   model->getChild();

This gave something like :

std::set<BON_SOME_PARADIGM::Child, ChildComparisonFunctor>   childs   
=   model->getChild<ChildComparisonFunctor>(ChildComparisonFunctor());

Which allowed me to retrieve the childs in a given order, specified by 
the ChildComparisonFunctor, instead of the default < method that 
compares the automatically assigned (and thus uncontrollable) object 
counter.

Here is how I proceeded to write the functor. This is an example where 
the Child object has an Aspect named "SomeAspect", and the code is 
absolutely not optimized :

        class ChildComparisonFunctor
        {
        public:
            bool operator()(const Child& _Left, const Child& _Right) const
            {
                bool    sameX   =   
(_Left->getRegistry()->getLocation("SomeAspect").first == 
_Right->getRegistry()->getLocation("SomeAspect").first);
                if (sameX)  return 
(_Left->getRegistry()->getLocation("SomeAspect").second < 
_Right->getRegistry()->getLocation("SomeAspect").second);
                return 
(_Left->getRegistry()->getLocation("SomeAspect").first < 
_Right->getRegistry()->getLocation("SomeAspect").first);
            }
        };

What it does is give a Comparison function to arrange Childs in the 
latin reading order.

You also have to modify the Child getter method in the model (named 
"Parent" for instance). What you add is a new getChild function, in 
SOME_PARADIGMBonExtension.h :

class ParentImpl :
  virtual public BON::ModelImpl
{
public:
    //
    // kind and role getters
    virtual std::set<AttributeTypeReference> getChild(); // This is 
automatically generated

    // This is the added template getter method
    template <class T>   
    std::set<Child, T> getChild(const T & aComparison)
    {
        std::set<Child, T> res;
        std::set<BON::FCO> roles = getChildFCOsAs("Child");
        for( std::set<BON::FCO>::iterator i = roles.begin(); i != 
roles.end(); ++i)
        {
            AttributeTypeReference elem(*i);
            ASSERT(elem);
            res.insert(elem);
        }
        return res;
    }
    ///BUP
    // add your own members here
    ///EUP
};

If you look closely, adding the parameter should not be needed, but the 
problem is that Visual 6.0 has trouble compiling that, so you have to 
help it a little bit, and add the template as an argument of the method. 
I think Zoltan Molar added this to version 4.5.18 of GME, but I have not 
checked it yet (sorry).

Jacques Kerner.


Krishnakumar B a écrit :

>Hi,
>
>I would like to know if there is a way in GME to control the order in which
>children of a Model are returned. Specifically, I have a Model which
>represents a IDL interface's method. I would like to preserve the order in
>which the children of this model, i.e., the parameters of the method, are
>stored and retrieved. I need this so that the parameters in the generated
>IDL always appear in the same order. Is this possible?
>
>Assume that the above is not possible, and I add an attribute to every
>child that governs the order of the children. Is there a way that I can
>automatically assign a value to this attribute everytime a child is created
>in the model? I would like to keep track of the count and
>increment/decrement the count on child creation/deletion. Is this achieved
>with a decorator?
>
>One more decorator related question. I would like to add support for
>hierarchical views in my models. By hierarchical, I mean that I want a
>Model's view to show the contents of the Model i.e, it's children and the
>connections between these children. Note that I don't want the children to
>appear as ports. I want the same view that GME will display when I
>double-click the Model's icon and open it, shown as a snapshot when viewed
>one level up in the hierarchy i.e, a miniature snapshot of the contents. Is
>there some guide/manual that will help me acheive this? This is a very
>critical feature that seems to be missing from our tool and there is a
>*lot* of interest in providing this capability.
>
>Essentially we have a Component Assembly (a Model) which shows the
>components in the assembly and the connections between them. But currently
>there is no support for composition, i.e, one cannot create an assembly of
>Component assemblies. But experience with using the tool to make models
>which have many instances of the same grouping of components i.e, an
>assembly, shows that the current view where one has to scroll the sheet to
>view the bigger assembly is not very intuitive. Hence my queries.
>
>Any suggestions/pointers/ideas are very welcome.
>
>Thanks,
>kitty.
>_______________________________________________
>gme-users mailing list
>gme-users at list.isis.vanderbilt.edu
>http://list.isis.vanderbilt.edu/mailman/listinfo/gme-users
>
>  
>


More information about the gme-users mailing list