stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r537489 - in /incubator/stdcxx/trunk/examples/manual: money_get.cpp out/money_get.out
Date Sat, 12 May 2007 17:17:43 GMT
Author: sebor
Date: Sat May 12 10:17:42 2007
New Revision: 537489

URL: http://svn.apache.org/viewvc?view=rev&rev=537489
Log:
2007-05-12  Martin Sebor  <sebor@roguewave.com>

	* money_get.cpp: Made example more interesting by using thousands
	separators and more decimal places than two in input, and by making
	it possible to specify all parameters on the command line.
	Simplified the invocation of money_get::get() by taking advantage
	of the implicit conversion from ios to istreambuf_iterator.
	* money_get.out: Adjusted to match the above changes.

Modified:
    incubator/stdcxx/trunk/examples/manual/money_get.cpp
    incubator/stdcxx/trunk/examples/manual/out/money_get.out

Modified: incubator/stdcxx/trunk/examples/manual/money_get.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/examples/manual/money_get.cpp?view=diff&rev=537489&r1=537488&r2=537489
==============================================================================
--- incubator/stdcxx/trunk/examples/manual/money_get.cpp (original)
+++ incubator/stdcxx/trunk/examples/manual/money_get.cpp Sat May 12 10:17:42 2007
@@ -1,21 +1,28 @@
 /**************************************************************************
  *
- * moneyget.cpp - Example program for the money_get facet. 
+ * money_get.cpp - Example program for the money_get facet. 
  *
  * $Id$
  *
  ***************************************************************************
  *
- * Copyright (c) 1994-2005 Quovadx,  Inc., acting through its  Rogue Wave
- * Software division. Licensed under the Apache License, Version 2.0 (the
- * "License");  you may  not use this file except  in compliance with the
- * License.    You    may   obtain   a   copy   of    the   License    at
- * http://www.apache.org/licenses/LICENSE-2.0.    Unless   required    by
- * applicable law  or agreed to  in writing,  software  distributed under
- * the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR
- * CONDITIONS OF  ANY KIND, either  express or implied.  See  the License
- * for the specific language governing permissions  and limitations under
- * the License.
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1998-2006 Rogue Wave Software.
  * 
  **************************************************************************/
 
@@ -27,59 +34,63 @@
 #include <examples.h>
 
 
-#if defined (__osf__)
+// hardcode the name of the English US locale for known systems
+#if defined (__FreeBSD__) || defined (__osf__)
+// FreeBSD and Tru64 UNIX
 const char en_US[] = "en_US.ISO8859-1";
 #elif defined (__hpux)
+// HP-UX
 const char en_US[] = "en_US.iso88591";
-#elif defined (_WIN32) || defined (_WIN64)
+// Windows
+#elif defined (_WIN32)
 const char en_US[] = "English";
 #else
+// AIX, IRIX, Linux, Solaris
 const char en_US[] = "en_US";
 #endif
 
 
-int main ()
+int main (int argc, char *argv[])
 {
     typedef std::istreambuf_iterator<char, std::char_traits<char> > Iter;
   
-    const char buffer[] = "$100.02";
+    // Get the monetary string and locale from the argument vector.
+    const char* const buffer  = 1 < argc ? argv [1] : "$1,234.6789";
+    const char* const locname = 2 < argc ? argv [2] : en_US;
+    const bool        intl    = 3 < argc;
 
-    std::string dest;
-    long double ldest = 0.0;
+    std::string smon;
+    long double fmon = 0.0;
 
     std::ios_base::iostate state = std::ios_base::goodbit;
-    Iter end;
 
-    // Retrieve the money_get facet from the global locale.
-    const std::locale loc (en_US);
+    // Retrieve the money_get facet from the named locale.
+    const std::locale loc (locname);
 
     const std::money_get<char, Iter> &mgf =
         std::use_facet<std::money_get<char, Iter> >(loc);
 
     {
-        // Build an istringstream from the buffer and construct
-        // a beginning iterator on it.
+        // Build an istringstream object from the buffer
+        // and imbue the locale in it.
         std::istringstream ins (buffer);
         ins.imbue (loc);
-        Iter begin (ins);
 
-        // Get a string representation of the monetary value
-        mgf.get (begin, end, false, ins, state, dest);
+        // Get a string representation of the monetary value.
+        mgf.get (ins, Iter (), intl, ins, state, smon);
     }
     {
-        // Build another istringstream from the buffer, etc.
-        // so we have an iterator pointing to the beginning
         std::istringstream ins (buffer);
         ins.imbue (loc);
-        Iter begin (ins);
 
-        // Get a a long double representation of the monetary value
-        mgf.get (begin, end, false, ins, state, ldest);
+        // Get a floating point representation of the monetary value.
+        mgf.get (ins, Iter (), intl, ins, state, fmon);
     }
 
-    std::cout << buffer << " --> "
-              << dest << " --> " << ldest << std::endl;
+    // Output the original sequence and its string and floating point
+    // representations.
+    std::cout << buffer << " --> \"" << smon << "\" --> " <<
fmon << '\n';
 
-    // return 0 on success, non-zero on failure
+    // Return 0 on success, non-zero on failure.
     return !(std::ios_base::eofbit == state);
 }

Modified: incubator/stdcxx/trunk/examples/manual/out/money_get.out
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/examples/manual/out/money_get.out?view=diff&rev=537489&r1=537488&r2=537489
==============================================================================
--- incubator/stdcxx/trunk/examples/manual/out/money_get.out (original)
+++ incubator/stdcxx/trunk/examples/manual/out/money_get.out Sat May 12 10:17:42 2007
@@ -1 +1 @@
-$100.02 --> 10002 --> 10002
+$1,234.6789 --> "123467" --> 123467



Mime
View raw message