[gme-users] Ordering of sets in Bon

Jacques Kerner jacques.kerner at oktal.fr
Tue Apr 20 16:26:08 CDT 2004


Hi, it's me again, on ordering (sorry).

I would still like to suggest an additional generated function to allow 
the user to specify how a returned set should be ordered. Note that my 
suggestion does not break the current API.

For instance, let's suppose we have Model "A" that can aggregate Atoms 
"B". What the BONExtender generates is :

class AImpl :
  virtual public BON::ModelImpl
{
public:
    std::set<B> getB();
};

and

std::set<B> AImpl::getB()
{
    std::set<B> res;
    std::set<BON::FCO> roles = getChildFCOsAs("B");
    for( std::set<BON::FCO>::iterator i = roles.begin(); i != 
roles.end(); ++i)
    {
        TypeReference elem(*i);
        ASSERT(elem);
        res.insert(elem);
    }
    return res;
}

ordering is done in the insert function, and uses the operator< that 
relies on the reference counter to compare two fcos. I suggest the 
addition of the following template function to the AImpl class declaration:

template <class T>
std::set<B, T> AImpl::getB()
{
    std::set<B, T> res;
    std::set<BON::FCO> roles = getChildFCOsAs("B");
    for( std::set<BON::FCO>::iterator i = roles.begin(); i != 
roles.end(); ++i)
    {
        TypeReference elem(*i);
        ASSERT(elem);
        res.insert(elem);
    }
    return res;
}

Adding this function allows the user to use his own comparison Trait :

std::set<B, BComparison>    bSet    =    b->getB<BComparison>();

with, for instance, a Comparison class based on the x coordinate in 
"MyAspect" aspect.

    class BComparison
    {
    public:
        //! This method orders two Bs with respect to their x coordinate 
in the diagram
        /** (thanks to Peter Volgyesi for the trick... :)
        */
        bool operator()(
            const B& _Left,
            const B& _Right
        ) const
        {
            return (_Left->getRegistry()->getLocation("MyAspect").first 
< _Right->getRegistry()->getLocation("MyAspect").first);
        }
    };

or whatever Trait the user defines for his own needs.

Again, please note that my suggestion does not break the current API, 
since the user can still call the regular untemplated getB() method. 
Furthermore, this does not imply any additional performance cost other 
than implied by the user comparison function. Using this avoids the need 
to reorder the sets after they have been recovered. If the user wants to 
get the set as fast as possible, she uses the untemplated getB() method, 
but if she wants to order it in her own way, this is still faster that 
getting the set and THEN reordering it.

I have succesfully tested this method with GME 4.3.17, with Visual 7.1. 
Hoping there are no issues with this that I am anaware of ...

Best Regards,

Jacques Kerner.

Peter Volgyesi a écrit :

>Hi,
>
>Collections coming from the model database are never ordered. (This is a
>property of our modeling engine and not BON specific, and it is because of
>internal caching mechanisms.) One can argue, why don't we order these lists,
>however it seems a better (general) approach to me to provide data as fast
>as possible that can be sorted by the upper layers on demand.
>
>Anyway, the MONTraverser interpreter (Paradigms/MetaGME folder) does
>implement some kind of sorting (MONDialog.cpp). Feel free to use that code.
>
>For retrieving graphical position of an object in a given aspect, use this:
>fco->getRegistry()->getLocation("AspectName");
>
>fco must be a BON FCO object (eg.: BON::Atom)
>
>Regards, 
>
>--
>peter
>
>
>  
>
>>-----Original Message-----
>>From: gme-users-bounces at list.isis.vanderbilt.edu 
>>[mailto:gme-users-bounces at list.isis.vanderbilt.edu] On Behalf 
>>Of Jacques Kerner
>>Sent: Tuesday, April 06, 2004 9:45 AM
>>To: A list for GME users to share thoughts and discuss bugs and fixes.
>>Subject: [gme-users] Ordering of sets in Bon
>>
>>Hi,
>>
>>I would like to know how the std::set<...> returned by 
>>BONExtender generated functions are ordered. For instance, I 
>>have a model named "Container" that aggregates "Contained" 
>>Atoms "contained1", "contained2" 
>>and "contained3" and I was uable to figure out how the 
>>ordering was made. Sometimes the order is by creation of the 
>>contained elements, sometimes not, ...
>>
>>Is there a way to impose the ordering on the returned sets ? 
>>Do I have to define a specific operator < for this ? Could 
>>BonExtender generate one from a rule in the meta model ?
>>
>>I also wondered if one can retrieve the position of elements 
>>in diagrams in BON .
>>
>>Thank you in advance.
>>
>>Jacques Kerner.
>>_______________________________________________
>>gme-users mailing list
>>gme-users at list.isis.vanderbilt.edu
>>http://list.isis.vanderbilt.edu/mailman/listinfo/gme-users
>>    
>>
>
>_______________________________________________
>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