Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

Container objects

This library is based on two container objects, the high level object OHL and the graph object OGraph. These two objects allow a pyramid structuring of graphical knowledge.

The OHL object
The OHL object is an object list to store different OGraphic objects. The following function gives an example of OHL use to create and write an arc with its center, and radius.
    void ohlArc()
    {
            OGraphic* p;
            OHL *my = new OHL();
            OPoint ptb(50,50),ptc(100,50),pte(100,100);
            //draw radius
            p = new OLine(ptb,ptc);
            my->newObject(p);
            p = new OLine(ptc,pte);
            my->newObject(p);
            //draw center
            p = new OPoint(ptc.getX(),ptc.getY());
            my->newObject(p);
            //draw arc
            p = new OArc(ptb,ptc,pte,false);
            my->newObject(p);
            my->print();
            gomWrite(my,"es.gom");
            xmlWrite(my,"es.xml");
            svgWrite(my,"es.svg");
            my->~OHL(); //here we delete all OHL's object, OPoint, OLine, and OArc
    }       //de
The OHL object contains a OGraphic* array (deque). So, OHL uses only OGraphic types. To copy an OHL you must use the OHL::clone() function like this:

    void ohlCopy()
    {
            OGraphic *p;
            OHL *h1 = new OHL();
            p = new OPoint(1,2);
            h1->newObject(p);
            p = new OPoint(3,4);
            h1->newObject(p);
            OGraphic *h2 = h1->clone(); //here we copy all OHL's objects
            h1->~OHL();
            h2->print();
            h2->~OGraphic();
    }       //de
In a same way, when you add some objects to an OHL you must clone these objects like this:

    void ohlWrite()
    {
            {
            OHL *h1 = new OHL();
            OHL *h2 = new OHL();
            OGraphic* p;
            p = new OPoint(1,2);
            h1->newObject(p);
            h2->newObject(p);
            p = new OPoint(3,4);
            h1->newObject(p);
            h2->newObject(p);
            h1->~OHL(); //free memory ok
            //h2->~OHL(); //error
            }
            {
            OHL *h1 = new OHL();
            OHL *h2 = new OHL();
            OGraphic* p;
            p = new OPoint(1,2);
            h1->newObject(p);
            h2->newObject(p->clone());
            p = new OPoint(3,4);
            h1->newObject(p);
            h2->newObject(p->clone());
            h1->~OHL(); //free memory ok
            h2->~OHL(); //free memory ok
            }
    }       //de
If you want to replace some objects, you can use the OHL::objectPush() and OHL::objectWrite() functions like this:

    void ohlPush()
    {
            {
            OHL *h = new OHL();
            OGraphic* p;
            p = new OPoint(1,2);
            h->newObject(p);
            p = new OPoint(3,4);
            h->objectWrite(p,0); //bad case, you don't delete the 1;2 point
            h->~OHL();
            }
            {
            OHL *h = new OHL();
            OGraphic* p;
            p = new OPoint(1,2);
            h->newObject(p);
            p = new OPoint(3,4);
            h->objectRead(0)->~OGraphic();
            h->objectWrite(p,0); //good case, you delete the 1;2 point
            h->~OHL();
            }
            {
            OHL *h = new OHL();
            OGraphic* p;
            p = new OPoint(1,2);
            h->newObject(p);
            p = new OPoint(3,4);
            h->objectPush(p,0); //good case, you delete the 1;2 point
            h->~OHL();
            }
    }       //de
The OGraph object
The OGraph object is an object to store different OGraphic objects, with structuring links between objects. The following function gives an example of OGraph use to create and write an arc with its center, and radius.
    void graphArc()
    {
            OGraph *o = new OGraph();
            OPoint ptb(50,50),ptc(100,50),pte(100,100);
            //draw center
            o->newNode(new OPoint(ptc.getX(),ptc.getY()));
            //draw radius
            o->newNode(new OLine(ptb,ptc));
            o->newNode(new OLine(ptc,pte));
            //draw arc
            o->newNode(new OArc(ptb,ptc,pte,false));
            //edge
            o->newEdge(0,1);
            o->newEdge(0,2);
            o->newEdge(1,3);
            o->newEdge(1,3);
            o->print();
            gomWrite(o,"es.gom");
            xmlWrite(o,"es.xml");
            svgWrite(o,"es.svg");
            o->~OGraph();
    }       //de
The OGraph object contains a OGraphic* array (deque). So, OGraph uses only OGraphic types. To copy an OGraph you must use the OHL::clone() function like this:

    void graphCopy()
    {
            //graph create
            OGraph *o = new OGraph();
            o->newNode(new OPoint(1,1));
            o->newNode(new OPoint(5,5));
            o->newEdge(0,1);
            //graph copy
            OGraphic *oc = o->clone();
            o->~OGraph();
            oc->print();
            oc->~OGraphic();
    }       //de
In a same way, when you add some objects to an OGraph you must clone these objects like this:

    void graphWrite()
    {
            {
            OGraph *o1 = new OGraph();
            OGraph *o2 = new OGraph();
            OGraphic* p;
            p = new OPoint(1,1);
            o1->newNode(p);
            o2->newNode(p);
            p = new OPoint(5,5);
            o1->newNode(p);
            o2->newNode(p);
            o1->newEdge(0,1);
            o2->newEdge(0,1);
            o1->~OGraph(); //free memory ok
            //o2->~OGraph(); //error
            }
            {
            OGraph *o1 = new OGraph();
            OGraph *o2 = new OGraph();
            OGraphic* p;
            p = new OPoint(1,1);
            o1->newNode(p);
            o2->newNode(p->clone());
            p = new OPoint(5,5);
            o1->newNode(p);
            o2->newNode(p->clone());
            o1->newEdge(0,1);
            o2->newEdge(0,1);
            o1->~OGraph(); //free memory ok
            o2->~OGraph(); //free memory ok
            }
    }       //de
If you want to replace some object, you can use the OGraph::objectPush() and OGraph::objectWrite() functions like this:

    void graphPush()
    {
            {
            OGraph *o = new OGraph();
            o->newNode(new OPoint(1,1));
            o->newNode(new OPoint(5,5));
            o->newEdge(0,1);
            o->objectWrite(new OPoint(6,6),0); //bad case, you don't delete the 1;1 point
            o->~OGraph();
            }
            {
            OGraph *o = new OGraph();
            o->newNode(new OPoint(1,1));
            o->newNode(new OPoint(5,5));
            o->newEdge(0,1);
            o->objectRead(0)->~OGraphic();
            o->objectWrite(new OPoint(6,6),0); //good case, you delete the 1;1 point
            o->~OGraph();
            }
            {
            OGraph *o = new OGraph();
            o->newNode(new OPoint(1,1));
            o->newNode(new OPoint(5,5));
            o->newEdge(0,1);
            o->objectPush(new OPoint(6,6),0); //good case, you delete the 1;1 point
            o->~OGraph();
            }
    }       //de

Generated on Fri Jul 30 19:21:03 2004 for GOMLib by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001