Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

gdcm::Util Class Reference

Here are some utility functions, belonging to the gdcm::Util class, dealing with strings, file names... that can be called from anywhere by whomsoever they can help. More...

#include <gdcmUtil.h>

List of all members.

Public Member Functions

void hifpswap (double *a, double *b)
void hNoifpswap (double *a, double *b)
void hfpswap (double *a, double *b)

Static Public Member Functions

static std::string Format (const char *format,...)
 Provide a better 'c++' approach for sprintf For example c code is: char result[2048]; // hope 2048 is enough sprintf(result, "%04x|%04x", group , elem);.
static void Tokenize (const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
 Because not available in C++ (?).
static int CountSubstring (const std::string &str, const std::string &subStr)
 Because not available in C++ (?) Counts the number of occurences of a substring within a string.
static std::string CreateCleanString (std::string const &s)
 Weed out a string from the non-printable characters (in order to avoid corrupting the terminal of invocation when printing).
static std::string CreateCleanString (uint8_t *s, int l)
 Weed out a string from the non-printable characters (in order to avoid corrupting the terminal of invocation when printing).
static bool IsCleanString (std::string const &s)
 Checks whether a 'string' is printable or not (in order to avoid corrupting the terminal of invocation when printing).
static bool IsCleanArea (uint8_t *s, int l)
 Checks whether an 'area' is printable or not (in order to avoid corrupting the terminal of invocation when printing).
static std::string NormalizePath (std::string const &name)
 Add a SEPARATOR to the end of the name if necessary.
static std::string GetPath (std::string const &fullName)
 Get the (directory) path from a full path file name.
static std::string GetName (std::string const &fullName)
 Get the (last) name of a full path file name.
static std::string GetCurrentDate ()
 Get the current date of the system in a dicom string.
static std::string GetCurrentTime ()
 Get the current time of the system in a dicom string.
static std::string GetCurrentDateTime ()
 Get both the date and time at the same time to avoid problem around midnight where the two calls could be before and after midnight.
static std::string GetVersion ()
 Provides a simple static GetVersion() function.
static unsigned int GetCurrentThreadID ()
static unsigned int GetCurrentProcessID ()
static bool IsCurrentProcessorBigEndian ()
 tells us whether the processor we are working with is BigEndian or not
static std::string DicomString (const char *s, size_t l)
 Create a /DICOM/ string: It should a of even length (no odd length ever) It can contain as many (if you are reading this from your editor the following character is backslash followed by zero that needed to be escaped with an extra backslash for doxygen) \0 as you want.
static std::string DicomString (const char *s)
 Create a /DICOM/ string: It should a of even length (no odd length ever) It can contain as many (if you are reading this from your editor the following character is backslash followed by zero that needed to be escaped with an extra backslash for doxygen) \0 as you want. This function is similar to DicomString(const char*), except it doesn't take a length. It only pad with a null character if length is odd.
static bool DicomStringEqual (const std::string &s1, const char *s2)
 Safely check the equality of two Dicom String:
  • Both strings should be of even length
  • We allow padding of even length string by either a null character of a space.

static bool CompareDicomString (const std::string &s1, const char *s2, int op)
 Safely compare two Dicom String:
  • Both strings should be of even length
  • We allow padding of even length string by either a null character of a space.

static std::string GetMACAddress ()
 Encode the mac address on a fixed length string of 15 characters. we save space this way.
static std::string CreateUniqueUID (const std::string &root="")
 Creates a new UID. As stipulated in the DICOM ref each time a DICOM image is created it should have a unique identifier (URI).
static void SetRootUID (const std::string &root="")
static const std::string & GetRootUID ()
static const uint8_t * GetFileMetaInformationVersion ()
static void SetFileMetaInformationVersion (uint16_t fmiv)
static void sthifpswap (double *a, double *b)
static void sthNoifpswap (double *a, double *b)

Static Private Member Functions

static std::string GetIPAddress ()
 Return the IP adress of the machine writting the DICOM image.

Static Private Attributes

static std::string RootUID = GDCM_UID
static const std::string GDCM_UID = "1.2.826.0.1.3680043.2.1143"
static uint8_t * FileMetaInformationVersion = (uint8_t *)&FMIV
static const uint16_t FMIV = 0x0100
static std::string GDCM_MAC_ADRESS = GetMACAddress()


Detailed Description

Here are some utility functions, belonging to the gdcm::Util class, dealing with strings, file names... that can be called from anywhere by whomsoever they can help.

Definition at line 36 of file gdcmUtil.h.


Member Function Documentation

bool gdcm::Util::CompareDicomString const std::string &  s1,
const char *  s2,
int  op
[static]
 

Safely compare two Dicom String:

  • Both strings should be of even length
  • We allow padding of even length string by either a null character of a space.

Definition at line 521 of file gdcmUtil.cxx.

References DicomString(), gdcm::GDCM_DIFFERENT, gdcm::GDCM_EQUAL, gdcm::GDCM_GREATER, gdcm::GDCM_GREATEROREQUAL, gdcm::GDCM_LESS, gdcm::GDCM_LESSOREQUAL, and gdcmDebugMacro.

Referenced by gdcm::SerieHelper::AddFileName().

00522 {
00523   // s2 is the string from the DICOM reference e.g. : 'MONOCHROME1'
00524   std::string s1_even = s1; //Never change input parameter
00525   std::string s2_even = DicomString( s2 );
00526   if ( s1_even[s1_even.size()-1] == ' ' )
00527   {
00528     s1_even[s1_even.size()-1] = '\0'; //replace space character by null
00529   }
00530   switch (op)
00531   {
00532      case GDCM_EQUAL :
00533         return s1_even == s2_even;
00534      case GDCM_DIFFERENT :  
00535         return s1_even != s2_even;
00536      case GDCM_GREATER :  
00537         return s1_even >  s2_even;  
00538      case GDCM_GREATEROREQUAL :  
00539         return s1_even >= s2_even;
00540      case GDCM_LESS :
00541         return s1_even <  s2_even;
00542      case GDCM_LESSOREQUAL :
00543         return s1_even <= s2_even;
00544      default :
00545         gdcmDebugMacro(" Wrong operator : " << op);
00546         return false;
00547   }
00548 }

int gdcm::Util::CountSubstring const std::string &  str,
const std::string &  subStr
[static]
 

Because not available in C++ (?) Counts the number of occurences of a substring within a string.

Parameters:
str string to check
subStr substring to count

Definition at line 170 of file gdcmUtil.cxx.

Referenced by gdcm::CheckVM().

00172 {
00173    int count = 0;                 // counts how many times it appears
00174    std::string::size_type x = 0;  // The index position in the string
00175 
00176    do
00177    {
00178       x = str.find(subStr,x);     // Find the substring
00179       if (x != std::string::npos) // If present
00180       {
00181          count++;                 // increase the count
00182          x += subStr.length();    // Skip this word
00183       }
00184    }
00185    while (x != std::string::npos);// Carry on until not present
00186 
00187    return count;
00188 }

std::string gdcm::Util::CreateCleanString uint8_t *  s,
int  l
[static]
 

Weed out a string from the non-printable characters (in order to avoid corrupting the terminal of invocation when printing).

Parameters:
s area to process (uint8_t is just for prototyping. feel free to cast)
l area length to check

Definition at line 261 of file gdcmUtil.cxx.

00262 {
00263    std::string str;
00264 
00265    for( int i=0; i<l; i++)
00266    {
00267       if (!isprint((unsigned char)s[i]) )
00268       {
00269          str = str + '.';
00270       }
00271    else
00272       {
00273          str = str + (char )s[i];
00274       }
00275    }
00276 
00277    return str;
00278 }

std::string gdcm::Util::CreateCleanString std::string const &  s  )  [static]
 

