Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Basic_Types.cpp

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

Generated on Mon Jun 16 11:19:13 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002