Return-Path: Delivered-To: apmail-incubator-stdcxx-commits-archive@www.apache.org Received: (qmail 34152 invoked from network); 11 Jan 2008 21:41:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Jan 2008 21:41:04 -0000 Received: (qmail 88663 invoked by uid 500); 11 Jan 2008 21:40:53 -0000 Delivered-To: apmail-incubator-stdcxx-commits-archive@incubator.apache.org Received: (qmail 88651 invoked by uid 500); 11 Jan 2008 21:40:53 -0000 Mailing-List: contact stdcxx-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-commits@incubator.apache.org Received: (qmail 88640 invoked by uid 99); 11 Jan 2008 21:40:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Jan 2008 13:40:53 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Jan 2008 21:40:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 523F71A9832; Fri, 11 Jan 2008 13:40:43 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r611308 - in /incubator/stdcxx/branches/4.2.x/examples: include/stocks.h tutorial/stocks.cpp Date: Fri, 11 Jan 2008 21:40:42 -0000 To: stdcxx-commits@incubator.apache.org From: vitek@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080111214043.523F71A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: vitek Date: Fri Jan 11 13:40:41 2008 New Revision: 611308 URL: http://svn.apache.org/viewvc?rev=611308&view=rev Log: 2008-01-11 Travis Vitek Merged rev 611307 from trunk with implementation of STDCXX-577 * examples/include/stocks.h: Removed StockXchange destructor implementation. * examples/tutorial/stocks.cpp: Add StockXchange destructor that properly deallocates memory. (main): Avoid allocation of facets when the locale that uses them is not available. Change Xchange to hold pair values to avoid having to deallocate those pairs explicitly. Cache the locale initially imbued on stream, then restore it to ensure that facets are deallocated. Modified: incubator/stdcxx/branches/4.2.x/examples/include/stocks.h incubator/stdcxx/branches/4.2.x/examples/tutorial/stocks.cpp Modified: incubator/stdcxx/branches/4.2.x/examples/include/stocks.h URL: http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/examples/include/stocks.h?rev=611308&r1=611307&r2=611308&view=diff ============================================================================== --- incubator/stdcxx/branches/4.2.x/examples/include/stocks.h (original) +++ incubator/stdcxx/branches/4.2.x/examples/include/stocks.h Fri Jan 11 13:40:41 2008 @@ -141,7 +141,7 @@ typedef std::locale::facet facet; StockXchange(std::size_t refs=0): facet(refs){} - virtual ~StockXchange(){} + virtual ~StockXchange(); static std::locale::id id; virtual bool put (std::ostream& os) const; Modified: incubator/stdcxx/branches/4.2.x/examples/tutorial/stocks.cpp URL: http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/examples/tutorial/stocks.cpp?rev=611308&r1=611307&r2=611308&view=diff ============================================================================== --- incubator/stdcxx/branches/4.2.x/examples/tutorial/stocks.cpp (original) +++ incubator/stdcxx/branches/4.2.x/examples/tutorial/stocks.cpp Fri Jan 11 13:40:41 2008 @@ -39,6 +39,16 @@ std::locale::id StockXchange::id; +StockXchange::~StockXchange () +{ + database::const_iterator begin = companyDatabase.begin (); + database::const_iterator end = companyDatabase.end (); + + while (begin < end) + delete *begin++; +} + + void StockXchange::localTime (std::ostream& os) const { const char pat[] = "%c"; @@ -115,37 +125,24 @@ int main () { typedef std::pair sl_pair; - typedef std::deque > Xchange; + typedef std::deque > Xchange; Xchange sXchange; std::ostream os (std::cout.rdbuf ()); - - // Add some hypothetical companies that went public. - // ("Company name" , "initial stock price") - - NewYorkStockXchange *nse = new NewYorkStockXchange; - nse->add ("Hyper Software", 20.50); - nse->add ("Florida Fish", 15.10); - nse->add ("Inka Inc", 9.50); - nse->add ("Emory Chemicals", 11.00); - - TokyoStockXchange *tse = new TokyoStockXchange; - tse->add ("Akiro Electronics", 12.30); - - FrankFurtStockXchange *fse = new FrankFurtStockXchange; - fse->add ("B\166rsen-Software", 9.75); - fse->add ("M\174nchner R\174ck", 19.75); - - ParisStockXchange *pse = new ParisStockXchange; - pse->add ("Wines Inc.", 11.50); - pse->add ("Eiffel Co.", 11.50); + const std::locale loc (os.getloc ()); const char *p = std::setlocale (LC_ALL, US_LOCALE); if (!p) std::cerr << "\nNot a valid locale: " << US_LOCALE << '\n'; else { + NewYorkStockXchange *nse = new NewYorkStockXchange; + nse->add ("Hyper Software", 20.50); + nse->add ("Florida Fish", 15.10); + nse->add ("Inka Inc", 9.50); + nse->add ("Emory Chemicals", 11.00); + os.imbue (std::locale (std::locale (US_LOCALE), nse)); - sXchange.push_front (new sl_pair (nse, os.getloc ())); + sXchange.push_front (sl_pair (nse, os.getloc ())); os << *nse; } @@ -153,8 +150,12 @@ if (!p) std::cerr<< "\nNot a valid locale: " << GERMAN_LOCALE << '\n'; else { + FrankFurtStockXchange *fse = new FrankFurtStockXchange; + fse->add ("B\166rsen-Software", 9.75); + fse->add ("M\174nchner R\174ck", 19.75); + os.imbue (std::locale (std::locale (GERMAN_LOCALE), fse)); - sXchange.push_front (new sl_pair (fse, os.getloc ())); + sXchange.push_front (sl_pair (fse, os.getloc ())); os << *fse; } @@ -162,8 +163,12 @@ if (!p) std::cerr << "\nNot a valid locale: " << FRENCH_LOCALE << '\n'; else { + ParisStockXchange *pse = new ParisStockXchange; + pse->add ("Wines Inc.", 11.50); + pse->add ("Eiffel Co.", 11.50); + os.imbue (std::locale (std::locale (FRENCH_LOCALE), pse)); - sXchange.push_front (new sl_pair (pse, os.getloc ())); + sXchange.push_front (sl_pair (pse, os.getloc ())); os << *pse; } @@ -171,8 +176,11 @@ if (!p) std::cerr << "\nNot a valid locale: " << JAPANESE_LOCALE << '\n'; else { + TokyoStockXchange *tse = new TokyoStockXchange; + tse->add ("Akiro Electronics", 12.30); + os.imbue (std::locale (std::locale (JAPANESE_LOCALE), tse)); - sXchange.push_front (new sl_pair (tse, os.getloc ())); + sXchange.push_front (sl_pair (tse, os.getloc ())); os << *tse; } @@ -183,8 +191,8 @@ Xchange::const_iterator it_begin = sXchange.begin (); Xchange::const_iterator it_end = sXchange.end (); while (it_begin < it_end) { - os.imbue ((*it_begin)->second); - os << (*(*it_begin)->first); + os.imbue ((*it_begin).second); + os << (*(*it_begin).first); it_begin++; } } @@ -192,7 +200,9 @@ break; } - std::cout << '\n'; + os << '\n'; + + os.imbue (loc); return 0; }