<div dir="ltr"><div><div>//The NODE and the WHEEL of NODES<br>//Written By Billy Stiltner COPYRIGHT 1996 Billy Stiltner<br>/*/<br>Copyright (C) 1995  Billy Stiltner<br><br>This program is free software; you can redistribute it and/or<br>modify it under the terms of the GNU General Public License<br>as published by the Free Software Foundation; <br><br>This program is distributed in the hope that it will be useful,<br>but WITHOUT ANY WARRANTY; without even the implied warranty of<br>MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>GNU General Public License for more details.<br><br>You should have received a copy of the GNU General Public License<br>along with this program; if not, write to the Free Software<br>Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.<br>/*/<br>//#include<alloc.h><br>//This is a very simple set of classes for a Node and List <br>///////////////////////////////////////////////////////////////////<br>unsigned long nexusconstructors;<br>unsigned long roticonstructors;<br>unsigned long nexusdestructors;<br>unsigned long rotidestructors;<br>class NEXUS;<br>typedef void (NEXUS::*pMF)();<br>//typedef class *pC;<br><br>class NEXUS<br>{<br>public:<br>//data members<br>NEXUS *next;<br>NEXUS *previous;<br>//member functions<br>NEXUS();<br>NEXUS *GET_NEXT();<br>NEXUS *operator ++();<br>NEXUS *operator --();<br>//NEXUS *operator +(int n);<br>//NEXUS *operator -(int n);<br>int IS_PRIMUS();<br>int IS_MAXIMUS();<br>int IS_INTERNEXUS();<br>int IS_UNUSNEXUS();<br>virtual ~NEXUS();<br>};<br>///////////////////////////////////////////////////////////////////     .<br><br><br>///////////////////////////////////////////////////////////////////////////<br>class ROTI : public NEXUS<br>{<br>public:<br> //data members<br> NEXUS *PRIMUS;<br> NEXUS *MAXIMUS;<br> NEXUS *PROXIMUS;<br> NEXUS *BUFF;<br> //member functions<br> ROTI();<br> void PUT_PRIMUS(NEXUS *p);<br> void PUT_MAXIMUS(NEXUS *p);<br> void PUT_BEFORE_PROXIMUS(NEXUS *p);<br> void PUT_AFTER_PROXIMUS(NEXUS *p);<br> void PUT_BEFORE_NEXUS(NEXUS *p,NEXUS *q);<br> void PUT_AFTER_NEXUS(NEXUS *p,NEXUS *q);<br> void XFER(NEXUS *n,ROTI *r);<br> void DELETE_NEXUS(NEXUS *p);<br> void FOR_EACH(pMF pFunc);<br> void EXTRACT_NEXUS(NEXUS *p);<br>~ROTI();<br>};<br>/////////////////////////////////////////////////////////////////////<br><br><br>///////////////////////////////////////////////////////////////////////////<br>NEXUS::NEXUS()<br>{<br>//nexusconstructors++;<br>next=NULL;<br>previous=NULL;<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>//////////////////////////////////////////////////////////////////////////////<br>int NEXUS::IS_PRIMUS()<br>{<br>if((previous==NULL)&&(next!=NULL))<br>return(1);else return(0);<br>}<br>//////////////////////////////////////////////////////////////////////////////<br><br>//////////////////////////////////////////////////////////////////////////////<br>int NEXUS::IS_MAXIMUS()<br>{<br>if((next==NULL)&&(previous!=NULL))<br>return(1);else return(0);<br>}<br>//////////////////////////////////////////////////////////////////////////////<br><br>//////////////////////////////////////////////////////////////////////////////<br>int NEXUS::IS_INTERNEXUS()<br>{<br>if((previous!=NULL)&&(next!=NULL))<br>return(1);else return(0);<br>}<br>//////////////////////////////////////////////////////////////////////////////<br><br>//////////////////////////////////////////////////////////////////////////////<br>int NEXUS::IS_UNUSNEXUS()<br>{<br>if((previous==NULL)&&(next==NULL))<br>return(1);else return(0);<br>}<br>//////////////////////////////////////////////////////////////////////////////<br><br><br>///////////////////////////////////////////////////////////////////////////<br>NEXUS *NEXUS::GET_NEXT()<br>{ // NEXUS *j;<br>//j=this->next;<br>return(next);<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>inline NEXUS *NEXUS::operator ++()<br>{ // NEXUS *j;<br>//j=this->next;<br>return(next);<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>inline NEXUS *NEXUS::operator --()<br>{<br>return(previous);<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>/*///////////////////////////////////////////////////////////////////////////<br>inline NEXUS *NEXUS::operator +(int n)<br>{<br> int c;<br> NEXUS *np;<br>np=this;<br>if(np!=NULL)<br>{<br> for(c=0;c<n;c++)<br>     {<br>      np=np->next;<br>      if(np==NULL)break;<br>      };<br>};<br>return(np);<br>};<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>inline NEXUS *NEXUS::operator -(int n)<br>{<br> int c;<br> NEXUS *np;<br>np=this;<br>if(np!=NULL)<br>{<br> for(c=0;c<n;c++)<br>     {<br>      np=np->previous;<br>      if(np==NULL)break;<br>      };<br>};<br>return(np);<br>};<br>//*/////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>NEXUS::~NEXUS()<br>{<br>//nexusdestructors++;<br>//cout<<"IN NEXUS Destructor"<<"\n";<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>////////////////////////////////////////////////////////////////////////////<br>ROTI::ROTI():NEXUS()<br>{<br>//roticonstructors++;<br> PRIMUS=NULL;<br> MAXIMUS=NULL;<br> PROXIMUS=NULL;<br> BUFF=NULL;<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////<br>void ROTI::PUT_PRIMUS(NEXUS *p)<br>{<br> p->next = PRIMUS;<br> p->previous = NULL;<br> if(!p->IS_UNUSNEXUS()){<br> p->next->previous = p;<br> }else{<br>        MAXIMUS = p;<br>        };<br> PRIMUS = p;<br>}<br>////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////<br>void ROTI::PUT_MAXIMUS(NEXUS *p)<br>{<br> p->previous = MAXIMUS;<br> p->next = NULL;<br> if(!p->IS_UNUSNEXUS()){<br> p->previous->next = p;<br> }else{<br>        PRIMUS = p;<br>        };<br> MAXIMUS = p;<br>}<br>///////////////////////////////////////////////////////////////////<br><br>////////////////////////////////////////////////////////////////////////////<br>void ROTI::PUT_BEFORE_PROXIMUS(NEXUS *p)<br>{<br>if(PROXIMUS!=NULL)PUT_BEFORE_NEXUS(p,PROXIMUS);<br>}<br>////////////////////////////////////////////////////////////////////////////<br><br>////////////////////////////////////////////////////////////////////////////<br>void ROTI::PUT_AFTER_PROXIMUS(NEXUS *p)<br>{<br>if(PROXIMUS!=NULL)PUT_AFTER_NEXUS(p,PROXIMUS);<br>}<br>////////////////////////////////////////////////////////////////////////////<br><br>////////////////////////////////////////////////////////////////////////////<br>void ROTI::PUT_BEFORE_NEXUS(NEXUS *p,NEXUS *q)<br>{<br>if(q!=NULL)<br>  {<br>    if((q->IS_INTERNEXUS())||(q->IS_MAXIMUS()))<br>      {<br>        p->next=q;<br>        p->previous=q->previous;<br>        q->previous->next=p;<br>        q->previous=p;<br>      }else{<br>      if(q->IS_PRIMUS())PUT_PRIMUS(p);<br>      }<br>  }<br>}<br>////////////////////////////////////////////////////////////////////////////<br><br>////////////////////////////////////////////////////////////////////////////<br>void ROTI::PUT_AFTER_NEXUS(NEXUS *p,NEXUS *q)<br>{<br>if(q!=NULL)<br>  {<br>  if((q->IS_INTERNEXUS())||(q->IS_PRIMUS()))<br>     {<br>      p->previous=q;<br>      p->next=q->next;<br>      q->next->previous=p;<br>      q->next=p;<br>     }else{<br>      if(q->IS_MAXIMUS())PUT_MAXIMUS(p);<br>     }<br>  }<br>}<br>////////////////////////////////////////////////////////////////////////////<br><br>////////////////////////////////////////////////////////////////////////////<br>void ROTI::XFER(NEXUS *n,ROTI *r)<br>{<br> //-+EXTRACT_NEXUS(n);<br> r->PUT_MAXIMUS(n);<br>}<br>////////////////////////////////////////////////////////////////////////////<br><br>////////////////////////////////////////////////////////////////////////////<br>//REMOVES NEXUS FROM ROTI AND DELETES NEXUS<br>void ROTI::DELETE_NEXUS(NEXUS *p)<br>{<br>if((p->next!=NULL)&&(p->previous!=NULL)) //if p is between<br>{<br> p->previous->next=p->next;//adjust previous<br> p->next->previous=p->previous;//adjust next<br> if(PROXIMUS==p)PROXIMUS=p->next; //if p was PROXIMUS make next PROXIMUS<br> if(p!=NULL)delete p;//delete p<br> return;<br>}<br>if(p->next==NULL)<br>{<br> MAXIMUS=p->previous;<br> p->previous->next=NULL;<br> if(PROXIMUS==p)<br> {<br> if(p->previous==NULL){<br>    PROXIMUS=NULL;}else{PROXIMUS=p->previous;}<br> }<br>    if(p!=NULL)delete p;<br>    return;<br>}<br><br>if(p->previous==NULL)<br>{<br> PRIMUS=p->next;<br> p->next->previous=NULL;<br> if(PROXIMUS==NULL)<br> {<br>  if(p->next==NULL){<br>         PROXIMUS=NULL;}else{PROXIMUS=p->next;}<br> }<br>    if(p!=NULL)delete p;<br> return;<br>}<br>//if(p->pPORTAL!=NULL)delete p->pPORTAL;<br>}<br>//////////////////////////////////////////////////////////////////////////<br><br>//////////////////////////////////////////////////////////////////////////<br>//EXTRACTS A NEXUS FROM LIST WITHOUT DELETING<br>void ROTI::EXTRACT_NEXUS(NEXUS *p)<br>{<br> if(p->previous==NULL){<br>     PRIMUS=p->next;<br>     p->next->previous=NULL;<br>     }<br> if(p->next==NULL){<br>     MAXIMUS=p->previous;<br>     p->previous->next=NULL;<br>     }<br> if((p->next!=NULL)&&(p->previous!=NULL)){<br> p->previous->next=p->next;<br> p->next->previous=p->previous;<br> }<br>}<br>//////////////////////////////////////////////////////////////////////////<br><br>//////////////////////////////////////////////////////////////////////////<br>void ROTI::FOR_EACH(pMF pFunc)<br>{<br> if((PRIMUS!=NULL)&&(MAXIMUS!=NULL))//if not emptty<br> for(NEXUS *current=PRIMUS;         //start on PRIMUS<br>      current!=NULL;                 //Stop after Maximus<br>      current=++(*current))          //increment current<br> (current->*pFunc)();               //call current function<br><br><br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>ROTI::~ROTI()<br>{<br>//rotidestructors++;<br>//cout<<"\n"<<"IN ROTI Destructor"<<"\n";<br>/*/<br>//roti can only be a base class and nexus can only be a base class<br>if(PRIMUS!=NULL)<br> {<br> NEXUS *NEXT;<br>  NEXUS* current = PRIMUS;<br>  for(;;)<br>      {<br>      NEXT=current->next;<br>        if(current!=NULL)delete current;<br>        if(current == NULL)break;<br>        current=NEXT;<br>      };<br>  };<br> /*/<br>}<br>///////////////////////////////////////////////////////////////////<br></div><br>I know Miller doesn't use c++, <br></div>I only use a limited subset of c++<br><div><div><br></div><div>here is the above code used in more code<br></div><div>I would like to know how do do this in c<br></div><div>about the only thing I used c++ for is <br></div><div>object oriented programming so that data of classes could have functions associated with them, the inheritance model i used might be a bit hard to follow then there is the problem of using borland style macros which simplifies defining member functions , it was something dreamed up in the development of borland's visual studio so that windows programs could be visually written, kind of how puredata is a visusual programming environment except the 2 approaches are very different.<br></div><div>What are the differences?<br><br>/*/<br>Impulse.h See below for description.<br>Copyright (C) 1995  Billy Stiltner<br><br>This program is free software; you can redistribute it and/or<br>modify it under the terms of the GNU General Public License<br>as published by the Free Software Foundation; either version 2<br>of the License,<br><br>This program is distributed in the hope that it will be useful,<br>but WITHOUT ANY WARRANTY; without even the implied warranty of<br>MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>GNU General Public License for more details.<br><br>You should have received a copy of the GNU General Public License<br>along with this program; if not, write to the Free Software<br>Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.<br>/*/<br><br>//The classes herein can be used together to provide a basis for a<br>//response mechanism.<br>//<br>//The impulse is a node based object.<br>//<br>//The Reactor is a list based object.<br>//<br>//The Coordinator is used as a wrapper in that it maintains two Reactors,<br>//an ACTIVE Reactor, and an INACTIVE Reactor so that responses can be<br>//loaded and unloaded hence DYNAMIC RESPONSE LOADING (DRL).<br>//<br>//The Coordinator can make reflexes and responses.<br>//<br>//The impulse is a dual natured class, it can be a reflex or a response.<br>//<br>//The reflex is created with a pointer to a variable uint *Var, a uint<br>//Condition, and a pMF pFunc. HOW IT WORKS: reflex's VAR is set to Var,<br>//CONDITION is set to Condition, and RESPOND is set to pFunc, if *VAR,<br>//wherever it may be, is equal to CONDITION, whatever it may be, RESPOND,<br>//whatever it does, is CALLED.<br>//<br>//The response is created with a uint Message and a pMF pFunc. HOW IT WORKS:<br>//response's CONDITION is set to Message and RESPOND is set to pFunc, *VAR<br>//must be provided at response time if *VAR = CONDITION then RESPOND is CALLED.<br>//<br>//The Reactor maintains reflexes and responses, it can only hold one<br>//type of impulse, but can hold as many as there is memory to put them.<br>//<br>//<br>//include files//////////////////////////////////////////////////////////////<br>//#include<objects.h><br>//#include<nexus.h><br>//#include"c:\program\svga\objects.h"<br>/////////////////////////////////////////////////////////////////////////////<br><br>//defines////////////////////////////////////////////////////////////////////<br>#define TORPID 0L<br>#define AWAKE 1L<br>/////////////////////////////////////////////////////////////////////////////<br><br>//variables//////////////////////////////////////////////////////////////////<br>unsigned long impulseconstructors;<br>unsigned long coordinatorconstructors;<br>unsigned long impulsedestructors;<br>unsigned long coordinatordestructors;<br>/////////////////////////////////////////////////////////////////////////////<br><br>//classes////////////////////////////////////////////////////////////////////<br>class impulse:  public NEXUS<br>{<br> public://access modifier<br>//data members///////////////////////////////////////////////////////////////<br> pMF RESPOND;                   //*function to call if message = CONDITION<br> unsigned int *VAR;             //unsigned int pointer to a variable to check<br> unsigned int CONDITION;        //value to compare condition with<br>//member functions///////////////////////////////////////////////////////////<br> //impulse();                             //default constructor sets all to NULL<br> impulse(impulse *i);                   //constructer using impulse *<br> impulse(unsigned int Message,          //consructor to make a response<br>     pMF pFunc);<br> impulse(unsigned int *Var,             //consructor to make a reflex<br>     unsigned int Condition,<br>     pMF pFunc);<br> void makeresponse(unsigned int Message,//function to make a response<br>            pMF pFunc);<br> void makereflex(unsigned int *Var,     //function to make a reflex<br>         unsigned int Condition,<br>         pMF pFunc);<br> void respond(NEXUS *pN);               //function to call when responding<br><br> ~impulse();                   //destructor<br>};<br>/////////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>class Reactor : public ROTI<br>{<br>public:<br> //data members<br> //member functions<br> Reactor();<br> //void DefineResponse(impulse *im);<br>  impulse *DefineReflex(unsigned int *Var,<br>             unsigned int Condition,<br>             pMF pFunc);<br>  impulse *DefineResponse(unsigned int Message,<br>              pMF pFunc);<br>  virtual void Reflex(NEXUS *pN);<br>  virtual void Respond(MSG *Msg,NEXUS *pN);<br>  ~Reactor();<br>};<br>////////////////////////////////////////////////////////////////////////////<br><br><br>/////////////////////////////////////////////////////////////////////<br>class Coordinator<br>{<br>public:<br>Reactor *ACTIVE;<br>Reactor *INACTIVE;<br>Coordinator();<br>impulse *MakeReflex(unsigned int *Var,<br>             unsigned int Condition,<br>             pMF pFunc);<br>impulse *MakeResponse(unsigned int Message,<br>              pMF pFunc);<br>void Activate(impulse *i);<br>void Deactivate(impulse *i);<br>virtual void Reflex(NEXUS *pN);<br>virtual void Respond(MSG *Msg,NEXUS *pN);<br>~Coordinator();<br>};<br>////////////////////////////////////////////////////////////////////<br><br>//SUGGESTION:<br>//make a member of class x<br><br>// x::MakeResponseTable()<br>// {<br>// DEFINE_RESPONSE(x,MessageId,NameOfFunctionCalledInResponseToMessageId);<br>// etc...<br>// }<br>////////////////////////////////////////////////////////////////////////<br>#define DEFINE_RESPONSE(classname,\<br>            imessage,\<br>            ifunctionname)\<br>    DefineResponse(imessage,\<br>                 (pMF)&classname::ifunctionname);<br>//////////////////////////////////////////////////////////////////////////<br><br>//////////////////////////////////////////////////////////////////////////<br>#define DEFINE_REFLEX(classname,\<br>                nvar,\<br>                ncondittion,\<br>                nfunctionname)\<br>    DefineReflex(nvar,\<br>              ncondittion,\<br>              (pMF)&classname::nfunctionname);<br>//////////////////////////////////////////////////////////////////////////<br><br>////////////////////////////////////////////////////////////////////////<br>#define MAKE_RESPONSE(classname,\<br>            imessage,\<br>            ifunctionname)\<br>    MakeResponse(imessage,\<br>                 (pMF)&classname::ifunctionname);<br>//////////////////////////////////////////////////////////////////////////<br><br>//////////////////////////////////////////////////////////////////////////<br>#define MAKE_REFLEX(classname,\<br>                nvar,\<br>                ncondittion,\<br>                nfunctionname)\<br>    MakeReflex(nvar,\<br>              ncondittion,\<br>              (pMF)&classname::nfunctionname);<br>//////////////////////////////////////////////////////////////////////////<br><br>////////////////////////////////////////////////////////////////////////////<br>impulse::impulse(unsigned int Message,pMF pFunc) : NEXUS()<br>{  // void (impulse::*pFunc)()):NEXUS()<br>impulseconstructors++;<br>CONDITION=Message;<br>RESPOND=pFunc;<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>impulse::impulse(impulse *i):NEXUS()<br>{<br>impulseconstructors++;<br>RESPOND=i->RESPOND;<br>VAR=i->VAR;<br>CONDITION=i->CONDITION;<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>//impulse::impulse():NEXUS()<br>//{<br>//impulseconstructors++;<br>//VAR=NULL;<br>//CONDITION=NULL;<br>//RESPOND=NULL;<br>//};<br>///////////////////////////////////////////////////////////////////////////<br><br>////////////////////////////////////////////////////////////////////////////<br>impulse::impulse(unsigned int *Var,<br>             unsigned int Condition,<br>             pMF pFunc):NEXUS()<br>{<br>impulseconstructors++;<br>VAR=Var;<br>CONDITION=Condition;<br>RESPOND=pFunc;<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>void impulse::makeresponse(unsigned int Message, pMF pFunc)<br>{<br>CONDITION=Message;<br>RESPOND=pFunc;<br>VAR=NULL;<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>void impulse::respond(NEXUS *pN)<br>{<br> (pN->*RESPOND)();//This works but all RESPOND functions must be NEXUS<br> //(this->*RESPOND)();<br> //RESPOND();<br> //return(RESPOND);<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>impulse::~impulse()<br>{<br>impulsedestructors++;<br>//cout<<"\n"<<"IN impulse Destructor"<<"\n";<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>void impulse::makereflex(unsigned int *Var,<br>              unsigned int Condition,<br>              pMF pFunc)<br>{<br>VAR=Var;<br>CONDITION=Condition;<br>RESPOND=pFunc;<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>////////////////////////////////////////////////////////////////////////////<br>Reactor::Reactor():ROTI()<br>{<br>coordinatorconstructors++;<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////<br>impulse * Reactor::DefineResponse(unsigned int Message,<br>                 pMF pFunc)<br>{<br> impulse* newimpulse = new impulse(Message,pFunc);<br> PUT_MAXIMUS(newimpulse);<br> return(newimpulse);<br>}<br>///////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////<br><br>impulse * Reactor::DefineReflex(unsigned int *Var,<br>                unsigned int Condition,<br>                pMF pFunc)<br>{<br> impulse* newnatural = new impulse(Var,Condition,pFunc);<br> PUT_MAXIMUS(newnatural);<br> return(newnatural);<br>}<br>///////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>void Reactor::Respond(MSG *Msg,NEXUS *pN)<br>{<br>if(PRIMUS!=NULL)<br> {<br>  impulse* current = (impulse *)PRIMUS;<br>  for(;;)<br>      {<br>        if(current->CONDITION==Msg->message){<br>        current->respond(pN);<br>        break;<br>        }<br>        if(current->next == NULL)break;<br>        current=(impulse *)current->next;<br>      }<br>  }<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>void Reactor::Reflex(NEXUS *pN)<br>{<br>if(PRIMUS!=NULL)<br> {<br>  impulse* current =(impulse *) PRIMUS;<br>  for(;;)<br>      {<br>        if(current->CONDITION==*(current->VAR)){<br>        current->respond(pN);<br>        }<br>        if(current->next == NULL)break;<br>        current=(impulse *)current->next;<br>      }<br>  }<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>Reactor::~Reactor()<br>{<br>coordinatordestructors++;<br><br>if((PRIMUS!=NULL)&&(MAXIMUS!=NULL))//if not emptty<br>for(NEXUS *current=PRIMUS;         //start on PRIMUS<br>     current!=NULL;                 //Stop after Maximus<br>     current=++(*current))          //increment current<br>delete current;<br>//cout<<"\n"<<"IN Reactor Destructor"<<"\n";<br>//NEXUS* NEXT;<br>//NEXUS* current = PRIMUS;//IDLE->PRIMUS;<br>//if(PRIMUS!=NULL)//IDLE->PRIMUS!=NULL)<br> //{<br>  //for(;;)<br>     // {<br>     // NEXT=current->next;<br>     //    if(current!=NULL)delete current;<br>      //    if(current == NULL)break;<br>      //    current=NEXT;<br>      //    }<br>  //}<br>}<br>///////////////////////////////////////////////////////////////////<br><br>Coordinator::Coordinator()<br>{<br>ACTIVE=new Reactor();<br>INACTIVE=new Reactor();<br>}<br>///////////////////////////////////////////////////////////////////<br>impulse * Coordinator::MakeResponse(unsigned int Message,<br>                 pMF pFunc)<br>{<br> impulse* newimpulse = ACTIVE->DefineResponse(Message,pFunc);<br> return(newimpulse);<br>}<br>///////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////<br>impulse * Coordinator::MakeReflex(unsigned int *Var,<br>                unsigned int Condition,<br>                pMF pFunc)<br>{<br> impulse *newreflex;<br> newreflex=ACTIVE->DefineReflex(Var,Condition,pFunc);<br> return(newreflex);<br>}<br>/////////////////////////////////////////////////////////////////////////////<br><br>/////////////////////////////////////////////////////////////////////////////<br>void Coordinator::Activate(impulse *i)<br>{<br>//this method of activation is slower than another type that would take<br>//up more memory so this type takes up less memory<br>//so this is the small slow version<br>//1 see if i is inactive<br>//2 see if i is already active<br>impulse *current;<br>//iterate through the inactive list<br>for(current=(impulse *)INACTIVE->PRIMUS;<br>     current!=NULL;<br>     current=(impulse *)current->next)<br>//see if i is in here<br>if(i==current)<br>{<br>//if so iterate through the active list<br>for(current=(impulse *)ACTIVE->PRIMUS;<br>     current!=NULL;<br>     current=(impulse *)current->next)<br>     if(i==current)return;//get out if i is already in the active  list<br>     //if we made it here i aint already active<br>INACTIVE->EXTRACT_NEXUS(i);//if not active get i out of inactive list<br>ACTIVE->PUT_MAXIMUS(i);//and put i in active list<br>break;<br>}<br>}<br>/////////////////////////////////////////////////////////////////////////////<br><br><br>/////////////////////////////////////////////////////////////////////////////<br>void Coordinator::Deactivate(impulse *i)<br>{<br>//1 see if i is active<br>//2 see if i is already inactive<br>impulse *current;<br>for(current=(impulse *)ACTIVE->PRIMUS;<br>     current!=NULL;<br>     current=(impulse *)current->next)<br>if(i==current)<br>{<br>for(current=(impulse *)INACTIVE->PRIMUS;<br>     current!=NULL;<br>     current=(impulse *)current->next)if(i==current)return;<br>ACTIVE->EXTRACT_NEXUS(i);<br>INACTIVE->PUT_MAXIMUS(i);<br>break;<br>}<br>}<br><br><br>///////////////////////////////////////////////////////////////////////////<br>void Coordinator::Respond(MSG *Msg,NEXUS *pN)<br>{<br> ACTIVE->Respond(Msg,pN);<br>};<br>///////////////////////////////////////////////////////////////////////////<br><br>///////////////////////////////////////////////////////////////////////////<br>void Coordinator::Reflex(NEXUS *pN)<br>{<br> ACTIVE->Reflex(pN);<br>}<br>///////////////////////////////////////////////////////////////////////////<br><br><br>Coordinator::~Coordinator()<br>{<br>if(ACTIVE!=NULL)delete ACTIVE;<br>if(INACTIVE!=NULL)delete INACTIVE;<br>}<br><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 31, 2017 at 8:44 AM, Billy Stiltner <span dir="ltr"><<a href="mailto:billy.stiltner@gmail.com" target="_blank">billy.stiltner@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>i dont like tree structures at the moment<br></div>but here ya go<br>void Spider(xTreeItem CurrentItem)<br>{<br>    int s;<br>    CString spaces;<br>    CString xStr;<br>    //There Could Probably Be More Vars Here To Save Space<br>    //Down There...  There Also Needs To Be Some Space<br>    //Generating Loop Code Put Into A Function <br><br>    //CurrentItem Is Either A Branch Or A Leaf<br>    //The Processing Of CurrentItem Will Be Different <br>    //For Each State Of CurrentItem<br>    if(CurrentItem.IsBranch())<br>    {<br>        CString currentpath;<br>        CString currenturl;<br>        <br>        //Set Up All The Path Variables And File Names<br>        //And Levels<br>        CurrentLevel ++;<br>        currentpath = BasePath;<br>        currenturl = BaseURL;    <br>        CurrentItem.FileName = "index.txt";<br>        CurrentItem.Level = CurrentLevel;            <br>        DirectoryL[CurrentLevel] = CurrentItem.Directory;<br>        <br>        for(int l = 1; l <= CurrentLevel; l ++)<br>        {<br>            currentpath += "\\" + DirectoryL[l];<br>            currenturl += "/" + DirectoryL[l];     <br>        }<br><br>        CurrentItem.LocalHtmlPath=<wbr>currentpath + "\\index.html";<br>        CurrentItem.Url = currenturl + "/index.html";<br>        currentpath += "\\index.txt";<br>        <br>        //Add This Branch Item To The Flat List<br>        xTreeItems.Add(xTreeItem(<wbr>CurrentItem));<br><br>        spaces = MakeSpace(CurrentLevel);<br>        TocFile.WriteString(spaces);//<wbr>Toc File Was Opened For Append Each<br>                                 //Write To Eat Bugs<br>        <br>        //Start A New Division<br>        TocFile.WriteString("<UL>\n<<wbr>LI>\n");<br>        TocFile.WriteString(<wbr>CurrentItem.MakeSiteMapObject(<wbr>));<br>        <br>        //This Is A New Branch So Keep Spidering<br>        InputIndexFile[CurrentLevel].<wbr>Open(currentpath, <br>                            CFile::modeRead | <br>                            CFile::typeText);<br>        HtmlOutputFile[CurrentLevel].<wbr>Open(CurrentItem.<wbr>LocalHtmlPath,<br>                            CFile::modeCreate | <br>                            CFile::modeWrite | CFile::typeText );<br>        //Start A Fresh Html Page<br>        HtmlOutputFile[CurrentLevel].<wbr>WriteString("<HTML>\n<Body>\n"<wbr>);<br>        <br>        //Create A Link From The Entry<br>        HrefL[CurrentLevel] = CurrentItem.MakeHref();<br><br>        //Make A Line Hrefs That Link To The Parent Level(s)<br>        CString DirectoryBar;<br>        DirectoryBar="";<br>        for(int h = 1; h < CurrentLevel; h++)<br>        {<br>            DirectoryBar += HrefL[h] + " / ";<br>        }<br><br>        //Put The DirectoryBar On The Page<br>        HtmlOutputFile[CurrentLevel].<wbr>WriteString(DirectoryBar + <br>                                            CurrentItem.Name + <br>                                            "<BR><BR>\n");<br>        <br>        //If This Is Not The Root<br>        if(CurrentLevel > 1)<br>        {<br>            //Then Put A Link To This Page <br>            //On This Item's Parent's Page<br>            HtmlOutputFile[CurrentLevel - 1].WriteString(<br>                                            CurrentItem.MakeHref() +<br>                                             "<BR>\n");<br>        }<br>        <br>        <br>        for(;;)<br>        {<br>            //If We Don't Hit EOF Spider Recursively    <br>            if(InputIndexFile[<wbr>CurrentLevel].ReadString(xStr)<wbr>)<br>            {<br>                xTreeItem NewTreeItem;<br>                NewTreeItem.InitFromTxtEntry(<wbr>xStr);<br>                Spider(NewTreeItem);    <br>            }<br>            //If We Do Hit EOF <br>            else<br>            {        <br>                //Close This Division<br>                TocFile.WriteString("</UL>\n")<wbr>;<br><br>                //Close This Input File<br>                InputIndexFile[CurrentLevel].<wbr>Close();<br><br>                //This Could Be A (Nifty Page Ground)<br>                //HtmlOutputFile[CurrentLevel]<wbr>.WriteString(themeFooter);<br><br>                //Close The Html And Body Tags And The File<br>                HtmlOutputFile[CurrentLevel].<wbr>WriteString(<br>                                            "</Body>\n</Html>\n");<br>                HtmlOutputFile[CurrentLevel].<wbr>Close();<br><br>                //Decrement The CurrentLevel And Break Out Of The Loop<br>                //So We Can Return To Whence We Came Which Was <br>                //Probably Up There Where It Says Spider(NewTreeItem);<br>                CurrentLevel --;<br>                break;<br>                //Maybe This Is Where The Recursive Action Ends Hmmm...<br>                //All Those pMFs Pushed On The Stack Get Popped Right<br>                //Back On To IP... OH Wait The Class This Function Used <br>                //To Belong To Has Probably Been Removed For The Sake<br>                //Of Simpleness So pFs If So<br>            }<br>        }    <br>    }<br>    //Here Is Where The Leaf Gets Processed<br>    else<br>    {<br>        //First We Need To Make Sure CurrentItem Has A URL    <br>        if(CurrentItem.Url)<br>        {<br>            xTreeItem LeafTreeItem;<br>            LeafTreeItem.copy(CurrentItem)<wbr>;<br>            <br>            //The Leaf Is As Far As The Spider Will Crawl<br>            //So There's No Need To Increment The CurrentLevel <br>            //Just Set The LeafTreeItem's Level To CurrentLevel + 1<br>            LeafTreeItem.Level = CurrentLevel + 1;<br>            <br>            //Ah Add The Item To The Flat List<br>            xTreeItems.Add(xTreeItem(<wbr>LeafTreeItem));    <br>            <br>            //Nothing Done With Spaces Yet Here<br>            //Need To Standardize And Functionize The TocFile Writes<br>            spaces = MakeSpace(CurentLevel + 1);<br>            <br>            //Start A New Division I The Toc And Put This Item <br>            //In As The Head Of The Division<br>            TocFile.WriteString("<UL>\n<<wbr>LI>\n");<br>            TocFile.WriteString(<wbr>LeafTreeItem.<wbr>MakeSiteMapObject());<br><br>            <br>            //Throw It In It's Parent's List Of Links<br>            HtmlOutputFile[CurrentLevel].<wbr>WriteString(LeafTreeItem.<wbr>MakeHref() +<br>                                                 "<BR>\n");<br>            <br>            //Loop Through The Rest Of The File<br>            //Here Is Where It's Assumed That All<br>            //Items That Follow Are Leaves<br>            //This Is Fine For Our DirectoryTree Spider<br>            //Where All The Links In The Deepest Folder<br>            //Are Outside Of The Crawler's Space<br>            //But Not For A Web Crawler<br>            for(;;)<br>            {<br>                <br>                if(InputIndexFile[<wbr>CurrentLevel].ReadString(xStr)<wbr>)<br>                {<br>                    //Again As Above<br>                    LeafTreeItem.InitFromTxtEntry(<wbr>xStr);<br>                    LeafTreeItem.Level = CurrentLevel + 1;<br>                    <br>                    xTreeItems.Add(xTreeItem(<wbr>LeafTreeItem));        <br><br>                    //Those Spaces Again<br>                    spaces = MakeSpace(CurrentLevel + 1);<br>                    <br>                    //We Are Allready In A Division So Just<br>                    //Make A New Entry<br>                    TocFile.WriteString("<LI>\n");<wbr>        <br>                    TocFile.WriteString(<wbr>LeafTreeItem.<wbr>MakeSiteMapObject());<br>                    <br>                    //Throw It In It's Parent's List Of Links<br>                    HtmlOutputFile[CurrentLevel].<wbr>WriteString(<br>                                  LeafTreeItem.MakeHref() + "<BR>\n");<br>                }<br>                else<br>                {<br>                    //Close The Division... We Ran Out Of File                    <br>                    TocFile.WriteString("</UL>\n")<wbr>;<br><br>                    //Get Out Of The Loop And Return To Next Line Of Caller<br>                    //Which Was Probably This Very Function                <br>                    break;<br><br>                    //This Could Be Where The Recursive Action Ends<br>                    //Nah I Think It's Up There At The Branch Break<br>                    //Cause You Have To Start The Spider On A Branch<br>                    //Unless The Spider Drops From Another Tree And<br>                    //Lands On A Leaf<br>                }<br>                <br>            }<br>        }        <br>    }<br>}<br><br></div>more on the spider later<br><a href="http://geocities.ws/billy_stiltner/code/OSOS-3_25_am_06_06_02.zip" target="_blank">http://geocities.ws/billy_<wbr>stiltner/code/OSOS-3_25_am_06_<wbr>06_02.zip</a><br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 30, 2017 at 9:28 AM, Christof Ressi <span dir="ltr"><<a href="mailto:christof.ressi@gmx.at" target="_blank">christof.ressi@gmx.at</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>> If it was possible to have an array of pointers,<br>
<br>
</span>I get your idea. You can already have [list]s of pointers but this is rather cumbersome. Sometimes I've wished that pointers could be fields in structs (don't know why that's not possible...). Together with a mechanism to compare pointers (right now you can only route them by their type) these could indeed add some new possibilities.<br>
<br>
Gesendet: Mittwoch, 29. März 2017 um 15:37 Uhr<br>
Von: "José de Abreu" <<a href="mailto:abreubacelar@gmail.com" target="_blank">abreubacelar@gmail.com</a>><br>
An: "Derek Kwan" <<a href="mailto:derek.x.kwan@gmail.com" target="_blank">derek.x.kwan@gmail.com</a>>, "Christof Ressi" <<a href="mailto:christof.ressi@gmx.at" target="_blank">christof.ressi@gmx.at</a>>, <a href="mailto:pd-list@lists.iem.at" target="_blank">pd-list@lists.iem.at</a><br>
<span>Betreff: Re: [PD] [text define] functionality for text in structs?<br>
</span><span>Hello, this is my first e-mail on the list, and i don't understand the code of pd or anything like that, but I have an idea. Plus, sorry for bad english.<br>
If it was possible to have an array of pointers, maintained by the user, we could jump to some scalar in the list, say I have 1000 scalars, and an array with pointers to 100th, 200th, 300th, or any combination. This would improve the search.<br>
Maybe this would be a list/array of pointers inside another scalar? What do you think?<br>
Using this design, the user itself can create his own structures with pointers, creating trees,  graphs with the scalars themself.<br>
It make sense?<br>
 <br>
