From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,740e91341085efe3 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 07 Apr 2005 23:43:33 -0500 From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Some help for a C++ guy References: <1112912062.146885.324110@o13g2000cwo.googlegroups.com> X-Newsreader: Tom's custom newsreader Message-ID: Date: Thu, 07 Apr 2005 23:43:34 -0500 NNTP-Posting-Host: 67.161.24.234 X-Trace: sv3-wQchm3yJ8oEYYUw/APvSms+MtxK3Yq9Ojm4VHqlXdQFoliVBGoT30Q52d6FT8yF+r274xPUDE/QECgh!clHwL+BNNMs6NiznydHPEkKS32mwKWKFW1Vd+Tda4OtUU3Q5UDi8PQu7ppAiAA== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.31 Xref: g2news1.google.com comp.lang.ada:10328 Date: 2005-04-07T23:43:34-05:00 List-Id: >generic >package Message_Handler is > procedure Message_Callback (Status : in M1553.IO_Status_T); >... > function Num_Message_Callbacks return OS_Types.Unsigned_Word; >... > Data_Buf_Ptr : constant M1553.Data_Buf_VPtr_T := new M1553.Data_Buf; > Stat_Buf_Ptr : constant M1553.Status_Buf_VPtr_T := new M1553.Status_Buf_T; >... >Then in the implementation code, there's stuff like: > > package Message_0_Handler is new Message_Handler; > package Message_5_Handler is new Message_Handler; >... >I don't much like this. It's cumbersome even for a couple of messages, >let alone when we grow to 20 or more, because we have duplicated code >for each registration. > >What I'd like is to have some sort of array of the messages. That way >for errors. I guess I'm thinking an OO approach, as long as the various >members could be passed as arguments to the registration routines. Since the generic has no parameters, what you're getting is in effect a single body of code, with separate data for each instantiation, and you call Message_0_Handler.Message_Callbacks (Status); instead of Message_Handler.Message_Callbacks (Message_0, Status); So you could just drop the "generic" and put the package's local data into a record: package Message_Handler is type Message_State_Type is private; procedure Message_Callback (State : in Message_State_Type; Status : in M1553.IO_Status_T); ... function Num_Message_Callbacks (State : in Message_State_Type) return OS_Types.Unsigned_Word; ... -- make Data_Buf_Ptr readable, but not writeable function Data_Buf_Ptr (State : in Message_State_Type) return M1553.Data_Buf_VPtr_T; function Stat_Buf_Ptr (State : in Message_State_Type) return M1553.Status_Buf_VPtr_T; ... Then you could have Message_List : array(0 .. 5) of Message_State_Type; and call Message_Handler.Message_Callback (Message_List(0), Status); etc That seems the most vanilla change, and you can probably change all your source code by a simple macro in your editor. Or am I missing something?