[gme-users] GME Tutorial Question

Peter Volgyesi peter.volgyesi at vanderbilt.edu
Thu Mar 18 19:17:32 CDT 2010


Abdul,

I never really understood the way BON2 and the extender implement the
visitor pattern (I suspect they get this pattern wrong...badly).
The traversal is implemented in the stock BON2 classes. So if you do
not use the extender, you can easily create a Visitor class and the
::visit<...>Impl methods will be called by the framework as it
traverses trhough the containment hierarchy (you should initiate this
by calling the accept() method on a higher level container object).
The extender complicates this. It uses the traversal code of the stock
(non-domain specific) framework as described above and at every
::visit<...>Impl method call in the generated visitor skeleton the
generated code tries to cast the object pointer to all extended types
(eg. an atom pointer to all domain specific type which are of the atom
stereotype) and will call a visi<...>Impl method with the casted
pointer. If you inherit from the generated visitor you can override
these visit<...>Impl methods, but I guess you should check for null
pointers because of this trial and error casting logic (???).

If the whole thing does not work as I described (or at all), the error
probably is not with you.

Have fun.

--
peter



On Thu, Mar 18, 2010 at 5:22 PM, Sowayan, Abdullah (N-ED Software
Inc.) <abdullah.sowayan at lmco.com> wrote:
> Hi folks,
>
>
>
> So I was able to move a little forward with the tutorial example. I
> instantiate my visitor in invokeEx and call accept on the NetDiagram.
>
>
>
> My question is a simple one, do I have to do the traversal myself, or can I
> pass the root model (NetDiagram) and have something traverse it for me and
> call accept on the visitor?
>
>
>
>
>
> void Component::invokeEx( Project& project, FCO& currentFCO, const
> std::set<FCO>& setSelectedFCOs, long lParam )
>
> {
>
> #ifdef GME_ADDON
>
>       project->setAutoCommit( false);
>
> #endif
>
>       using namespace GMEConsole;
>
>       Console::Out::WriteLine("Interpreter started...");
>
>       // ======================
>
>       // TODO: Insert application specific code here
>
>
>
>   Console::Out::WriteLine((std::string("Router list for network ") +
> project->getRootFolder()->getName()).c_str());
>
>       std::set<BON::Object> diagrams =
> project->getRootFolder()->getChildObjects("NetDiagram");
>
>       for (std::set<BON::Object>::iterator it = diagrams.begin(); it !=
> diagrams.end(); it++) {
>
>             Networking::NetDiagram diagram = *it;
>
>     Networking::networkingVisitor* netvisit = new
> Networking::networkingVisitor;
>
>     diagram->accept(netvisit);
>
>     delete netvisit;
>
> //          ProcessDiagram(diagram);
>
>       }
>
>
>
>       Console::Out::WriteLine("Interpreter completed...");
>
> }
>
>
>
>
>
>
>
>
>
> bool networkingVisitor::visitNetDiagram( const Networking::NetDiagram&
> object )
>
> {
>
>       if ( !object)
>
>             return false;
>
>
>
>   GMEConsole::Console::Out::WriteLine("Abdul Abdul Abdul");
>
>
>
>       return true;
>
> }
>
>
>
> Thanks,
>
> Abdul
>
>
>
>
>
> From: gme-users-bounces at list.isis.vanderbilt.edu
> [mailto:gme-users-bounces at list.isis.vanderbilt.edu] On Behalf Of Sowayan,
> Abdullah (N-ED Software Inc.)
> Sent: Thursday, March 18, 2010 5:33 PM
> To: A list for GME users to share thoughts and discuss bugs and fixes.
> Subject: [gme-users] GME Tutorial Question
>
>
>
> Hi folks,
>
>
>
> I am trying to follow the GME tutorial. It has been many, many years since I
> wrote an interpreter. I was specifically intrigued with the BON2 Extender.
>
>
>
> I have generated the visitor classes using the BON2Extender interpreter in
> GME, and my whole project builds fine. What I can’t seem to figure out is
> how to get my visitor invoked.
>
>
>
> In my simple interpreter (based on the tutorial) I have this:
>
>
>
> networkingVisitor::networkingVisitor()
>
> {
>
>   myfile.open("Abdul.txt");
>
> }
>
>
>
> bool networkingVisitor::visitHost( const Networking::Host& object )
>
> {
>
>       if ( !object)
>
>             return false;
>
>
>
>   myfile << "Abdul Abdul Abdul" << std::endl;
>
>
>
>       return true;
>
> }
>
>
>
>
>
> Abdul.txt never gets created. It is not clear to me where I should
> instantiate my visitor and call accept() method.
>
>
>
> Any help would be greatly appreciated.
>
>
>
> Thanks,
>
> Abdul
>
>
>
>
>
> _______________________________________________
> 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