|
|
Choosing A Webhost: |
CVS update of carob/src (ParameterStatement.cpp): msg#00191db.carob.cvs
Date: Thursday, January 26, 2006 @ 22:21:28 Author: marc Path: /cvsroot/carob/carob/src Modified: ParameterStatement.cpp (1.8 -> 1.9) Templatized stream settings specific to floats and doubles. Inf & NaN still not handled/"translated". CAROB-31 & CAROB-55. ------------------------+ ParameterStatement.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 64 insertions(+), 4 deletions(-) Index: carob/src/ParameterStatement.cpp diff -u carob/src/ParameterStatement.cpp:1.8 carob/src/ParameterStatement.cpp:1.9 --- carob/src/ParameterStatement.cpp:1.8 Tue Jan 24 19:37:27 2006 +++ carob/src/ParameterStatement.cpp Thu Jan 26 22:21:28 2006 @@ -139,6 +139,64 @@ std::locale locC = std::locale::classic(); } +namespace CarobNS { + +using std::basic_ostream; + + +// Template<datatype> stream manipulators +// No pointer to function template (type safety?), so let's do a functor +template <class T, class Ch = wchar_t> +class streamSettingsFor +{ +public: + void doManip(basic_ostream<Ch>& s) const { }; +}; + +// stream operator<< for the functor just above +template <class T, class Ch> +basic_ostream<Ch>& +operator<< (basic_ostream<Ch>& s, streamSettingsFor<T, Ch> m) +{ + m.doManip(s); + return s; +} + +// partial specialization code shared by float & double +template<class Ch> void +streamSettingsForFloatingPoint(basic_ostream<Ch>& s) +{ + s.imbue(locC); + s.setf(std::ios_base::scientific, std::ios_base::floatfield); +} + +// template specialization for float +template<class Ch> +class streamSettingsFor<float, Ch> +{ +public: + void doManip(basic_ostream<Ch>& s) const + { + streamSettingsForFloatingPoint(s); + s.precision(9); + }; +}; + +// template specialization for float +template<class Ch> +class streamSettingsFor<double, Ch> +{ +public: + void doManip(basic_ostream<Ch>& s) const + { + streamSettingsForFloatingPoint(s); + s.precision(17); + }; +}; + +} // namespace CarobNS + + template <class T> void ParameterStatement::set(const int paramIndex, const std::wstring &typeTag, const T& value) throw (DriverException, UnexpectedException) @@ -146,12 +204,14 @@ if (paramIndex < 1 || paramIndex > (int)inStrings.size()) throw DriverException(L"Parameter index out of range."); + // As an optimization, we could make this stream a member. + // That would just require a member lock for thread-safety std::wostringstream buffer; - buffer.imbue(locC); - buffer.setf(std::ios_base::scientific, std::ios_base::floatfield); - buffer.precision(18); // std::numeric_limits<double>::digits10 + some - buffer << START_PARAM_TAG << typeTag << value << END_PARAM_TAG; + + // TODO: catch inf & NaN + buffer << START_PARAM_TAG << typeTag << streamSettingsFor<T>() << value << END_PARAM_TAG; + inStrings[paramIndex-1] = buffer.str(); }
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | CVS update of carob/src (SQLDataSerialization.cpp), marc-Tt5JLJuBijYiZlD9aYmxOGD2FQJk+8+b |
|---|---|
| Next by Date: | CVS update of carob/src (ParameterStatement.cpp), marc-Tt5JLJuBijYiZlD9aYmxOGD2FQJk+8+b |
| Previous by Thread: | CVS update of carob/src (ParameterStatement.cpp), marc-Tt5JLJuBijYiZlD9aYmxOGD2FQJk+8+b |
| Next by Thread: | CVS update of carob/src (ParameterStatement.cpp), marc-Tt5JLJuBijYiZlD9aYmxOGD2FQJk+8+b |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |
Home
| advertise | OSDir is
an inevitable website.
|