[ace-users] No overloaded ostream operator << for ACE_Time_Value?

  • Follow


Hi,

I was wondering if there is a reason why there is no operator<<() for the c=
lass ACE_Time_Value. If this by design?

without it the following statement compile:

ACE_Time_Value val(1000,0);
std::cout << val;

but it does not give the expected result. It prints out an address and I th=
ink this is because the typecast operator const timeval *() const is implic=
itly called.

I could propose the following implementation but I am not sure where you wo=
uld want to place it:

#include <iomanip>

std::ostream &operator<<(std::ostream &o, const ACE_Time_Value &v)
{
    o << v.sec() << '.' << std::setw(4) << std::setfill('0') << v.msec();
    return o;
}

Olivier Langlois
C++ Technical Lead

STREAMTHEWORLD

t. 1 866 448 4037 ext. 675
t. 1 514 448 4037 ext. 675
f. 1 514 807 1861

olivier.langlois@streamtheworld.com
streamtheworld.com
=A0
StreamTheWorld launches its new BlackBerry application. Learn more

0
Reply Olivier 1/19/2010 11:48:15 PM

On Jan 19, 6:48=A0pm, Olivier Langlois
<Olivier.Langl...@streamtheworld.com> wrote:
> Hi,
>
> I was wondering if there is a reason why there is no operator<<() for the=
 class ACE_Time_Value. If this by design?
>
> without it the following statement compile:
>
> ACE_Time_Value val(1000,0);
> std::cout << val;
>
> but it does not give the expected result. It prints out an address and I =
think this is because the typecast operator const timeval *() const is impl=
icitly called.
>
> I could propose the following implementation but I am not sure where you =
would want to place it:
>
> #include <iomanip>
>
> std::ostream &operator<<(std::ostream &o, const ACE_Time_Value &v)
> {
> =A0 =A0 o << v.sec() << '.' << std::setw(4) << std::setfill('0') << v.mse=
c();
> =A0 =A0 return o;
>
> }
>
> Olivier Langlois
> C++ Technical Lead
>

This will not give a very useful time for an absolute time.
ACE_Time_Value::msec() returns an unsigned long which will overflow
(assuming unsigned long is 32-bits, the typical value). If it
overflows, msec() returns the max unsigned long value (0xFFFFFFFF).

--
Paul Carter
0
Reply Paul 1/20/2010 3:53:22 PM


1 Replies
315 Views

(page loaded in 0.046 seconds)

Similiar Articles:





7/26/2012 9:45:09 PM


Reply: