You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by vi...@apache.org on 2008/01/11 22:36:12 UTC

svn commit: r611307 - in /incubator/stdcxx/trunk/examples: include/stocks.h tutorial/stocks.cpp

Author: vitek
Date: Fri Jan 11 13:36:11 2008
New Revision: 611307

URL: http://svn.apache.org/viewvc?rev=611307&view=rev
Log:

2008-01-11  Travis Vitek  <vi...@roguewave.com>

	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/trunk/examples/include/stocks.h
    incubator/stdcxx/trunk/examples/tutorial/stocks.cpp

Modified: incubator/stdcxx/trunk/examples/include/stocks.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/examples/include/stocks.h?rev=611307&r1=611306&r2=611307&view=diff
==============================================================================
--- incubator/stdcxx/trunk/examples/include/stocks.h (original)
+++ incubator/stdcxx/trunk/examples/include/stocks.h Fri Jan 11 13:36:11 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/trunk/examples/tutorial/stocks.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/examples/tutorial/stocks.cpp?rev=611307&r1=611306&r2=611307&view=diff
==============================================================================
--- incubator/stdcxx/trunk/examples/tutorial/stocks.cpp (original)
+++ incubator/stdcxx/trunk/examples/tutorial/stocks.cpp Fri Jan 11 13:36:11 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<StockXchange*, std::locale> sl_pair;
-    typedef std::deque<sl_pair*, std::allocator<sl_pair*> > Xchange;
+    typedef std::deque<sl_pair, std::allocator<sl_pair> > 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;
 }



Re: svn commit: r611307 - in /incubator/stdcxx/trunk/examples: include/stocks.h tutorial/stocks.cpp

Posted by Travis Vitek <vi...@roguewave.com>.


Martin Sebor wrote:
> 
> Farid Zaripov wrote:
>>> -----Original Message-----
>>> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
>>> Sent: Saturday, January 12, 2008 12:43 AM
>>> To: stdcxx-dev@incubator.apache.org
>>> Subject: Re: svn commit: r611307 - in 
>>> /incubator/stdcxx/trunk/examples: include/stocks.h tutorial/stocks.cpp
>>>
>>> vitek@apache.org wrote:
>>>> Author: vitek
>>>> Date: Fri Jan 11 13:36:11 2008
>>>> New Revision: 611307
>>>>
>>>> URL: http://svn.apache.org/viewvc?rev=611307&view=rev
>>>> Log:
>>> [...]
>>>> @@ -153,8 +150,12 @@
>>>>      if (!p)
>>>>          std::cerr<< "\nNot a valid locale: " << 
>>> GERMAN_LOCALE << '\n';
>>>>      else {
>>>> +        FrankFurtStockXchange *fse = new FrankFurtStockXchange;   
>>> We should probably fix the spelling here, too. The city is 
>>> Frankfurt, not Frank Furt. That makes me laugh! ;-)
>> 
>>   Strictly speaking in Germany (since I were there recently) exists 2
>> Frankfurt's:
>> Frankfurt on the Main and Frankfurt on the Oder... Probably then we
>> should rename
>> FrankfurtStockXchange to BerlinStockXchange
>> (FrankfurtOnTheMainStockXchange is not
>> so convinient, and all other city's are the country capital's except
>> NewYork) :-).
> 
> I see someone's been traveling! ;-) How was your trip?
> 
> There's only one Frankfurt Stock Exchange and its name is
> Frankfurter Wertpapierbörse (I assume it's in Frankfurt on
> the Main).
> 
> New York Stock Exchange isn't called The City of New York Stock
> Exchange even though the official name of the city is actually
> The City of New York (i.e., not just New York).
> 
> Martin
> 
>> 
>> Farid.
>> 
> 

Class renamed to FrankfurtStockXchange in
http://svn.apache.org/viewvc?view=rev&revision=613232. I also updated the
locale names for AIX and Compaq in
http://svn.apache.org/viewvc?view=rev&revision=613234. The previously named
locales weren't installed on any of our test machines.

Travis
-- 
View this message in context: http://www.nabble.com/Re%3A-svn-commit%3A-r611307---in--incubator-stdcxx-trunk-examples%3A-include-stocks.h-tutorial-stocks.cpp-tp14766973p14957761.html
Sent from the stdcxx-dev mailing list archive at Nabble.com.


