Program: gdcm
Module: $RCSfile: gdcmUtil.cxx,v $
Language: C++
- Date: $Date: 2005/01/28 09:37:29 $
- Version: $Revision: 1.126 $
+ Date: $Date: 2005/02/02 10:02:18 $
+ Version: $Revision: 1.129 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmUtil.h"
#include "gdcmDebug.h"
#include <iostream>
-#include <algorithm>
// For GetCurrentDate, GetCurrentTime
#include <time.h>
#include <stdio.h> //only included in implementation file
#if defined(_MSC_VER) || defined(__MINGW32__)
- #include <winsock.h> // for gethostname & gethostbyname
+ #include <winsock.h> // for gethostname and gethostbyname
#undef GetCurrentTime
#else
#ifndef __BORLANDC__
// For GetCurrentThreadID()
#ifdef __linux__
-#include <sys/types.h>
-#include <linux/unistd.h>
+ #include <sys/types.h>
+ #include <linux/unistd.h>
#endif
#ifdef __sun
-#include <thread.h>
+ #include <thread.h>
#endif
namespace gdcm
{
+//-------------------------------------------------------------------------
const std::string Util::GDCM_UID = "1.2.826.0.1.3680043.2.1143";
std::string Util::RootUID = GDCM_UID;
+//-------------------------------------------------------------------------
/**
* \brief Provide a better 'c++' approach for sprintf
* For example c code is:
* gdcm style code is
* Format("%04x|%04x", group , elem);
*/
-
std::string Util::Format(const char *format, ...)
{
char buffer[2048];
*/
void Util::Tokenize (const std::string &str,
std::vector<std::string> &tokens,
- const std::string& delimiters)
+ const std::string &delimiters)
{
std::string::size_type lastPos = str.find_first_not_of(delimiters,0);
std::string::size_type pos = str.find_first_of (delimiters,lastPos);
#endif
}
-
-
#ifdef _WIN32
-typedef BOOL(WINAPI * pSnmpExtensionInit) (
- IN DWORD dwTimeZeroReference,
- OUT HANDLE * hPollForTrapEvent,
- OUT AsnObjectIdentifier * supportedView);
-
-typedef BOOL(WINAPI * pSnmpExtensionTrap) (
- OUT AsnObjectIdentifier * enterprise,
- OUT AsnInteger * genericTrap,
- OUT AsnInteger * specificTrap,
- OUT AsnTimeticks * timeStamp,
- OUT RFC1157VarBindList * variableBindings);
-
-typedef BOOL(WINAPI * pSnmpExtensionQuery) (
- IN BYTE requestType,
- IN OUT RFC1157VarBindList * variableBindings,
- OUT AsnInteger * errorStatus,
- OUT AsnInteger * errorIndex);
-
-typedef BOOL(WINAPI * pSnmpExtensionInitEx) (
- OUT AsnObjectIdentifier * supportedView);
+ typedef BOOL(WINAPI * pSnmpExtensionInit) (
+ IN DWORD dwTimeZeroReference,
+ OUT HANDLE * hPollForTrapEvent,
+ OUT AsnObjectIdentifier * supportedView);
+
+ typedef BOOL(WINAPI * pSnmpExtensionTrap) (
+ OUT AsnObjectIdentifier * enterprise,
+ OUT AsnInteger * genericTrap,
+ OUT AsnInteger * specificTrap,
+ OUT AsnTimeticks * timeStamp,
+ OUT RFC1157VarBindList * variableBindings);
+
+ typedef BOOL(WINAPI * pSnmpExtensionQuery) (
+ IN BYTE requestType,
+ IN OUT RFC1157VarBindList * variableBindings,
+ OUT AsnInteger * errorStatus,
+ OUT AsnInteger * errorIndex);
+
+ typedef BOOL(WINAPI * pSnmpExtensionInitEx) (
+ OUT AsnObjectIdentifier * supportedView);
#endif //_WIN32
// We should investiage the use of SIZEOF_ADDR_IFREQ
//
#ifdef HAVE_SA_LEN
-#ifndef max
-#define max(a,b) ((a) > (b) ? (a) : (b))
-#endif
-#define ifreq_size(i) max(sizeof(struct ifreq),\
- sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
+ #ifndef max
+ #define max(a,b) ((a) > (b) ? (a) : (b))
+ #endif
+ #define ifreq_size(i) max(sizeof(struct ifreq),\
+ sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
#else
-#define ifreq_size(i) sizeof(struct ifreq)
+ #define ifreq_size(i) sizeof(struct ifreq)
#endif // HAVE_SA_LEN
if( (sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0 )
while(!zero)
{
res = getlastdigit(addr);
- sres += ('0' + res);
+ sres.insert(sres.begin(), '0' + res);
zero = (addr[0] == 0) && (addr[1] == 0) && (addr[2] == 0) && (addr[3] == 0) && (addr[4] == 0) && (addr[5] == 0);
}
- // Since we push back the proper number is reversed:
- std::reverse(sres.begin(),sres.end());
return sres;
}
// SUSv2 guarantees that `Host names are limited to 255 bytes'.
// POSIX 1003.1-2001 guarantees that `Host names (not including the
// terminating NUL) are limited to HOST_NAME_MAX bytes'.
-# define HOST_NAME_MAX 255
+#define HOST_NAME_MAX 255
// In this case we should maybe check the string was not truncated.
// But I don't known how to check that...
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
// get process identification, POSIX
return (unsigned int)getpid();
#endif
-
}
/**
return RootUID;
}
+//-------------------------------------------------------------------------
/**
* \brief
* @param os ostream to write to
return os.write(val.c_str(), val.size());
}
+//-------------------------------------------------------------------------
} // end namespace gdcm