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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,243dc2fb696a49cd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews1.google.com!not-for-mail From: kevin.cline@gmail.com (Kevin Cline) Newsgroups: comp.lang.ada Subject: Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl) Date: 2 Oct 2004 13:39:56 -0700 Organization: http://groups.google.com Message-ID: References: <1636756.M7hCqjsVMv@linux1.krischik.com> <415c36c0$0$91010$39cecf19@news.twtelecom.net> <4c2ec8a8.0410012335.dcf9001@posting.google.com> NNTP-Posting-Host: 24.219.97.214 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1096749596 32471 127.0.0.1 (2 Oct 2004 20:39:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 2 Oct 2004 20:39:56 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:4576 Date: 2004-10-02T13:39:56-07:00 List-Id: Brian May wrote in message news:... > >>>>> "K" == K writes: > > K> dbmap order_map; > > K> order_map.insert("ORDER.NUMBER", &Order::number) > K> .insert("ORDER.CUSTOMER", &Order::customer_number) > K> .insert("ORDER.ACCEPTED", &Order::acceptance_date) > K> .insert("ORDER.PROMISED", &Order::promised_ship_date) > K> ... > > K> and then be able to write: > > K> Order order; > K> order_map.read(dbreader, order); > K> order.promised_ship_date = ship_date(order.line_items); > K> order_map.update(dbconnection, order); > > Hmmmm... Thinking aloud: One approach that might work, at least for > some applications: > > declare > type Index_Type is (Number, Customer_Number, Acceptance_Date, > Promised_Ship_Date, ...); > begin > insert(Order_Map, Number); > insert(Order_Map, Customer_Number); > insert(Order_Map, Acceptance_Date); > insert(Order_Map, Promised_Ship_Date); Sorry, I didn't make it clear that not all thes data members are integers. The dates have Date type, and other members will be strings or other user-defined types. > ... > end; > > (not tested; syntax may not be exactly correct) > > The obvious problem with this is that all values need be the same > type. I am not sure if your code has this limitation or not. No, it doesn't. That's the point. The insert function is a template member function with a declaration like this: template class DatabaseMap { vector entries; ... template DatabaseMap& insert(Column c, MemberType RecordType::*member_pointer) { entries.push_back(new ColumnMemberMap (c, member_pointer)); return this; } } Matt has suggested ways this can be done in Ada, but it requires to create a function for every data member to be mapped, and additionally you will have to instantiate the insert function for each different member type. That is so much work that it destroys the value of the technique.