Weed out a string from the non-printable characters (in order to avoid corrupting the terminal of invocation when printing).

Parameters:
s string to check (uint8_t is just for prototyping. feel free to cast)

Definition at line 229 of file gdcmUtil.cxx.

Referenced by gdcm::DataEntry::Print().

00230 {
00231    std::string str = s;
00232 
00233    for(unsigned int i=0; i<str.size(); i++)
00234    {
00235       if (!isprint((unsigned char)str[i]) )
00236       {
00237          str[i] = '.';
00238       }
00239    }
00240 
00241    if (str.size() > 0 )
00242    {
00243       if (!isprint((unsigned char)s[str.size()-1]) )
00244       {
00245          if (s[str.size()-1] == 0 )
00246          {
00247             str[str.size()-1] = ' ';
00248          }
00249       }
00250    }
00251 
00252    return str;
00253 }

std::string gdcm::Util::CreateUniqueUID const std::string &  root = ""  )  [static]
 

Creates a new UID. As stipulated in the DICOM ref each time a DICOM image is created it should have a unique identifier (URI).

Parameters:
root is the DICOM prefix assigned by IOS group

Definition at line 900 of file gdcmUtil.cxx.

References GDCM_MAC_ADRESS, gdcmStaticErrorMacro, GetCurrentDateTime(), and RootUID.

