Program: gdcm
Module: $RCSfile: gdcmUtil.cxx,v $
Language: C++
- Date: $Date: 2005/01/06 19:39:24 $
- Version: $Revision: 1.76 $
+ 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
#ifdef _WIN32
#include <snmp.h>
#include <conio.h>
-#include <stdio.h>
typedef BOOL(WINAPI * pSnmpExtensionInit) (
IN DWORD dwTimeZeroReference,
OUT HANDLE * hPollForTrapEvent,
printf("Interface #%i is a NULL address\n", j);
continue;
}
- 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]);
- 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);
}
}
}
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());
}