Go to the documentation of this file.00001 #include "ace/Basic_Types.h"
00002
00003 #if !defined (__ACE_INLINE__)
00004 # include "ace/Basic_Types.inl"
00005 #endif
00006
00007
00008 ACE_RCSID (ace,
00009 Basic_Types,
00010 "$Id: Basic_Types.cpp 80826 2008-03-04 14:51:23Z wotte $")
00011
00012
00013 #if defined (ACE_LACKS_LONGLONG_T) && !defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
00014 # include "ace/Log_Msg.h"
00015 # include "ace/OS_NS_stdio.h"
00016 # include "ace/OS_NS_string.h"
00017 # if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
00018
00019 # include "ace/streams.h"
00020 # endif
00021
00022 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00023
00024 void
00025 ACE_U_LongLong::output (FILE *file) const
00026 {
00027 if (h_ () > 0)
00028 ACE_OS::fprintf (file, "0x%lx%0*lx", h_ (), 2 * sizeof l_ (), l_ ());
00029 else
00030 ACE_OS::fprintf (file, "0x%lx", l_ ());
00031 }
00032
00033
00034 ACE_TCHAR *
00035 ACE_U_LongLong::as_string (ACE_TCHAR *output,
00036 unsigned int base,
00037 unsigned int uppercase) const
00038 {
00039 if (*this == 0)
00040 {
00041 ACE_OS::strcpy(output, "0");
00042 }
00043 else
00044 {
00045 switch(base)
00046 {
00047 case 8:
00048 {
00049 unsigned int index = 0;
00050 int bshift = 31;
00051 while(bshift >= 1)
00052 {
00053 unsigned int sval = (this->h_ () >> bshift) & 7;
00054 if (sval > 0 || index != 0)
00055 {
00056 output[index] = sval + '0';
00057 ++index;
00058 }
00059 bshift -= 3;
00060 }
00061 bshift = 30;
00062 while(bshift >= 0)
00063 {
00064 unsigned int sval = (this->l_ () >> bshift) & 7;
00065
00066 if (bshift == 30)
00067 {
00068 sval |= (this->h_ () & 1) << 2;
00069 }
00070 if (sval > 0 || index != 0)
00071 {
00072 output[index] = sval + '0';
00073 ++index;
00074 }
00075 bshift -= 3;
00076 }
00077 output[index] = '\0';
00078 break;
00079 }
00080 case 10:
00081 {
00082 ACE_OS::sprintf(output, "%.0f", *this / 1.0);
00083 break;
00084 }
00085 case 16:
00086 {
00087 if (this->h_ () != 0)
00088 {
00089 ACE_OS::sprintf(output,
00090 (uppercase ? "%lX%0*lX" : "%lx%0*lx"),
00091 this->h_ (), 2 * sizeof this->l_ (),
00092 this->l_ ());
00093 }
00094 else
00095 {
00096 ACE_OS::sprintf(output,
00097 (uppercase ? "%lX" : "%lx"), this->l_ ());
00098
00099 }
00100 break;
00101 }
00102 default:
00103 {
00104 ACE_DEBUG ((LM_DEBUG,
00105 ACE_TEXT ("Unsupported base = %u\n"), base));
00106 output[0] = '\0';
00107 }
00108 }
00109 }
00110
00111 return output;
00112 }
00113
00114
00115 # if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
00116 ostream&
00117 operator<< (ostream& os, const ACE_U_LongLong& ll)
00118 {
00119 #ifdef __TANDEM && (__CPLUSPLUS_VERSION >= 3)
00120 unsigned long flags = os.flags();
00121 #else
00122 unsigned long flags = os.setf(0);
00123 #endif
00124 char buffer[32];
00125
00126 if ((flags & ios::oct) != 0)
00127 os << ll.as_string (buffer, 8);
00128 else if ((flags & ios::hex) != 0)
00129 os << ll.as_string (buffer, 16, (flags & ios::uppercase));
00130 else
00131 os << ll.as_string (buffer);
00132 return os;
00133 }
00134 # endif
00135
00136 ACE_END_VERSIONED_NAMESPACE_DECL
00137
00138 #endif
00139