Referenced by gdcm::FileHelper::CheckMandatoryElements(), and gdcm::DicomDirMeta::WriteContent().

00901 {
00902    std::string prefix;
00903    std::string append;
00904    if ( root.empty() )
00905    {
00906       // gdcm UID prefix, as supplied by http://www.medicalconnections.co.uk
00907       prefix = RootUID; 
00908    }
00909    else
00910    {
00911       prefix = root;
00912    }
00913 
00914    // A root was specified use it to forge our new UID:
00915    append += ".";
00916    //append += Util::GetMACAddress(); // to save CPU time
00917    append += Util::GDCM_MAC_ADRESS;
00918    append += ".";
00919    append += Util::GetCurrentDateTime();
00920    append += ".";
00921    //Also add a mini random number just in case:
00922    char tmp[10];
00923    int r = (int) (100.0*rand()/RAND_MAX);
00924    // Don't use Util::Format to accelerate the execution
00925    sprintf(tmp,"%02d", r);
00926    append += tmp;
00927 
00928    // If append is too long we need to rehash it
00929    if ( (prefix + append).size() > 64 )
00930    {
00931       gdcmStaticErrorMacro( "Size of UID is too long." );
00932       // we need a hash function to truncate this number
00933       // if only md5 was cross plateform
00934       // MD5(append);
00935    }
00936 
00937    return prefix + append;
00938 }

std::string gdcm::Util::DicomString const char *  s  )  [static]
 

Create a /DICOM/ string: It should a of even length (no odd length ever) It can contain as many (if you are reading this from your editor the following character is backslash followed by zero that needed to be escaped with an extra backslash for doxygen) \0 as you want. This function is similar to DicomString(const char*), except it doesn't take a length. It only pad with a null character if length is odd.

Definition at line 485 of file gdcmUtil.cxx.

References gdcmAssertMacro.

00486 {
00487    size_t l = strlen(s);
00488    if ( l%2 )
00489    {
00490       l++;
00491    }
00492    std::string r(s, s+l);
00493    gdcmAssertMacro( !(r.size() % 2) );
00494    return r;
00495 }

std::string gdcm::Util::DicomString const char *  s,
size_t  l
[static]
 

Create a /DICOM/ string: It should a of even length (no odd length ever) It can contain as many (if you are reading this from your editor the following character is backslash followed by zero that needed to be escaped with an extra backslash for doxygen) \0 as you want.

Definition at line 467 of file gdcmUtil.cxx.

References gdcmAssertMacro.

Referenced by CompareDicomString(), DicomStringEqual(), gdcm::FileHelper::SetWriteFileTypeToExplicitVR(), gdcm::FileHelper::SetWriteFileTypeToImplicitVR(), gdcm::FileHelper::SetWriteFileTypeToJPEG(), and gdcm::File::Write().

00468 {
00469    std::string r(s, s+l);
00470    gdcmAssertMacro( !(r.size() % 2) ); // == basically 'l' is even
00471    return r;
00472 }

bool gdcm::Util::DicomStringEqual const std::string &  s1,
const char *  s2
[static]
 

Safely check the equality of two Dicom String:

  • Both strings should be of even length
  • We allow padding of even length string by either a null character of a space.

Definition at line 503 of file gdcmUtil.cxx.

References DicomString().

Referenced by gdcm::SerieHelper::AddGdcmFile(), gdcm::File::GetNumberOfScalarComponents(), gdcm::File::IsMonochrome(), and gdcm::File::IsMonochrome1().

00504 {
00505   // s2 is the string from the DICOM reference e.g. : 'MONOCHROME1'
00506   std::string s1_even = s1; //Never change input parameter
00507   std::string s2_even = DicomString( s2 );
00508   if ( s1_even[s1_even.size()-1] == ' ' )
00509   {
00510     s1_even[s1_even.size()-1] = '\0'; //replace space character by null
00511   }
00512   return s1_even == s2_even;
00513 }

std::string gdcm::Util::Format const char *  format,
  ...