<br>
</span><div><div class="m_-4392881754592803297h5">Em Qua, 29 de mar de 2017 08:47, Derek Kwan <<a href="mailto:derek.x.kwan@gmail.com" target="_blank">derek.x.kwan@gmail.com</a>[mailto<wbr>:<a href="mailto:derek.x.kwan@gmail.com" target="_blank">derek.x.kwan@gmail.com</a>]> escreveu:"Christof Ressi" <<a href="mailto:christof.ressi@gmx.at" target="_blank">christof.ressi@gmx.at</a>[mailto:<a href="mailto:christof.ressi@gmx.at" target="_blank"><wbr>christof.ressi@gmx.at</a>]> writes:<br>
<br>
<br>
> I have - and traversing large lists of scalars by pointer can be veeeery slow.<br>
><br>
yeahhhh, i figured that could be the case =P<br>
<br>
> you could hide the fact that it's a linked list from the user but I<br>
> don't know if that's a good thing to do. It doesn't seem transparent<br>
> to me ("why is accessing the 1000th elements slower than the 1st<br>
> element?").<br>
<br>
I suppose you could tell the user via documentation, but then you'd have<br>
go into what a linked list is and why linked list indexing is<br>
O(n) versus array O(1) to explain the speed difference and yeah,<br>
I see your point haha. And it's probably not good either to have a layer<br>
of abstraction that isn't totally necessary either.<br>
<br>
><br>
> if you don't use the graphical representation, you can just as well<br>
> work with data structure arrays and get fast random access. there is<br>
> one little but unfortunate drawback compared to using lists of<br>
> scalars: drawn instances of array elements don't respond to mouse<br>
> events, making them more or less useless as UI elements. if you<br>
> click/select an element, you only get a pointer to the array, not to<br>
> the element(s). if you click on the canvas, you get pointers to the<br>
> array + all array elements (for whatever reason).<br>
> The right behaviour IMHO would be that clicking/selecting array<br>
> elements gives you pointers to the array *and* the clicked/selected<br>
> element(s). clicking on the empty canvas shouldn't trigger any mouse<br>
> events!<br>
><br>
> Apart from that, data structure arrays are quite easy to handle and<br>
> much more efficient than linked lists of scalars<br>
<br>
ah, that's interesting. admittedly, i haven't used pd structs that much<br>
in my pd work as of yet but the stuff i want to do seems to be<br>
increasingly lending itself to that (or a similar) sort of paradigm so<br>
i'll keep that in mind!<br>
<br>
Derek<br>
<br>
--<br>
Derek Kwan<br>
</div></div><a href="http://www.derekxkwan.com" rel="noreferrer" target="_blank">www.derekxkwan.com</a>[<a href="http://www.derekxkwan.com" rel="noreferrer" target="_blank">http://www.<wbr>derekxkwan.com</a>]<br>
<br>
______________________________<wbr>_________________<br>
<a href="mailto:Pd-list@lists.iem.at" target="_blank">Pd-list@lists.iem.at</a>[mailto:<a href="mailto:Pd-list@lists.iem.at" target="_blank">Pd<wbr>-list@lists.iem.at</a>] mailing list<br>
UNSUBSCRIBE and account-management -> <a href="https://lists.puredata.info/listinfo/pd-list%5Bhttps://lists.puredata.info/listinfo/pd-list%5D" rel="noreferrer" target="_blank">https://lists.puredata.info/li<wbr>stinfo/pd-list[https://lists.<wbr>puredata.info/listinfo/pd-<wbr>list]</a><br>
<div class="m_-4392881754592803297HOEnZb"><div class="m_-4392881754592803297h5"><br>
______________________________<wbr>_________________<br>
<a href="mailto:Pd-list@lists.iem.at" target="_blank">Pd-list@lists.iem.at</a> mailing list<br>
UNSUBSCRIBE and account-management -> <a href="https://lists.puredata.info/listinfo/pd-list" rel="noreferrer" target="_blank">https://lists.puredata.info/li<wbr>stinfo/pd-list</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>