Re: svn commit: r611307 - in /incubator/stdcxx/trunk/examples: include/stocks.h tutorial/stocks.cpp

Posted by Martin Sebor <se...@roguewave.com>.
Farid Zaripov wrote:
>> -----Original Message-----
>> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
>> Sent: Saturday, January 12, 2008 12:43 AM
>> To: stdcxx-dev@incubator.apache.org
>> Subject: Re: svn commit: r611307 - in 
>> /incubator/stdcxx/trunk/examples: include/stocks.h tutorial/stocks.cpp
>>
>> vitek@apache.org wrote:
>>> Author: vitek
>>> Date: Fri Jan 11 13:36:11 2008
>>> New Revision: 611307
>>>
>>> URL: http://svn.apache.org/viewvc?rev=611307&view=rev
>>> Log:
>> [...]
>>> @@ -153,8 +150,12 @@
>>>      if (!p)
>>>          std::cerr<< "\nNot a valid locale: " << 
>> GERMAN_LOCALE << '\n';
>>>      else {
>>> +        FrankFurtStockXchange *fse = new FrankFurtStockXchange;   
>> We should probably fix the spelling here, too. The city is 
>> Frankfurt, not Frank Furt. That makes me laugh! ;-)
> 
>   Strictly speaking in Germany (since I were there recently) exists 2
> Frankfurt's:
> Frankfurt on the Main and Frankfurt on the Oder... Probably then we
> should rename
> FrankfurtStockXchange to BerlinStockXchange
> (FrankfurtOnTheMainStockXchange is not
> so convinient, and all other city's are the country capital's except
> NewYork) :-).

I see someone's been traveling! ;-) How was your trip?

There's only one Frankfurt Stock Exchange and its name is
Frankfurter Wertpapierbörse (I assume it's in Frankfurt on
the Main).

New York Stock Exchange isn't called The City of New York Stock
Exchange even though the official name of the city is actually
The City of New York (i.e., not just New York).

Martin

> 
> Farid.
> 


RE: svn commit: r611307 - in /incubator/stdcxx/trunk/examples: include/stocks.h tutorial/stocks.cpp

Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Saturday, January 12, 2008 12:43 AM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: svn commit: r611307 - in 
> /incubator/stdcxx/trunk/examples: include/stocks.h tutorial/stocks.cpp
> 
> vitek@apache.org wrote:
> > Author: vitek
> > Date: Fri Jan 11 13:36:11 2008
> > New Revision: 611307
> > 
> > URL: http://svn.apache.org/viewvc?rev=611307&view=rev
> > Log:
> [...]
> > @@ -153,8 +150,12 @@
> >      if (!p)
> >          std::cerr<< "\nNot a valid locale: " << 
> GERMAN_LOCALE << '\n';
> >      else {
> > +        FrankFurtStockXchange *fse = new FrankFurtStockXchange;   
> 
> We should probably fix the spelling here, too. The city is 
> Frankfurt, not Frank Furt. That makes me laugh! ;-)

  Strictly speaking in Germany (since I were there recently) exists 2
Frankfurt's:
Frankfurt on the Main and Frankfurt on the Oder... Probably then we
should rename
FrankfurtStockXchange to BerlinStockXchange
(FrankfurtOnTheMainStockXchange is not
so convinient, and all other city's are the country capital's except
NewYork) :-).

Farid.

Re: svn commit: r611307 - in /incubator/stdcxx/trunk/examples: include/stocks.h tutorial/stocks.cpp

Posted by Martin Sebor <se...@roguewave.com>.
vitek@apache.org wrote:
> Author: vitek
> Date: Fri Jan 11 13:36:11 2008
> New Revision: 611307
> 
> URL: http://svn.apache.org/viewvc?rev=611307&view=rev
> Log:
[...]
> @@ -153,8 +150,12 @@
>      if (!p)
>          std::cerr<< "\nNot a valid locale: " << GERMAN_LOCALE << '\n';
>      else {
> +        FrankFurtStockXchange *fse = new FrankFurtStockXchange;   

We should probably fix the spelling here, too. The city is Frankfurt,
not Frank Furt. That makes me laugh! ;-)

Martin