[static]
 

Provide a better 'c++' approach for sprintf For example c code is: char result[2048]; // hope 2048 is enough sprintf(result, "%04x|%04x", group , elem);.

c++ code is std::ostringstream buf; buf << std::right << std::setw(4) << std::setfill('0') << std::hex << group << "|" << std::right << std::setw(4) << std::setfill('0') << std::hex << elem; buf.str();

gdcm style code is string result; result = gdcm::Util::Format("%04x|%04x", group , elem);

Definition at line 129 of file gdcmUtil.cxx.

Referenced by GetIPAddress(), gdcm::Document::OpenFile(), gdcm::DocEntry::Print(), gdcm::Document::ReadNextDocEntry(), and gdcm::File::Write().

00130 {
00131    char buffer[2048]; // hope 2048 is enough
00132    va_list args;
00133    va_start(args, format);
00134    vsprintf(buffer, format, args);  //might be a security flaw
00135    va_end(args); // Each invocation of va_start should be matched 
00136                  // by a corresponding invocation of va_end
00137                  // args is then 'undefined'
00138    return buffer;
00139 }

std::string gdcm::Util::GetCurrentDate  )  [static]
 

Get the current date of the system in a dicom string.

Definition at line 358 of file gdcmUtil.cxx.

Referenced by gdcm::FileHelper::CheckMandatoryElements().

00359 {
00360     char tmp[512];
00361     time_t tloc;
00362     time (&tloc);    
00363     strftime(tmp,512,"%Y%m%d", localtime(&tloc) );
00364     return tmp;
00365 }

std::string gdcm::Util::GetCurrentDateTime  )  [static]
 

Get both the date and time at the same time to avoid problem around midnight where the two calls could be before and after midnight.

Definition at line 383 of file gdcmUtil.cxx.

Referenced by CreateUniqueUID().

00384 {
00385    char tmp[40];
00386    long milliseconds;
00387    time_t timep;
00388   
00389    // We need implementation specific functions to obtain millisecond precision
00390 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
00391    struct timeb tb;
00392    ::ftime(&tb);
00393    timep = tb.time;
00394    milliseconds = tb.millitm;
00395 #else
00396    struct timeval tv;
00397    gettimeofday (&tv, NULL);
00398    timep = tv.tv_sec;
00399    // Compute milliseconds from microseconds.
00400    milliseconds = tv.tv_usec / 1000;
00401 #endif
00402    // Obtain the time of day, and convert it to a tm struct.
00403    struct tm *ptm = localtime (&timep);
00404    // Format the date and time, down to a single second.
00405    strftime (tmp, sizeof (tmp), "%Y%m%d%H%M%S", ptm);
00406 
00407    // Add milliseconds
00408    // Don't use Util::Format to accelerate execution of code
00409    char tmpAll[80];
00410    sprintf(tmpAll,"%s%03ld",tmp,milliseconds);
00411 
00412    return tmpAll;
00413 }

unsigned int gdcm::Util::GetCurrentProcessID  )  [static]
 

Definition at line 436 of file gdcmUtil.cxx.

00437 {
00438 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
00439   // NOTE: There is also a _getpid()...
00440   return (unsigned int)GetCurrentProcessId();
00441 #else
00442   // get process identification, POSIX
00443   return (unsigned int)getpid();
00444 #endif
00445 }

unsigned int gdcm::Util::GetCurrentThreadID  )  [static]
 

Definition at line 415 of file gdcmUtil.cxx.

00416 {
00417 // FIXME the implementation is far from complete
00418 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
00419   return (unsigned int)GetCurrentThreadId();
00420 #else
00421 #ifdef __linux__
00422    return 0;
00423    // Doesn't work on fedora, but is in the man page...
00424    //return (unsigned int)gettid();
00425 #else
00426 #ifdef __sun
00427    return (unsigned int)thr_self();
00428 #else
00429    //default implementation
00430    return 0;
00431 #endif // __sun
00432 #endif // __linux__
00433 #endif // Win32
00434 }

std::string gdcm::Util::GetCurrentTime  )  [static]
 

Get the current time of the system in a dicom string.

Definition at line 370 of file gdcmUtil.cxx.

Referenced by gdcm::FileHelper::CheckMandatoryElements().

00371 {
00372     char tmp[512];
00373     time_t tloc;
00374     time (&tloc);
00375     strftime(tmp,512,"%H%M%S", localtime(&tloc) );
00376     return tmp;  
00377 }

