Program: gdcm
Module: $RCSfile: gdcmUtil.cxx,v $
Language: C++
- Date: $Date: 2005/01/06 18:53:02 $
- Version: $Revision: 1.73 $
+ 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
#include "gdcmUtil.h"
#include "gdcmDebug.h"
+#include <iostream>
// For GetCurrentDate, GetCurrentTime
#include <time.h>
* buf.str();
*/
-std::string Util::Format(const char* format, ...)
+std::string Util::Format(const char *format, ...)
{
char buffer[2048];
va_list args;
* \ingroup Globals
* \brief Because not available in C++ (?)
*/
-void Util::Tokenize (const std::string& str,
- 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);
* Counts the number of occurences of a substring within a string
*/
-int Util::CountSubstring (const std::string& str,
- const std::string& subStr)
+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
* 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;
* \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 = '\\';
* \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("/");
* \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;
* that needed to be escaped with an extra backslash for doxygen) \\0
* as you want.
*/
-std::string Util::DicomString(const char* s, 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;
}
* except it doesn't take a lenght.
* It only pad with a null character if length is odd
*/
-std::string Util::DicomString(const char* s)
+std::string Util::DicomString(const char *s)
{
size_t l = strlen(s);
if( l%2 )
l++;
}
std::string r(s, s+l);
- assert( !(r.size() % 2) );
+ gdcmAssertMacro( !(r.size() % 2) );
return r;
}
* - We allow padding of even lenght string by either a null
* character of a space
*/
-bool Util::DicomStringEqual(const std::string& s1, 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
#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,
typedef BOOL(WINAPI * pSnmpExtensionInitEx) (
OUT AsnObjectIdentifier * supportedView);
+#else
+#include <strings.h> //for bzero on unix
#endif //_WIN32
#ifdef __linux__
WSADATA WinsockData;
if (WSAStartup(MAKEWORD(2, 0), &WinsockData) != 0) {
fprintf(stderr, "This program requires Winsock 2.x!\n");
- return;
+ return -1;
}
HINSTANCE m_hInst;
m_hInst = LoadLibrary("inetmib1.dll");
if (m_hInst < (HINSTANCE) HINSTANCE_ERROR) {
m_hInst = NULL;
- return;
+ return -1;
}
m_Init =
(pSnmpExtensionInit) GetProcAddress(m_hInst, "SnmpExtensionInit");
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);
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) {
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 (
/* 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);
}
}
}
return -1;
}
-//std::string Util::GetMACAddress()
-//{
-// // This is a rip from: http://cplus.kompf.de/macaddr.html for Linux, HPUX and AIX
-// // and http://tangentsoft.net/wskfaq/examples/src/snmpmac.cpp for windows version
-// long stat;
-// int i;
-// u_char addr[6];
-//
-// stat = mac_addr_sys( addr);
-// if (0 == stat)
-// {
-// printf( "MAC address = ");
-// for (i=0; i<6; ++i) {
-// printf("%2.2x", addr[i]);
-// }
-// printf( "\n");
-// }
-// else {
-// fprintf( stderr, "can't get MAC address\n");
-// exit( 1);
-// }
-//}
+std::string Util::GetMACAddress()
+{
+ // This is a rip from: http://cplus.kompf.de/macaddr.html for Linux, HPUX and AIX
+ // and http://tangentsoft.net/wskfaq/examples/src/snmpmac.cpp for windows version
+ long stat;
+ u_char addr[6];
+ std::string macaddr;
+
+ stat = GetMacAddrSys( addr);
+ if (0 == stat)
+ {
+ //printf( "MAC address = ");
+ for (int i=0; i<6; ++i)
+ {
+ //printf("%2.2x", addr[i]);
+ macaddr += Format("%2.2x", addr[i]);
+ }
+ // printf( "\n");
+ return macaddr;
+ }
+ else
+ {
+ //printf( "No MAC address !\n" );
+ return "";
+ }
+}
/**
* \ingroup Util
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++ )
{
* each time a DICOM image is create it should have
* a unique identifier (URI)
*/
-std::string Util::CreateUniqueUID(const std::string& root)
+std::string Util::CreateUniqueUID(const std::string &root)
{
// The code works as follow:
// echo "gdcm" | od -b
}
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;
#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;
#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());
}