]> Creatis software - gdcm.git/blobdiff - src/gdcmUtil.cxx
COMP: doh !
[gdcm.git] / src / gdcmUtil.cxx
index 8c980a3159f2a1b8ef1b445ca2b73d79da358c47..c48efce51cc0cec2cf6939e6d4a866e69173f410 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/06 19:10:07 $
-  Version:   $Revision: 1.74 $
+  Date:      $Date: 2005/01/07 23:44:46 $
+  Version:   $Revision: 1.80 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -18,6 +18,7 @@
 
 #include "gdcmUtil.h"
 #include "gdcmDebug.h"
+#include <iostream>
 
 // For GetCurrentDate, GetCurrentTime
 #include <time.h>
@@ -53,7 +54,7 @@ namespace gdcm
  * buf.str();
  */
 
-std::string Util::Format(const charformat, ...)
+std::string Util::Format(const char *format, ...)
 {
    char buffer[2048];
    va_list args;
@@ -70,8 +71,8 @@ std::string Util::Format(const char* format, ...)
  * \ingroup Globals
  * \brief Because not available in C++ (?)
  */
-void Util::Tokenize (const std::stringstr,
-                     std::vector<std::string>tokens,
+void Util::Tokenize (const std::string &str,
+                     std::vector<std::string> &tokens,
                      const std::string& delimiters)
 {
    std::string::size_type lastPos = str.find_first_not_of(delimiters,0);
@@ -90,8 +91,8 @@ void Util::Tokenize (const std::string& str,
  *        Counts the number of occurences of a substring within a string
  */
  
-int Util::CountSubstring (const std::stringstr,
-                          const std::stringsubStr)
+int Util::CountSubstring (const std::string &str,
+                          const std::string &subStr)
 {
    int count = 0;   // counts how many times it appears
    std::string::size_type x = 0;       // The index position in the string
@@ -116,7 +117,7 @@ int Util::CountSubstring (const std::string& str,
  *         to avoid corrupting the terminal of invocation when printing)
  * @param s string to remove non printable characters from
  */
-std::string Util::CreateCleanString(std::string const & s)
+std::string Util::CreateCleanString(std::string const &s)
 {
    std::string str = s;
 
@@ -147,7 +148,7 @@ std::string Util::CreateCleanString(std::string const & s)
  * \brief   Add a SEPARATOR to the end of the name is necessary
  * @param   pathname file/directory name to normalize 
  */
-std::string Util::NormalizePath(std::string const & pathname)
+std::string Util::NormalizePath(std::string const &pathname)
 {
    const char SEPARATOR_X      = '/';
    const char SEPARATOR_WIN    = '\\';
@@ -167,7 +168,7 @@ std::string Util::NormalizePath(std::string const & pathname)
  * \brief   Get the (directory) path from a full path file name
  * @param   fullName file/directory name to extract Path from
  */
-std::string Util::GetPath(std::string const & fullName)
+std::string Util::GetPath(std::string const &fullName)
 {
    std::string res = fullName;
    int pos1 = res.rfind("/");
@@ -189,7 +190,7 @@ std::string Util::GetPath(std::string const & fullName)
  * \brief   Get the (last) name of a full path file name
  * @param   fullName file/directory name to extract end name from
  */
-std::string Util::GetName(std::string const & fullName)
+std::string Util::GetName(std::string const &fullName)
 {   
   std::string filename = fullName;
 
@@ -240,10 +241,10 @@ std::string Util::GetCurrentTime()
  * that needed to be escaped with an extra backslash for doxygen) \\0
  * as you want.
  */
-std::string Util::DicomString(const chars, size_t l)
+std::string Util::DicomString(const char *s, size_t l)
 {
    std::string r(s, s+l);
-   assert( !(r.size() % 2) ); // == basically 'l' is even
+   gdcmAssertMacro( !(r.size() % 2) ); // == basically 'l' is even
    return r;
 }
 
@@ -259,7 +260,7 @@ std::string Util::DicomString(const char* s, size_t l)
  * except it doesn't take a lenght. 
  * It only pad with a null character if length is odd
  */
-std::string Util::DicomString(const chars)
+std::string Util::DicomString(const char *s)
 {
    size_t l = strlen(s);
    if( l%2 )
@@ -267,7 +268,7 @@ std::string Util::DicomString(const char* s)
       l++;
    }
    std::string r(s, s+l);
-   assert( !(r.size() % 2) );
+   gdcmAssertMacro( !(r.size() % 2) );
    return r;
 }
 
@@ -278,7 +279,7 @@ std::string Util::DicomString(const char* s)
  *        - We allow padding of even lenght string by either a null 
  *          character of a space
  */
-bool Util::DicomStringEqual(const std::strings1, const char *s2)
+bool Util::DicomStringEqual(const std::string &s1, const char *s2)
 {
   // s2 is the string from the DICOM reference: 'MONOCHROME1'
   std::string s1_even = s1; //Never change input parameter
@@ -312,13 +313,10 @@ bool Util::IsCurrentProcessorBigEndian()
 #include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
-#include <strings.h> //for bzero
-#include <unistd.h>
 
 #ifdef _WIN32
 #include <snmp.h>
 #include <conio.h>
-#include <stdio.h>
 typedef BOOL(WINAPI * pSnmpExtensionInit) (
         IN DWORD dwTimeZeroReference,
         OUT HANDLE * hPollForTrapEvent,
@@ -339,6 +337,8 @@ typedef BOOL(WINAPI * pSnmpExtensionQuery) (
 
 typedef BOOL(WINAPI * pSnmpExtensionInitEx) (
         OUT AsnObjectIdentifier * supportedView);
+#else
+#include <strings.h> //for bzero on unix
 #endif //_WIN32
 
 #ifdef __linux__
@@ -364,7 +364,7 @@ long GetMacAddrSys ( u_char *addr)
    WSADATA WinsockData;
    if (WSAStartup(MAKEWORD(2, 0), &WinsockData) != 0) {
        fprintf(stderr, "This program requires Winsock 2.x!\n");
-       return;
+       return -1;
    }
 
    HINSTANCE m_hInst;
@@ -413,7 +413,7 @@ long GetMacAddrSys ( u_char *addr)
    m_hInst = LoadLibrary("inetmib1.dll");
    if (m_hInst < (HINSTANCE) HINSTANCE_ERROR) {
        m_hInst = NULL;
-       return;
+       return -1;
    }
    m_Init =
        (pSnmpExtensionInit) GetProcAddress(m_hInst, "SnmpExtensionInit");
@@ -439,8 +439,8 @@ long GetMacAddrSys ( u_char *addr)
    ret =
        m_Query(ASN_RFC1157_GETNEXTREQUEST, &varBindList, &errorStatus,
                &errorIndex);
-//   printf("# of adapters in this system : %i\n",
-//          varBind[0].value.asnValue.number); varBindList.len = 2;
+   printf("# of adapters in this system : %i\n",
+          varBind[0].value.asnValue.number); varBindList.len = 2;
 
    /* Copy in the OID of ifType, the type of interface */
    SNMP_oidcpy(&varBind[0].name, &MIB_ifEntryType);
@@ -464,7 +464,7 @@ long GetMacAddrSys ( u_char *addr)
                             MIB_ifEntryType.idLength); if (!ret) {
            j++;
            dtmp = varBind[0].value.asnValue.number;
-           //printf("Interface #%i type : %i\n", j, dtmp);
+           printf("Interface #%i type : %i\n", j, dtmp);
 
            /* Type 6 describes ethernet interfaces */
            if (dtmp == 6) {
@@ -488,7 +488,7 @@ long GetMacAddrSys ( u_char *addr)
                            0x00)) {
 
                        /* Ignore all dial-up networking adapters */
-                       //printf("Interface #%i is a DUN adapter\n", j);
+                       printf("Interface #%i is a DUN adapter\n", j);
                        continue;
                    }
                    if (
@@ -507,17 +507,18 @@ long GetMacAddrSys ( u_char *addr)
 
                        /* Ignore NULL addresses returned by other network
                           interfaces */
-                       //printf("Interface #%i is a NULL address\n", j);
+                       printf("Interface #%i is a NULL address\n", j);
                        continue;
                    }
-                   sprintf(addr, "%02x%02x%02x%02x%02x%02x",
-                           varBind[1].value.asnValue.address.stream[0],
-                           varBind[1].value.asnValue.address.stream[1],
-                           varBind[1].value.asnValue.address.stream[2],
-                           varBind[1].value.asnValue.address.stream[3],
-                           varBind[1].value.asnValue.address.stream[4],
-                           varBind[1].value.asnValue.address.stream[5]);
-                   //printf("MAC Address of interface #%i: %s\n", j, TempEthernet);
+                   //sprintf((char*)addr, "%02x%02x%02x%02x%02x%02x",
+                   //        varBind[1].value.asnValue.address.stream[0],
+                   //        varBind[1].value.asnValue.address.stream[1],
+                   //        varBind[1].value.asnValue.address.stream[2],
+                   //        varBind[1].value.asnValue.address.stream[3],
+                   //        varBind[1].value.asnValue.address.stream[4],
+                   //        varBind[1].value.asnValue.address.stream[5]);
+                   memcpy( addr, varBind[1].value.asnValue.address.stream, 6);
+                   //printf("MAC Address of interface #%i: %s\n", j, addr);
               }
            }
        }
@@ -702,7 +703,7 @@ std::string Util::GetIPAddress()
   if( r == 0 )
   {
     // Get host adresses
-    struct hostent * pHost = gethostbyname(szHostName);
+    struct hostent *pHost = gethostbyname(szHostName);
 
     for( int i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
     {
@@ -732,7 +733,7 @@ std::string Util::GetIPAddress()
  *        each time a DICOM image is create it should have 
  *        a unique identifier (URI)
  */
-std::string Util::CreateUniqueUID(const std::stringroot)
+std::string Util::CreateUniqueUID(const std::string &root)
 {
   // The code works as follow:
   // echo "gdcm" | od -b
@@ -758,12 +759,12 @@ std::string Util::CreateUniqueUID(const std::string& root)
 }
 
 template <class T>
-std::ostream& binary_write(std::ostream& os, const T& val)
+std::ostream &binary_write(std::ostream &os, const T &val)
 {
     return os.write(reinterpret_cast<const char*>(&val), sizeof val);
 }
 
-std::ostream& binary_write(std::ostream& os, const uint16_t& val)
+std::ostream &binary_write(std::ostream &os, const uint16_t &val)
 {
 #ifdef GDCM_WORDS_BIGENDIAN
     uint16_t swap;
@@ -774,7 +775,7 @@ std::ostream& binary_write(std::ostream& os, const uint16_t& val)
 #endif //GDCM_WORDS_BIGENDIAN
 }
 
-std::ostream& binary_write(std::ostream& os, const uint32_t& val)
+std::ostream &binary_write(std::ostream &os, const uint32_t &val)
 {
 #ifdef GDCM_WORDS_BIGENDIAN
     uint32_t swap;
@@ -786,12 +787,12 @@ std::ostream& binary_write(std::ostream& os, const uint32_t& val)
 #endif //GDCM_WORDS_BIGENDIAN
 }
 
-std::ostream& binary_write(std::ostream& os, const char* val)
+std::ostream &binary_write(std::ostream &os, const char *val)
 {
     return os.write(val, strlen(val));
 }
 
-std::ostream& binary_write(std::ostream& os, std::string const & val)
+std::ostream &binary_write(std::ostream &os, std::string const &val)
 {
     return os.write(val.c_str(), val.size());
 }