static const uint8_t* gdcm::Util::GetFileMetaInformationVersion  )  [inline, static]
 

Definition at line 74 of file gdcmUtil.h.

Referenced by gdcm::FileHelper::CheckMandatoryElements().

00075                      { return FileMetaInformationVersion;}

std::string gdcm::Util::GetIPAddress  )  [static, private]
 

Return the IP adress of the machine writting the DICOM image.

Definition at line 1106 of file gdcmUtil.cxx.

References Format(), and HOST_NAME_MAX.

01107 {
01108    // This is a rip from 
01109    // http://www.codeguru.com/Cpp/I-N/internet/network/article.php/c3445/
01110 #ifndef HOST_NAME_MAX
01111    // SUSv2 guarantees that `Host names are limited to 255 bytes'.
01112    // POSIX 1003.1-2001 guarantees that `Host names (not including the
01113    // terminating NUL) are limited to HOST_NAME_MAX bytes'.
01114 #define HOST_NAME_MAX 255
01115    // In this case we should maybe check the string was not truncated.
01116    // But I don't known how to check that...
01117 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
01118    // with WinSock DLL we need to initialize the WinSock before using gethostname
01119    WORD wVersionRequested = MAKEWORD(1,0);
01120    WSADATA WSAData;
01121    int err = WSAStartup(wVersionRequested,&WSAData);
01122    if (err != 0)
01123    {
01124       // Tell the user that we could not find a usable
01125       // WinSock DLL.
01126       WSACleanup();
01127       return "127.0.0.1";
01128    }
01129 #endif
01130   
01131 #endif //HOST_NAME_MAX
01132 
01133    std::string str;
01134    char szHostName[HOST_NAME_MAX+1];
01135    int r = gethostname(szHostName, HOST_NAME_MAX);
01136  
01137    if ( r == 0 )
01138    {
01139       // Get host adresses
01140       struct hostent *pHost = gethostbyname(szHostName);
01141  
01142       for( int i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
01143       {
01144          for( int j = 0; j<pHost->h_length; j++ )
01145          {
01146             if ( j > 0 ) str += ".";
01147  
01148             str += Util::Format("%u", 
01149                 (unsigned int)((unsigned char*)pHost->h_addr_list[i])[j]);
01150          }
01151          // str now contains one local IP address 
01152  
01153 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
01154    WSACleanup();
01155 #endif
01156 
01157       }
01158    }
01159    // If an error occur r == -1
01160    // Most of the time it will return 127.0.0.1...
01161    return str;
01162 }

std::string gdcm::Util::GetMACAddress  )  [static]
 

Encode the mac address on a fixed length string of 15 characters. we save space this way.

Definition at line 859 of file gdcmUtil.cxx.

References gdcmStaticWarningMacro, gdcm::getlastdigit(), and gdcm::GetMacAddrSys().

00860 {
00861    // This code is the result of a long internet search to find something
00862    // as compact as possible (not OS independant). We only have to separate
00863    // 3 OS: Win32, SunOS and 'real' POSIX
00864    // http://groups-beta.google.com/group/comp.unix.solaris/msg/ad36929d783d63be
00865    // http://bdn.borland.com/article/0,1410,26040,00.html
00866    unsigned char addr[6];
00867 
00868    int stat = GetMacAddrSys(addr);
00869    if (stat == 0)
00870    {
00871       // We need to convert a 6 digit number from base 256 to base 10, using integer
00872       // would requires a 48bits one. To avoid this we have to reimplement the div + modulo 
00873       // with string only
00874       bool zero = false;
00875       int res;
00876       std::string sres;
00877       while(!zero)
00878       {
00879          res = getlastdigit(addr);
00880          sres.insert(sres.begin(), '0' + res);
00881          zero = (addr[0] == 0) && (addr[1] == 0) && (addr[2] == 0) 
00882              && (addr[3] == 0) && (addr[4] == 0) && (addr[5] == 0);
00883       }
00884 
00885       return sres;
00886    }
00887    else
00888    {
00889       gdcmStaticWarningMacro("Problem in finding the MAC Address");
00890       return "";
00891    }
00892 }

std::string gdcm::Util::GetName std::string const &  fullName  )  [static]
 

Get the (last) name of a full path file name.

Parameters:
fullName file/directory name to extract end name from

Definition at line 334 of file gdcmUtil.cxx.

References gdcm::GDCM_FILESEPARATOR.

Referenced by gdcm::DicomDir::SetElement().

00335 {   
00336   std::string filename = fullName;
00337 /*
00338   std::string::size_type slash_pos = filename.rfind("/");
00339   std::string::size_type backslash_pos = filename.rfind("\\");
00340   // At least with my gcc4.0.1, unfound char results in pos =4294967295 ...
00341   //slash_pos = slash_pos > backslash_pos ? slash_pos : backslash_pos;  
00342   slash_pos = slash_pos < backslash_pos ? slash_pos : backslash_pos;
00343 */
00344   std::string::size_type slash_pos = filename.rfind(GDCM_FILESEPARATOR);
00345   if (slash_pos != std::string::npos )
00346     {
00347     return filename.substr(slash_pos + 1);
00348     }
00349   else
00350     {
00351     return filename;
00352     }
00353 } 

std::string gdcm::Util::GetPath std::string const &  fullName  )  [static]
 

Get the (directory) path from a full path file name.

Parameters:
fullName file/directory name to extract Path from

Definition at line 309 of file gdcmUtil.cxx.

References gdcm::GDCM_FILESEPARATOR.

00310 {
00311    std::string res = fullName;
00312 /*
00313    
00314    int pos1 = res.rfind("/");
00315    int pos2 = res.rfind("\\");
00316    if ( pos1 > pos2 )
00317    {
00318       res.resize(pos1);
00319    }
00320    else
00321    {
00322       res.resize(pos2);
00323    }
00324 */
00325    int pos = res.rfind(GDCM_FILESEPARATOR);
00326    res.resize(pos);
00327    return res;
00328 }

const std::string & gdcm::Util::GetRootUID  )  [static]
 

Definition at line 948 of file gdcmUtil.cxx.

References RootUID.

00949 {
00950    return RootUID;
00951 }

static std::string gdcm::Util::GetVersion  )  [inline, static]
 

Provides a simple static GetVersion() function.

Definition at line 57 of file gdcmUtil.h.

Referenced by gdcm::FileHelper::CheckMandatoryElements().

00058                       { return GDCM_VERSION;}

void gdcm::Util::hfpswap double *  a,
double *  b
 

Definition at line 1164 of file gdcmUtil.cxx.

01165 {
01166    double tmp;
01167    tmp=*a;
01168    *a=*b;
01169    *b=tmp;
01170 }

void gdcm::Util::hifpswap double *  a,
double *  b
[inline]
 

Definition at line 85 of file gdcmUtil.h.

00086    {
00087       double tmp;
00088       tmp = *a;
00089       *a = *b;
00090       *b = tmp;
00091    }

void gdcm::Util::hNoifpswap double *  a,
double *  b
[inline]
 

Definition at line 92 of file gdcmUtil.h.

00093    {
00094       double tmp;
00095       tmp = *a;
00096       *a = *b;
00097       *b = tmp;
00098    }    

bool gdcm::Util::IsCleanArea uint8_t *  s,
int  l
[static]
 

Checks whether an 'area' is printable or not (in order to avoid corrupting the terminal of invocation when printing).

Parameters:
s area to check (uint8_t is just for prototyping. feel free to cast)
l area length to check

Definition at line 213 of file gdcmUtil.cxx.

Referenced by gdcm::DataEntry::Print().

00214 {
00215    for( int i=0; i<l; i++)
00216    {
00217       if (!isprint((unsigned char)s[i]) )
00218       {
00219          return false;
00220       }
00221    }
00222    return true;   
00223 }

bool gdcm::Util::IsCleanString std::string const &  s  )  [static]
 

Checks whether a 'string' is printable or not (in order to avoid corrupting the terminal of invocation when printing).

Parameters:
s string to check

Definition at line 195 of file gdcmUtil.cxx.

00196 {
00197    for(unsigned int i=0; i<s.size(); i++)
00198    {
00199       if (!isprint((unsigned char)s[i]) )
00200       {
00201          return false;
00202       }
00203    }
00204    return true;   
00205 }

bool gdcm::Util::IsCurrentProcessorBigEndian  )  [static]
 

tells us whether the processor we are working with is BigEndian or not

Definition at line 450 of file gdcmUtil.cxx.

Referenced by gdcm::Document::CheckSwap(), and gdcm::RLEFramesInfo::ConvertRLE16BitsFromRLE8Bits().

00451 {
00452 #if defined(GDCM_WORDS_BIGENDIAN)
00453    return true;
00454 #else
00455    return false;
00456 #endif
00457 }

std::string gdcm::Util::NormalizePath std::string const &  pathname  )  [static]
 

Add a SEPARATOR to the end of the name if necessary.

Parameters:
pathname file/directory name to normalize

Definition at line 283 of file gdcmUtil.cxx.

References gdcm::GDCM_FILESEPARATOR.

Referenced by gdcm::DirList::Explore().

00284 {
00285 /*
00286    const char SEPARATOR_X      = '/';
00287    const char SEPARATOR_WIN    = '\\';
00288 #ifdef _WIN32
00289    const std::string SEPARATOR = "\\";
00290 #else
00291    const std::string SEPARATOR = "/";
00292 #endif
00293 */
00294    std::string name = pathname;
00295    int size = name.size();
00296 
00297 //   if ( name[size-1] != SEPARATOR_X && name[size-1] != SEPARATOR_WIN )
00298    if ( name[size-1] != GDCM_FILESEPARATOR )
00299    {
00300       name += GDCM_FILESEPARATOR;
00301    }
00302    return name;
00303 }

static void gdcm::Util::SetFileMetaInformationVersion uint16_t  fmiv  )  [inline, static]
 

Definition at line 76 of file gdcmUtil.h.

00077                      { FileMetaInformationVersion = (uint8_t *)&fmiv; }

void gdcm::Util::SetRootUID const std::string &  root = ""  )  [static]
 

Definition at line 940 of file gdcmUtil.cxx.

References GDCM_UID, and RootUID.

00941 {
00942    if ( root.empty() )
00943       RootUID = GDCM_UID;
00944    else
00945       RootUID = root;
00946 }

static void gdcm::Util::sthifpswap double *  a,
double *  b
[inline, static]
 

Definition at line 100 of file gdcmUtil.h.

00101    {
00102       double tmp;
00103       tmp = *a;
00104       *a = *b;
00105       *b = tmp;
00106    }

static void gdcm::Util::sthNoifpswap double *  a,
double *  b
[inline, static]
 

Definition at line 107 of file gdcmUtil.h.

00108    {
00109       double tmp;
00110       tmp = *a;
00111       *a = *b;
00112       *b = tmp;
00113    }    

void gdcm::Util::Tokenize const std::string &  str,
std::vector< std::string > &  tokens,
const std::string &  delimiters = " "
[static]
 

Because not available in C++ (?).

Parameters:
str string to check
tokens std::vector to receive the tokenized substrings
delimiters string containing the character delimitors

Definition at line 149 of file gdcmUtil.cxx.

Referenced by gdcm::File::GetLUTNbits(), and gdcm::DataEntry::SetString().

00152 {
00153    std::string::size_type lastPos = str.find_first_not_of(delimiters,0);
00154    std::string::size_type pos     = str.find_first_of    (delimiters,lastPos);
00155    while (std::string::npos != pos || std::string::npos != lastPos)
00156    {
00157       tokens.push_back(str.substr(lastPos, pos - lastPos));
00158       lastPos = str.find_first_not_of(delimiters, pos);
00159       pos     = str.find_first_of    (delimiters, lastPos);
00160    }
00161 }


Member Data Documentation

uint8_t * gdcm::Util::FileMetaInformationVersion = (uint8_t *)&FMIV [static, private]
 

Definition at line 120 of file gdcmUtil.h.

const uint16_t gdcm::Util::FMIV = 0x0100 [static, private]
 

Definition at line 121 of file gdcmUtil.h.

std::string gdcm::Util::GDCM_MAC_ADRESS = GetMACAddress() [static, private]
 

Definition at line 122 of file gdcmUtil.h.

Referenced by CreateUniqueUID().

const std::string gdcm::Util::GDCM_UID = "1.2.826.0.1.3680043.2.1143" [static, private]
 

Definition at line 119 of file gdcmUtil.h.

Referenced by SetRootUID().

std::string gdcm::Util::RootUID = GDCM_UID [static, private]
 

Definition at line 118 of file gdcmUtil.h.

Referenced by CreateUniqueUID(), GetRootUID(), and SetRootUID().


The documentation for this class was generated from the following files:
Generated on Fri Jan 20 10:14:38 2006 for gdcm by  doxygen 1.4.4